| 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 | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 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 | |
| 53 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 55 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 56 | #include "lpfc_hw.h" |
| 57 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 58 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 59 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 62 | #include "lpfc_scsi.h" |
| 63 | #include "lpfc_nvme.h" |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 64 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | #include "lpfc_logmsg.h" |
| 66 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 67 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 69 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 70 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 71 | static enum cpuhp_state lpfc_cpuhp_state; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 72 | /* Used when mapping IRQ vectors in a driver centric manner */ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 73 | static uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 74 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 75 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 76 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 77 | static void lpfc_cpuhp_add(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 79 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 80 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 81 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 82 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 83 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 84 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 85 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 86 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 87 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 88 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 89 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 90 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 91 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 92 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 93 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 94 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 95 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 96 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 97 | 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] | 98 | static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | |
| 100 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 101 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 103 | #define LPFC_NVMET_BUF_POST 254 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 106 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 107 | * @phba: pointer to lpfc hba data structure. |
| 108 | * |
| 109 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 110 | * mailbox command. It retrieves the revision information from the HBA and |
| 111 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 112 | * configuration of the HBA. |
| 113 | * |
| 114 | * Return codes: |
| 115 | * 0 - success. |
| 116 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 117 | * Any other value - indicates an error. |
| 118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 120 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 121 | { |
| 122 | lpfc_vpd_t *vp = &phba->vpd; |
| 123 | int i = 0, rc; |
| 124 | LPFC_MBOXQ_t *pmb; |
| 125 | MAILBOX_t *mb; |
| 126 | char *lpfc_vpd_data = NULL; |
| 127 | uint16_t offset = 0; |
| 128 | static char licensed[56] = |
| 129 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 130 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 131 | |
| 132 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 133 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 134 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | return -ENOMEM; |
| 136 | } |
| 137 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 138 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 139 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | |
| 141 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 142 | if (init_key) { |
| 143 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 145 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 146 | *ptext = cpu_to_be32(*ptext); |
| 147 | init_key = 0; |
| 148 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | |
| 150 | lpfc_read_nv(phba, pmb); |
| 151 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 152 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 153 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 154 | sizeof (licensed)); |
| 155 | |
| 156 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 157 | |
| 158 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 159 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 160 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | "error, mbxCmd x%x READ_NVPARM, " |
| 162 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | mb->mbxCommand, mb->mbxStatus); |
| 164 | mempool_free(pmb, phba->mbox_mem_pool); |
| 165 | return -ERESTART; |
| 166 | } |
| 167 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 168 | sizeof(phba->wwnn)); |
| 169 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 170 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 173 | /* |
| 174 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 175 | * which was already set in lpfc_get_cfgparam() |
| 176 | */ |
| 177 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | /* Setup and issue mailbox READ REV command */ |
| 180 | lpfc_read_rev(phba, pmb); |
| 181 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 182 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 184 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | mb->mbxCommand, mb->mbxStatus); |
| 187 | mempool_free( pmb, phba->mbox_mem_pool); |
| 188 | return -ERESTART; |
| 189 | } |
| 190 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 191 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 192 | /* |
| 193 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 194 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 196 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 199 | "0440 Adapter failed to init, READ_REV has " |
| 200 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | mempool_free(pmb, phba->mbox_mem_pool); |
| 202 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | } |
| 204 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 205 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 206 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 207 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 208 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 209 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 211 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 213 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 214 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 215 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 216 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 218 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 219 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 220 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 221 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 222 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 223 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 224 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 225 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 226 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 227 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 228 | /* If the sli feature level is less then 9, we must |
| 229 | * tear down all RPIs and VPIs on link down if NPIV |
| 230 | * is enabled. |
| 231 | */ |
| 232 | if (vp->rev.feaLevelHigh < 9) |
| 233 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 236 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 237 | sizeof (phba->RandomData)); |
| 238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 241 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 242 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 244 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 246 | |
| 247 | if (rc != MBX_SUCCESS) { |
| 248 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 249 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 252 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 254 | /* dump mem may return a zero when finished or we got a |
| 255 | * mailbox error, either way we are done. |
| 256 | */ |
| 257 | if (mb->un.varDmp.word_cnt == 0) |
| 258 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 259 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 260 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 261 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 262 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 263 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 264 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 265 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 266 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | |
| 268 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | out_free_mbox: |
| 270 | mempool_free(pmb, phba->mbox_mem_pool); |
| 271 | return 0; |
| 272 | } |
| 273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 275 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 276 | * @phba: pointer to lpfc hba data structure. |
| 277 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 278 | * |
| 279 | * This is the completion handler for driver's configuring asynchronous event |
| 280 | * mailbox command to the device. If the mailbox command returns successfully, |
| 281 | * it will set internal async event support flag to 1; otherwise, it will |
| 282 | * set internal async event support flag to 0. |
| 283 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 284 | static void |
| 285 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 286 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 287 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 288 | phba->temp_sensor_support = 1; |
| 289 | else |
| 290 | phba->temp_sensor_support = 0; |
| 291 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 292 | return; |
| 293 | } |
| 294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 296 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 297 | * @phba: pointer to lpfc hba data structure. |
| 298 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 299 | * |
| 300 | * This is the completion handler for dump mailbox command for getting |
| 301 | * wake up parameters. When this command complete, the response contain |
| 302 | * Option rom version of the HBA. This function translate the version number |
| 303 | * into a human readable string and store it in OptionROMVersion. |
| 304 | **/ |
| 305 | static void |
| 306 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 307 | { |
| 308 | struct prog_id *prg; |
| 309 | uint32_t prog_id_word; |
| 310 | char dist = ' '; |
| 311 | /* character array used for decoding dist type. */ |
| 312 | char dist_char[] = "nabx"; |
| 313 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 314 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 315 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 316 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 317 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 318 | |
| 319 | prg = (struct prog_id *) &prog_id_word; |
| 320 | |
| 321 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 322 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 323 | |
| 324 | /* Decode the Option rom version word to a readable string */ |
| 325 | if (prg->dist < 4) |
| 326 | dist = dist_char[prg->dist]; |
| 327 | |
| 328 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 329 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 330 | prg->ver, prg->rev, prg->lev); |
| 331 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 332 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 333 | prg->ver, prg->rev, prg->lev, |
| 334 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 335 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
| 339 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 340 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 341 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 342 | * @vport: pointer to lpfc vport data structure. |
| 343 | * |
| 344 | * |
| 345 | * Return codes |
| 346 | * None. |
| 347 | **/ |
| 348 | void |
| 349 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 350 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 351 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 352 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 353 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 354 | /* If the soft name exists then update it using the service params */ |
| 355 | if (vport->phba->cfg_soft_wwnn) |
| 356 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 357 | vport->fc_sparam.nodeName.u.wwn); |
| 358 | if (vport->phba->cfg_soft_wwpn) |
| 359 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 360 | vport->fc_sparam.portName.u.wwn); |
| 361 | |
| 362 | /* |
| 363 | * If the name is empty or there exists a soft name |
| 364 | * then copy the service params name, otherwise use the fc name |
| 365 | */ |
| 366 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 367 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 368 | sizeof(struct lpfc_name)); |
| 369 | else |
| 370 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 371 | sizeof(struct lpfc_name)); |
| 372 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 373 | /* |
| 374 | * If the port name has changed, then set the Param changes flag |
| 375 | * to unreg the login |
| 376 | */ |
| 377 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 378 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 379 | sizeof(struct lpfc_name))) |
| 380 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 381 | |
| 382 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 383 | vport->phba->cfg_soft_wwpn || |
| 384 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 385 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 386 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 387 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 388 | vport->vport_flag &= ~FAWWPN_SET; |
| 389 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 390 | vport->vport_flag |= FAWWPN_SET; |
| 391 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 392 | else |
| 393 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 394 | sizeof(struct lpfc_name)); |
| 395 | } |
| 396 | |
| 397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 398 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 399 | * @phba: pointer to lpfc hba data structure. |
| 400 | * |
| 401 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 402 | * command call. It performs all internal resource and state setups on the |
| 403 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 404 | * ELS ring timers, etc. |
| 405 | * |
| 406 | * Return codes |
| 407 | * 0 - success. |
| 408 | * Any other value - error. |
| 409 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 414 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | LPFC_MBOXQ_t *pmb; |
| 416 | MAILBOX_t *mb; |
| 417 | struct lpfc_dmabuf *mp; |
| 418 | struct lpfc_sli *psli = &phba->sli; |
| 419 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 420 | int i, j; |
| 421 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 423 | spin_lock_irq(&phba->hbalock); |
| 424 | /* |
| 425 | * If the Config port completed correctly the HBA is not |
| 426 | * over heated any more. |
| 427 | */ |
| 428 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 429 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 430 | spin_unlock_irq(&phba->hbalock); |
| 431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 433 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | return -ENOMEM; |
| 436 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 437 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 440 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 441 | if (rc) { |
| 442 | mempool_free(pmb, phba->mbox_mem_pool); |
| 443 | return -ENOMEM; |
| 444 | } |
| 445 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 446 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 447 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 449 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 452 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 453 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 454 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 455 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 456 | kfree(mp); |
| 457 | return -EIO; |
| 458 | } |
| 459 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 460 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 462 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 463 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 464 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 465 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 466 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 467 | |
| 468 | /* Update the fc_host data structures with new wwn. */ |
| 469 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 470 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 471 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 474 | /* This should be consolidated into parse_vpd ? - mr */ |
| 475 | if (phba->SerialNumber[0] == 0) { |
| 476 | uint8_t *outptr; |
| 477 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | for (i = 0; i < 12; i++) { |
| 480 | status = *outptr++; |
| 481 | j = ((status & 0xf0) >> 4); |
| 482 | if (j <= 9) |
| 483 | phba->SerialNumber[i] = |
| 484 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 485 | else |
| 486 | phba->SerialNumber[i] = |
| 487 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 488 | i++; |
| 489 | j = (status & 0xf); |
| 490 | if (j <= 9) |
| 491 | phba->SerialNumber[i] = |
| 492 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 493 | else |
| 494 | phba->SerialNumber[i] = |
| 495 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 496 | } |
| 497 | } |
| 498 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 500 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 503 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | mempool_free( pmb, phba->mbox_mem_pool); |
| 508 | return -EIO; |
| 509 | } |
| 510 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 511 | /* Check if the port is disabled */ |
| 512 | lpfc_sli_read_link_ste(phba); |
| 513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 515 | i = (mb->un.varRdConfig.max_xri + 1); |
| 516 | if (phba->cfg_hba_queue_depth > i) { |
| 517 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 518 | "3359 HBA queue depth changed from %d to %d\n", |
| 519 | phba->cfg_hba_queue_depth, i); |
| 520 | phba->cfg_hba_queue_depth = i; |
| 521 | } |
| 522 | |
| 523 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 524 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 525 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 526 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 527 | "3360 LUN queue depth changed from %d to %d\n", |
| 528 | phba->pport->cfg_lun_queue_depth, i); |
| 529 | phba->pport->cfg_lun_queue_depth = i; |
| 530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | |
| 532 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 533 | |
| 534 | /* Get the default values for Model Name and Description */ |
| 535 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 536 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 537 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 539 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 540 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 541 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 542 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 543 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 544 | |
| 545 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 546 | if (phba->sli_rev != 3) |
| 547 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 549 | /* |
| 550 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 551 | */ |
| 552 | if (phba->intr_type == MSIX) { |
| 553 | rc = lpfc_config_msi(phba, pmb); |
| 554 | if (rc) { |
| 555 | mempool_free(pmb, phba->mbox_mem_pool); |
| 556 | return -EIO; |
| 557 | } |
| 558 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 559 | if (rc != MBX_SUCCESS) { |
| 560 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 561 | "0352 Config MSI mailbox command " |
| 562 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 563 | pmb->u.mb.mbxCommand, |
| 564 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 565 | mempool_free(pmb, phba->mbox_mem_pool); |
| 566 | return -EIO; |
| 567 | } |
| 568 | } |
| 569 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 570 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 571 | /* Initialize ERATT handling flag */ |
| 572 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 575 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 576 | spin_unlock_irq(&phba->hbalock); |
| 577 | return -EIO; |
| 578 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 579 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 580 | if (psli->num_rings > 0) |
| 581 | status |= HC_R0INT_ENA; |
| 582 | if (psli->num_rings > 1) |
| 583 | status |= HC_R1INT_ENA; |
| 584 | if (psli->num_rings > 2) |
| 585 | status |= HC_R2INT_ENA; |
| 586 | if (psli->num_rings > 3) |
| 587 | status |= HC_R3INT_ENA; |
| 588 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 589 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 590 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 591 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | writel(status, phba->HCregaddr); |
| 594 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 595 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 597 | /* Set up ring-0 (ELS) timer */ |
| 598 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 599 | mod_timer(&vport->els_tmofunc, |
| 600 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 601 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 602 | mod_timer(&phba->hb_tmofunc, |
| 603 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 604 | phba->hb_outstanding = 0; |
| 605 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 606 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 607 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 608 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 610 | if (phba->hba_flag & LINK_DISABLED) { |
| 611 | lpfc_printf_log(phba, |
| 612 | KERN_ERR, LOG_INIT, |
| 613 | "2598 Adapter Link is disabled.\n"); |
| 614 | lpfc_down_link(phba, pmb); |
| 615 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 616 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 617 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 618 | lpfc_printf_log(phba, |
| 619 | KERN_ERR, LOG_INIT, |
| 620 | "2599 Adapter failed to issue DOWN_LINK" |
| 621 | " mbox command rc 0x%x\n", rc); |
| 622 | |
| 623 | mempool_free(pmb, phba->mbox_mem_pool); |
| 624 | return -EIO; |
| 625 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 626 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 627 | mempool_free(pmb, phba->mbox_mem_pool); |
| 628 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 629 | if (rc) |
| 630 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | } |
| 632 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 633 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 634 | if (!pmb) { |
| 635 | phba->link_state = LPFC_HBA_ERROR; |
| 636 | return -ENOMEM; |
| 637 | } |
| 638 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 639 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 640 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 641 | pmb->vport = phba->pport; |
| 642 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 644 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 645 | lpfc_printf_log(phba, |
| 646 | KERN_ERR, |
| 647 | LOG_INIT, |
| 648 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 649 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 650 | rc); |
| 651 | mempool_free(pmb, phba->mbox_mem_pool); |
| 652 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 653 | |
| 654 | /* Get Option rom version */ |
| 655 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 656 | if (!pmb) { |
| 657 | phba->link_state = LPFC_HBA_ERROR; |
| 658 | return -ENOMEM; |
| 659 | } |
| 660 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 661 | lpfc_dump_wakeup_param(phba, pmb); |
| 662 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 663 | pmb->vport = phba->pport; |
| 664 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 665 | |
| 666 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 667 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 668 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 669 | mempool_free(pmb, phba->mbox_mem_pool); |
| 670 | } |
| 671 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 672 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 673 | } |
| 674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 675 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 676 | * lpfc_hba_init_link - Initialize the FC link |
| 677 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 678 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 679 | * |
| 680 | * This routine will issue the INIT_LINK mailbox command call. |
| 681 | * It is available to other drivers through the lpfc_hba data |
| 682 | * structure for use as a delayed link up mechanism with the |
| 683 | * module parameter lpfc_suppress_link_up. |
| 684 | * |
| 685 | * Return code |
| 686 | * 0 - success |
| 687 | * Any other value - error |
| 688 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 689 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 690 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 691 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 692 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 697 | * @phba: pointer to lpfc hba data structure. |
| 698 | * @fc_topology: desired fc topology. |
| 699 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 700 | * |
| 701 | * This routine will issue the INIT_LINK mailbox command call. |
| 702 | * It is available to other drivers through the lpfc_hba data |
| 703 | * structure for use as a delayed link up mechanism with the |
| 704 | * module parameter lpfc_suppress_link_up. |
| 705 | * |
| 706 | * Return code |
| 707 | * 0 - success |
| 708 | * Any other value - error |
| 709 | **/ |
| 710 | int |
| 711 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 712 | uint32_t flag) |
| 713 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 714 | struct lpfc_vport *vport = phba->pport; |
| 715 | LPFC_MBOXQ_t *pmb; |
| 716 | MAILBOX_t *mb; |
| 717 | int rc; |
| 718 | |
| 719 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 720 | if (!pmb) { |
| 721 | phba->link_state = LPFC_HBA_ERROR; |
| 722 | return -ENOMEM; |
| 723 | } |
| 724 | mb = &pmb->u.mb; |
| 725 | pmb->vport = vport; |
| 726 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 727 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 728 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 729 | !(phba->lmt & LMT_1Gb)) || |
| 730 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 731 | !(phba->lmt & LMT_2Gb)) || |
| 732 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 733 | !(phba->lmt & LMT_4Gb)) || |
| 734 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 735 | !(phba->lmt & LMT_8Gb)) || |
| 736 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 737 | !(phba->lmt & LMT_10Gb)) || |
| 738 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 739 | !(phba->lmt & LMT_16Gb)) || |
| 740 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 741 | !(phba->lmt & LMT_32Gb)) || |
| 742 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 743 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 744 | /* Reset link speed to auto */ |
| 745 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 746 | "1302 Invalid speed for this board:%d " |
| 747 | "Reset link speed to auto.\n", |
| 748 | phba->cfg_link_speed); |
| 749 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 750 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 751 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 752 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 753 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 754 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 755 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 756 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 757 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 758 | "0498 Adapter failed to init, mbxCmd x%x " |
| 759 | "INIT_LINK, mbxStatus x%x\n", |
| 760 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 761 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 762 | /* Clear all interrupt enable conditions */ |
| 763 | writel(0, phba->HCregaddr); |
| 764 | readl(phba->HCregaddr); /* flush */ |
| 765 | /* Clear all pending interrupts */ |
| 766 | writel(0xffffffff, phba->HAregaddr); |
| 767 | readl(phba->HAregaddr); /* flush */ |
| 768 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 769 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 770 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 771 | mempool_free(pmb, phba->mbox_mem_pool); |
| 772 | return -EIO; |
| 773 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 774 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 775 | if (flag == MBX_POLL) |
| 776 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 783 | * @phba: pointer to lpfc hba data structure. |
| 784 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 785 | * |
| 786 | * This routine will issue the DOWN_LINK mailbox command call. |
| 787 | * It is available to other drivers through the lpfc_hba data |
| 788 | * structure for use to stop the link. |
| 789 | * |
| 790 | * Return code |
| 791 | * 0 - success |
| 792 | * Any other value - error |
| 793 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 794 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 795 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 796 | { |
| 797 | LPFC_MBOXQ_t *pmb; |
| 798 | int rc; |
| 799 | |
| 800 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 801 | if (!pmb) { |
| 802 | phba->link_state = LPFC_HBA_ERROR; |
| 803 | return -ENOMEM; |
| 804 | } |
| 805 | |
| 806 | lpfc_printf_log(phba, |
| 807 | KERN_ERR, LOG_INIT, |
| 808 | "0491 Adapter Link is disabled.\n"); |
| 809 | lpfc_down_link(phba, pmb); |
| 810 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 811 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 812 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 813 | lpfc_printf_log(phba, |
| 814 | KERN_ERR, LOG_INIT, |
| 815 | "2522 Adapter failed to issue DOWN_LINK" |
| 816 | " mbox command rc 0x%x\n", rc); |
| 817 | |
| 818 | mempool_free(pmb, phba->mbox_mem_pool); |
| 819 | return -EIO; |
| 820 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 821 | if (flag == MBX_POLL) |
| 822 | mempool_free(pmb, phba->mbox_mem_pool); |
| 823 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 828 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 829 | * @phba: pointer to lpfc HBA data structure. |
| 830 | * |
| 831 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 832 | * bringing down the SLI Layer. |
| 833 | * |
| 834 | * Return codes |
| 835 | * 0 - success. |
| 836 | * Any other value - error. |
| 837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 839 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 841 | struct lpfc_vport **vports; |
| 842 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 843 | |
| 844 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 845 | /* Disable interrupts */ |
| 846 | writel(0, phba->HCregaddr); |
| 847 | readl(phba->HCregaddr); /* flush */ |
| 848 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 850 | if (phba->pport->load_flag & FC_UNLOADING) |
| 851 | lpfc_cleanup_discovery_resources(phba->pport); |
| 852 | else { |
| 853 | vports = lpfc_create_vport_work_array(phba); |
| 854 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 855 | for (i = 0; i <= phba->max_vports && |
| 856 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 857 | lpfc_cleanup_discovery_resources(vports[i]); |
| 858 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 859 | } |
| 860 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | } |
| 862 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 863 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 864 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 865 | * rspiocb which got deferred |
| 866 | * |
| 867 | * @phba: pointer to lpfc HBA data structure. |
| 868 | * |
| 869 | * This routine will cleanup completed slow path events after HBA is reset |
| 870 | * when bringing down the SLI Layer. |
| 871 | * |
| 872 | * |
| 873 | * Return codes |
| 874 | * void. |
| 875 | **/ |
| 876 | static void |
| 877 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 878 | { |
| 879 | struct lpfc_iocbq *rspiocbq; |
| 880 | struct hbq_dmabuf *dmabuf; |
| 881 | struct lpfc_cq_event *cq_event; |
| 882 | |
| 883 | spin_lock_irq(&phba->hbalock); |
| 884 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 885 | spin_unlock_irq(&phba->hbalock); |
| 886 | |
| 887 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 888 | /* Get the response iocb from the head of work queue */ |
| 889 | spin_lock_irq(&phba->hbalock); |
| 890 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 891 | cq_event, struct lpfc_cq_event, list); |
| 892 | spin_unlock_irq(&phba->hbalock); |
| 893 | |
| 894 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 895 | case CQE_CODE_COMPL_WQE: |
| 896 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 897 | cq_event); |
| 898 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 899 | break; |
| 900 | case CQE_CODE_RECEIVE: |
| 901 | case CQE_CODE_RECEIVE_V1: |
| 902 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 903 | cq_event); |
| 904 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 910 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 911 | * @phba: pointer to lpfc HBA data structure. |
| 912 | * |
| 913 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 914 | * when bringing down the SLI Layer. |
| 915 | * |
| 916 | * |
| 917 | * Return codes |
| 918 | * void. |
| 919 | **/ |
| 920 | static void |
| 921 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 922 | { |
| 923 | struct lpfc_sli *psli = &phba->sli; |
| 924 | struct lpfc_sli_ring *pring; |
| 925 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 926 | LIST_HEAD(buflist); |
| 927 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 928 | |
| 929 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 930 | lpfc_sli_hbqbuf_free_all(phba); |
| 931 | else { |
| 932 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 933 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 934 | spin_lock_irq(&phba->hbalock); |
| 935 | list_splice_init(&pring->postbufq, &buflist); |
| 936 | spin_unlock_irq(&phba->hbalock); |
| 937 | |
| 938 | count = 0; |
| 939 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 940 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 941 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 942 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 943 | kfree(mp); |
| 944 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 945 | |
| 946 | spin_lock_irq(&phba->hbalock); |
| 947 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 948 | spin_unlock_irq(&phba->hbalock); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 954 | * @phba: pointer to lpfc HBA data structure. |
| 955 | * |
| 956 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 957 | * down the SLI Layer. |
| 958 | * |
| 959 | * Return codes |
| 960 | * void |
| 961 | **/ |
| 962 | static void |
| 963 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 964 | { |
| 965 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 966 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 967 | struct lpfc_sli_ring *pring; |
| 968 | LIST_HEAD(completions); |
| 969 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 970 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 971 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 972 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 973 | for (i = 0; i < psli->num_rings; i++) { |
| 974 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 975 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 976 | /* At this point in time the HBA is either reset or DOA |
| 977 | * Nothing should be on txcmplq as it will |
| 978 | * NEVER complete. |
| 979 | */ |
| 980 | list_splice_init(&pring->txcmplq, &completions); |
| 981 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 982 | spin_unlock_irq(&phba->hbalock); |
| 983 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 984 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 985 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 986 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 987 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 988 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 989 | return; |
| 990 | } |
| 991 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 992 | pring = qp->pring; |
| 993 | if (!pring) |
| 994 | continue; |
| 995 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 996 | list_for_each_entry_safe(piocb, next_iocb, |
| 997 | &pring->txcmplq, list) |
| 998 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 999 | list_splice_init(&pring->txcmplq, &completions); |
| 1000 | pring->txcmplq_cnt = 0; |
| 1001 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1002 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1003 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1004 | /* Cancel all the IOCBs from the completions list */ |
| 1005 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 1006 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1010 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1011 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1012 | * @phba: pointer to lpfc HBA data structure. |
| 1013 | * |
| 1014 | * This routine will do uninitialization after the HBA is reset when bring |
| 1015 | * down the SLI Layer. |
| 1016 | * |
| 1017 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1018 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1019 | * Any other value - error. |
| 1020 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1021 | static int |
| 1022 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1023 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1024 | lpfc_hba_free_post_buf(phba); |
| 1025 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1028 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1029 | /** |
| 1030 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1031 | * @phba: pointer to lpfc HBA data structure. |
| 1032 | * |
| 1033 | * This routine will do uninitialization after the HBA is reset when bring |
| 1034 | * down the SLI Layer. |
| 1035 | * |
| 1036 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1037 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1038 | * Any other value - error. |
| 1039 | **/ |
| 1040 | static int |
| 1041 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1042 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1043 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1044 | struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1045 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1046 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1047 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1048 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1049 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1050 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1051 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1052 | |
| 1053 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1054 | lpfc_hba_clean_txcmplq(phba); |
| 1055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | /* At this point in time the HBA is either reset or DOA. Either |
| 1057 | * 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] | 1058 | * 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] | 1059 | * driver is unloading or reposted if the driver is restarting |
| 1060 | * the port. |
| 1061 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1062 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1064 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1065 | * list. |
| 1066 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1067 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1068 | list_for_each_entry(sglq_entry, |
| 1069 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1070 | sglq_entry->state = SGL_FREED; |
| 1071 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1072 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1074 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1075 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1076 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1077 | |
| 1078 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1079 | * list. |
| 1080 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1081 | cnt = 0; |
| 1082 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1083 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1084 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1085 | spin_lock(&qp->abts_io_buf_list_lock); |
| 1086 | list_splice_init(&qp->lpfc_abts_io_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1087 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1088 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1089 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1090 | psb->pCmd = NULL; |
| 1091 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1092 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1093 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1094 | spin_lock(&qp->io_buf_list_put_lock); |
| 1095 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1096 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1097 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1098 | qp->abts_scsi_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1099 | qp->abts_nvme_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1100 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1101 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1102 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1103 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1104 | |
| 1105 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1106 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1107 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1108 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1109 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1110 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
| 1111 | ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1112 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1113 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1114 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1115 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1116 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1117 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1122 | * @phba: pointer to lpfc HBA data structure. |
| 1123 | * |
| 1124 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1125 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1126 | * |
| 1127 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1128 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1129 | * Any other value - error. |
| 1130 | **/ |
| 1131 | int |
| 1132 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1133 | { |
| 1134 | return (*phba->lpfc_hba_down_post)(phba); |
| 1135 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1137 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1138 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1139 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1140 | * |
| 1141 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1142 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1143 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1144 | * event will be used by the worker thread to invoke the actual timeout |
| 1145 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1146 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1147 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1148 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1149 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1150 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1151 | { |
| 1152 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1153 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1154 | unsigned long iflag; |
| 1155 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1156 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1157 | |
| 1158 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1159 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1160 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1161 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1162 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1163 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1164 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1165 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1166 | if (!tmo_posted) |
| 1167 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1168 | return; |
| 1169 | } |
| 1170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1171 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1173 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1174 | * |
| 1175 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1176 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1177 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1178 | * event will be used by the worker thread to invoke the actual timeout |
| 1179 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1180 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1181 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1182 | **/ |
| 1183 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1184 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1185 | { |
| 1186 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1187 | unsigned long iflag; |
| 1188 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1189 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1190 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1191 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1192 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1193 | else |
| 1194 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1195 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1196 | |
| 1197 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1198 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1202 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1203 | * @phba: pointer to lpfc hba data structure. |
| 1204 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1205 | * |
| 1206 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1207 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1208 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1209 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1210 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1211 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1212 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1213 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1214 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1215 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1216 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1217 | static void |
| 1218 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1219 | { |
| 1220 | unsigned long drvr_flag; |
| 1221 | |
| 1222 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1223 | phba->hb_outstanding = 0; |
| 1224 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1225 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1226 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1227 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1228 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1229 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1230 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1231 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1232 | jiffies + |
| 1233 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1234 | return; |
| 1235 | } |
| 1236 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1237 | static void |
| 1238 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1239 | { |
| 1240 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1241 | struct lpfc_hba, eq_delay_work); |
| 1242 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1243 | struct lpfc_queue *eq, *eq_next; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1244 | unsigned char *ena_delay = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1245 | uint32_t usdelay; |
| 1246 | int i; |
| 1247 | |
| 1248 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1249 | return; |
| 1250 | |
| 1251 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1252 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1253 | goto requeue; |
| 1254 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1255 | ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay), |
| 1256 | GFP_KERNEL); |
| 1257 | if (!ena_delay) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1258 | goto requeue; |
| 1259 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1260 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1261 | /* Get the EQ corresponding to the IRQ vector */ |
| 1262 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1263 | if (!eq) |
| 1264 | continue; |
| 1265 | if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) { |
| 1266 | eq->q_flag &= ~HBA_EQ_DELAY_CHK; |
| 1267 | ena_delay[eq->last_cpu] = 1; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1268 | } |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1269 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1270 | |
| 1271 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1272 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1273 | if (ena_delay[i]) { |
| 1274 | usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP; |
| 1275 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1276 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1277 | } else { |
| 1278 | usdelay = 0; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1279 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1280 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1281 | eqi->icnt = 0; |
| 1282 | |
| 1283 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1284 | if (unlikely(eq->last_cpu != i)) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1285 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1286 | eq->last_cpu); |
| 1287 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1288 | continue; |
| 1289 | } |
| 1290 | if (usdelay != eq->q_mode) |
| 1291 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1292 | usdelay); |
| 1293 | } |
| 1294 | } |
| 1295 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1296 | kfree(ena_delay); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1297 | |
| 1298 | requeue: |
| 1299 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1300 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1301 | } |
| 1302 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1303 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1304 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1305 | * @phba: pointer to lpfc hba data structure. |
| 1306 | * |
| 1307 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1308 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1309 | **/ |
| 1310 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1311 | { |
| 1312 | u32 i; |
| 1313 | u32 hwq_count; |
| 1314 | |
| 1315 | hwq_count = phba->cfg_hdw_queue; |
| 1316 | for (i = 0; i < hwq_count; i++) { |
| 1317 | /* Adjust XRIs in private pool */ |
| 1318 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1319 | |
| 1320 | /* Adjust high watermark */ |
| 1321 | lpfc_adjust_high_watermark(phba, i); |
| 1322 | |
| 1323 | #ifdef LPFC_MXP_STAT |
| 1324 | /* Snapshot pbl, pvt and busy count */ |
| 1325 | lpfc_snapshot_mxp(phba, i); |
| 1326 | #endif |
| 1327 | } |
| 1328 | } |
| 1329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1330 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1331 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1332 | * @phba: pointer to lpfc hba data structure. |
| 1333 | * |
| 1334 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1335 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1336 | * handler performs any periodic operations needed for the device. If such |
| 1337 | * periodic event has already been attended to either in the interrupt handler |
| 1338 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1339 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1340 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1341 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1342 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1343 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1344 | * to offline. |
| 1345 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1346 | void |
| 1347 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1348 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1349 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1350 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1351 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1352 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1353 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1354 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1355 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1356 | if (phba->cfg_xri_rebalancing) { |
| 1357 | /* Multi-XRI pools handler */ |
| 1358 | lpfc_hb_mxp_handler(phba); |
| 1359 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1360 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1361 | vports = lpfc_create_vport_work_array(phba); |
| 1362 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1363 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1364 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 1365 | lpfc_fdmi_change_check(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1366 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1367 | lpfc_destroy_vport_work_array(phba, vports); |
| 1368 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1369 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1370 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1371 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1372 | return; |
| 1373 | |
| 1374 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1375 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1376 | if (time_after(phba->last_completion_time + |
| 1377 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1378 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1379 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1380 | if (!phba->hb_outstanding) |
| 1381 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1382 | jiffies + |
| 1383 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1384 | else |
| 1385 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1386 | jiffies + |
| 1387 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1388 | return; |
| 1389 | } |
| 1390 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1391 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1392 | if (phba->elsbuf_cnt && |
| 1393 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1394 | spin_lock_irq(&phba->hbalock); |
| 1395 | list_splice_init(&phba->elsbuf, &completions); |
| 1396 | phba->elsbuf_cnt = 0; |
| 1397 | phba->elsbuf_prev_cnt = 0; |
| 1398 | spin_unlock_irq(&phba->hbalock); |
| 1399 | |
| 1400 | while (!list_empty(&completions)) { |
| 1401 | list_remove_head(&completions, buf_ptr, |
| 1402 | struct lpfc_dmabuf, list); |
| 1403 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1404 | kfree(buf_ptr); |
| 1405 | } |
| 1406 | } |
| 1407 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1408 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1409 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1410 | if (phba->cfg_enable_hba_heartbeat) { |
| 1411 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1412 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1413 | (list_empty(&psli->mboxq))) { |
| 1414 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1415 | GFP_KERNEL); |
| 1416 | if (!pmboxq) { |
| 1417 | mod_timer(&phba->hb_tmofunc, |
| 1418 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1419 | msecs_to_jiffies(1000 * |
| 1420 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1421 | return; |
| 1422 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1423 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1424 | lpfc_heart_beat(phba, pmboxq); |
| 1425 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1426 | pmboxq->vport = phba->pport; |
| 1427 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1428 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1429 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1430 | if (retval != MBX_BUSY && |
| 1431 | retval != MBX_SUCCESS) { |
| 1432 | mempool_free(pmboxq, |
| 1433 | phba->mbox_mem_pool); |
| 1434 | mod_timer(&phba->hb_tmofunc, |
| 1435 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1436 | msecs_to_jiffies(1000 * |
| 1437 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1438 | return; |
| 1439 | } |
| 1440 | phba->skipped_hb = 0; |
| 1441 | phba->hb_outstanding = 1; |
| 1442 | } else if (time_before_eq(phba->last_completion_time, |
| 1443 | phba->skipped_hb)) { |
| 1444 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1445 | "2857 Last completion time not " |
| 1446 | " updated in %d ms\n", |
| 1447 | jiffies_to_msecs(jiffies |
| 1448 | - phba->last_completion_time)); |
| 1449 | } else |
| 1450 | phba->skipped_hb = jiffies; |
| 1451 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1452 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1453 | jiffies + |
| 1454 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1455 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1456 | } else { |
| 1457 | /* |
| 1458 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1459 | * we need to give the hb mailbox cmd a chance to |
| 1460 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1461 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1462 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1463 | "0459 Adapter heartbeat still out" |
| 1464 | "standing:last compl time was %d ms.\n", |
| 1465 | jiffies_to_msecs(jiffies |
| 1466 | - phba->last_completion_time)); |
| 1467 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1468 | jiffies + |
| 1469 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1470 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1471 | } else { |
| 1472 | mod_timer(&phba->hb_tmofunc, |
| 1473 | jiffies + |
| 1474 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1479 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1480 | * @phba: pointer to lpfc hba data structure. |
| 1481 | * |
| 1482 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1483 | * other than Port Error 6 has been detected. |
| 1484 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1485 | static void |
| 1486 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1487 | { |
| 1488 | struct lpfc_sli *psli = &phba->sli; |
| 1489 | |
| 1490 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1491 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1492 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1493 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1494 | |
| 1495 | lpfc_offline(phba); |
| 1496 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1497 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1498 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1499 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1500 | lpfc_hba_down_post(phba); |
| 1501 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1502 | lpfc_unblock_mgmt_io(phba); |
| 1503 | phba->link_state = LPFC_HBA_ERROR; |
| 1504 | return; |
| 1505 | } |
| 1506 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1507 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1508 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1509 | * @phba: pointer to lpfc hba data structure. |
| 1510 | * |
| 1511 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1512 | * other than Port Error 6 has been detected. |
| 1513 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1514 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1515 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1516 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1517 | spin_lock_irq(&phba->hbalock); |
| 1518 | phba->link_state = LPFC_HBA_ERROR; |
| 1519 | spin_unlock_irq(&phba->hbalock); |
| 1520 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1521 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1522 | lpfc_sli_flush_io_rings(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1523 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1524 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1525 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1529 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1530 | * @phba: pointer to lpfc hba data structure. |
| 1531 | * |
| 1532 | * This routine is invoked to handle the deferred HBA hardware error |
| 1533 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1534 | * and another ER bit in the host status register. The driver will |
| 1535 | * wait until the ER1 bit clears before handling the error condition. |
| 1536 | **/ |
| 1537 | static void |
| 1538 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1539 | { |
| 1540 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1541 | struct lpfc_sli *psli = &phba->sli; |
| 1542 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1543 | /* If the pci channel is offline, ignore possible errors, |
| 1544 | * since we cannot communicate with the pci card anyway. |
| 1545 | */ |
| 1546 | if (pci_channel_offline(phba->pcidev)) { |
| 1547 | spin_lock_irq(&phba->hbalock); |
| 1548 | phba->hba_flag &= ~DEFER_ERATT; |
| 1549 | spin_unlock_irq(&phba->hbalock); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1554 | "0479 Deferred Adapter Hardware Error " |
| 1555 | "Data: x%x x%x x%x\n", |
| 1556 | phba->work_hs, |
| 1557 | phba->work_status[0], phba->work_status[1]); |
| 1558 | |
| 1559 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1560 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1561 | spin_unlock_irq(&phba->hbalock); |
| 1562 | |
| 1563 | |
| 1564 | /* |
| 1565 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1566 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1567 | * SCSI layer retry it after re-establishing link. |
| 1568 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1569 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1570 | |
| 1571 | /* |
| 1572 | * There was a firmware error. Take the hba offline and then |
| 1573 | * attempt to restart it. |
| 1574 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1575 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1576 | lpfc_offline(phba); |
| 1577 | |
| 1578 | /* Wait for the ER1 bit to clear.*/ |
| 1579 | while (phba->work_hs & HS_FFER1) { |
| 1580 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1581 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1582 | phba->work_hs = UNPLUG_ERR ; |
| 1583 | break; |
| 1584 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1585 | /* If driver is unloading let the worker thread continue */ |
| 1586 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1587 | phba->work_hs = 0; |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | /* |
| 1593 | * This is to ptrotect against a race condition in which |
| 1594 | * first write to the host attention register clear the |
| 1595 | * host status register. |
| 1596 | */ |
| 1597 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1598 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1599 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1600 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1601 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1602 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1603 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1604 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1605 | } |
| 1606 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1607 | static void |
| 1608 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1609 | { |
| 1610 | struct lpfc_board_event_header board_event; |
| 1611 | struct Scsi_Host *shost; |
| 1612 | |
| 1613 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1614 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1615 | shost = lpfc_shost_from_vport(phba->pport); |
| 1616 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1617 | sizeof(board_event), |
| 1618 | (char *) &board_event, |
| 1619 | LPFC_NL_VENDOR_ID); |
| 1620 | } |
| 1621 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1622 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1623 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1624 | * @phba: pointer to lpfc hba data structure. |
| 1625 | * |
| 1626 | * This routine is invoked to handle the following HBA hardware error |
| 1627 | * conditions: |
| 1628 | * 1 - HBA error attention interrupt |
| 1629 | * 2 - DMA ring index out of range |
| 1630 | * 3 - Mailbox command came back as unknown |
| 1631 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1632 | static void |
| 1633 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1636 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1637 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1638 | unsigned long temperature; |
| 1639 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1640 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1641 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1642 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1643 | * since we cannot communicate with the pci card anyway. |
| 1644 | */ |
| 1645 | if (pci_channel_offline(phba->pcidev)) { |
| 1646 | spin_lock_irq(&phba->hbalock); |
| 1647 | phba->hba_flag &= ~DEFER_ERATT; |
| 1648 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1649 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1650 | } |
| 1651 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1652 | /* If resets are disabled then leave the HBA alone and return */ |
| 1653 | if (!phba->cfg_enable_hba_reset) |
| 1654 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1655 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1656 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1657 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1658 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1659 | if (phba->hba_flag & DEFER_ERATT) |
| 1660 | lpfc_handle_deferred_eratt(phba); |
| 1661 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1662 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1663 | if (phba->work_hs & HS_FFER6) |
| 1664 | /* Re-establishing Link */ |
| 1665 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1666 | "1301 Re-establishing Link " |
| 1667 | "Data: x%x x%x x%x\n", |
| 1668 | phba->work_hs, phba->work_status[0], |
| 1669 | phba->work_status[1]); |
| 1670 | if (phba->work_hs & HS_FFER8) |
| 1671 | /* Device Zeroization */ |
| 1672 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1673 | "2861 Host Authentication device " |
| 1674 | "zeroization Data:x%x x%x x%x\n", |
| 1675 | phba->work_hs, phba->work_status[0], |
| 1676 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1677 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1678 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1679 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1680 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | |
| 1682 | /* |
| 1683 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1684 | * That could cause the I/Os dropped by the firmware. |
| 1685 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1686 | * retry it after re-establishing link. |
| 1687 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1688 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | /* |
| 1691 | * There was a firmware error. Take the hba offline and then |
| 1692 | * attempt to restart it. |
| 1693 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1694 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1696 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1698 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | return; |
| 1700 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1701 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1702 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1703 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1704 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1705 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1706 | temp_event_data.data = (uint32_t)temperature; |
| 1707 | |
| 1708 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1709 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1710 | "(%ld), taking this port offline " |
| 1711 | "Data: x%x x%x x%x\n", |
| 1712 | temperature, phba->work_hs, |
| 1713 | phba->work_status[0], phba->work_status[1]); |
| 1714 | |
| 1715 | shost = lpfc_shost_from_vport(phba->pport); |
| 1716 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1717 | sizeof(temp_event_data), |
| 1718 | (char *) &temp_event_data, |
| 1719 | SCSI_NL_VID_TYPE_PCI |
| 1720 | | PCI_VENDOR_ID_EMULEX); |
| 1721 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1722 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1723 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1724 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1725 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1726 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1727 | } else { |
| 1728 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1729 | * failure is a value other than FFER6. Do not call the offline |
| 1730 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1731 | */ |
| 1732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1733 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1734 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1735 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | phba->work_status[0], phba->work_status[1]); |
| 1737 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1738 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1739 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1740 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1741 | sizeof(event_data), (char *) &event_data, |
| 1742 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1743 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1744 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1746 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | } |
| 1748 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1749 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1750 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1751 | * @phba: pointer to lpfc hba data structure. |
| 1752 | * @mbx_action: flag for mailbox shutdown action. |
| 1753 | * |
| 1754 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1755 | * response to port status register polling attention. It waits for port |
| 1756 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1757 | * During this process, interrupt vectors are freed and later requested |
| 1758 | * for handling possible port resource change. |
| 1759 | **/ |
| 1760 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1761 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1762 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1763 | { |
| 1764 | int rc; |
| 1765 | uint32_t intr_mode; |
| 1766 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1767 | 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] | 1768 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1769 | /* |
| 1770 | * On error status condition, driver need to wait for port |
| 1771 | * ready before performing reset. |
| 1772 | */ |
| 1773 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1774 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1775 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1776 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1777 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1778 | /* need reset: attempt for port recovery */ |
| 1779 | if (en_rn_msg) |
| 1780 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1781 | "2887 Reset Needed: Attempting Port " |
| 1782 | "Recovery...\n"); |
| 1783 | lpfc_offline_prep(phba, mbx_action); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1784 | lpfc_sli_flush_io_rings(phba); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1785 | lpfc_offline(phba); |
| 1786 | /* release interrupt for possible resource change */ |
| 1787 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1788 | rc = lpfc_sli_brdrestart(phba); |
| 1789 | if (rc) { |
| 1790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1791 | "6309 Failed to restart board\n"); |
| 1792 | return rc; |
| 1793 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1794 | /* request and enable interrupt */ |
| 1795 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1796 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1798 | "3175 Failed to enable interrupt\n"); |
| 1799 | return -EIO; |
| 1800 | } |
| 1801 | phba->intr_mode = intr_mode; |
| 1802 | rc = lpfc_online(phba); |
| 1803 | if (rc == 0) |
| 1804 | lpfc_unblock_mgmt_io(phba); |
| 1805 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1806 | return rc; |
| 1807 | } |
| 1808 | |
| 1809 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1810 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1811 | * @phba: pointer to lpfc hba data structure. |
| 1812 | * |
| 1813 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1814 | * conditions. |
| 1815 | **/ |
| 1816 | static void |
| 1817 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1818 | { |
| 1819 | struct lpfc_vport *vport = phba->pport; |
| 1820 | uint32_t event_data; |
| 1821 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1822 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1823 | struct lpfc_register portstat_reg = {0}; |
| 1824 | uint32_t reg_err1, reg_err2; |
| 1825 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1826 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1827 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1828 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1829 | struct lpfc_register portsmphr_reg; |
| 1830 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1831 | |
| 1832 | /* If the pci channel is offline, ignore possible errors, since |
| 1833 | * we cannot communicate with the pci card anyway. |
| 1834 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1835 | if (pci_channel_offline(phba->pcidev)) { |
| 1836 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1837 | "3166 pci channel is offline\n"); |
| 1838 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1839 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1840 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1841 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1842 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1843 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1844 | switch (if_type) { |
| 1845 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1846 | pci_rd_rc1 = lpfc_readl( |
| 1847 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1848 | &uerrlo_reg); |
| 1849 | pci_rd_rc2 = lpfc_readl( |
| 1850 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1851 | &uemasklo_reg); |
| 1852 | /* consider PCI bus read error as pci_channel_offline */ |
| 1853 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1854 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1855 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1856 | lpfc_sli4_offline_eratt(phba); |
| 1857 | return; |
| 1858 | } |
| 1859 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1860 | "7623 Checking UE recoverable"); |
| 1861 | |
| 1862 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1863 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1864 | &portsmphr_reg.word0)) |
| 1865 | continue; |
| 1866 | |
| 1867 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1868 | &portsmphr_reg); |
| 1869 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1870 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1871 | break; |
| 1872 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1873 | msleep(1000); |
| 1874 | } |
| 1875 | |
| 1876 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1877 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1878 | smphr_port_status, i); |
| 1879 | |
| 1880 | /* Recoverable UE, reset the HBA device */ |
| 1881 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1882 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1883 | for (i = 0; i < 20; i++) { |
| 1884 | msleep(1000); |
| 1885 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1886 | &portsmphr_reg.word0) && |
| 1887 | (LPFC_POST_STAGE_PORT_READY == |
| 1888 | bf_get(lpfc_port_smphr_port_status, |
| 1889 | &portsmphr_reg))) { |
| 1890 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1891 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1892 | if (rc == 0) |
| 1893 | return; |
| 1894 | lpfc_printf_log(phba, |
| 1895 | KERN_ERR, LOG_INIT, |
| 1896 | "4215 Failed to recover UE"); |
| 1897 | break; |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1902 | "7624 Firmware not ready: Failing UE recovery," |
| 1903 | " waited %dSec", i); |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 1904 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1905 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1906 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1907 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1908 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1909 | pci_rd_rc1 = lpfc_readl( |
| 1910 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1911 | &portstat_reg.word0); |
| 1912 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1913 | if (pci_rd_rc1 == -EIO) { |
| 1914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1915 | "3151 PCI bus read access failure: x%x\n", |
| 1916 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1917 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1918 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1919 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1920 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1921 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1922 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1924 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1925 | "taking port offline Data: x%x x%x\n", |
| 1926 | reg_err1, reg_err2); |
| 1927 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1928 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1929 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1930 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1931 | temp_event_data.data = 0xFFFFFFFF; |
| 1932 | |
| 1933 | shost = lpfc_shost_from_vport(phba->pport); |
| 1934 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1935 | sizeof(temp_event_data), |
| 1936 | (char *)&temp_event_data, |
| 1937 | SCSI_NL_VID_TYPE_PCI |
| 1938 | | PCI_VENDOR_ID_EMULEX); |
| 1939 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1940 | spin_lock_irq(&phba->hbalock); |
| 1941 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1942 | spin_unlock_irq(&phba->hbalock); |
| 1943 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1944 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1945 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1946 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1947 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1949 | "3143 Port Down: Firmware Update " |
| 1950 | "Detected\n"); |
| 1951 | en_rn_msg = false; |
| 1952 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1953 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1954 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1955 | "3144 Port Down: Debug Dump\n"); |
| 1956 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1957 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1959 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1960 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1961 | /* If resets are disabled then leave the HBA alone and return */ |
| 1962 | if (!phba->cfg_enable_hba_reset) |
| 1963 | return; |
| 1964 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1965 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1966 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1967 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1968 | if (rc == 0) { |
| 1969 | /* don't report event on forced debug dump */ |
| 1970 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1971 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1972 | return; |
| 1973 | else |
| 1974 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1975 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1976 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 1978 | "3152 Unrecoverable error\n"); |
| 1979 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1980 | break; |
| 1981 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1982 | default: |
| 1983 | break; |
| 1984 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1985 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1986 | "3123 Report dump event to upper layer\n"); |
| 1987 | /* Send an internal error event to mgmt application */ |
| 1988 | lpfc_board_errevt_to_mgmt(phba); |
| 1989 | |
| 1990 | event_data = FC_REG_DUMP_EVENT; |
| 1991 | shost = lpfc_shost_from_vport(vport); |
| 1992 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1993 | sizeof(event_data), (char *) &event_data, |
| 1994 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | /** |
| 1998 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1999 | * @phba: pointer to lpfc HBA data structure. |
| 2000 | * |
| 2001 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2002 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2003 | * |
| 2004 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2005 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2006 | * Any other value - error. |
| 2007 | **/ |
| 2008 | void |
| 2009 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2010 | { |
| 2011 | (*phba->lpfc_handle_eratt)(phba); |
| 2012 | } |
| 2013 | |
| 2014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2015 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2016 | * @phba: pointer to lpfc hba data structure. |
| 2017 | * |
| 2018 | * 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] | 2019 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2020 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2022 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2023 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2024 | struct lpfc_vport *vport = phba->pport; |
| 2025 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | LPFC_MBOXQ_t *pmb; |
| 2027 | volatile uint32_t control; |
| 2028 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2029 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | |
| 2031 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2032 | if (!pmb) { |
| 2033 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2035 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2036 | |
| 2037 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2038 | if (!mp) { |
| 2039 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2041 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | |
| 2043 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2044 | if (!mp->virt) { |
| 2045 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2047 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2049 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2050 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | |
| 2052 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2053 | lpfc_read_topology(phba, pmb, mp); |
| 2054 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2055 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2056 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2057 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2058 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2059 | if (rc == MBX_NOT_FINISHED) { |
| 2060 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2061 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2062 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | |
| 2064 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | writel(HA_LATT, phba->HAregaddr); |
| 2067 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | |
| 2070 | return; |
| 2071 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2072 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2073 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2074 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2075 | lpfc_handle_latt_free_mp: |
| 2076 | kfree(mp); |
| 2077 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2078 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | lpfc_handle_latt_err_exit: |
| 2080 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2083 | control = readl(phba->HCregaddr); |
| 2084 | control |= HC_LAINT_ENA; |
| 2085 | writel(control, phba->HCregaddr); |
| 2086 | readl(phba->HCregaddr); /* flush */ |
| 2087 | |
| 2088 | /* Clear Link Attention in HA REG */ |
| 2089 | writel(HA_LATT, phba->HAregaddr); |
| 2090 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2091 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2093 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2095 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2096 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | |
| 2098 | return; |
| 2099 | } |
| 2100 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2101 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2102 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2103 | * @phba: pointer to lpfc hba data structure. |
| 2104 | * @vpd: pointer to the vital product data. |
| 2105 | * @len: length of the vital product data in bytes. |
| 2106 | * |
| 2107 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2108 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2109 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2110 | * |
| 2111 | * Return codes |
| 2112 | * 0 - pointer to the VPD passed in is NULL |
| 2113 | * 1 - success |
| 2114 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2115 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2116 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | { |
| 2118 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2119 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | int i, j; |
| 2121 | int finished = 0; |
| 2122 | int index = 0; |
| 2123 | |
| 2124 | if (!vpd) |
| 2125 | return 0; |
| 2126 | |
| 2127 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2128 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2129 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2131 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2132 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | switch (vpd[index]) { |
| 2134 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2135 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | index += 1; |
| 2137 | lenlo = vpd[index]; |
| 2138 | index += 1; |
| 2139 | lenhi = vpd[index]; |
| 2140 | index += 1; |
| 2141 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2142 | index += i; |
| 2143 | break; |
| 2144 | case 0x90: |
| 2145 | index += 1; |
| 2146 | lenlo = vpd[index]; |
| 2147 | index += 1; |
| 2148 | lenhi = vpd[index]; |
| 2149 | index += 1; |
| 2150 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2151 | if (Length > len - index) |
| 2152 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | while (Length > 0) { |
| 2154 | /* Look for Serial Number */ |
| 2155 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2156 | index += 2; |
| 2157 | i = vpd[index]; |
| 2158 | index += 1; |
| 2159 | j = 0; |
| 2160 | Length -= (3+i); |
| 2161 | while(i--) { |
| 2162 | phba->SerialNumber[j++] = vpd[index++]; |
| 2163 | if (j == 31) |
| 2164 | break; |
| 2165 | } |
| 2166 | phba->SerialNumber[j] = 0; |
| 2167 | continue; |
| 2168 | } |
| 2169 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2170 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2171 | index += 2; |
| 2172 | i = vpd[index]; |
| 2173 | index += 1; |
| 2174 | j = 0; |
| 2175 | Length -= (3+i); |
| 2176 | while(i--) { |
| 2177 | phba->ModelDesc[j++] = vpd[index++]; |
| 2178 | if (j == 255) |
| 2179 | break; |
| 2180 | } |
| 2181 | phba->ModelDesc[j] = 0; |
| 2182 | continue; |
| 2183 | } |
| 2184 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2185 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2186 | index += 2; |
| 2187 | i = vpd[index]; |
| 2188 | index += 1; |
| 2189 | j = 0; |
| 2190 | Length -= (3+i); |
| 2191 | while(i--) { |
| 2192 | phba->ModelName[j++] = vpd[index++]; |
| 2193 | if (j == 79) |
| 2194 | break; |
| 2195 | } |
| 2196 | phba->ModelName[j] = 0; |
| 2197 | continue; |
| 2198 | } |
| 2199 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2200 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2201 | index += 2; |
| 2202 | i = vpd[index]; |
| 2203 | index += 1; |
| 2204 | j = 0; |
| 2205 | Length -= (3+i); |
| 2206 | while(i--) { |
| 2207 | phba->ProgramType[j++] = vpd[index++]; |
| 2208 | if (j == 255) |
| 2209 | break; |
| 2210 | } |
| 2211 | phba->ProgramType[j] = 0; |
| 2212 | continue; |
| 2213 | } |
| 2214 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2215 | phba->vpd_flag |= VPD_PORT; |
| 2216 | index += 2; |
| 2217 | i = vpd[index]; |
| 2218 | index += 1; |
| 2219 | j = 0; |
| 2220 | Length -= (3+i); |
| 2221 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2222 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2223 | (phba->sli4_hba.pport_name_sta == |
| 2224 | LPFC_SLI4_PPNAME_GET)) { |
| 2225 | j++; |
| 2226 | index++; |
| 2227 | } else |
| 2228 | phba->Port[j++] = vpd[index++]; |
| 2229 | if (j == 19) |
| 2230 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2232 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2233 | (phba->sli4_hba.pport_name_sta == |
| 2234 | LPFC_SLI4_PPNAME_NON)) |
| 2235 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2236 | continue; |
| 2237 | } |
| 2238 | else { |
| 2239 | index += 2; |
| 2240 | i = vpd[index]; |
| 2241 | index += 1; |
| 2242 | index += i; |
| 2243 | Length -= (3 + i); |
| 2244 | } |
| 2245 | } |
| 2246 | finished = 0; |
| 2247 | break; |
| 2248 | case 0x78: |
| 2249 | finished = 1; |
| 2250 | break; |
| 2251 | default: |
| 2252 | index ++; |
| 2253 | break; |
| 2254 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2255 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | |
| 2257 | return(1); |
| 2258 | } |
| 2259 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2260 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2261 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2262 | * @phba: pointer to lpfc hba data structure. |
| 2263 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2264 | * @descp: pointer to the data structure to hold the derived description. |
| 2265 | * |
| 2266 | * This routine retrieves HBA's description based on its registered PCI device |
| 2267 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2268 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2269 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2270 | * function returns, the @mdp will be filled with the model name. |
| 2271 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2273 | 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] | 2274 | { |
| 2275 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2276 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2277 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2278 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2279 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2280 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2281 | char *name; |
| 2282 | char *bus; |
| 2283 | char *function; |
| 2284 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2285 | |
| 2286 | if (mdp && mdp[0] != '\0' |
| 2287 | && descp && descp[0] != '\0') |
| 2288 | return; |
| 2289 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2290 | if (phba->lmt & LMT_64Gb) |
| 2291 | max_speed = 64; |
| 2292 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2293 | max_speed = 32; |
| 2294 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2295 | max_speed = 16; |
| 2296 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2297 | max_speed = 10; |
| 2298 | else if (phba->lmt & LMT_8Gb) |
| 2299 | max_speed = 8; |
| 2300 | else if (phba->lmt & LMT_4Gb) |
| 2301 | max_speed = 4; |
| 2302 | else if (phba->lmt & LMT_2Gb) |
| 2303 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2304 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2305 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2306 | else |
| 2307 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | |
| 2309 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2311 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2312 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2313 | m = (typeof(m)){"LP6000", "PCI", |
| 2314 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2315 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | case PCI_DEVICE_ID_SUPERFLY: |
| 2317 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2318 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2320 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2321 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | break; |
| 2323 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2324 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2325 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | break; |
| 2327 | case PCI_DEVICE_ID_CENTAUR: |
| 2328 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2329 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2331 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2332 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | break; |
| 2334 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2335 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2336 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | break; |
| 2338 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2339 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2340 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | break; |
| 2342 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2343 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2344 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | break; |
| 2346 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2347 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2348 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | break; |
| 2350 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2351 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2352 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | break; |
| 2354 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2355 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2356 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | break; |
| 2358 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2359 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2360 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2362 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2363 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2364 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2365 | break; |
| 2366 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2367 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2368 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2369 | break; |
| 2370 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2371 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2372 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2373 | break; |
| 2374 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2375 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2376 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2377 | break; |
| 2378 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2379 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2380 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2381 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2383 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | break; |
| 2385 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2386 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2387 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | break; |
| 2389 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2390 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2392 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2393 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2394 | break; |
| 2395 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2396 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2397 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2398 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2400 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | break; |
| 2402 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2403 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | break; |
| 2405 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2406 | m = (typeof(m)){"LP101", "PCI-X", |
| 2407 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | break; |
| 2409 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2410 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2411 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2412 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2413 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2414 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2415 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2416 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2417 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2418 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2419 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2420 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2421 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2422 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2423 | break; |
| 2424 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2425 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2426 | break; |
| 2427 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2428 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2429 | break; |
| 2430 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2431 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2432 | break; |
| 2433 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2434 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2435 | break; |
| 2436 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2437 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2438 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2439 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2440 | m = (typeof(m)){"LP21000", "PCIe", |
| 2441 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2442 | GE = 1; |
| 2443 | break; |
| 2444 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2445 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2446 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2447 | break; |
| 2448 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2449 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2450 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2451 | break; |
| 2452 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2453 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2454 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2455 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2456 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2457 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2458 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2459 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2460 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2461 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2462 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2463 | break; |
| 2464 | case PCI_DEVICE_ID_FALCON: |
| 2465 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2466 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2467 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2468 | case PCI_DEVICE_ID_BALIUS: |
| 2469 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2470 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2471 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2472 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2473 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2474 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2475 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2476 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2477 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2478 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2479 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2480 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2481 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2482 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2483 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2484 | oneConnect = 1; |
| 2485 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2486 | "Obsolete, Unsupported FCoE"}; |
| 2487 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2488 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2489 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2490 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2491 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2492 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2493 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2494 | case PCI_DEVICE_ID_SKYHAWK: |
| 2495 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2496 | oneConnect = 1; |
| 2497 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2498 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2499 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2500 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2501 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2503 | |
| 2504 | if (mdp && mdp[0] == '\0') |
| 2505 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2506 | /* |
| 2507 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2508 | * and we put the port number on the end |
| 2509 | */ |
| 2510 | if (descp && descp[0] == '\0') { |
| 2511 | if (oneConnect) |
| 2512 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2513 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2514 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2515 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2516 | else if (max_speed == 0) |
| 2517 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2518 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2519 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2520 | else |
| 2521 | snprintf(descp, 255, |
| 2522 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2523 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2524 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2525 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | } |
| 2527 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2529 | * 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] | 2530 | * @phba: pointer to lpfc hba data structure. |
| 2531 | * @pring: pointer to a IOCB ring. |
| 2532 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2533 | * |
| 2534 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2535 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2536 | * |
| 2537 | * Return codes |
| 2538 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2539 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2541 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | { |
| 2543 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2544 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | struct lpfc_dmabuf *mp1, *mp2; |
| 2546 | |
| 2547 | cnt += pring->missbufcnt; |
| 2548 | |
| 2549 | /* While there are buffers to post */ |
| 2550 | while (cnt > 0) { |
| 2551 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2552 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | if (iocb == NULL) { |
| 2554 | pring->missbufcnt = cnt; |
| 2555 | return cnt; |
| 2556 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2557 | icmd = &iocb->iocb; |
| 2558 | |
| 2559 | /* 2 buffers can be posted per command */ |
| 2560 | /* Allocate buffer to post */ |
| 2561 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2562 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2563 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2564 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2565 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2566 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | pring->missbufcnt = cnt; |
| 2568 | return cnt; |
| 2569 | } |
| 2570 | |
| 2571 | INIT_LIST_HEAD(&mp1->list); |
| 2572 | /* Allocate buffer to post */ |
| 2573 | if (cnt > 1) { |
| 2574 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2575 | if (mp2) |
| 2576 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2577 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2578 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2579 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2581 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2582 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | pring->missbufcnt = cnt; |
| 2584 | return cnt; |
| 2585 | } |
| 2586 | |
| 2587 | INIT_LIST_HEAD(&mp2->list); |
| 2588 | } else { |
| 2589 | mp2 = NULL; |
| 2590 | } |
| 2591 | |
| 2592 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2593 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2594 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2595 | icmd->ulpBdeCount = 1; |
| 2596 | cnt--; |
| 2597 | if (mp2) { |
| 2598 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2599 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2600 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2601 | cnt--; |
| 2602 | icmd->ulpBdeCount = 2; |
| 2603 | } |
| 2604 | |
| 2605 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2606 | icmd->ulpLe = 1; |
| 2607 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2608 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2609 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2611 | kfree(mp1); |
| 2612 | cnt++; |
| 2613 | if (mp2) { |
| 2614 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2615 | kfree(mp2); |
| 2616 | cnt++; |
| 2617 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2618 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | return cnt; |
| 2621 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2623 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | } |
| 2626 | pring->missbufcnt = 0; |
| 2627 | return 0; |
| 2628 | } |
| 2629 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2630 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2631 | * 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] | 2632 | * @phba: pointer to lpfc hba data structure. |
| 2633 | * |
| 2634 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2635 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2636 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2637 | * |
| 2638 | * Return codes |
| 2639 | * 0 - success (currently always success) |
| 2640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | { |
| 2644 | struct lpfc_sli *psli = &phba->sli; |
| 2645 | |
| 2646 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2647 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | /* Ring 2 - FCP no buffers needed */ |
| 2649 | |
| 2650 | return 0; |
| 2651 | } |
| 2652 | |
| 2653 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2654 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2655 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2656 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2657 | * @HashResultPointer: pointer to an array as hash table. |
| 2658 | * |
| 2659 | * This routine sets up the initial values to the array of hash table entries |
| 2660 | * for the LC HBAs. |
| 2661 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | static void |
| 2663 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2664 | { |
| 2665 | HashResultPointer[0] = 0x67452301; |
| 2666 | HashResultPointer[1] = 0xEFCDAB89; |
| 2667 | HashResultPointer[2] = 0x98BADCFE; |
| 2668 | HashResultPointer[3] = 0x10325476; |
| 2669 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2670 | } |
| 2671 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2672 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2673 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2674 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2675 | * @HashWorkingPointer: pointer to an working hash table. |
| 2676 | * |
| 2677 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2678 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2679 | * The results are putting back to the initial hash table, returned through |
| 2680 | * the @HashResultPointer as the result hash table. |
| 2681 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | static void |
| 2683 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2684 | { |
| 2685 | int t; |
| 2686 | uint32_t TEMP; |
| 2687 | uint32_t A, B, C, D, E; |
| 2688 | t = 16; |
| 2689 | do { |
| 2690 | HashWorkingPointer[t] = |
| 2691 | S(1, |
| 2692 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2693 | 8] ^ |
| 2694 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2695 | } while (++t <= 79); |
| 2696 | t = 0; |
| 2697 | A = HashResultPointer[0]; |
| 2698 | B = HashResultPointer[1]; |
| 2699 | C = HashResultPointer[2]; |
| 2700 | D = HashResultPointer[3]; |
| 2701 | E = HashResultPointer[4]; |
| 2702 | |
| 2703 | do { |
| 2704 | if (t < 20) { |
| 2705 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2706 | } else if (t < 40) { |
| 2707 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2708 | } else if (t < 60) { |
| 2709 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2710 | } else { |
| 2711 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2712 | } |
| 2713 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2714 | E = D; |
| 2715 | D = C; |
| 2716 | C = S(30, B); |
| 2717 | B = A; |
| 2718 | A = TEMP; |
| 2719 | } while (++t <= 79); |
| 2720 | |
| 2721 | HashResultPointer[0] += A; |
| 2722 | HashResultPointer[1] += B; |
| 2723 | HashResultPointer[2] += C; |
| 2724 | HashResultPointer[3] += D; |
| 2725 | HashResultPointer[4] += E; |
| 2726 | |
| 2727 | } |
| 2728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2730 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2731 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2732 | * @HashWorking: pointer to the entry of the working hash array. |
| 2733 | * |
| 2734 | * This routine calculates the working hash array referred by @HashWorking |
| 2735 | * from the challenge random numbers associated with the host, referred by |
| 2736 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2737 | * array and returned by reference through @HashWorking. |
| 2738 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | static void |
| 2740 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2741 | { |
| 2742 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2743 | } |
| 2744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2745 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2746 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2747 | * @phba: pointer to lpfc hba data structure. |
| 2748 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2749 | * |
| 2750 | * This routine performs the special handling for LC HBA initialization. |
| 2751 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | void |
| 2753 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2754 | { |
| 2755 | int t; |
| 2756 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2757 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2759 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | if (!HashWorking) |
| 2761 | return; |
| 2762 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2764 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2765 | |
| 2766 | for (t = 0; t < 7; t++) |
| 2767 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2768 | |
| 2769 | lpfc_sha_init(hbainit); |
| 2770 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2771 | kfree(HashWorking); |
| 2772 | } |
| 2773 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2774 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2775 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2776 | * @vport: pointer to a virtual N_Port data structure. |
| 2777 | * |
| 2778 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2779 | * It invokes the discovery state machine to perform necessary state |
| 2780 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2781 | * the physical port is treated as @vport 0. |
| 2782 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2783 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2784 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2786 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2788 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2790 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2791 | lpfc_port_link_failure(vport); |
| 2792 | |
| 2793 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2794 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2795 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2796 | NLP_STE_UNUSED_NODE); |
| 2797 | if (!ndlp) |
| 2798 | continue; |
| 2799 | spin_lock_irq(&phba->ndlp_lock); |
| 2800 | NLP_SET_FREE_REQ(ndlp); |
| 2801 | spin_unlock_irq(&phba->ndlp_lock); |
| 2802 | /* Trigger the release of the ndlp memory */ |
| 2803 | lpfc_nlp_put(ndlp); |
| 2804 | continue; |
| 2805 | } |
| 2806 | spin_lock_irq(&phba->ndlp_lock); |
| 2807 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2808 | /* The ndlp should not be in memory free mode already */ |
| 2809 | spin_unlock_irq(&phba->ndlp_lock); |
| 2810 | continue; |
| 2811 | } else |
| 2812 | /* Indicate request for freeing ndlp memory */ |
| 2813 | NLP_SET_FREE_REQ(ndlp); |
| 2814 | spin_unlock_irq(&phba->ndlp_lock); |
| 2815 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2816 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2817 | ndlp->nlp_DID == Fabric_DID) { |
| 2818 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2819 | lpfc_nlp_put(ndlp); |
| 2820 | continue; |
| 2821 | } |
| 2822 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2823 | /* take care of nodes in unused state before the state |
| 2824 | * machine taking action. |
| 2825 | */ |
| 2826 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2827 | lpfc_nlp_put(ndlp); |
| 2828 | continue; |
| 2829 | } |
| 2830 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2831 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2832 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2833 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2834 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2835 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2836 | NLP_EVT_DEVICE_RM); |
| 2837 | } |
| 2838 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2839 | /* At this point, ALL ndlp's should be gone |
| 2840 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2841 | * Lets wait for this to happen, if needed. |
| 2842 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2843 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2844 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2845 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2846 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2847 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2848 | &vport->fc_nodes, nlp_listp) { |
| 2849 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2850 | LOG_NODE, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2851 | "0282 did:x%x ndlp:x%px " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2852 | "usgmap:x%x refcnt:%d\n", |
| 2853 | ndlp->nlp_DID, (void *)ndlp, |
| 2854 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2855 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2856 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2857 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2858 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2859 | |
| 2860 | /* Wait for any activity on ndlps to settle */ |
| 2861 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2862 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2863 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2864 | } |
| 2865 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2866 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2867 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2868 | * @vport: pointer to a virtual N_Port data structure. |
| 2869 | * |
| 2870 | * This routine stops all the timers associated with a @vport. This function |
| 2871 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2872 | * port is treated as @vport 0. |
| 2873 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2874 | void |
| 2875 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2877 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2878 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2879 | lpfc_can_disctmo(vport); |
| 2880 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | } |
| 2882 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2883 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2884 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2885 | * @phba: pointer to lpfc hba data structure. |
| 2886 | * |
| 2887 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2888 | * caller of this routine should already hold the host lock. |
| 2889 | **/ |
| 2890 | void |
| 2891 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2892 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2893 | /* Clear pending FCF rediscovery wait flag */ |
| 2894 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2895 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2896 | /* Now, try to stop the timer */ |
| 2897 | del_timer(&phba->fcf.redisc_wait); |
| 2898 | } |
| 2899 | |
| 2900 | /** |
| 2901 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2902 | * @phba: pointer to lpfc hba data structure. |
| 2903 | * |
| 2904 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2905 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2906 | * lock held before proceeding with disabling the timer and clearing the |
| 2907 | * wait timer pendig flag. |
| 2908 | **/ |
| 2909 | void |
| 2910 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2911 | { |
| 2912 | spin_lock_irq(&phba->hbalock); |
| 2913 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2914 | /* FCF rediscovery timer already fired or stopped */ |
| 2915 | spin_unlock_irq(&phba->hbalock); |
| 2916 | return; |
| 2917 | } |
| 2918 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2919 | /* Clear failover in progress flags */ |
| 2920 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2921 | spin_unlock_irq(&phba->hbalock); |
| 2922 | } |
| 2923 | |
| 2924 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2925 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2926 | * @phba: pointer to lpfc hba data structure. |
| 2927 | * |
| 2928 | * This routine stops all the timers associated with a HBA. This function is |
| 2929 | * invoked before either putting a HBA offline or unloading the driver. |
| 2930 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2931 | void |
| 2932 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2933 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 2934 | if (phba->pport) |
| 2935 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 2936 | cancel_delayed_work_sync(&phba->eq_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2938 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2939 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2940 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2941 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2942 | del_timer_sync(&phba->rrq_tmr); |
| 2943 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2944 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2945 | phba->hb_outstanding = 0; |
| 2946 | |
| 2947 | switch (phba->pci_dev_grp) { |
| 2948 | case LPFC_PCI_DEV_LP: |
| 2949 | /* Stop any LightPulse device specific driver timers */ |
| 2950 | del_timer_sync(&phba->fcp_poll_timer); |
| 2951 | break; |
| 2952 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 2953 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2954 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2955 | break; |
| 2956 | default: |
| 2957 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2958 | "0297 Invalid device group (x%x)\n", |
| 2959 | phba->pci_dev_grp); |
| 2960 | break; |
| 2961 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2962 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | } |
| 2964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2966 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2967 | * @phba: pointer to lpfc hba data structure. |
| 2968 | * |
| 2969 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2970 | * management interface is marked as blocked, all the user space access to |
| 2971 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2972 | * all be blocked. The HBA is set to block the management interface when the |
| 2973 | * driver prepares the HBA interface for online or offline. |
| 2974 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2975 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2976 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2977 | { |
| 2978 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2979 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2980 | unsigned long timeout; |
| 2981 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2982 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2983 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2984 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2985 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2986 | return; |
| 2987 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2988 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2989 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2990 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2991 | /* Determine how long we might wait for the active mailbox |
| 2992 | * command to be gracefully completed by firmware. |
| 2993 | */ |
| 2994 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2995 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2996 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2997 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2998 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2999 | /* Wait for the outstnading mailbox command to complete */ |
| 3000 | while (phba->sli.mbox_active) { |
| 3001 | /* Check active mailbox complete status every 2ms */ |
| 3002 | msleep(2); |
| 3003 | if (time_after(jiffies, timeout)) { |
| 3004 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3005 | "2813 Mgmt IO is Blocked %x " |
| 3006 | "- mbox cmd %x still active\n", |
| 3007 | phba->sli.sli_flag, actcmd); |
| 3008 | break; |
| 3009 | } |
| 3010 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3013 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3014 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3015 | * @phba: pointer to lpfc hba data structure. |
| 3016 | * |
| 3017 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3018 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3019 | * is to fixup the temporary rpi assignments. |
| 3020 | **/ |
| 3021 | void |
| 3022 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3023 | { |
| 3024 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3025 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3026 | int i, rpi; |
| 3027 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3028 | |
| 3029 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3030 | return; |
| 3031 | |
| 3032 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3033 | if (vports == NULL) |
| 3034 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3035 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3036 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3037 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3038 | continue; |
| 3039 | |
| 3040 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3041 | &vports[i]->fc_nodes, |
| 3042 | nlp_listp) { |
| 3043 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3044 | continue; |
| 3045 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3046 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3047 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3048 | NLP_CLR_NODE_ACT(ndlp); |
| 3049 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3050 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3051 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3052 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3053 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3054 | LOG_NODE | LOG_DISCOVERY, |
| 3055 | "0009 Assign RPI x%x to ndlp x%px " |
| 3056 | "DID:x%06x flg:x%x map:x%x\n", |
| 3057 | ndlp->nlp_rpi, ndlp, ndlp->nlp_DID, |
| 3058 | ndlp->nlp_flag, ndlp->nlp_usg_map); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | lpfc_destroy_vport_work_array(phba, vports); |
| 3062 | } |
| 3063 | |
| 3064 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3065 | * lpfc_create_expedite_pool - create expedite pool |
| 3066 | * @phba: pointer to lpfc hba data structure. |
| 3067 | * |
| 3068 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3069 | * to expedite pool. Mark them as expedite. |
| 3070 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3071 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3072 | { |
| 3073 | struct lpfc_sli4_hdw_queue *qp; |
| 3074 | struct lpfc_io_buf *lpfc_ncmd; |
| 3075 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3076 | struct lpfc_epd_pool *epd_pool; |
| 3077 | unsigned long iflag; |
| 3078 | |
| 3079 | epd_pool = &phba->epd_pool; |
| 3080 | qp = &phba->sli4_hba.hdwq[0]; |
| 3081 | |
| 3082 | spin_lock_init(&epd_pool->lock); |
| 3083 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3084 | spin_lock(&epd_pool->lock); |
| 3085 | INIT_LIST_HEAD(&epd_pool->list); |
| 3086 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3087 | &qp->lpfc_io_buf_list_put, list) { |
| 3088 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3089 | lpfc_ncmd->expedite = true; |
| 3090 | qp->put_io_bufs--; |
| 3091 | epd_pool->count++; |
| 3092 | if (epd_pool->count >= XRI_BATCH) |
| 3093 | break; |
| 3094 | } |
| 3095 | spin_unlock(&epd_pool->lock); |
| 3096 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3097 | } |
| 3098 | |
| 3099 | /** |
| 3100 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3101 | * @phba: pointer to lpfc hba data structure. |
| 3102 | * |
| 3103 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3104 | * of HWQ 0. Clear the mark. |
| 3105 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3106 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3107 | { |
| 3108 | struct lpfc_sli4_hdw_queue *qp; |
| 3109 | struct lpfc_io_buf *lpfc_ncmd; |
| 3110 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3111 | struct lpfc_epd_pool *epd_pool; |
| 3112 | unsigned long iflag; |
| 3113 | |
| 3114 | epd_pool = &phba->epd_pool; |
| 3115 | qp = &phba->sli4_hba.hdwq[0]; |
| 3116 | |
| 3117 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3118 | spin_lock(&epd_pool->lock); |
| 3119 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3120 | &epd_pool->list, list) { |
| 3121 | list_move_tail(&lpfc_ncmd->list, |
| 3122 | &qp->lpfc_io_buf_list_put); |
| 3123 | lpfc_ncmd->flags = false; |
| 3124 | qp->put_io_bufs++; |
| 3125 | epd_pool->count--; |
| 3126 | } |
| 3127 | spin_unlock(&epd_pool->lock); |
| 3128 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3129 | } |
| 3130 | |
| 3131 | /** |
| 3132 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3133 | * @phba: pointer to lpfc hba data structure. |
| 3134 | * |
| 3135 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3136 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3137 | * Initialized. |
| 3138 | **/ |
| 3139 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3140 | { |
| 3141 | u32 i, j; |
| 3142 | u32 hwq_count; |
| 3143 | u32 count_per_hwq; |
| 3144 | struct lpfc_io_buf *lpfc_ncmd; |
| 3145 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3146 | unsigned long iflag; |
| 3147 | struct lpfc_sli4_hdw_queue *qp; |
| 3148 | struct lpfc_multixri_pool *multixri_pool; |
| 3149 | struct lpfc_pbl_pool *pbl_pool; |
| 3150 | struct lpfc_pvt_pool *pvt_pool; |
| 3151 | |
| 3152 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3153 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3154 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3155 | phba->sli4_hba.io_xri_cnt); |
| 3156 | |
| 3157 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3158 | lpfc_create_expedite_pool(phba); |
| 3159 | |
| 3160 | hwq_count = phba->cfg_hdw_queue; |
| 3161 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3162 | |
| 3163 | for (i = 0; i < hwq_count; i++) { |
| 3164 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3165 | |
| 3166 | if (!multixri_pool) { |
| 3167 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3168 | "1238 Failed to allocate memory for " |
| 3169 | "multixri_pool\n"); |
| 3170 | |
| 3171 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3172 | lpfc_destroy_expedite_pool(phba); |
| 3173 | |
| 3174 | j = 0; |
| 3175 | while (j < i) { |
| 3176 | qp = &phba->sli4_hba.hdwq[j]; |
| 3177 | kfree(qp->p_multixri_pool); |
| 3178 | j++; |
| 3179 | } |
| 3180 | phba->cfg_xri_rebalancing = 0; |
| 3181 | return; |
| 3182 | } |
| 3183 | |
| 3184 | qp = &phba->sli4_hba.hdwq[i]; |
| 3185 | qp->p_multixri_pool = multixri_pool; |
| 3186 | |
| 3187 | multixri_pool->xri_limit = count_per_hwq; |
| 3188 | multixri_pool->rrb_next_hwqid = i; |
| 3189 | |
| 3190 | /* Deal with public free xri pool */ |
| 3191 | pbl_pool = &multixri_pool->pbl_pool; |
| 3192 | spin_lock_init(&pbl_pool->lock); |
| 3193 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3194 | spin_lock(&pbl_pool->lock); |
| 3195 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3196 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3197 | &qp->lpfc_io_buf_list_put, list) { |
| 3198 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3199 | qp->put_io_bufs--; |
| 3200 | pbl_pool->count++; |
| 3201 | } |
| 3202 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3203 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3204 | pbl_pool->count, i); |
| 3205 | spin_unlock(&pbl_pool->lock); |
| 3206 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3207 | |
| 3208 | /* Deal with private free xri pool */ |
| 3209 | pvt_pool = &multixri_pool->pvt_pool; |
| 3210 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3211 | pvt_pool->low_watermark = XRI_BATCH; |
| 3212 | spin_lock_init(&pvt_pool->lock); |
| 3213 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3214 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3215 | pvt_pool->count = 0; |
| 3216 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | /** |
| 3221 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3222 | * @phba: pointer to lpfc hba data structure. |
| 3223 | * |
| 3224 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3225 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3226 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3227 | { |
| 3228 | u32 i; |
| 3229 | u32 hwq_count; |
| 3230 | struct lpfc_io_buf *lpfc_ncmd; |
| 3231 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3232 | unsigned long iflag; |
| 3233 | struct lpfc_sli4_hdw_queue *qp; |
| 3234 | struct lpfc_multixri_pool *multixri_pool; |
| 3235 | struct lpfc_pbl_pool *pbl_pool; |
| 3236 | struct lpfc_pvt_pool *pvt_pool; |
| 3237 | |
| 3238 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3239 | lpfc_destroy_expedite_pool(phba); |
| 3240 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3241 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3242 | lpfc_sli_flush_io_rings(phba); |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3243 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3244 | hwq_count = phba->cfg_hdw_queue; |
| 3245 | |
| 3246 | for (i = 0; i < hwq_count; i++) { |
| 3247 | qp = &phba->sli4_hba.hdwq[i]; |
| 3248 | multixri_pool = qp->p_multixri_pool; |
| 3249 | if (!multixri_pool) |
| 3250 | continue; |
| 3251 | |
| 3252 | qp->p_multixri_pool = NULL; |
| 3253 | |
| 3254 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3255 | |
| 3256 | /* Deal with public free xri pool */ |
| 3257 | pbl_pool = &multixri_pool->pbl_pool; |
| 3258 | spin_lock(&pbl_pool->lock); |
| 3259 | |
| 3260 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3261 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3262 | pbl_pool->count, i); |
| 3263 | |
| 3264 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3265 | &pbl_pool->list, list) { |
| 3266 | list_move_tail(&lpfc_ncmd->list, |
| 3267 | &qp->lpfc_io_buf_list_put); |
| 3268 | qp->put_io_bufs++; |
| 3269 | pbl_pool->count--; |
| 3270 | } |
| 3271 | |
| 3272 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3273 | pbl_pool->count = 0; |
| 3274 | |
| 3275 | spin_unlock(&pbl_pool->lock); |
| 3276 | |
| 3277 | /* Deal with private free xri pool */ |
| 3278 | pvt_pool = &multixri_pool->pvt_pool; |
| 3279 | spin_lock(&pvt_pool->lock); |
| 3280 | |
| 3281 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3282 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3283 | pvt_pool->count, i); |
| 3284 | |
| 3285 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3286 | &pvt_pool->list, list) { |
| 3287 | list_move_tail(&lpfc_ncmd->list, |
| 3288 | &qp->lpfc_io_buf_list_put); |
| 3289 | qp->put_io_bufs++; |
| 3290 | pvt_pool->count--; |
| 3291 | } |
| 3292 | |
| 3293 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3294 | pvt_pool->count = 0; |
| 3295 | |
| 3296 | spin_unlock(&pvt_pool->lock); |
| 3297 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3298 | |
| 3299 | kfree(multixri_pool); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3304 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3305 | * @phba: pointer to lpfc hba data structure. |
| 3306 | * |
| 3307 | * This routine initializes the HBA and brings a HBA online. During this |
| 3308 | * process, the management interface is blocked to prevent user space access |
| 3309 | * to the HBA interfering with the driver initialization. |
| 3310 | * |
| 3311 | * Return codes |
| 3312 | * 0 - successful |
| 3313 | * 1 - failed |
| 3314 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3315 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3316 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3318 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3319 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3320 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3321 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3322 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | if (!phba) |
| 3324 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3325 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3326 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3327 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | return 0; |
| 3329 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3330 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3331 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3333 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3335 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3336 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3337 | lpfc_unblock_mgmt_io(phba); |
| 3338 | return 1; |
| 3339 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3340 | spin_lock_irq(&phba->hbalock); |
| 3341 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3342 | vpis_cleared = true; |
| 3343 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3344 | |
| 3345 | /* Reestablish the local initiator port. |
| 3346 | * The offline process destroyed the previous lport. |
| 3347 | */ |
| 3348 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3349 | !phba->nvmet_support) { |
| 3350 | error = lpfc_nvme_create_localport(phba->pport); |
| 3351 | if (error) |
| 3352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3353 | "6132 NVME restore reg failed " |
| 3354 | "on nvmei error x%x\n", error); |
| 3355 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3356 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3357 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3358 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3359 | lpfc_unblock_mgmt_io(phba); |
| 3360 | return 1; |
| 3361 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3362 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3364 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3365 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3366 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3367 | struct Scsi_Host *shost; |
| 3368 | shost = lpfc_shost_from_vport(vports[i]); |
| 3369 | spin_lock_irq(shost->host_lock); |
| 3370 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3371 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3372 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3373 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3374 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3375 | if ((vpis_cleared) && |
| 3376 | (vports[i]->port_type != |
| 3377 | LPFC_PHYSICAL_PORT)) |
| 3378 | vports[i]->vpi = 0; |
| 3379 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3380 | spin_unlock_irq(shost->host_lock); |
| 3381 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3382 | } |
| 3383 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3385 | if (phba->cfg_xri_rebalancing) |
| 3386 | lpfc_create_multixri_pools(phba); |
| 3387 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3388 | lpfc_cpuhp_add(phba); |
| 3389 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3390 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | return 0; |
| 3392 | } |
| 3393 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3394 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3395 | * 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] | 3396 | * @phba: pointer to lpfc hba data structure. |
| 3397 | * |
| 3398 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3399 | * HBA's management interface is marked as not blocked, all the user space |
| 3400 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3401 | * interface will be allowed. The HBA is set to block the management interface |
| 3402 | * when the driver prepares the HBA interface for online or offline and then |
| 3403 | * set to unblock the management interface afterwards. |
| 3404 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3405 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3406 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3407 | { |
| 3408 | unsigned long iflag; |
| 3409 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3411 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3412 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3413 | } |
| 3414 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3415 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3416 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3417 | * @phba: pointer to lpfc hba data structure. |
| 3418 | * |
| 3419 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3420 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3421 | * queue to make it ready to be brought offline. |
| 3422 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3423 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3424 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3425 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3426 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3427 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3428 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3429 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3430 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3432 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3433 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3434 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3435 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3436 | |
| 3437 | lpfc_linkdown(phba); |
| 3438 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3439 | /* Issue an unreg_login to all nodes on all vports */ |
| 3440 | vports = lpfc_create_vport_work_array(phba); |
| 3441 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3442 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3443 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3444 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3445 | shost = lpfc_shost_from_vport(vports[i]); |
| 3446 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3447 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3448 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3449 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3450 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3451 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3452 | shost = lpfc_shost_from_vport(vports[i]); |
| 3453 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3454 | &vports[i]->fc_nodes, |
| 3455 | nlp_listp) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3456 | if ((!NLP_CHK_NODE_ACT(ndlp)) || |
| 3457 | ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 3458 | /* Driver must assume RPI is invalid for |
| 3459 | * any unused or inactive node. |
| 3460 | */ |
| 3461 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3462 | continue; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3465 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3466 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3467 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3468 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3469 | NULL, NLP_EVT_DEVICE_RM); |
| 3470 | } |
| 3471 | spin_lock_irq(shost->host_lock); |
| 3472 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3473 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3474 | /* |
| 3475 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3476 | * RPI. Get a new RPI when the adapter port |
| 3477 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3478 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3479 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3480 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3481 | LOG_NODE | LOG_DISCOVERY, |
| 3482 | "0011 Free RPI x%x on " |
| 3483 | "ndlp:x%px did x%x " |
| 3484 | "usgmap:x%x\n", |
| 3485 | ndlp->nlp_rpi, ndlp, |
| 3486 | ndlp->nlp_DID, |
| 3487 | ndlp->nlp_usg_map); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3488 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3489 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3490 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3491 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3492 | } |
| 3493 | } |
| 3494 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3495 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3497 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3498 | |
| 3499 | if (phba->wq) |
| 3500 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3501 | } |
| 3502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3503 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3504 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3505 | * @phba: pointer to lpfc hba data structure. |
| 3506 | * |
| 3507 | * This routine actually brings a HBA offline. It stops all the timers |
| 3508 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3509 | * marks the HBA as in offline state for the upper layer protocol. |
| 3510 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3511 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3512 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3513 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3514 | struct Scsi_Host *shost; |
| 3515 | struct lpfc_vport **vports; |
| 3516 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3517 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3518 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3519 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3520 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3521 | /* stop port and all timers associated with this hba */ |
| 3522 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3523 | |
| 3524 | /* Tear down the local and target port registrations. The |
| 3525 | * nvme transports need to cleanup. |
| 3526 | */ |
| 3527 | lpfc_nvmet_destroy_targetport(phba); |
| 3528 | lpfc_nvme_destroy_localport(phba->pport); |
| 3529 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3530 | vports = lpfc_create_vport_work_array(phba); |
| 3531 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3532 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3533 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3534 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3535 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3536 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3538 | now. */ |
| 3539 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3540 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3541 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3542 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3543 | vports = lpfc_create_vport_work_array(phba); |
| 3544 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3545 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3546 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3547 | spin_lock_irq(shost->host_lock); |
| 3548 | vports[i]->work_port_events = 0; |
| 3549 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3550 | spin_unlock_irq(shost->host_lock); |
| 3551 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3552 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3553 | __lpfc_cpuhp_remove(phba); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3554 | |
| 3555 | if (phba->cfg_xri_rebalancing) |
| 3556 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3557 | } |
| 3558 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3559 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3560 | * 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] | 3561 | * @phba: pointer to lpfc hba data structure. |
| 3562 | * |
| 3563 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3564 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3565 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3566 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3567 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3568 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3569 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3570 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3571 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3572 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3573 | return; |
| 3574 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3575 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3576 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3577 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3578 | |
| 3579 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3580 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3581 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3583 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3584 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3585 | kfree(sb); |
| 3586 | phba->total_scsi_bufs--; |
| 3587 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3588 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3589 | |
| 3590 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3591 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3592 | list) { |
| 3593 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3594 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3595 | sb->dma_handle); |
| 3596 | kfree(sb); |
| 3597 | phba->total_scsi_bufs--; |
| 3598 | } |
| 3599 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3600 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3601 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3602 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3603 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3604 | * 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] | 3605 | * @phba: pointer to lpfc hba data structure. |
| 3606 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3607 | * 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] | 3608 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3609 | * the internal resources before the device is removed from the system. |
| 3610 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3611 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3612 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3613 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3614 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3615 | struct lpfc_sli4_hdw_queue *qp; |
| 3616 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3617 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3618 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3619 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3620 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3621 | spin_lock(&qp->io_buf_list_put_lock); |
| 3622 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3623 | &qp->lpfc_io_buf_list_put, |
| 3624 | list) { |
| 3625 | list_del(&lpfc_ncmd->list); |
| 3626 | qp->put_io_bufs--; |
| 3627 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3628 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3629 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3630 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3631 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3632 | kfree(lpfc_ncmd); |
| 3633 | qp->total_io_bufs--; |
| 3634 | } |
| 3635 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3636 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3637 | spin_lock(&qp->io_buf_list_get_lock); |
| 3638 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3639 | &qp->lpfc_io_buf_list_get, |
| 3640 | list) { |
| 3641 | list_del(&lpfc_ncmd->list); |
| 3642 | qp->get_io_bufs--; |
| 3643 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3644 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3645 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3646 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3647 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3648 | kfree(lpfc_ncmd); |
| 3649 | qp->total_io_bufs--; |
| 3650 | } |
| 3651 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3652 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3653 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3654 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3655 | /** |
| 3656 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3657 | * @phba: pointer to lpfc hba data structure. |
| 3658 | * |
| 3659 | * This routine first calculates the sizes of the current els and allocated |
| 3660 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3661 | * XRIs assigned due to port function reset. During port initialization, the |
| 3662 | * current els and allocated scsi sgl lists are 0s. |
| 3663 | * |
| 3664 | * Return codes |
| 3665 | * 0 - successful (for now, it always returns 0) |
| 3666 | **/ |
| 3667 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3668 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3669 | { |
| 3670 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3671 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3672 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3673 | int rc; |
| 3674 | |
| 3675 | /* |
| 3676 | * update on pci function's els xri-sgl list |
| 3677 | */ |
| 3678 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3679 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3680 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3681 | /* els xri-sgl expanded */ |
| 3682 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3683 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3684 | "3157 ELS xri-sgl count increased from " |
| 3685 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3686 | els_xri_cnt); |
| 3687 | /* allocate the additional els sgls */ |
| 3688 | for (i = 0; i < xri_cnt; i++) { |
| 3689 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3690 | GFP_KERNEL); |
| 3691 | if (sglq_entry == NULL) { |
| 3692 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3693 | "2562 Failure to allocate an " |
| 3694 | "ELS sgl entry:%d\n", i); |
| 3695 | rc = -ENOMEM; |
| 3696 | goto out_free_mem; |
| 3697 | } |
| 3698 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3699 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3700 | &sglq_entry->phys); |
| 3701 | if (sglq_entry->virt == NULL) { |
| 3702 | kfree(sglq_entry); |
| 3703 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3704 | "2563 Failure to allocate an " |
| 3705 | "ELS mbuf:%d\n", i); |
| 3706 | rc = -ENOMEM; |
| 3707 | goto out_free_mem; |
| 3708 | } |
| 3709 | sglq_entry->sgl = sglq_entry->virt; |
| 3710 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3711 | sglq_entry->state = SGL_FREED; |
| 3712 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3713 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3714 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3715 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3716 | list_splice_init(&els_sgl_list, |
| 3717 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3718 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3719 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3720 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3721 | /* els xri-sgl shrinked */ |
| 3722 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3723 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3724 | "3158 ELS xri-sgl count decreased from " |
| 3725 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3726 | els_xri_cnt); |
| 3727 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3728 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3729 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3730 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3731 | /* release extra els sgls from list */ |
| 3732 | for (i = 0; i < xri_cnt; i++) { |
| 3733 | list_remove_head(&els_sgl_list, |
| 3734 | sglq_entry, struct lpfc_sglq, list); |
| 3735 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3736 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3737 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3738 | kfree(sglq_entry); |
| 3739 | } |
| 3740 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3741 | list_splice_init(&els_sgl_list, |
| 3742 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3743 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3744 | spin_unlock_irq(&phba->hbalock); |
| 3745 | } else |
| 3746 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3747 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3748 | els_xri_cnt); |
| 3749 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3750 | |
| 3751 | /* update xris to els sgls on the list */ |
| 3752 | sglq_entry = NULL; |
| 3753 | sglq_entry_next = NULL; |
| 3754 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3755 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3756 | lxri = lpfc_sli4_next_xritag(phba); |
| 3757 | if (lxri == NO_XRI) { |
| 3758 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3759 | "2400 Failed to allocate xri for " |
| 3760 | "ELS sgl\n"); |
| 3761 | rc = -ENOMEM; |
| 3762 | goto out_free_mem; |
| 3763 | } |
| 3764 | sglq_entry->sli4_lxritag = lxri; |
| 3765 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3766 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3767 | return 0; |
| 3768 | |
| 3769 | out_free_mem: |
| 3770 | lpfc_free_els_sgl_list(phba); |
| 3771 | return rc; |
| 3772 | } |
| 3773 | |
| 3774 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3775 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3776 | * @phba: pointer to lpfc hba data structure. |
| 3777 | * |
| 3778 | * This routine first calculates the sizes of the current els and allocated |
| 3779 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3780 | * XRIs assigned due to port function reset. During port initialization, the |
| 3781 | * current els and allocated scsi sgl lists are 0s. |
| 3782 | * |
| 3783 | * Return codes |
| 3784 | * 0 - successful (for now, it always returns 0) |
| 3785 | **/ |
| 3786 | int |
| 3787 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3788 | { |
| 3789 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3790 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3791 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3792 | LIST_HEAD(nvmet_sgl_list); |
| 3793 | int rc; |
| 3794 | |
| 3795 | /* |
| 3796 | * update on pci function's nvmet xri-sgl list |
| 3797 | */ |
| 3798 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3799 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3800 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3801 | 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] | 3802 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3803 | /* els xri-sgl expanded */ |
| 3804 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3805 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3806 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3807 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3808 | /* allocate the additional nvmet sgls */ |
| 3809 | for (i = 0; i < xri_cnt; i++) { |
| 3810 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3811 | GFP_KERNEL); |
| 3812 | if (sglq_entry == NULL) { |
| 3813 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3814 | "6303 Failure to allocate an " |
| 3815 | "NVMET sgl entry:%d\n", i); |
| 3816 | rc = -ENOMEM; |
| 3817 | goto out_free_mem; |
| 3818 | } |
| 3819 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3820 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3821 | &sglq_entry->phys); |
| 3822 | if (sglq_entry->virt == NULL) { |
| 3823 | kfree(sglq_entry); |
| 3824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3825 | "6304 Failure to allocate an " |
| 3826 | "NVMET buf:%d\n", i); |
| 3827 | rc = -ENOMEM; |
| 3828 | goto out_free_mem; |
| 3829 | } |
| 3830 | sglq_entry->sgl = sglq_entry->virt; |
| 3831 | memset(sglq_entry->sgl, 0, |
| 3832 | phba->cfg_sg_dma_buf_size); |
| 3833 | sglq_entry->state = SGL_FREED; |
| 3834 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3835 | } |
| 3836 | spin_lock_irq(&phba->hbalock); |
| 3837 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3838 | list_splice_init(&nvmet_sgl_list, |
| 3839 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3840 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3841 | spin_unlock_irq(&phba->hbalock); |
| 3842 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3843 | /* nvmet xri-sgl shrunk */ |
| 3844 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3845 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3846 | "6305 NVMET xri-sgl count decreased from " |
| 3847 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3848 | nvmet_xri_cnt); |
| 3849 | spin_lock_irq(&phba->hbalock); |
| 3850 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3851 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3852 | &nvmet_sgl_list); |
| 3853 | /* release extra nvmet sgls from list */ |
| 3854 | for (i = 0; i < xri_cnt; i++) { |
| 3855 | list_remove_head(&nvmet_sgl_list, |
| 3856 | sglq_entry, struct lpfc_sglq, list); |
| 3857 | if (sglq_entry) { |
| 3858 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3859 | sglq_entry->phys); |
| 3860 | kfree(sglq_entry); |
| 3861 | } |
| 3862 | } |
| 3863 | list_splice_init(&nvmet_sgl_list, |
| 3864 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3865 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3866 | spin_unlock_irq(&phba->hbalock); |
| 3867 | } else |
| 3868 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3869 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3870 | nvmet_xri_cnt); |
| 3871 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3872 | |
| 3873 | /* update xris to nvmet sgls on the list */ |
| 3874 | sglq_entry = NULL; |
| 3875 | sglq_entry_next = NULL; |
| 3876 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3877 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3878 | lxri = lpfc_sli4_next_xritag(phba); |
| 3879 | if (lxri == NO_XRI) { |
| 3880 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3881 | "6307 Failed to allocate xri for " |
| 3882 | "NVMET sgl\n"); |
| 3883 | rc = -ENOMEM; |
| 3884 | goto out_free_mem; |
| 3885 | } |
| 3886 | sglq_entry->sli4_lxritag = lxri; |
| 3887 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3888 | } |
| 3889 | return 0; |
| 3890 | |
| 3891 | out_free_mem: |
| 3892 | lpfc_free_nvmet_sgl_list(phba); |
| 3893 | return rc; |
| 3894 | } |
| 3895 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3896 | int |
| 3897 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3898 | { |
| 3899 | LIST_HEAD(blist); |
| 3900 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3901 | struct lpfc_io_buf *lpfc_cmd; |
| 3902 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3903 | int idx, cnt, xri, inserted; |
| 3904 | |
| 3905 | cnt = 0; |
| 3906 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3907 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3908 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 3909 | spin_lock(&qp->io_buf_list_put_lock); |
| 3910 | |
| 3911 | /* Take everything off the get and put lists */ |
| 3912 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 3913 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 3914 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 3915 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 3916 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 3917 | qp->get_io_bufs = 0; |
| 3918 | qp->put_io_bufs = 0; |
| 3919 | qp->total_io_bufs = 0; |
| 3920 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3921 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 3922 | } |
| 3923 | |
| 3924 | /* |
| 3925 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 3926 | * This is because POST_SGL takes a sequential range of XRIs |
| 3927 | * to post to the firmware. |
| 3928 | */ |
| 3929 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3930 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3931 | if (!lpfc_cmd) |
| 3932 | return cnt; |
| 3933 | if (idx == 0) { |
| 3934 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3935 | continue; |
| 3936 | } |
| 3937 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 3938 | inserted = 0; |
| 3939 | prev_iobufp = NULL; |
| 3940 | list_for_each_entry(iobufp, cbuf, list) { |
| 3941 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 3942 | if (prev_iobufp) |
| 3943 | list_add(&lpfc_cmd->list, |
| 3944 | &prev_iobufp->list); |
| 3945 | else |
| 3946 | list_add(&lpfc_cmd->list, cbuf); |
| 3947 | inserted = 1; |
| 3948 | break; |
| 3949 | } |
| 3950 | prev_iobufp = iobufp; |
| 3951 | } |
| 3952 | if (!inserted) |
| 3953 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3954 | } |
| 3955 | return cnt; |
| 3956 | } |
| 3957 | |
| 3958 | int |
| 3959 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3960 | { |
| 3961 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3962 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3963 | int idx, cnt; |
| 3964 | |
| 3965 | qp = phba->sli4_hba.hdwq; |
| 3966 | cnt = 0; |
| 3967 | while (!list_empty(cbuf)) { |
| 3968 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3969 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3970 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3971 | if (!lpfc_cmd) |
| 3972 | return cnt; |
| 3973 | cnt++; |
| 3974 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 3975 | lpfc_cmd->hdwq_no = idx; |
| 3976 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3977 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 3978 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 3979 | spin_lock(&qp->io_buf_list_put_lock); |
| 3980 | list_add_tail(&lpfc_cmd->list, |
| 3981 | &qp->lpfc_io_buf_list_put); |
| 3982 | qp->put_io_bufs++; |
| 3983 | qp->total_io_bufs++; |
| 3984 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3985 | } |
| 3986 | } |
| 3987 | return cnt; |
| 3988 | } |
| 3989 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3990 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3991 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3992 | * @phba: pointer to lpfc hba data structure. |
| 3993 | * |
| 3994 | * This routine first calculates the sizes of the current els and allocated |
| 3995 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3996 | * XRIs assigned due to port function reset. During port initialization, the |
| 3997 | * current els and allocated scsi sgl lists are 0s. |
| 3998 | * |
| 3999 | * Return codes |
| 4000 | * 0 - successful (for now, it always returns 0) |
| 4001 | **/ |
| 4002 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4003 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4004 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4005 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4006 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4007 | uint16_t io_xri_cnt, io_xri_max; |
| 4008 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4009 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4010 | |
| 4011 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4012 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4013 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4014 | |
| 4015 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4016 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4017 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4018 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4019 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4020 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4021 | "6074 Current allocated XRI sgl count:%d, " |
| 4022 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4023 | phba->sli4_hba.io_xri_cnt, |
| 4024 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4025 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4026 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4027 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4028 | 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] | 4029 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4030 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4031 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4032 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4033 | for (i = 0; i < io_xri_cnt; i++) { |
| 4034 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4035 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4036 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4037 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4038 | lpfc_ncmd->data, |
| 4039 | lpfc_ncmd->dma_handle); |
| 4040 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4041 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4042 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4043 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4044 | } |
| 4045 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4046 | /* update xris associated to remaining allocated nvme buffers */ |
| 4047 | lpfc_ncmd = NULL; |
| 4048 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4049 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4050 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4051 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4052 | lxri = lpfc_sli4_next_xritag(phba); |
| 4053 | if (lxri == NO_XRI) { |
| 4054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4055 | "6075 Failed to allocate xri for " |
| 4056 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4057 | rc = -ENOMEM; |
| 4058 | goto out_free_mem; |
| 4059 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4060 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4061 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4062 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4063 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4064 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4065 | |
| 4066 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4067 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4068 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | } |
| 4070 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4071 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4072 | * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4073 | * @vport: The virtual port for which this call being executed. |
| 4074 | * @num_to_allocate: The requested number of buffers to allocate. |
| 4075 | * |
| 4076 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4077 | * the nvme buffer contains all the necessary information needed to initiate |
| 4078 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4079 | * them on a list, it post them to the port by using SGL block post. |
| 4080 | * |
| 4081 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4082 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4083 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4084 | **/ |
| 4085 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4086 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4087 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4088 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4089 | struct lpfc_iocbq *pwqeq; |
| 4090 | uint16_t iotag, lxri = 0; |
| 4091 | int bcnt, num_posted; |
| 4092 | LIST_HEAD(prep_nblist); |
| 4093 | LIST_HEAD(post_nblist); |
| 4094 | LIST_HEAD(nvme_nblist); |
| 4095 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4096 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4097 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | 7f9989b | 2019-08-27 14:27:46 -0700 | [diff] [blame] | 4098 | lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4099 | if (!lpfc_ncmd) |
| 4100 | break; |
| 4101 | /* |
| 4102 | * Get memory from the pci pool to map the virt space to |
| 4103 | * pci bus space for an I/O. The DMA buffer includes the |
| 4104 | * number of SGE's necessary to support the sg_tablesize. |
| 4105 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4106 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4107 | GFP_KERNEL, |
| 4108 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4109 | if (!lpfc_ncmd->data) { |
| 4110 | kfree(lpfc_ncmd); |
| 4111 | break; |
| 4112 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4113 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4114 | if (phba->cfg_xpsgl && !phba->nvmet_support) { |
| 4115 | INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list); |
| 4116 | } else { |
| 4117 | /* |
| 4118 | * 4K Page alignment is CRITICAL to BlockGuard, double |
| 4119 | * check to be sure. |
| 4120 | */ |
| 4121 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4122 | (((unsigned long)(lpfc_ncmd->data) & |
| 4123 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
| 4124 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 4125 | "3369 Memory alignment err: " |
| 4126 | "addr=%lx\n", |
| 4127 | (unsigned long)lpfc_ncmd->data); |
| 4128 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4129 | lpfc_ncmd->data, |
| 4130 | lpfc_ncmd->dma_handle); |
| 4131 | kfree(lpfc_ncmd); |
| 4132 | break; |
| 4133 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4134 | } |
| 4135 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4136 | INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list); |
| 4137 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4138 | lxri = lpfc_sli4_next_xritag(phba); |
| 4139 | if (lxri == NO_XRI) { |
| 4140 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4141 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4142 | kfree(lpfc_ncmd); |
| 4143 | break; |
| 4144 | } |
| 4145 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4146 | |
| 4147 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4148 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4149 | if (iotag == 0) { |
| 4150 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4151 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4152 | kfree(lpfc_ncmd); |
| 4153 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, |
| 4154 | "6121 Failed to allocate IOTAG for" |
| 4155 | " XRI:0x%x\n", lxri); |
| 4156 | lpfc_sli4_free_xri(phba, lxri); |
| 4157 | break; |
| 4158 | } |
| 4159 | pwqeq->sli4_lxritag = lxri; |
| 4160 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4161 | pwqeq->context1 = lpfc_ncmd; |
| 4162 | |
| 4163 | /* Initialize local short-hand pointers. */ |
| 4164 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4165 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4166 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4167 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4168 | |
| 4169 | /* add the nvme buffer to a post list */ |
| 4170 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4171 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4172 | } |
| 4173 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4174 | "6114 Allocate %d out of %d requested new NVME " |
| 4175 | "buffers\n", bcnt, num_to_alloc); |
| 4176 | |
| 4177 | /* post the list of nvme buffer sgls to port if available */ |
| 4178 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4179 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4180 | phba, &post_nblist, bcnt); |
| 4181 | else |
| 4182 | num_posted = 0; |
| 4183 | |
| 4184 | return num_posted; |
| 4185 | } |
| 4186 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4187 | static uint64_t |
| 4188 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4189 | { |
| 4190 | uint64_t wwn; |
| 4191 | int rc; |
| 4192 | LPFC_MBOXQ_t *mboxq; |
| 4193 | MAILBOX_t *mb; |
| 4194 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4195 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4196 | GFP_KERNEL); |
| 4197 | if (!mboxq) |
| 4198 | return (uint64_t)-1; |
| 4199 | |
| 4200 | /* First get WWN of HBA instance */ |
| 4201 | lpfc_read_nv(phba, mboxq); |
| 4202 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4203 | if (rc != MBX_SUCCESS) { |
| 4204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4205 | "6019 Mailbox failed , mbxCmd x%x " |
| 4206 | "READ_NV, mbxStatus x%x\n", |
| 4207 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4208 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4209 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4210 | return (uint64_t) -1; |
| 4211 | } |
| 4212 | mb = &mboxq->u.mb; |
| 4213 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4214 | /* wwn is WWPN of HBA instance */ |
| 4215 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4216 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4217 | return be64_to_cpu(wwn); |
| 4218 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4219 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4223 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4224 | * @phba: pointer to lpfc hba data structure. |
| 4225 | * @instance: a unique integer ID to this FC port. |
| 4226 | * @dev: pointer to the device data structure. |
| 4227 | * |
| 4228 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4229 | * can be created on top of either a physical port or a virtual port provided |
| 4230 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4231 | * and associates the FC port created before adding the shost into the SCSI |
| 4232 | * layer. |
| 4233 | * |
| 4234 | * Return codes |
| 4235 | * @vport - pointer to the virtual N_Port data structure. |
| 4236 | * NULL - port create failed. |
| 4237 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4238 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4239 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4240 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4241 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4242 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4244 | int i; |
| 4245 | uint64_t wwn; |
| 4246 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4247 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4248 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4249 | if (lpfc_no_hba_reset_cnt) { |
| 4250 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4251 | dev == &phba->pcidev->dev) { |
| 4252 | /* Reset the port first */ |
| 4253 | lpfc_sli_brdrestart(phba); |
| 4254 | rc = lpfc_sli_chipset_init(phba); |
| 4255 | if (rc) |
| 4256 | return NULL; |
| 4257 | } |
| 4258 | wwn = lpfc_get_wwpn(phba); |
| 4259 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4260 | |
| 4261 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4262 | if (wwn == lpfc_no_hba_reset[i]) { |
| 4263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4264 | "6020 Setting use_no_reset port=%llx\n", |
| 4265 | wwn); |
| 4266 | use_no_reset_hba = true; |
| 4267 | break; |
| 4268 | } |
| 4269 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4270 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4271 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4272 | if (dev != &phba->pcidev->dev) { |
| 4273 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 4274 | sizeof(struct lpfc_vport)); |
| 4275 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4276 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4277 | shost = scsi_host_alloc(&lpfc_template, |
| 4278 | sizeof(struct lpfc_vport)); |
| 4279 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4280 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4281 | sizeof(struct lpfc_vport)); |
| 4282 | } |
| 4283 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 4284 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4285 | sizeof(struct lpfc_vport)); |
| 4286 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | if (!shost) |
| 4288 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4289 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4290 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4291 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4293 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4294 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4295 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4296 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4297 | /* Adjust value in vport */ |
| 4298 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4299 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4300 | shost->unique_id = instance; |
| 4301 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4302 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4303 | shost->this_id = -1; |
| 4304 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4305 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4306 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 77ffd34 | 2019-08-15 19:36:49 -0700 | [diff] [blame] | 4307 | if (!phba->cfg_fcp_mq_threshold || |
| 4308 | phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue) |
| 4309 | phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue; |
| 4310 | |
| 4311 | shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(), |
| 4312 | phba->cfg_fcp_mq_threshold); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4313 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4314 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4315 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4316 | |
| 4317 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 4318 | shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE; |
| 4319 | else |
| 4320 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4321 | } else |
| 4322 | /* SLI-3 has a limited number of hardware queues (3), |
| 4323 | * thus there is only one for FCP processing. |
| 4324 | */ |
| 4325 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4326 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4327 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4328 | * Set initial can_queue value since 0 is no longer supported and |
| 4329 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4330 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4331 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4333 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4334 | shost->transportt = lpfc_vport_transport_template; |
| 4335 | vport->port_type = LPFC_NPIV_PORT; |
| 4336 | } else { |
| 4337 | shost->transportt = lpfc_transport_template; |
| 4338 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4339 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | /* Initialize all internally managed lists. */ |
| 4342 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4343 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4345 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4346 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4347 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4348 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4349 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4350 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4351 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4352 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4353 | lpfc_setup_bg(phba, shost); |
| 4354 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4355 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | if (error) |
| 4357 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4358 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4359 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4361 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4363 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | out_put_shost: |
| 4365 | scsi_host_put(shost); |
| 4366 | out: |
| 4367 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4368 | } |
| 4369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4371 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4372 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4373 | * |
| 4374 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4375 | * resources associated with the port are released. |
| 4376 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | void |
| 4378 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4379 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4380 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4381 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4382 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4383 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | fc_remove_host(shost); |
| 4385 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4386 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4387 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4388 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4389 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4391 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4392 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4393 | } |
| 4394 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4395 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4396 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4397 | * |
| 4398 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4399 | * uses the kernel idr facility to perform the task. |
| 4400 | * |
| 4401 | * Return codes: |
| 4402 | * instance - a unique integer ID allocated as the new instance. |
| 4403 | * -1 - lpfc get instance failed. |
| 4404 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | int |
| 4406 | lpfc_get_instance(void) |
| 4407 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4408 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4409 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4410 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4411 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4412 | } |
| 4413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4415 | * 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] | 4416 | * @shost: pointer to SCSI host data structure. |
| 4417 | * @time: elapsed time of the scan in jiffies. |
| 4418 | * |
| 4419 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4420 | * whether the scan host is finished. |
| 4421 | * |
| 4422 | * Note: there is no scan_start function as adapter initialization will have |
| 4423 | * asynchronously kicked off the link initialization. |
| 4424 | * |
| 4425 | * Return codes |
| 4426 | * 0 - SCSI host scan is not over yet. |
| 4427 | * 1 - SCSI host scan is over. |
| 4428 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4429 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4430 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4431 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4432 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4433 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4434 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4435 | spin_lock_irq(shost->host_lock); |
| 4436 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4437 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4438 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4439 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4440 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4441 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4442 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4443 | "0461 Scanning longer than 30 " |
| 4444 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4445 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4446 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4447 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4448 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4449 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4451 | "0465 Link down longer than 15 " |
| 4452 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4453 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4458 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4460 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4461 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4462 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4464 | goto finished; |
| 4465 | |
| 4466 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4467 | |
| 4468 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4469 | spin_unlock_irq(shost->host_lock); |
| 4470 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4471 | } |
| 4472 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4473 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4476 | struct lpfc_hba *phba = vport->phba; |
| 4477 | |
| 4478 | fc_host_supported_speeds(shost) = 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4479 | if (phba->lmt & LMT_128Gb) |
| 4480 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4481 | if (phba->lmt & LMT_64Gb) |
| 4482 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4483 | if (phba->lmt & LMT_32Gb) |
| 4484 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4485 | if (phba->lmt & LMT_16Gb) |
| 4486 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4487 | if (phba->lmt & LMT_10Gb) |
| 4488 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4489 | if (phba->lmt & LMT_8Gb) |
| 4490 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4491 | if (phba->lmt & LMT_4Gb) |
| 4492 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4493 | if (phba->lmt & LMT_2Gb) |
| 4494 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4495 | if (phba->lmt & LMT_1Gb) |
| 4496 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4497 | } |
| 4498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4500 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4501 | * @shost: pointer to SCSI host data structure. |
| 4502 | * |
| 4503 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4504 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4505 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4506 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4507 | { |
| 4508 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4509 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4510 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4512 | */ |
| 4513 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4515 | 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] | 4516 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4517 | |
| 4518 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4520 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4521 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4522 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4523 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4524 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4525 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4526 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4527 | |
| 4528 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4530 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4531 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4532 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4533 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4534 | /* This value is also unchanging */ |
| 4535 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4537 | fc_host_active_fc4s(shost)[2] = 1; |
| 4538 | fc_host_active_fc4s(shost)[7] = 1; |
| 4539 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4540 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4541 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4542 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4543 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4544 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4546 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4547 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4548 | * @phba: pointer to lpfc hba data structure. |
| 4549 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4550 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4551 | * from generating interrupts and stops the device driver's timers for the |
| 4552 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4553 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4554 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4555 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4556 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4557 | /* Clear all interrupt enable conditions */ |
| 4558 | writel(0, phba->HCregaddr); |
| 4559 | readl(phba->HCregaddr); /* flush */ |
| 4560 | /* Clear all pending interrupts */ |
| 4561 | writel(0xffffffff, phba->HAregaddr); |
| 4562 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4563 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4564 | /* Reset some HBA SLI setup states */ |
| 4565 | lpfc_stop_hba_timers(phba); |
| 4566 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4567 | } |
| 4568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4569 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4570 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4571 | * @phba: pointer to lpfc hba data structure. |
| 4572 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4573 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4574 | * from generating interrupts and stops the device driver's timers for the |
| 4575 | * device. |
| 4576 | **/ |
| 4577 | static void |
| 4578 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4579 | { |
| 4580 | /* Reset some HBA SLI4 setup states */ |
| 4581 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4582 | if (phba->pport) |
| 4583 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4584 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
| 4588 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4589 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4590 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4591 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4592 | * the API jump table function pointer from the lpfc_hba struct. |
| 4593 | **/ |
| 4594 | void |
| 4595 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4596 | { |
| 4597 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4598 | |
| 4599 | if (phba->wq) |
| 4600 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4604 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4605 | * @phba: Pointer to hba for which this call is being executed. |
| 4606 | * |
| 4607 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4608 | **/ |
| 4609 | void |
| 4610 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4611 | { |
| 4612 | unsigned long fcf_redisc_wait_tmo = |
| 4613 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4614 | /* Start fcf rediscovery wait period timer */ |
| 4615 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4616 | spin_lock_irq(&phba->hbalock); |
| 4617 | /* Allow action to new fcf asynchronous event */ |
| 4618 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4619 | /* Mark the FCF rediscovery pending state */ |
| 4620 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4621 | spin_unlock_irq(&phba->hbalock); |
| 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4626 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4627 | * |
| 4628 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4629 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4630 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4631 | * list, and then worker thread shall be waked up for processing from the |
| 4632 | * worker thread context. |
| 4633 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4634 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4635 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4636 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4637 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4638 | |
| 4639 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4640 | spin_lock_irq(&phba->hbalock); |
| 4641 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4642 | spin_unlock_irq(&phba->hbalock); |
| 4643 | return; |
| 4644 | } |
| 4645 | /* Clear FCF rediscovery timer pending flag */ |
| 4646 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4647 | /* FCF rediscovery event to worker thread */ |
| 4648 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4649 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4650 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4651 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4652 | /* wake up worker thread */ |
| 4653 | lpfc_worker_wake_up(phba); |
| 4654 | } |
| 4655 | |
| 4656 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4657 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4658 | * @phba: pointer to lpfc hba data structure. |
| 4659 | * @acqe_link: pointer to the async link completion queue entry. |
| 4660 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4661 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4662 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4663 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4664 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4665 | struct lpfc_acqe_link *acqe_link) |
| 4666 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4667 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4668 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4669 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4670 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4671 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | break; |
| 4673 | default: |
| 4674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4675 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4676 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4677 | break; |
| 4678 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4683 | * @phba: pointer to lpfc hba data structure. |
| 4684 | * @acqe_link: pointer to the async link completion queue entry. |
| 4685 | * |
| 4686 | * This routine is to parse the SLI4 link attention type and translate it |
| 4687 | * into the base driver's link attention type coding. |
| 4688 | * |
| 4689 | * Return: Link attention type in terms of base driver's coding. |
| 4690 | **/ |
| 4691 | static uint8_t |
| 4692 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4693 | struct lpfc_acqe_link *acqe_link) |
| 4694 | { |
| 4695 | uint8_t att_type; |
| 4696 | |
| 4697 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4698 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4699 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4700 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4701 | break; |
| 4702 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4703 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4704 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | break; |
| 4706 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4707 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4708 | break; |
| 4709 | default: |
| 4710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4711 | "0399 Invalid link attention type: x%x\n", |
| 4712 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4713 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4714 | break; |
| 4715 | } |
| 4716 | return att_type; |
| 4717 | } |
| 4718 | |
| 4719 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4720 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4721 | * @phba: pointer to lpfc hba data structure. |
| 4722 | * |
| 4723 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4724 | * |
| 4725 | * Return: link speed in terms of Mbps. |
| 4726 | **/ |
| 4727 | uint32_t |
| 4728 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4729 | { |
| 4730 | uint32_t link_speed; |
| 4731 | |
| 4732 | if (!lpfc_is_link_up(phba)) |
| 4733 | return 0; |
| 4734 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4735 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4736 | switch (phba->fc_linkspeed) { |
| 4737 | case LPFC_LINK_SPEED_1GHZ: |
| 4738 | link_speed = 1000; |
| 4739 | break; |
| 4740 | case LPFC_LINK_SPEED_2GHZ: |
| 4741 | link_speed = 2000; |
| 4742 | break; |
| 4743 | case LPFC_LINK_SPEED_4GHZ: |
| 4744 | link_speed = 4000; |
| 4745 | break; |
| 4746 | case LPFC_LINK_SPEED_8GHZ: |
| 4747 | link_speed = 8000; |
| 4748 | break; |
| 4749 | case LPFC_LINK_SPEED_10GHZ: |
| 4750 | link_speed = 10000; |
| 4751 | break; |
| 4752 | case LPFC_LINK_SPEED_16GHZ: |
| 4753 | link_speed = 16000; |
| 4754 | break; |
| 4755 | default: |
| 4756 | link_speed = 0; |
| 4757 | } |
| 4758 | } else { |
| 4759 | if (phba->sli4_hba.link_state.logical_speed) |
| 4760 | link_speed = |
| 4761 | phba->sli4_hba.link_state.logical_speed; |
| 4762 | else |
| 4763 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4764 | } |
| 4765 | return link_speed; |
| 4766 | } |
| 4767 | |
| 4768 | /** |
| 4769 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4770 | * @phba: pointer to lpfc hba data structure. |
| 4771 | * @evt_code: asynchronous event code. |
| 4772 | * @speed_code: asynchronous event link speed code. |
| 4773 | * |
| 4774 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4775 | * value of Mbps for the link speed. |
| 4776 | * |
| 4777 | * Return: link speed in terms of Mbps. |
| 4778 | **/ |
| 4779 | static uint32_t |
| 4780 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4781 | uint8_t speed_code) |
| 4782 | { |
| 4783 | uint32_t port_speed; |
| 4784 | |
| 4785 | switch (evt_code) { |
| 4786 | case LPFC_TRAILER_CODE_LINK: |
| 4787 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4788 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4789 | port_speed = 0; |
| 4790 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4791 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4792 | port_speed = 10; |
| 4793 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4794 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4795 | port_speed = 100; |
| 4796 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4797 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4798 | port_speed = 1000; |
| 4799 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4800 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4801 | port_speed = 10000; |
| 4802 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4803 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4804 | port_speed = 20000; |
| 4805 | break; |
| 4806 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4807 | port_speed = 25000; |
| 4808 | break; |
| 4809 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4810 | port_speed = 40000; |
| 4811 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4812 | default: |
| 4813 | port_speed = 0; |
| 4814 | } |
| 4815 | break; |
| 4816 | case LPFC_TRAILER_CODE_FC: |
| 4817 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4818 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4819 | port_speed = 0; |
| 4820 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4821 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4822 | port_speed = 1000; |
| 4823 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4824 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4825 | port_speed = 2000; |
| 4826 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4827 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4828 | port_speed = 4000; |
| 4829 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4830 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4831 | port_speed = 8000; |
| 4832 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4833 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4834 | port_speed = 10000; |
| 4835 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4836 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4837 | port_speed = 16000; |
| 4838 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4839 | case LPFC_FC_LA_SPEED_32G: |
| 4840 | port_speed = 32000; |
| 4841 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4842 | case LPFC_FC_LA_SPEED_64G: |
| 4843 | port_speed = 64000; |
| 4844 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4845 | case LPFC_FC_LA_SPEED_128G: |
| 4846 | port_speed = 128000; |
| 4847 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4848 | default: |
| 4849 | port_speed = 0; |
| 4850 | } |
| 4851 | break; |
| 4852 | default: |
| 4853 | port_speed = 0; |
| 4854 | } |
| 4855 | return port_speed; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4859 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4860 | * @phba: pointer to lpfc hba data structure. |
| 4861 | * @acqe_link: pointer to the async link completion queue entry. |
| 4862 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4863 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4864 | **/ |
| 4865 | static void |
| 4866 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4867 | struct lpfc_acqe_link *acqe_link) |
| 4868 | { |
| 4869 | struct lpfc_dmabuf *mp; |
| 4870 | LPFC_MBOXQ_t *pmb; |
| 4871 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4872 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4873 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4874 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4875 | |
| 4876 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4877 | 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] | 4878 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4879 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4880 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4881 | if (!pmb) { |
| 4882 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4883 | "0395 The mboxq allocation failed\n"); |
| 4884 | return; |
| 4885 | } |
| 4886 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4887 | if (!mp) { |
| 4888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4889 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4890 | goto out_free_pmb; |
| 4891 | } |
| 4892 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4893 | if (!mp->virt) { |
| 4894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4895 | "0397 The mbuf allocation failed\n"); |
| 4896 | goto out_free_dmabuf; |
| 4897 | } |
| 4898 | |
| 4899 | /* Cleanup any outstanding ELS commands */ |
| 4900 | lpfc_els_flush_all_cmd(phba); |
| 4901 | |
| 4902 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4903 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4904 | |
| 4905 | /* Update link event statistics */ |
| 4906 | phba->sli.slistat.link_event++; |
| 4907 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4908 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4909 | lpfc_read_topology(phba, pmb, mp); |
| 4910 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4911 | pmb->vport = phba->pport; |
| 4912 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4914 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4915 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4916 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4917 | phba->sli4_hba.link_state.duplex = |
| 4918 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4919 | phba->sli4_hba.link_state.status = |
| 4920 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4921 | phba->sli4_hba.link_state.type = |
| 4922 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4923 | phba->sli4_hba.link_state.number = |
| 4924 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4925 | phba->sli4_hba.link_state.fault = |
| 4926 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4927 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4928 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4929 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4930 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4931 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4932 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4933 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4934 | phba->sli4_hba.link_state.speed, |
| 4935 | phba->sli4_hba.link_state.topology, |
| 4936 | phba->sli4_hba.link_state.status, |
| 4937 | phba->sli4_hba.link_state.type, |
| 4938 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4939 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4940 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4941 | /* |
| 4942 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4943 | * topology info. Note: Optional for non FC-AL ports. |
| 4944 | */ |
| 4945 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4946 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4947 | if (rc == MBX_NOT_FINISHED) |
| 4948 | goto out_free_dmabuf; |
| 4949 | return; |
| 4950 | } |
| 4951 | /* |
| 4952 | * For FCoE Mode: fill in all the topology information we need and call |
| 4953 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4954 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4955 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4956 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4957 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4958 | mb->mbxStatus = MBX_SUCCESS; |
| 4959 | |
| 4960 | /* Parse port fault information field */ |
| 4961 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4962 | |
| 4963 | /* Parse and translate link attention fields */ |
| 4964 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4965 | la->eventTag = acqe_link->event_tag; |
| 4966 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4967 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4968 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4969 | |
| 4970 | /* Fake the the following irrelvant fields */ |
| 4971 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4972 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4973 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4974 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4975 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4976 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4977 | |
| 4978 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4979 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4980 | |
| 4981 | return; |
| 4982 | |
| 4983 | out_free_dmabuf: |
| 4984 | kfree(mp); |
| 4985 | out_free_pmb: |
| 4986 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4987 | } |
| 4988 | |
| 4989 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4990 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 4991 | * topology. |
| 4992 | * @phba: pointer to lpfc hba data structure. |
| 4993 | * @evt_code: asynchronous event code. |
| 4994 | * @speed_code: asynchronous event link speed code. |
| 4995 | * |
| 4996 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4997 | * value of Read topology link speed. |
| 4998 | * |
| 4999 | * Return: link speed in terms of Read topology. |
| 5000 | **/ |
| 5001 | static uint8_t |
| 5002 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5003 | { |
| 5004 | uint8_t port_speed; |
| 5005 | |
| 5006 | switch (speed_code) { |
| 5007 | case LPFC_FC_LA_SPEED_1G: |
| 5008 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5009 | break; |
| 5010 | case LPFC_FC_LA_SPEED_2G: |
| 5011 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5012 | break; |
| 5013 | case LPFC_FC_LA_SPEED_4G: |
| 5014 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5015 | break; |
| 5016 | case LPFC_FC_LA_SPEED_8G: |
| 5017 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5018 | break; |
| 5019 | case LPFC_FC_LA_SPEED_16G: |
| 5020 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5021 | break; |
| 5022 | case LPFC_FC_LA_SPEED_32G: |
| 5023 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5024 | break; |
| 5025 | case LPFC_FC_LA_SPEED_64G: |
| 5026 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5027 | break; |
| 5028 | case LPFC_FC_LA_SPEED_128G: |
| 5029 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5030 | break; |
| 5031 | case LPFC_FC_LA_SPEED_256G: |
| 5032 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5033 | break; |
| 5034 | default: |
| 5035 | port_speed = 0; |
| 5036 | break; |
| 5037 | } |
| 5038 | |
| 5039 | return port_speed; |
| 5040 | } |
| 5041 | |
| 5042 | #define trunk_link_status(__idx)\ |
| 5043 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5044 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5045 | "Link up" : "Link down") : "NA" |
| 5046 | /* Did port __idx reported an error */ |
| 5047 | #define trunk_port_fault(__idx)\ |
| 5048 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5049 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5050 | |
| 5051 | static void |
| 5052 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5053 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5054 | { |
| 5055 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5056 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5057 | |
| 5058 | phba->sli4_hba.link_state.speed = |
| 5059 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5060 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5061 | |
| 5062 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5063 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5064 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5065 | phba->fc_linkspeed = |
| 5066 | lpfc_async_link_speed_to_read_top( |
| 5067 | phba, |
| 5068 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5069 | |
| 5070 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5071 | phba->trunk_link.link0.state = |
| 5072 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5073 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5074 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5075 | } |
| 5076 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5077 | phba->trunk_link.link1.state = |
| 5078 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5079 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5080 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5081 | } |
| 5082 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5083 | phba->trunk_link.link2.state = |
| 5084 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5085 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5086 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5087 | } |
| 5088 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5089 | phba->trunk_link.link3.state = |
| 5090 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5091 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5092 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5096 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5097 | "\tLogical speed:%d " |
| 5098 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5099 | phba->sli4_hba.link_state.speed, |
| 5100 | phba->sli4_hba.link_state.logical_speed, |
| 5101 | trunk_link_status(0), trunk_link_status(1), |
| 5102 | trunk_link_status(2), trunk_link_status(3)); |
| 5103 | |
| 5104 | if (port_fault) |
| 5105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5106 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5107 | /* |
| 5108 | * SLI-4: We have only 0xA error codes |
| 5109 | * defined as of now. print an appropriate |
| 5110 | * message in case driver needs to be updated. |
| 5111 | */ |
| 5112 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5113 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5114 | trunk_port_fault(0), trunk_port_fault(1), |
| 5115 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5116 | } |
| 5117 | |
| 5118 | |
| 5119 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5120 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5121 | * @phba: pointer to lpfc hba data structure. |
| 5122 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5123 | * |
| 5124 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5125 | * that the event was received and then issue a read_topology mailbox command so |
| 5126 | * that the rest of the driver will treat it the same as SLI3. |
| 5127 | **/ |
| 5128 | static void |
| 5129 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5130 | { |
| 5131 | struct lpfc_dmabuf *mp; |
| 5132 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5133 | MAILBOX_t *mb; |
| 5134 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5135 | int rc; |
| 5136 | |
| 5137 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5138 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 5139 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5140 | "2895 Non FC link Event detected.(%d)\n", |
| 5141 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5142 | return; |
| 5143 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5144 | |
| 5145 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5146 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5147 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5148 | return; |
| 5149 | } |
| 5150 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5151 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5152 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5153 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5154 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5155 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5156 | phba->sli4_hba.link_state.topology = |
| 5157 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5158 | phba->sli4_hba.link_state.status = |
| 5159 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5160 | phba->sli4_hba.link_state.type = |
| 5161 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5162 | phba->sli4_hba.link_state.number = |
| 5163 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5164 | phba->sli4_hba.link_state.fault = |
| 5165 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5166 | |
| 5167 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5168 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5169 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5170 | else if (!phba->sli4_hba.conf_trunk) |
| 5171 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5172 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5173 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5174 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5175 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5176 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5177 | "%dMbps Fault:%d\n", |
| 5178 | phba->sli4_hba.link_state.speed, |
| 5179 | phba->sli4_hba.link_state.topology, |
| 5180 | phba->sli4_hba.link_state.status, |
| 5181 | phba->sli4_hba.link_state.type, |
| 5182 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5183 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5184 | phba->sli4_hba.link_state.fault); |
| 5185 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5186 | if (!pmb) { |
| 5187 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5188 | "2897 The mboxq allocation failed\n"); |
| 5189 | return; |
| 5190 | } |
| 5191 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5192 | if (!mp) { |
| 5193 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5194 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5195 | goto out_free_pmb; |
| 5196 | } |
| 5197 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5198 | if (!mp->virt) { |
| 5199 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5200 | "2899 The mbuf allocation failed\n"); |
| 5201 | goto out_free_dmabuf; |
| 5202 | } |
| 5203 | |
| 5204 | /* Cleanup any outstanding ELS commands */ |
| 5205 | lpfc_els_flush_all_cmd(phba); |
| 5206 | |
| 5207 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5208 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5209 | |
| 5210 | /* Update link event statistics */ |
| 5211 | phba->sli.slistat.link_event++; |
| 5212 | |
| 5213 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5214 | lpfc_read_topology(phba, pmb, mp); |
| 5215 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5216 | pmb->vport = phba->pport; |
| 5217 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5218 | 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] | 5219 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5220 | |
| 5221 | switch (phba->sli4_hba.link_state.status) { |
| 5222 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5223 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5224 | break; |
| 5225 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5226 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5227 | break; |
| 5228 | default: |
| 5229 | break; |
| 5230 | } |
| 5231 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5232 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5233 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5234 | mb->mbxStatus = MBX_SUCCESS; |
| 5235 | |
| 5236 | /* Parse port fault information field */ |
| 5237 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5238 | |
| 5239 | /* Parse and translate link attention fields */ |
| 5240 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5241 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5242 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5243 | if (phba->sli4_hba.link_state.status == |
| 5244 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5245 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5246 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5247 | } else { |
| 5248 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5249 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5250 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5251 | /* Invoke the mailbox command callback function */ |
| 5252 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5253 | |
| 5254 | return; |
| 5255 | } |
| 5256 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5257 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5258 | if (rc == MBX_NOT_FINISHED) |
| 5259 | goto out_free_dmabuf; |
| 5260 | return; |
| 5261 | |
| 5262 | out_free_dmabuf: |
| 5263 | kfree(mp); |
| 5264 | out_free_pmb: |
| 5265 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5266 | } |
| 5267 | |
| 5268 | /** |
| 5269 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5270 | * @phba: pointer to lpfc hba data structure. |
| 5271 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 5272 | * |
| 5273 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5274 | **/ |
| 5275 | static void |
| 5276 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5277 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5278 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5279 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5280 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5281 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5282 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5283 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5284 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5285 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5286 | struct lpfc_vport **vports; |
| 5287 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5288 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5289 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5290 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5291 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5292 | "2901 Async SLI event - Type:%d, Event Data: x%08x " |
| 5293 | "x%08x x%08x x%08x\n", evt_type, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5294 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5295 | acqe_sli->reserved, acqe_sli->trailer); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5296 | |
| 5297 | port_name = phba->Port[0]; |
| 5298 | if (port_name == 0x00) |
| 5299 | port_name = '?'; /* get port name is empty */ |
| 5300 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5301 | switch (evt_type) { |
| 5302 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5303 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5304 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5305 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5306 | |
| 5307 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5308 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5309 | acqe_sli->event_data1, port_name); |
| 5310 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5311 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5312 | shost = lpfc_shost_from_vport(phba->pport); |
| 5313 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5314 | sizeof(temp_event_data), |
| 5315 | (char *)&temp_event_data, |
| 5316 | SCSI_NL_VID_TYPE_PCI |
| 5317 | | PCI_VENDOR_ID_EMULEX); |
| 5318 | break; |
| 5319 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5320 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5321 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5322 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5323 | |
| 5324 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5325 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5326 | acqe_sli->event_data1, port_name); |
| 5327 | |
| 5328 | shost = lpfc_shost_from_vport(phba->pport); |
| 5329 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5330 | sizeof(temp_event_data), |
| 5331 | (char *)&temp_event_data, |
| 5332 | SCSI_NL_VID_TYPE_PCI |
| 5333 | | PCI_VENDOR_ID_EMULEX); |
| 5334 | break; |
| 5335 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5336 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5337 | &acqe_sli->event_data1; |
| 5338 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5339 | /* fetch the status for this port */ |
| 5340 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5341 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5342 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5343 | &misconfigured->theEvent); |
| 5344 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5345 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5346 | break; |
| 5347 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5348 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5349 | &misconfigured->theEvent); |
| 5350 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5351 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5352 | break; |
| 5353 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5354 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5355 | &misconfigured->theEvent); |
| 5356 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5357 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5358 | break; |
| 5359 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5360 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5361 | &misconfigured->theEvent); |
| 5362 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5363 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5364 | break; |
| 5365 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5366 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5367 | "3296 " |
| 5368 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5369 | "event: Invalid link %d", |
| 5370 | phba->sli4_hba.lnk_info.lnk_no); |
| 5371 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5372 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5373 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5374 | /* Skip if optic state unchanged */ |
| 5375 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5376 | return; |
| 5377 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5378 | switch (status) { |
| 5379 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5380 | sprintf(message, "Physical Link is functional"); |
| 5381 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5382 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5383 | sprintf(message, "Optics faulted/incorrectly " |
| 5384 | "installed/not installed - Reseat optics, " |
| 5385 | "if issue not resolved, replace."); |
| 5386 | break; |
| 5387 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5388 | sprintf(message, |
| 5389 | "Optics of two types installed - Remove one " |
| 5390 | "optic or install matching pair of optics."); |
| 5391 | break; |
| 5392 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5393 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5394 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5395 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5396 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5397 | sprintf(message, "Unqualified optics - Replace with " |
| 5398 | "Avago optics for Warranty and Technical " |
| 5399 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5400 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5401 | break; |
| 5402 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5403 | sprintf(message, "Uncertified optics - Replace with " |
| 5404 | "Avago-certified optics to enable link " |
| 5405 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5406 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5407 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5408 | default: |
| 5409 | /* firmware is reporting a status we don't know about */ |
| 5410 | sprintf(message, "Unknown event status x%02x", status); |
| 5411 | break; |
| 5412 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5413 | |
| 5414 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5415 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5416 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5417 | phba->lmt = 0; |
| 5418 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5419 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5420 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5421 | } |
| 5422 | vports = lpfc_create_vport_work_array(phba); |
| 5423 | if (vports != NULL) { |
| 5424 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5425 | i++) { |
| 5426 | shost = lpfc_shost_from_vport(vports[i]); |
| 5427 | lpfc_host_supported_speeds_set(shost); |
| 5428 | } |
| 5429 | } |
| 5430 | lpfc_destroy_vport_work_array(phba, vports); |
| 5431 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5432 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5433 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5434 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5435 | break; |
| 5436 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5437 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5438 | "3192 Remote DPort Test Initiated - " |
| 5439 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5440 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5441 | break; |
James Smart | e7d8595 | 2019-10-18 14:18:29 -0700 | [diff] [blame] | 5442 | case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN: |
| 5443 | /* Misconfigured WWN. Reports that the SLI Port is configured |
| 5444 | * to use FA-WWN, but the attached device doesn’t support it. |
| 5445 | * No driver action is required. |
| 5446 | * Event Data1 - N.A, Event Data2 - N.A |
| 5447 | */ |
| 5448 | lpfc_log_msg(phba, KERN_WARNING, LOG_SLI, |
| 5449 | "2699 Misconfigured FA-WWN - Attached device does " |
| 5450 | "not support FA-WWN\n"); |
| 5451 | break; |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5452 | case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE: |
| 5453 | /* EEPROM failure. No driver action is required */ |
| 5454 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5455 | "2518 EEPROM failure - " |
| 5456 | "Event Data1: x%08x Event Data2: x%08x\n", |
| 5457 | acqe_sli->event_data1, acqe_sli->event_data2); |
| 5458 | break; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5459 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5460 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5461 | "3193 Unrecognized SLI event, type: 0x%x", |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5462 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5463 | break; |
| 5464 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5468 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5469 | * @vport: pointer to vport data structure. |
| 5470 | * |
| 5471 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5472 | * response to a CVL event. |
| 5473 | * |
| 5474 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5475 | * return NULL. |
| 5476 | **/ |
| 5477 | static struct lpfc_nodelist * |
| 5478 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5479 | { |
| 5480 | struct lpfc_nodelist *ndlp; |
| 5481 | struct Scsi_Host *shost; |
| 5482 | struct lpfc_hba *phba; |
| 5483 | |
| 5484 | if (!vport) |
| 5485 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5486 | phba = vport->phba; |
| 5487 | if (!phba) |
| 5488 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5489 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5490 | if (!ndlp) { |
| 5491 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5492 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5493 | if (!ndlp) |
| 5494 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5495 | /* Set the node type */ |
| 5496 | ndlp->nlp_type |= NLP_FABRIC; |
| 5497 | /* Put ndlp onto node list */ |
| 5498 | lpfc_enqueue_node(vport, ndlp); |
| 5499 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5500 | /* re-setup ndlp without removing from node list */ |
| 5501 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5502 | if (!ndlp) |
| 5503 | return 0; |
| 5504 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5505 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5506 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5507 | return NULL; |
| 5508 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5509 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5510 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5511 | return NULL; |
| 5512 | shost = lpfc_shost_from_vport(vport); |
| 5513 | if (!shost) |
| 5514 | return NULL; |
| 5515 | lpfc_linkdown_port(vport); |
| 5516 | lpfc_cleanup_pending_mbox(vport); |
| 5517 | spin_lock_irq(shost->host_lock); |
| 5518 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5519 | spin_unlock_irq(shost->host_lock); |
| 5520 | |
| 5521 | return ndlp; |
| 5522 | } |
| 5523 | |
| 5524 | /** |
| 5525 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 5526 | * @vport: pointer to lpfc hba data structure. |
| 5527 | * |
| 5528 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5529 | * response to a FCF dead event. |
| 5530 | **/ |
| 5531 | static void |
| 5532 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5533 | { |
| 5534 | struct lpfc_vport **vports; |
| 5535 | int i; |
| 5536 | |
| 5537 | vports = lpfc_create_vport_work_array(phba); |
| 5538 | if (vports) |
| 5539 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5540 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5541 | lpfc_destroy_vport_work_array(phba, vports); |
| 5542 | } |
| 5543 | |
| 5544 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5545 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5546 | * @phba: pointer to lpfc hba data structure. |
| 5547 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 5548 | * |
| 5549 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5550 | **/ |
| 5551 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5552 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5553 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5554 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5555 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5556 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5557 | struct lpfc_vport *vport; |
| 5558 | struct lpfc_nodelist *ndlp; |
| 5559 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5560 | int active_vlink_present; |
| 5561 | struct lpfc_vport **vports; |
| 5562 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5563 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5564 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5565 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5566 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5567 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5568 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5569 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5570 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5571 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5572 | "2546 New FCF event, evt_tag:x%x, " |
| 5573 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5574 | acqe_fip->event_tag, |
| 5575 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5576 | else |
| 5577 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5578 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5579 | "2788 FCF param modified event, " |
| 5580 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5581 | acqe_fip->event_tag, |
| 5582 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5583 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5584 | /* |
| 5585 | * During period of FCF discovery, read the FCF |
| 5586 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5587 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5588 | */ |
| 5589 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5590 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5591 | "2779 Read FCF (x%x) for updating " |
| 5592 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5593 | acqe_fip->index); |
| 5594 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5595 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5596 | |
| 5597 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5598 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5599 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5600 | spin_unlock_irq(&phba->hbalock); |
| 5601 | break; |
| 5602 | } |
| 5603 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5604 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5605 | spin_unlock_irq(&phba->hbalock); |
| 5606 | break; |
| 5607 | } |
| 5608 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5609 | /* If the FCF has been in discovered state, do nothing. */ |
| 5610 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5611 | spin_unlock_irq(&phba->hbalock); |
| 5612 | break; |
| 5613 | } |
| 5614 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5615 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5616 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5617 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5618 | "2770 Start FCF table scan per async FCF " |
| 5619 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5620 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5621 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5622 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5623 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5624 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5625 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5626 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5627 | break; |
| 5628 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5629 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5630 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5631 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5632 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5633 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5634 | break; |
| 5635 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5636 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5637 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5638 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5639 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5640 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5641 | /* |
| 5642 | * If we are in the middle of FCF failover process, clear |
| 5643 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5644 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5645 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5646 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5647 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5648 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5649 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5650 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5651 | break; |
| 5652 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5653 | spin_unlock_irq(&phba->hbalock); |
| 5654 | |
| 5655 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5656 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5657 | break; |
| 5658 | |
| 5659 | /* |
| 5660 | * Otherwise, request the port to rediscover the entire FCF |
| 5661 | * table for a fast recovery from case that the current FCF |
| 5662 | * is no longer valid as we are not in the middle of FCF |
| 5663 | * failover process already. |
| 5664 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5665 | spin_lock_irq(&phba->hbalock); |
| 5666 | /* Mark the fast failover process in progress */ |
| 5667 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5668 | spin_unlock_irq(&phba->hbalock); |
| 5669 | |
| 5670 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5671 | "2771 Start FCF fast failover process due to " |
| 5672 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5673 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5674 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5675 | if (rc) { |
| 5676 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5677 | LOG_DISCOVERY, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5678 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5679 | "command failed, fail through to FCF " |
| 5680 | "dead event\n"); |
| 5681 | spin_lock_irq(&phba->hbalock); |
| 5682 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5683 | spin_unlock_irq(&phba->hbalock); |
| 5684 | /* |
| 5685 | * Last resort will fail over by treating this |
| 5686 | * as a link down to FCF registration. |
| 5687 | */ |
| 5688 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5689 | } else { |
| 5690 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5691 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5692 | /* |
| 5693 | * Handling fast FCF failover to a DEAD FCF event is |
| 5694 | * considered equalivant to receiving CVL to all vports. |
| 5695 | */ |
| 5696 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5697 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5698 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5699 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5700 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5701 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5702 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5703 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5704 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5705 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5706 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5707 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5708 | if (!ndlp) |
| 5709 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5710 | active_vlink_present = 0; |
| 5711 | |
| 5712 | vports = lpfc_create_vport_work_array(phba); |
| 5713 | if (vports) { |
| 5714 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5715 | i++) { |
| 5716 | if ((!(vports[i]->fc_flag & |
| 5717 | FC_VPORT_CVL_RCVD)) && |
| 5718 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5719 | active_vlink_present = 1; |
| 5720 | break; |
| 5721 | } |
| 5722 | } |
| 5723 | lpfc_destroy_vport_work_array(phba, vports); |
| 5724 | } |
| 5725 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5726 | /* |
| 5727 | * Don't re-instantiate if vport is marked for deletion. |
| 5728 | * If we are here first then vport_delete is going to wait |
| 5729 | * for discovery to complete. |
| 5730 | */ |
| 5731 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5732 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5733 | /* |
| 5734 | * If there are other active VLinks present, |
| 5735 | * re-instantiate the Vlink using FDISC. |
| 5736 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5737 | mod_timer(&ndlp->nlp_delayfunc, |
| 5738 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5739 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5740 | spin_lock_irq(shost->host_lock); |
| 5741 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5742 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5743 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5744 | vport->port_state = LPFC_FDISC; |
| 5745 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5746 | /* |
| 5747 | * Otherwise, we request port to rediscover |
| 5748 | * the entire FCF table for a fast recovery |
| 5749 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5750 | * is no longer valid if we are not already |
| 5751 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5752 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5753 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5754 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5755 | spin_unlock_irq(&phba->hbalock); |
| 5756 | break; |
| 5757 | } |
| 5758 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5759 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5760 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5761 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5762 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5763 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5764 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5765 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5766 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5767 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5768 | LOG_DISCOVERY, |
| 5769 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5770 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5771 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5772 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5773 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5774 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5775 | /* |
| 5776 | * Last resort will be re-try on the |
| 5777 | * the current registered FCF entry. |
| 5778 | */ |
| 5779 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5780 | } else |
| 5781 | /* |
| 5782 | * Reset FCF roundrobin bmask for new |
| 5783 | * discovery. |
| 5784 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5785 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5786 | } |
| 5787 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5788 | default: |
| 5789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5790 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5791 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5792 | break; |
| 5793 | } |
| 5794 | } |
| 5795 | |
| 5796 | /** |
| 5797 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5798 | * @phba: pointer to lpfc hba data structure. |
| 5799 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5800 | * |
| 5801 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5802 | **/ |
| 5803 | static void |
| 5804 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5805 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5806 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5807 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5808 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5809 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5810 | "handled yet\n"); |
| 5811 | } |
| 5812 | |
| 5813 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5814 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5815 | * @phba: pointer to lpfc hba data structure. |
| 5816 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5817 | * |
| 5818 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5819 | * is an asynchronous notified of a logical link speed change. The Port |
| 5820 | * reports the logical link speed in units of 10Mbps. |
| 5821 | **/ |
| 5822 | static void |
| 5823 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5824 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5825 | { |
| 5826 | uint16_t prev_ll_spd; |
| 5827 | |
| 5828 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5829 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5830 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5831 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5832 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5833 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5834 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5835 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5836 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5840 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5841 | * @phba: pointer to lpfc hba data structure. |
| 5842 | * |
| 5843 | * This routine is invoked by the worker thread to process all the pending |
| 5844 | * SLI4 asynchronous events. |
| 5845 | **/ |
| 5846 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5847 | { |
| 5848 | struct lpfc_cq_event *cq_event; |
| 5849 | |
| 5850 | /* First, declare the async event has been handled */ |
| 5851 | spin_lock_irq(&phba->hbalock); |
| 5852 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5853 | spin_unlock_irq(&phba->hbalock); |
| 5854 | /* Now, handle all the async events */ |
| 5855 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5856 | /* Get the first event from the head of the event queue */ |
| 5857 | spin_lock_irq(&phba->hbalock); |
| 5858 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5859 | cq_event, struct lpfc_cq_event, list); |
| 5860 | spin_unlock_irq(&phba->hbalock); |
| 5861 | /* Process the asynchronous event */ |
| 5862 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5863 | case LPFC_TRAILER_CODE_LINK: |
| 5864 | lpfc_sli4_async_link_evt(phba, |
| 5865 | &cq_event->cqe.acqe_link); |
| 5866 | break; |
| 5867 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5868 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5869 | break; |
| 5870 | case LPFC_TRAILER_CODE_DCBX: |
| 5871 | lpfc_sli4_async_dcbx_evt(phba, |
| 5872 | &cq_event->cqe.acqe_dcbx); |
| 5873 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5874 | case LPFC_TRAILER_CODE_GRP5: |
| 5875 | lpfc_sli4_async_grp5_evt(phba, |
| 5876 | &cq_event->cqe.acqe_grp5); |
| 5877 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5878 | case LPFC_TRAILER_CODE_FC: |
| 5879 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5880 | break; |
| 5881 | case LPFC_TRAILER_CODE_SLI: |
| 5882 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5883 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5884 | default: |
| 5885 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 5886 | "1804 Invalid asynchronous event code: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5887 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5888 | &cq_event->cqe.mcqe_cmpl)); |
| 5889 | break; |
| 5890 | } |
| 5891 | /* Free the completion event processed to the free pool */ |
| 5892 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5893 | } |
| 5894 | } |
| 5895 | |
| 5896 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5897 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5898 | * @phba: pointer to lpfc hba data structure. |
| 5899 | * |
| 5900 | * This routine is invoked by the worker thread to process FCF table |
| 5901 | * rediscovery pending completion event. |
| 5902 | **/ |
| 5903 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5904 | { |
| 5905 | int rc; |
| 5906 | |
| 5907 | spin_lock_irq(&phba->hbalock); |
| 5908 | /* Clear FCF rediscovery timeout event */ |
| 5909 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5910 | /* Clear driver fast failover FCF record flag */ |
| 5911 | phba->fcf.failover_rec.flag = 0; |
| 5912 | /* Set state for FCF fast failover */ |
| 5913 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5914 | spin_unlock_irq(&phba->hbalock); |
| 5915 | |
| 5916 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5917 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5918 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5919 | 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] | 5920 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5921 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5922 | "2747 Issue FCF scan read FCF mailbox " |
| 5923 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5927 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5928 | * @phba: pointer to lpfc hba data structure. |
| 5929 | * @dev_grp: The HBA PCI-Device group number. |
| 5930 | * |
| 5931 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5932 | * API jump table entries. |
| 5933 | * |
| 5934 | * Return: 0 if success, otherwise -ENODEV |
| 5935 | **/ |
| 5936 | int |
| 5937 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5938 | { |
| 5939 | int rc; |
| 5940 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5941 | /* Set up lpfc PCI-device group */ |
| 5942 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5943 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5944 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5945 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5946 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5947 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5948 | /* Set up device INIT API function jump table */ |
| 5949 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5950 | if (rc) |
| 5951 | return -ENODEV; |
| 5952 | /* Set up SCSI API function jump table */ |
| 5953 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5954 | if (rc) |
| 5955 | return -ENODEV; |
| 5956 | /* Set up SLI API function jump table */ |
| 5957 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5958 | if (rc) |
| 5959 | return -ENODEV; |
| 5960 | /* Set up MBOX API function jump table */ |
| 5961 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5962 | if (rc) |
| 5963 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5964 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5965 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5969 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5970 | * @phba: pointer to lpfc hba data structure. |
| 5971 | * @intr_mode: active interrupt mode adopted. |
| 5972 | * |
| 5973 | * This routine it invoked to log the currently used active interrupt mode |
| 5974 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5975 | **/ |
| 5976 | 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] | 5977 | { |
| 5978 | switch (intr_mode) { |
| 5979 | case 0: |
| 5980 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5981 | "0470 Enable INTx interrupt mode.\n"); |
| 5982 | break; |
| 5983 | case 1: |
| 5984 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5985 | "0481 Enabled MSI interrupt mode.\n"); |
| 5986 | break; |
| 5987 | case 2: |
| 5988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5989 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5990 | break; |
| 5991 | default: |
| 5992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5993 | "0482 Illegal interrupt mode.\n"); |
| 5994 | break; |
| 5995 | } |
| 5996 | return; |
| 5997 | } |
| 5998 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5999 | /** |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 6000 | * lpfc_cpumask_of_node_init - initalizes cpumask of phba's NUMA node |
| 6001 | * @phba: Pointer to HBA context object. |
| 6002 | * |
| 6003 | **/ |
| 6004 | static void |
| 6005 | lpfc_cpumask_of_node_init(struct lpfc_hba *phba) |
| 6006 | { |
| 6007 | unsigned int cpu, numa_node; |
Bart Van Assche | 61951a6 | 2019-11-08 14:59:47 -0800 | [diff] [blame] | 6008 | struct cpumask *numa_mask = &phba->sli4_hba.numa_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 6009 | |
| 6010 | cpumask_clear(numa_mask); |
| 6011 | |
| 6012 | /* Check if we're a NUMA architecture */ |
Bart Van Assche | 61951a6 | 2019-11-08 14:59:47 -0800 | [diff] [blame] | 6013 | numa_node = dev_to_node(&phba->pcidev->dev); |
| 6014 | if (numa_node == NUMA_NO_NODE) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 6015 | return; |
| 6016 | |
| 6017 | for_each_possible_cpu(cpu) |
| 6018 | if (cpu_to_node(cpu) == numa_node) |
| 6019 | cpumask_set_cpu(cpu, numa_mask); |
| 6020 | } |
| 6021 | |
| 6022 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6023 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6024 | * @phba: pointer to lpfc hba data structure. |
| 6025 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6026 | * This routine is invoked to enable the PCI device that is common to all |
| 6027 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6028 | * |
| 6029 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6030 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6031 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6032 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6033 | static int |
| 6034 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6035 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6036 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6037 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6038 | /* Obtain PCI device reference */ |
| 6039 | if (!phba->pcidev) |
| 6040 | goto out_error; |
| 6041 | else |
| 6042 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6043 | /* Enable PCI device */ |
| 6044 | if (pci_enable_device_mem(pdev)) |
| 6045 | goto out_error; |
| 6046 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6047 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6048 | goto out_disable_device; |
| 6049 | /* Set up device as PCI master and save state for EEH */ |
| 6050 | pci_set_master(pdev); |
| 6051 | pci_try_set_mwi(pdev); |
| 6052 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6053 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6054 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6055 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6056 | pdev->needs_freset = 1; |
| 6057 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6058 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6059 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6060 | out_disable_device: |
| 6061 | pci_disable_device(pdev); |
| 6062 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 6063 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6064 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6065 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6069 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6070 | * @phba: pointer to lpfc hba data structure. |
| 6071 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6072 | * This routine is invoked to disable the PCI device that is common to all |
| 6073 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6074 | **/ |
| 6075 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6076 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6077 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6078 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6079 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6080 | /* Obtain PCI device reference */ |
| 6081 | if (!phba->pcidev) |
| 6082 | return; |
| 6083 | else |
| 6084 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6085 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6086 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6087 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6088 | |
| 6089 | return; |
| 6090 | } |
| 6091 | |
| 6092 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6093 | * lpfc_reset_hba - Reset a hba |
| 6094 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6095 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6096 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6097 | * offline, performs a board restart, and then brings the board back |
| 6098 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6099 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6100 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6101 | void |
| 6102 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6103 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6104 | /* If resets are disabled then set error state and return. */ |
| 6105 | if (!phba->cfg_enable_hba_reset) { |
| 6106 | phba->link_state = LPFC_HBA_ERROR; |
| 6107 | return; |
| 6108 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6109 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 6110 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 6111 | else |
| 6112 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6113 | lpfc_offline(phba); |
| 6114 | lpfc_sli_brdrestart(phba); |
| 6115 | lpfc_online(phba); |
| 6116 | lpfc_unblock_mgmt_io(phba); |
| 6117 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6118 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6119 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6120 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6121 | * @phba: pointer to lpfc hba data structure. |
| 6122 | * |
| 6123 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6124 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6125 | * enable the number of virtual functions to the physical function. As |
| 6126 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6127 | * API call does not considered as an error condition for most of the device. |
| 6128 | **/ |
| 6129 | uint16_t |
| 6130 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6131 | { |
| 6132 | struct pci_dev *pdev = phba->pcidev; |
| 6133 | uint16_t nr_virtfn; |
| 6134 | int pos; |
| 6135 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6136 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6137 | if (pos == 0) |
| 6138 | return 0; |
| 6139 | |
| 6140 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6141 | return nr_virtfn; |
| 6142 | } |
| 6143 | |
| 6144 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6145 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6146 | * @phba: pointer to lpfc hba data structure. |
| 6147 | * @nr_vfn: number of virtual functions to be enabled. |
| 6148 | * |
| 6149 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6150 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6151 | * enable the number of virtual functions to the physical function. As |
| 6152 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6153 | * API call does not considered as an error condition for most of the device. |
| 6154 | **/ |
| 6155 | int |
| 6156 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6157 | { |
| 6158 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6159 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6160 | int rc; |
| 6161 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6162 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6163 | if (nr_vfn > max_nr_vfn) { |
| 6164 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6165 | "3057 Requested vfs (%d) greater than " |
| 6166 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6167 | return -EINVAL; |
| 6168 | } |
| 6169 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6170 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6171 | if (rc) { |
| 6172 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6173 | "2806 Failed to enable sriov on this device " |
| 6174 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6175 | nr_vfn, rc); |
| 6176 | } else |
| 6177 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6178 | "2807 Successful enable sriov on this device " |
| 6179 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6180 | return rc; |
| 6181 | } |
| 6182 | |
| 6183 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6184 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6185 | * @phba: pointer to lpfc hba data structure. |
| 6186 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6187 | * This routine is invoked to set up the driver internal resources before the |
| 6188 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6189 | * |
| 6190 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6191 | * 0 - successful |
| 6192 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6193 | **/ |
| 6194 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6195 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6196 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6197 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6198 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6199 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6200 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6201 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6202 | atomic_set(&phba->fast_event_count, 0); |
| 6203 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6204 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6205 | /* Initialize ndlp management spinlock */ |
| 6206 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6207 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6208 | /* Initialize port_list spinlock */ |
| 6209 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6210 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6211 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6212 | INIT_LIST_HEAD(&phba->work_list); |
| 6213 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6214 | |
| 6215 | /* Initialize the wait queue head for the kernel thread */ |
| 6216 | init_waitqueue_head(&phba->work_waitq); |
| 6217 | |
| 6218 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6219 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6220 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6221 | "SCSI" : " "), |
| 6222 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6223 | "NVME" : " "), |
| 6224 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6225 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6226 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6227 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6228 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6229 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6230 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6231 | |
| 6232 | /* Initialize the fabric iocb list */ |
| 6233 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6234 | |
| 6235 | /* Initialize list to save ELS buffers */ |
| 6236 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6237 | |
| 6238 | /* Initialize FCF connection rec list */ |
| 6239 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6240 | |
| 6241 | /* Initialize OAS configuration list */ |
| 6242 | spin_lock_init(&phba->devicelock); |
| 6243 | INIT_LIST_HEAD(&phba->luns); |
| 6244 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6245 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6246 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6247 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6248 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6249 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6250 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6251 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6252 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6253 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6254 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6255 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
| 6258 | |
| 6259 | /** |
| 6260 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6261 | * @phba: pointer to lpfc hba data structure. |
| 6262 | * |
| 6263 | * This routine is invoked to set up the driver internal resources specific to |
| 6264 | * support the SLI-3 HBA device it attached to. |
| 6265 | * |
| 6266 | * Return codes |
| 6267 | * 0 - successful |
| 6268 | * other values - error |
| 6269 | **/ |
| 6270 | static int |
| 6271 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6272 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6273 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6274 | |
| 6275 | /* |
| 6276 | * Initialize timers used by driver |
| 6277 | */ |
| 6278 | |
| 6279 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6280 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6281 | |
| 6282 | /* Host attention work mask setup */ |
| 6283 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6284 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6285 | |
| 6286 | /* Get all the module params for configuring this host */ |
| 6287 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6288 | /* Set up phase-1 common device driver resources */ |
| 6289 | |
| 6290 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6291 | if (rc) |
| 6292 | return -ENODEV; |
| 6293 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6294 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6295 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6296 | /* check for menlo minimum sg count */ |
| 6297 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6298 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6299 | } |
| 6300 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6301 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6302 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6303 | sizeof(struct lpfc_sli_ring), |
| 6304 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6305 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6306 | return -ENOMEM; |
| 6307 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6308 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6309 | * 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] | 6310 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6311 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6312 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6313 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6314 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 6315 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 6316 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6317 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6318 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6319 | entry_sz = sizeof(struct sli4_sge); |
| 6320 | else |
| 6321 | entry_sz = sizeof(struct ulp_bde64); |
| 6322 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6323 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6324 | if (phba->cfg_enable_bg) { |
| 6325 | /* |
| 6326 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6327 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6328 | * over how many protection data segments the SCSI Layer |
| 6329 | * will hand us (ie: there could be one for every block |
| 6330 | * in the IO), we just allocate enough BDEs to accomidate |
| 6331 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6332 | * minimize the risk of running out. |
| 6333 | */ |
| 6334 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6335 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6336 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6337 | |
| 6338 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6339 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6340 | |
| 6341 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6342 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6343 | } else { |
| 6344 | /* |
| 6345 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6346 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6347 | * cfg_sg_seg_cnt data segments. |
| 6348 | */ |
| 6349 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6350 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6351 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6352 | |
| 6353 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6354 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6355 | } |
| 6356 | |
| 6357 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6358 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 6359 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6360 | phba->cfg_total_seg_cnt); |
| 6361 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6362 | phba->max_vpi = LPFC_MAX_VPI; |
| 6363 | /* This will be set to correct value after config_port mbox */ |
| 6364 | phba->max_vports = 0; |
| 6365 | |
| 6366 | /* |
| 6367 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6368 | */ |
| 6369 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6370 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6371 | |
| 6372 | /* Allocate device driver memory */ |
| 6373 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6374 | return -ENOMEM; |
| 6375 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6376 | phba->lpfc_sg_dma_buf_pool = |
| 6377 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6378 | &phba->pcidev->dev, phba->cfg_sg_dma_buf_size, |
| 6379 | BPL_ALIGN_SZ, 0); |
| 6380 | |
| 6381 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6382 | goto fail_free_mem; |
| 6383 | |
| 6384 | phba->lpfc_cmd_rsp_buf_pool = |
| 6385 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6386 | &phba->pcidev->dev, |
| 6387 | sizeof(struct fcp_cmnd) + |
| 6388 | sizeof(struct fcp_rsp), |
| 6389 | BPL_ALIGN_SZ, 0); |
| 6390 | |
| 6391 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6392 | goto fail_free_dma_buf_pool; |
| 6393 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6394 | /* |
| 6395 | * Enable sr-iov virtual functions if supported and configured |
| 6396 | * through the module parameter. |
| 6397 | */ |
| 6398 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6399 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6400 | phba->cfg_sriov_nr_virtfn); |
| 6401 | if (rc) { |
| 6402 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6403 | "2808 Requested number of SR-IOV " |
| 6404 | "virtual functions (%d) is not " |
| 6405 | "supported\n", |
| 6406 | phba->cfg_sriov_nr_virtfn); |
| 6407 | phba->cfg_sriov_nr_virtfn = 0; |
| 6408 | } |
| 6409 | } |
| 6410 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6411 | return 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6412 | |
| 6413 | fail_free_dma_buf_pool: |
| 6414 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 6415 | phba->lpfc_sg_dma_buf_pool = NULL; |
| 6416 | fail_free_mem: |
| 6417 | lpfc_mem_free(phba); |
| 6418 | return -ENOMEM; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | /** |
| 6422 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6423 | * @phba: pointer to lpfc hba data structure. |
| 6424 | * |
| 6425 | * This routine is invoked to unset the driver internal resources set up |
| 6426 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6427 | **/ |
| 6428 | static void |
| 6429 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6430 | { |
| 6431 | /* Free device driver memory allocated */ |
| 6432 | lpfc_mem_free_all(phba); |
| 6433 | |
| 6434 | return; |
| 6435 | } |
| 6436 | |
| 6437 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6438 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6439 | * @phba: pointer to lpfc hba data structure. |
| 6440 | * |
| 6441 | * This routine is invoked to set up the driver internal resources specific to |
| 6442 | * support the SLI-4 HBA device it attached to. |
| 6443 | * |
| 6444 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6445 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6446 | * other values - error |
| 6447 | **/ |
| 6448 | static int |
| 6449 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6450 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6451 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6452 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6453 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6454 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 6455 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6456 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6457 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6458 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6459 | u32 if_type; |
| 6460 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6461 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6462 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | eede497 | 2019-11-21 09:55:56 -0800 | [diff] [blame] | 6463 | phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6464 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 6465 | lpfc_cpumask_of_node_init(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6466 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6467 | /* Get all the module params for configuring this host */ |
| 6468 | lpfc_get_cfgparam(phba); |
| 6469 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6470 | /* Set up phase-1 common device driver resources */ |
| 6471 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6472 | if (rc) |
| 6473 | return -ENODEV; |
| 6474 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6475 | /* Before proceed, wait for POST done and device ready */ |
| 6476 | rc = lpfc_sli4_post_status_check(phba); |
| 6477 | if (rc) |
| 6478 | return -ENODEV; |
| 6479 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 6480 | /* Allocate all driver workqueues here */ |
| 6481 | |
| 6482 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6483 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6484 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6485 | /* |
| 6486 | * Initialize timers used by driver |
| 6487 | */ |
| 6488 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6489 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6490 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6491 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6492 | 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] | 6493 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6494 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6495 | * Control structure for handling external multi-buffer mailbox |
| 6496 | * command pass-through. |
| 6497 | */ |
| 6498 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6499 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6500 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6501 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6502 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6503 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6504 | /* This will be set to correct value after the read_config mbox */ |
| 6505 | phba->max_vports = 0; |
| 6506 | |
| 6507 | /* Program the default value of vlan_id and fc_map */ |
| 6508 | phba->valid_vlan = 0; |
| 6509 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6510 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6511 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6512 | |
| 6513 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6514 | * 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] | 6515 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6516 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6517 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6518 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6519 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6520 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6521 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6522 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6523 | |
| 6524 | /* |
| 6525 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6526 | */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 6527 | /* Initialize the Abort buffer list used by driver */ |
| 6528 | spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock); |
| 6529 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6530 | |
| 6531 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6532 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6533 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6534 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6535 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6536 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6537 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6538 | } |
| 6539 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6540 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6541 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6542 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6543 | |
| 6544 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6545 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6546 | */ |
| 6547 | |
| 6548 | /* Driver internel slow-path CQ Event pool */ |
| 6549 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6550 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6551 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6552 | /* Asynchronous event CQ Event work queue list */ |
| 6553 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 6554 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 6555 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 6556 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6557 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6558 | /* Receive queue CQ Event work queue list */ |
| 6559 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6560 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6561 | /* Initialize extent block lists. */ |
| 6562 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6563 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6564 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6565 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6566 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6567 | /* Initialize mboxq lists. If the early init routines fail |
| 6568 | * these lists need to be correctly initialized. |
| 6569 | */ |
| 6570 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6571 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6572 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6573 | /* initialize optic_state to 0xFF */ |
| 6574 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6575 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6576 | /* Allocate device driver memory */ |
| 6577 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6578 | if (rc) |
| 6579 | return -ENOMEM; |
| 6580 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6581 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6582 | 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] | 6583 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6584 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6585 | if (unlikely(rc)) { |
| 6586 | rc = -ENODEV; |
| 6587 | goto out_free_mem; |
| 6588 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6589 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6590 | } |
| 6591 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6592 | /* Create the bootstrap mailbox command */ |
| 6593 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6594 | if (unlikely(rc)) |
| 6595 | goto out_free_mem; |
| 6596 | |
| 6597 | /* Set up the host's endian order with the device. */ |
| 6598 | rc = lpfc_setup_endian_order(phba); |
| 6599 | if (unlikely(rc)) |
| 6600 | goto out_free_bsmbx; |
| 6601 | |
| 6602 | /* Set up the hba's configuration parameters. */ |
| 6603 | rc = lpfc_sli4_read_config(phba); |
| 6604 | if (unlikely(rc)) |
| 6605 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6606 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6607 | if (unlikely(rc)) |
| 6608 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6609 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6610 | /* IF Type 0 ports get initialized now. */ |
| 6611 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6612 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6613 | rc = lpfc_pci_function_reset(phba); |
| 6614 | if (unlikely(rc)) |
| 6615 | goto out_free_bsmbx; |
| 6616 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6617 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6618 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6619 | GFP_KERNEL); |
| 6620 | if (!mboxq) { |
| 6621 | rc = -ENOMEM; |
| 6622 | goto out_free_bsmbx; |
| 6623 | } |
| 6624 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6625 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6626 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6627 | if (lpfc_enable_nvmet_cnt) { |
| 6628 | |
| 6629 | /* First get WWN of HBA instance */ |
| 6630 | lpfc_read_nv(phba, mboxq); |
| 6631 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6632 | if (rc != MBX_SUCCESS) { |
| 6633 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6634 | "6016 Mailbox failed , mbxCmd x%x " |
| 6635 | "READ_NV, mbxStatus x%x\n", |
| 6636 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6637 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6638 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6639 | rc = -EIO; |
| 6640 | goto out_free_bsmbx; |
| 6641 | } |
| 6642 | mb = &mboxq->u.mb; |
| 6643 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6644 | sizeof(uint64_t)); |
| 6645 | wwn = cpu_to_be64(wwn); |
| 6646 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6647 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6648 | sizeof(uint64_t)); |
| 6649 | /* wwn is WWPN of HBA instance */ |
| 6650 | wwn = cpu_to_be64(wwn); |
| 6651 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6652 | |
| 6653 | /* Check to see if it matches any module parameter */ |
| 6654 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6655 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6656 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6657 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6658 | break; |
| 6659 | |
| 6660 | phba->nvmet_support = 1; /* a match */ |
| 6661 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6663 | "6017 NVME Target %016llx\n", |
| 6664 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6665 | #else |
| 6666 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6667 | "6021 Can't enable NVME Target." |
| 6668 | " NVME_TARGET_FC infrastructure" |
| 6669 | " is not in kernel\n"); |
| 6670 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6671 | /* Not supported for NVMET */ |
| 6672 | phba->cfg_xri_rebalancing = 0; |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6673 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6674 | } |
| 6675 | } |
| 6676 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6677 | |
| 6678 | lpfc_nvme_mod_param_dep(phba); |
| 6679 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6680 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6681 | lpfc_supported_pages(mboxq); |
| 6682 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6683 | if (!rc) { |
| 6684 | mqe = &mboxq->u.mqe; |
| 6685 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6686 | LPFC_MAX_SUPPORTED_PAGES); |
| 6687 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6688 | switch (pn_page[i]) { |
| 6689 | case LPFC_SLI4_PARAMETERS: |
| 6690 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6691 | break; |
| 6692 | default: |
| 6693 | break; |
| 6694 | } |
| 6695 | } |
| 6696 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6697 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6698 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6699 | if (rc) { |
| 6700 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6701 | rc = -EIO; |
| 6702 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6703 | } |
| 6704 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6705 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6706 | /* |
| 6707 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6708 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6709 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6710 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6711 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6712 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6713 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6714 | &phba->sli4_hba.sli_intf); |
| 6715 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6716 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6717 | if (phba->sli4_hba.extents_in_use && |
| 6718 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6719 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6720 | "2999 Unsupported SLI4 Parameters " |
| 6721 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6722 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6723 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6724 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6725 | rc = -EIO; |
| 6726 | goto out_free_bsmbx; |
| 6727 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6728 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6729 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6730 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6731 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6732 | rc = -EIO; |
| 6733 | goto out_free_bsmbx; |
| 6734 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6735 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6736 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6737 | /* |
| 6738 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6739 | * for boundary conditions in its max_sgl_segment template. |
| 6740 | */ |
| 6741 | extra = 2; |
| 6742 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6743 | extra++; |
| 6744 | |
| 6745 | /* |
| 6746 | * It doesn't matter what family our adapter is in, we are |
| 6747 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6748 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6749 | */ |
| 6750 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 6751 | |
| 6752 | /* |
| 6753 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6754 | * used to create the sg_dma_buf_pool must be calculated. |
| 6755 | */ |
| 6756 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 6757 | /* Both cfg_enable_bg and cfg_external_dif code paths */ |
| 6758 | |
| 6759 | /* |
| 6760 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6761 | * the FCP rsp, and a SGE. Sice we have no control |
| 6762 | * over how many protection segments the SCSI Layer |
| 6763 | * will hand us (ie: there could be one for every block |
| 6764 | * in the IO), just allocate enough SGEs to accomidate |
| 6765 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6766 | * to minimize the risk of running out. |
| 6767 | */ |
| 6768 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6769 | sizeof(struct fcp_rsp) + max_buf_size; |
| 6770 | |
| 6771 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6772 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6773 | |
| 6774 | /* |
| 6775 | * If supporting DIF, reduce the seg count for scsi to |
| 6776 | * allow room for the DIF sges. |
| 6777 | */ |
| 6778 | if (phba->cfg_enable_bg && |
| 6779 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6780 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6781 | else |
| 6782 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6783 | |
| 6784 | } else { |
| 6785 | /* |
| 6786 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
| 6787 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6788 | * cfg_sg_seg_cnt data segments. |
| 6789 | */ |
| 6790 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6791 | sizeof(struct fcp_rsp) + |
| 6792 | ((phba->cfg_sg_seg_cnt + extra) * |
| 6793 | sizeof(struct sli4_sge)); |
| 6794 | |
| 6795 | /* Total SGEs for scsi_sg_list */ |
| 6796 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
| 6797 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6798 | |
| 6799 | /* |
| 6800 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
| 6801 | * need to post 1 page for the SGL. |
| 6802 | */ |
| 6803 | } |
| 6804 | |
| 6805 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 6806 | phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE; |
| 6807 | else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6808 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6809 | else |
| 6810 | phba->cfg_sg_dma_buf_size = |
| 6811 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6812 | |
| 6813 | phba->border_sge_num = phba->cfg_sg_dma_buf_size / |
| 6814 | sizeof(struct sli4_sge); |
| 6815 | |
| 6816 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6817 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6818 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6819 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6820 | "6300 Reducing NVME sg segment " |
| 6821 | "cnt to %d\n", |
| 6822 | LPFC_MAX_NVME_SEG_CNT); |
| 6823 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6824 | } else |
| 6825 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6826 | } |
| 6827 | |
| 6828 | /* Initialize the host templates with the updated values. */ |
| 6829 | lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6830 | lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6831 | lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6832 | |
| 6833 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6834 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6835 | "total:%d scsi:%d nvme:%d\n", |
| 6836 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6837 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6838 | phba->cfg_nvme_seg_cnt); |
| 6839 | |
| 6840 | if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE) |
| 6841 | i = phba->cfg_sg_dma_buf_size; |
| 6842 | else |
| 6843 | i = SLI4_PAGE_SIZE; |
| 6844 | |
| 6845 | phba->lpfc_sg_dma_buf_pool = |
| 6846 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6847 | &phba->pcidev->dev, |
| 6848 | phba->cfg_sg_dma_buf_size, |
| 6849 | i, 0); |
| 6850 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6851 | goto out_free_bsmbx; |
| 6852 | |
| 6853 | phba->lpfc_cmd_rsp_buf_pool = |
| 6854 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6855 | &phba->pcidev->dev, |
| 6856 | sizeof(struct fcp_cmnd) + |
| 6857 | sizeof(struct fcp_rsp), |
| 6858 | i, 0); |
| 6859 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6860 | goto out_free_sg_dma_buf; |
| 6861 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6862 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6863 | |
| 6864 | /* Verify OAS is supported */ |
| 6865 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6866 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6867 | /* Verify RAS support on adapter */ |
| 6868 | lpfc_sli4_ras_init(phba); |
| 6869 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6870 | /* Verify all the SLI4 queues */ |
| 6871 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6872 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6873 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6874 | |
| 6875 | /* Create driver internal CQE event pool */ |
| 6876 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6877 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6878 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6879 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6880 | /* Initialize sgl lists per host */ |
| 6881 | lpfc_init_sgl_list(phba); |
| 6882 | |
| 6883 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6884 | rc = lpfc_init_active_sgl_array(phba); |
| 6885 | if (rc) { |
| 6886 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6887 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6888 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6889 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6890 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6891 | if (rc) { |
| 6892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6893 | "1432 Failed to initialize rpi headers.\n"); |
| 6894 | goto out_free_active_sgl; |
| 6895 | } |
| 6896 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6897 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6898 | 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] | 6899 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6900 | GFP_KERNEL); |
| 6901 | if (!phba->fcf.fcf_rr_bmask) { |
| 6902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6903 | "2759 Failed allocate memory for FCF round " |
| 6904 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6905 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6906 | goto out_remove_rpi_hdrs; |
| 6907 | } |
| 6908 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 6909 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6910 | sizeof(struct lpfc_hba_eq_hdl), |
| 6911 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6912 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6913 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6914 | "2572 Failed allocate memory for " |
| 6915 | "fast-path per-EQ handle array\n"); |
| 6916 | rc = -ENOMEM; |
| 6917 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6918 | } |
| 6919 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6920 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6921 | sizeof(struct lpfc_vector_map_info), |
| 6922 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6923 | if (!phba->sli4_hba.cpu_map) { |
| 6924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6925 | "3327 Failed allocate memory for msi-x " |
| 6926 | "interrupt vector mapping\n"); |
| 6927 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6928 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6929 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6930 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6931 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 6932 | if (!phba->sli4_hba.eq_info) { |
| 6933 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6934 | "3321 Failed allocation for per_cpu stats\n"); |
| 6935 | rc = -ENOMEM; |
| 6936 | goto out_free_hba_cpu_map; |
| 6937 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6938 | /* |
| 6939 | * Enable sr-iov virtual functions if supported and configured |
| 6940 | * through the module parameter. |
| 6941 | */ |
| 6942 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6943 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6944 | phba->cfg_sriov_nr_virtfn); |
| 6945 | if (rc) { |
| 6946 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6947 | "3020 Requested number of SR-IOV " |
| 6948 | "virtual functions (%d) is not " |
| 6949 | "supported\n", |
| 6950 | phba->cfg_sriov_nr_virtfn); |
| 6951 | phba->cfg_sriov_nr_virtfn = 0; |
| 6952 | } |
| 6953 | } |
| 6954 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6955 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6956 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6957 | out_free_hba_cpu_map: |
| 6958 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6959 | out_free_hba_eq_hdl: |
| 6960 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6961 | out_free_fcf_rr_bmask: |
| 6962 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6963 | out_remove_rpi_hdrs: |
| 6964 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6965 | out_free_active_sgl: |
| 6966 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6967 | out_destroy_cq_event_pool: |
| 6968 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6969 | out_free_cmd_rsp_buf: |
| 6970 | dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool); |
| 6971 | phba->lpfc_cmd_rsp_buf_pool = NULL; |
| 6972 | out_free_sg_dma_buf: |
| 6973 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 6974 | phba->lpfc_sg_dma_buf_pool = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6975 | out_free_bsmbx: |
| 6976 | lpfc_destroy_bootstrap_mbox(phba); |
| 6977 | out_free_mem: |
| 6978 | lpfc_mem_free(phba); |
| 6979 | return rc; |
| 6980 | } |
| 6981 | |
| 6982 | /** |
| 6983 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6984 | * @phba: pointer to lpfc hba data structure. |
| 6985 | * |
| 6986 | * This routine is invoked to unset the driver internal resources set up |
| 6987 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6988 | **/ |
| 6989 | static void |
| 6990 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6991 | { |
| 6992 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6993 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6994 | free_percpu(phba->sli4_hba.eq_info); |
| 6995 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6996 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6997 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6998 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6999 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7000 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 7001 | cpumask_clear(&phba->sli4_hba.numa_mask); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7002 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7003 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7004 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7005 | |
| 7006 | /* Free the allocated rpi headers. */ |
| 7007 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 7008 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7009 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7010 | /* Free eligible FCF index bmask */ |
| 7011 | kfree(phba->fcf.fcf_rr_bmask); |
| 7012 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7013 | /* Free the ELS sgl list */ |
| 7014 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7015 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7016 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7017 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7018 | /* Free the completion queue EQ event pool */ |
| 7019 | lpfc_sli4_cq_event_release_all(phba); |
| 7020 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7021 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7022 | /* Release resource identifiers. */ |
| 7023 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 7024 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7025 | /* Free the bsmbx region. */ |
| 7026 | lpfc_destroy_bootstrap_mbox(phba); |
| 7027 | |
| 7028 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 7029 | lpfc_mem_free_all(phba); |
| 7030 | |
| 7031 | /* Free the current connect table */ |
| 7032 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7033 | &phba->fcf_conn_rec_list, list) { |
| 7034 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7035 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7036 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7037 | |
| 7038 | return; |
| 7039 | } |
| 7040 | |
| 7041 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7042 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7043 | * @phba: The hba struct for which this call is being executed. |
| 7044 | * @dev_grp: The HBA PCI-Device group number. |
| 7045 | * |
| 7046 | * This routine sets up the device INIT interface API function jump table |
| 7047 | * in @phba struct. |
| 7048 | * |
| 7049 | * Returns: 0 - success, -ENODEV - failure. |
| 7050 | **/ |
| 7051 | int |
| 7052 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7053 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 7054 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 7055 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 7056 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7057 | switch (dev_grp) { |
| 7058 | case LPFC_PCI_DEV_LP: |
| 7059 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 7060 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 7061 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 7062 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | case LPFC_PCI_DEV_OC: |
| 7064 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 7065 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 7066 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 7067 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7068 | default: |
| 7069 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7070 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 7071 | dev_grp); |
| 7072 | return -ENODEV; |
| 7073 | break; |
| 7074 | } |
| 7075 | return 0; |
| 7076 | } |
| 7077 | |
| 7078 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7079 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 7080 | * @phba: pointer to lpfc hba data structure. |
| 7081 | * |
| 7082 | * This routine is invoked to set up the driver internal resources after the |
| 7083 | * device specific resource setup to support the HBA device it attached to. |
| 7084 | * |
| 7085 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7086 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7087 | * other values - error |
| 7088 | **/ |
| 7089 | static int |
| 7090 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 7091 | { |
| 7092 | int error; |
| 7093 | |
| 7094 | /* Startup the kernel thread for this host adapter. */ |
| 7095 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 7096 | "lpfc_worker_%d", phba->brd_no); |
| 7097 | if (IS_ERR(phba->worker_thread)) { |
| 7098 | error = PTR_ERR(phba->worker_thread); |
| 7099 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7100 | } |
| 7101 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7102 | return 0; |
| 7103 | } |
| 7104 | |
| 7105 | /** |
| 7106 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7107 | * @phba: pointer to lpfc hba data structure. |
| 7108 | * |
| 7109 | * This routine is invoked to unset the driver internal resources set up after |
| 7110 | * the device specific resource setup for supporting the HBA device it |
| 7111 | * attached to. |
| 7112 | **/ |
| 7113 | static void |
| 7114 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7115 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7116 | if (phba->wq) { |
| 7117 | flush_workqueue(phba->wq); |
| 7118 | destroy_workqueue(phba->wq); |
| 7119 | phba->wq = NULL; |
| 7120 | } |
| 7121 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7122 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7123 | if (phba->worker_thread) |
| 7124 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | /** |
| 7128 | * lpfc_free_iocb_list - Free iocb list. |
| 7129 | * @phba: pointer to lpfc hba data structure. |
| 7130 | * |
| 7131 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7132 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7133 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7134 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7135 | { |
| 7136 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7137 | |
| 7138 | spin_lock_irq(&phba->hbalock); |
| 7139 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7140 | &phba->lpfc_iocb_list, list) { |
| 7141 | list_del(&iocbq_entry->list); |
| 7142 | kfree(iocbq_entry); |
| 7143 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7144 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7145 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7146 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7147 | return; |
| 7148 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7149 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7150 | /** |
| 7151 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7152 | * @phba: pointer to lpfc hba data structure. |
| 7153 | * |
| 7154 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7155 | * list and set up the IOCB tag array accordingly. |
| 7156 | * |
| 7157 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7158 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7159 | * other values - error |
| 7160 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7161 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7162 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7163 | { |
| 7164 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7165 | uint16_t iotag; |
| 7166 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7167 | |
| 7168 | /* Initialize and populate the iocb list per host. */ |
| 7169 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7170 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7171 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7172 | if (iocbq_entry == NULL) { |
| 7173 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7174 | "expected %d count. Unloading driver.\n", |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7175 | __func__, i, iocb_count); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7176 | goto out_free_iocbq; |
| 7177 | } |
| 7178 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7179 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7180 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7181 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7182 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7183 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7184 | goto out_free_iocbq; |
| 7185 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7186 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7187 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7188 | |
| 7189 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7190 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7191 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7192 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7193 | } |
| 7194 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7195 | return 0; |
| 7196 | |
| 7197 | out_free_iocbq: |
| 7198 | lpfc_free_iocb_list(phba); |
| 7199 | |
| 7200 | return -ENOMEM; |
| 7201 | } |
| 7202 | |
| 7203 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7204 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7205 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7206 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7207 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7208 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7209 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7210 | void |
| 7211 | 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] | 7212 | { |
| 7213 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7214 | |
| 7215 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7216 | list_del(&sglq_entry->list); |
| 7217 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7218 | kfree(sglq_entry); |
| 7219 | } |
| 7220 | } |
| 7221 | |
| 7222 | /** |
| 7223 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7224 | * @phba: pointer to lpfc hba data structure. |
| 7225 | * |
| 7226 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7227 | **/ |
| 7228 | static void |
| 7229 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7230 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7231 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7232 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7233 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7234 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7235 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7236 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 7237 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7238 | spin_unlock_irq(&phba->hbalock); |
| 7239 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7240 | /* Now free the sgl list */ |
| 7241 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7245 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7246 | * @phba: pointer to lpfc hba data structure. |
| 7247 | * |
| 7248 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7249 | **/ |
| 7250 | static void |
| 7251 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7252 | { |
| 7253 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7254 | LIST_HEAD(sglq_list); |
| 7255 | |
| 7256 | /* Retrieve all nvmet sgls from driver list */ |
| 7257 | spin_lock_irq(&phba->hbalock); |
| 7258 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7259 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7260 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7261 | spin_unlock_irq(&phba->hbalock); |
| 7262 | |
| 7263 | /* Now free the sgl list */ |
| 7264 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7265 | list_del(&sglq_entry->list); |
| 7266 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7267 | kfree(sglq_entry); |
| 7268 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7269 | |
| 7270 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7271 | * The next initialization cycle sets the count and allocates |
| 7272 | * the sgls over again. |
| 7273 | */ |
| 7274 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7275 | } |
| 7276 | |
| 7277 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7278 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7279 | * @phba: pointer to lpfc hba data structure. |
| 7280 | * |
| 7281 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7282 | * This array will hold the sglq_entry's for active IOs. |
| 7283 | **/ |
| 7284 | static int |
| 7285 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7286 | { |
| 7287 | int size; |
| 7288 | size = sizeof(struct lpfc_sglq *); |
| 7289 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7290 | |
| 7291 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7292 | kzalloc(size, GFP_KERNEL); |
| 7293 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7294 | return -ENOMEM; |
| 7295 | return 0; |
| 7296 | } |
| 7297 | |
| 7298 | /** |
| 7299 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7300 | * @phba: pointer to lpfc hba data structure. |
| 7301 | * |
| 7302 | * This routine is invoked to walk through the array of active sglq entries |
| 7303 | * and free all of the resources. |
| 7304 | * This is just a place holder for now. |
| 7305 | **/ |
| 7306 | static void |
| 7307 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7308 | { |
| 7309 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7310 | } |
| 7311 | |
| 7312 | /** |
| 7313 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7314 | * @phba: pointer to lpfc hba data structure. |
| 7315 | * |
| 7316 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7317 | * list and set up the sgl xritag tag array accordingly. |
| 7318 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7319 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7320 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7321 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7322 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7323 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7324 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7325 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7326 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7327 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7328 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7329 | /* els xri-sgl book keeping */ |
| 7330 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7331 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7332 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7333 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | /** |
| 7337 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7338 | * @phba: pointer to lpfc hba data structure. |
| 7339 | * |
| 7340 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7341 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7342 | * 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] | 7343 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7344 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7345 | * |
| 7346 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7347 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7348 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7349 | **/ |
| 7350 | int |
| 7351 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7352 | { |
| 7353 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7354 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7355 | |
| 7356 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7357 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7358 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7359 | if (phba->sli4_hba.extents_in_use) |
| 7360 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7361 | |
| 7362 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7363 | if (!rpi_hdr) { |
| 7364 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7365 | "0391 Error during rpi post operation\n"); |
| 7366 | lpfc_sli4_remove_rpis(phba); |
| 7367 | rc = -ENODEV; |
| 7368 | } |
| 7369 | |
| 7370 | return rc; |
| 7371 | } |
| 7372 | |
| 7373 | /** |
| 7374 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7375 | * @phba: pointer to lpfc hba data structure. |
| 7376 | * |
| 7377 | * This routine is invoked to allocate a single 4KB memory region to |
| 7378 | * support rpis and stores them in the phba. This single region |
| 7379 | * provides support for up to 64 rpis. The region is used globally |
| 7380 | * by the device. |
| 7381 | * |
| 7382 | * Returns: |
| 7383 | * A valid rpi hdr on success. |
| 7384 | * A NULL pointer on any failure. |
| 7385 | **/ |
| 7386 | struct lpfc_rpi_hdr * |
| 7387 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7388 | { |
| 7389 | uint16_t rpi_limit, curr_rpi_range; |
| 7390 | struct lpfc_dmabuf *dmabuf; |
| 7391 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7392 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7393 | /* |
| 7394 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7395 | * required. Set the expected maximum count and let the actual value |
| 7396 | * get set when extents are fully allocated. |
| 7397 | */ |
| 7398 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7399 | return NULL; |
| 7400 | if (phba->sli4_hba.extents_in_use) |
| 7401 | return NULL; |
| 7402 | |
| 7403 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7404 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7405 | |
| 7406 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7407 | /* |
| 7408 | * Establish the starting RPI in this header block. The starting |
| 7409 | * rpi is normalized to a zero base because the physical rpi is |
| 7410 | * port based. |
| 7411 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7412 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7413 | spin_unlock_irq(&phba->hbalock); |
| 7414 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7415 | /* Reached full RPI range */ |
| 7416 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7417 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7418 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7419 | /* |
| 7420 | * First allocate the protocol header region for the port. The |
| 7421 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7422 | */ |
| 7423 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7424 | if (!dmabuf) |
| 7425 | return NULL; |
| 7426 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7427 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7428 | LPFC_HDR_TEMPLATE_SIZE, |
| 7429 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7430 | if (!dmabuf->virt) { |
| 7431 | rpi_hdr = NULL; |
| 7432 | goto err_free_dmabuf; |
| 7433 | } |
| 7434 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7435 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7436 | rpi_hdr = NULL; |
| 7437 | goto err_free_coherent; |
| 7438 | } |
| 7439 | |
| 7440 | /* Save the rpi header data for cleanup later. */ |
| 7441 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7442 | if (!rpi_hdr) |
| 7443 | goto err_free_coherent; |
| 7444 | |
| 7445 | rpi_hdr->dmabuf = dmabuf; |
| 7446 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7447 | rpi_hdr->page_count = 1; |
| 7448 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7449 | |
| 7450 | /* The rpi_hdr stores the logical index only. */ |
| 7451 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7452 | 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] | 7453 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7454 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7455 | spin_unlock_irq(&phba->hbalock); |
| 7456 | return rpi_hdr; |
| 7457 | |
| 7458 | err_free_coherent: |
| 7459 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7460 | dmabuf->virt, dmabuf->phys); |
| 7461 | err_free_dmabuf: |
| 7462 | kfree(dmabuf); |
| 7463 | return NULL; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
| 7467 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7468 | * @phba: pointer to lpfc hba data structure. |
| 7469 | * |
| 7470 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7471 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7472 | * presumes the caller has released all rpis consumed by fabric or port |
| 7473 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7474 | **/ |
| 7475 | void |
| 7476 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7477 | { |
| 7478 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7479 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7480 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7481 | goto exit; |
| 7482 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7483 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7484 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7485 | list_del(&rpi_hdr->list); |
| 7486 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7487 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7488 | kfree(rpi_hdr->dmabuf); |
| 7489 | kfree(rpi_hdr); |
| 7490 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7491 | exit: |
| 7492 | /* There are no rpis available to the port now. */ |
| 7493 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7497 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7498 | * @pdev: pointer to pci device data structure. |
| 7499 | * |
| 7500 | * This routine is invoked to allocate the driver hba data structure for an |
| 7501 | * HBA device. If the allocation is successful, the phba reference to the |
| 7502 | * PCI device data structure is set. |
| 7503 | * |
| 7504 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7505 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7506 | * NULL - error |
| 7507 | **/ |
| 7508 | static struct lpfc_hba * |
| 7509 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7510 | { |
| 7511 | struct lpfc_hba *phba; |
| 7512 | |
| 7513 | /* Allocate memory for HBA structure */ |
| 7514 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7515 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7516 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7517 | return NULL; |
| 7518 | } |
| 7519 | |
| 7520 | /* Set reference to PCI device in HBA structure */ |
| 7521 | phba->pcidev = pdev; |
| 7522 | |
| 7523 | /* Assign an unused board number */ |
| 7524 | phba->brd_no = lpfc_get_instance(); |
| 7525 | if (phba->brd_no < 0) { |
| 7526 | kfree(phba); |
| 7527 | return NULL; |
| 7528 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7529 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7530 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7531 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7532 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7534 | return phba; |
| 7535 | } |
| 7536 | |
| 7537 | /** |
| 7538 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7539 | * @phba: pointer to lpfc hba data structure. |
| 7540 | * |
| 7541 | * This routine is invoked to free the driver hba data structure with an |
| 7542 | * HBA device. |
| 7543 | **/ |
| 7544 | static void |
| 7545 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7546 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7547 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7548 | kfree(phba->sli4_hba.hdwq); |
| 7549 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7550 | /* Release the driver assigned board number */ |
| 7551 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7552 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7553 | /* Free memory allocated with sli3 rings */ |
| 7554 | kfree(phba->sli.sli3_ring); |
| 7555 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7556 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7557 | kfree(phba); |
| 7558 | return; |
| 7559 | } |
| 7560 | |
| 7561 | /** |
| 7562 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7563 | * @phba: pointer to lpfc hba data structure. |
| 7564 | * |
| 7565 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7566 | * host with it. |
| 7567 | * |
| 7568 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7569 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7570 | * other values - error |
| 7571 | **/ |
| 7572 | static int |
| 7573 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7574 | { |
| 7575 | struct lpfc_vport *vport; |
| 7576 | struct Scsi_Host *shost; |
| 7577 | |
| 7578 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7579 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7580 | phba->fc_ratov = FF_DEF_RATOV; |
| 7581 | phba->fc_altov = FF_DEF_ALTOV; |
| 7582 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7583 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7584 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7585 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7586 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7587 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7588 | |
| 7589 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7590 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7591 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7592 | if (phba->nvmet_support) { |
| 7593 | /* Only 1 vport (pport) will support NVME target */ |
James Smart | ea85a20 | 2019-10-18 14:18:25 -0700 | [diff] [blame] | 7594 | phba->targetport = NULL; |
| 7595 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7596 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC, |
| 7597 | "6076 NVME Target Found\n"); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7598 | } |
| 7599 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7600 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7601 | /* Put reference to SCSI host to driver's device private data */ |
| 7602 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7603 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7604 | /* |
| 7605 | * At this point we are fully registered with PSA. In addition, |
| 7606 | * any initial discovery should be completed. |
| 7607 | */ |
| 7608 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7609 | if (phba->cfg_enable_SmartSAN || |
| 7610 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7611 | |
| 7612 | /* Setup appropriate attribute masks */ |
| 7613 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7614 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7615 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7616 | else |
| 7617 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7618 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7619 | return 0; |
| 7620 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7621 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7622 | /** |
| 7623 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7624 | * @phba: pointer to lpfc hba data structure. |
| 7625 | * |
| 7626 | * This routine is invoked to destroy HBA physical port and the associated |
| 7627 | * SCSI host. |
| 7628 | **/ |
| 7629 | static void |
| 7630 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7631 | { |
| 7632 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7633 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7634 | /* Destroy physical port that associated with the SCSI host */ |
| 7635 | destroy_port(vport); |
| 7636 | |
| 7637 | return; |
| 7638 | } |
| 7639 | |
| 7640 | /** |
| 7641 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7642 | * @phba: pointer to lpfc hba data structure. |
| 7643 | * @shost: the shost to be used to detect Block guard settings. |
| 7644 | * |
| 7645 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7646 | * This routine also allocates memory for debugging bg buffers. |
| 7647 | **/ |
| 7648 | static void |
| 7649 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7650 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7651 | uint32_t old_mask; |
| 7652 | uint32_t old_guard; |
| 7653 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7654 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7655 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7656 | "1478 Registering BlockGuard with the " |
| 7657 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7658 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7659 | old_mask = phba->cfg_prot_mask; |
| 7660 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7661 | |
| 7662 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7663 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7664 | SHOST_DIX_TYPE0_PROTECTION | |
| 7665 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7666 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7667 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7668 | |
| 7669 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7670 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7671 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7672 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7673 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7674 | if ((old_mask != phba->cfg_prot_mask) || |
| 7675 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7676 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7677 | "1475 Registering BlockGuard with the " |
| 7678 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7679 | phba->cfg_prot_mask, |
| 7680 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7681 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7682 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7683 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7684 | } else |
| 7685 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7686 | "1479 Not Registering BlockGuard with the SCSI " |
| 7687 | "layer, Bad protection parameters: %d %d\n", |
| 7688 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7689 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | /** |
| 7693 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7694 | * @phba: pointer to lpfc hba data structure. |
| 7695 | * |
| 7696 | * This routine is invoked to perform all the necessary post initialization |
| 7697 | * setup for the device. |
| 7698 | **/ |
| 7699 | static void |
| 7700 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7701 | { |
| 7702 | struct Scsi_Host *shost; |
| 7703 | struct lpfc_adapter_event_header adapter_event; |
| 7704 | |
| 7705 | /* Get the default values for Model Name and Description */ |
| 7706 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7707 | |
| 7708 | /* |
| 7709 | * hba setup may have changed the hba_queue_depth so we need to |
| 7710 | * adjust the value of can_queue. |
| 7711 | */ |
| 7712 | shost = pci_get_drvdata(phba->pcidev); |
| 7713 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7714 | |
| 7715 | lpfc_host_attrib_init(shost); |
| 7716 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7717 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7718 | spin_lock_irq(shost->host_lock); |
| 7719 | lpfc_poll_start_timer(phba); |
| 7720 | spin_unlock_irq(shost->host_lock); |
| 7721 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7722 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7723 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7724 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7725 | /* Send board arrival event to upper layer */ |
| 7726 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7727 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7728 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7729 | sizeof(adapter_event), |
| 7730 | (char *) &adapter_event, |
| 7731 | LPFC_NL_VENDOR_ID); |
| 7732 | return; |
| 7733 | } |
| 7734 | |
| 7735 | /** |
| 7736 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7737 | * @phba: pointer to lpfc hba data structure. |
| 7738 | * |
| 7739 | * This routine is invoked to set up the PCI device memory space for device |
| 7740 | * with SLI-3 interface spec. |
| 7741 | * |
| 7742 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7743 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7744 | * other values - error |
| 7745 | **/ |
| 7746 | static int |
| 7747 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7748 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7749 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7750 | unsigned long bar0map_len, bar2map_len; |
| 7751 | int i, hbq_count; |
| 7752 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7753 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7754 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7755 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7756 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7757 | |
| 7758 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7759 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7760 | if (error) |
| 7761 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7762 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7763 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7764 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7765 | |
| 7766 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7767 | * required by each mapping. |
| 7768 | */ |
| 7769 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7770 | bar0map_len = pci_resource_len(pdev, 0); |
| 7771 | |
| 7772 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7773 | bar2map_len = pci_resource_len(pdev, 2); |
| 7774 | |
| 7775 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7776 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7777 | if (!phba->slim_memmap_p) { |
| 7778 | dev_printk(KERN_ERR, &pdev->dev, |
| 7779 | "ioremap failed for SLIM memory.\n"); |
| 7780 | goto out; |
| 7781 | } |
| 7782 | |
| 7783 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7784 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7785 | if (!phba->ctrl_regs_memmap_p) { |
| 7786 | dev_printk(KERN_ERR, &pdev->dev, |
| 7787 | "ioremap failed for HBA control registers.\n"); |
| 7788 | goto out_iounmap_slim; |
| 7789 | } |
| 7790 | |
| 7791 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7792 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7793 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7794 | if (!phba->slim2p.virt) |
| 7795 | goto out_iounmap; |
| 7796 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7797 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7798 | phba->mbox_ext = (phba->slim2p.virt + |
| 7799 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7800 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7801 | phba->IOCBs = (phba->slim2p.virt + |
| 7802 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7803 | |
| 7804 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7805 | lpfc_sli_hbq_size(), |
| 7806 | &phba->hbqslimp.phys, |
| 7807 | GFP_KERNEL); |
| 7808 | if (!phba->hbqslimp.virt) |
| 7809 | goto out_free_slim; |
| 7810 | |
| 7811 | hbq_count = lpfc_sli_hbq_count(); |
| 7812 | ptr = phba->hbqslimp.virt; |
| 7813 | for (i = 0; i < hbq_count; ++i) { |
| 7814 | phba->hbqs[i].hbq_virt = ptr; |
| 7815 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7816 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7817 | sizeof(struct lpfc_hbq_entry)); |
| 7818 | } |
| 7819 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7820 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7821 | |
| 7822 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7823 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7824 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7825 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7826 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7827 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7828 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7829 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7830 | return 0; |
| 7831 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7832 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7833 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7834 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7835 | out_iounmap: |
| 7836 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7837 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7838 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7839 | out: |
| 7840 | return error; |
| 7841 | } |
| 7842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7843 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7844 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7845 | * @phba: pointer to lpfc hba data structure. |
| 7846 | * |
| 7847 | * This routine is invoked to unset the PCI device memory space for device |
| 7848 | * with SLI-3 interface spec. |
| 7849 | **/ |
| 7850 | static void |
| 7851 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7852 | { |
| 7853 | struct pci_dev *pdev; |
| 7854 | |
| 7855 | /* Obtain PCI device reference */ |
| 7856 | if (!phba->pcidev) |
| 7857 | return; |
| 7858 | else |
| 7859 | pdev = phba->pcidev; |
| 7860 | |
| 7861 | /* Free coherent DMA memory allocated */ |
| 7862 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7863 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7864 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7865 | phba->slim2p.virt, phba->slim2p.phys); |
| 7866 | |
| 7867 | /* I/O memory unmap */ |
| 7868 | iounmap(phba->ctrl_regs_memmap_p); |
| 7869 | iounmap(phba->slim_memmap_p); |
| 7870 | |
| 7871 | return; |
| 7872 | } |
| 7873 | |
| 7874 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7875 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7876 | * @phba: pointer to lpfc hba data structure. |
| 7877 | * |
| 7878 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7879 | * done and check status. |
| 7880 | * |
| 7881 | * Return 0 if successful, otherwise -ENODEV. |
| 7882 | **/ |
| 7883 | int |
| 7884 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7885 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7886 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7887 | struct lpfc_register reg_data; |
| 7888 | int i, port_error = 0; |
| 7889 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7890 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7891 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7892 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7893 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7894 | return -ENODEV; |
| 7895 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7896 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7897 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7898 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7899 | &portsmphr_reg.word0) || |
| 7900 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7901 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7902 | port_error = -ENODEV; |
| 7903 | break; |
| 7904 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7905 | if (LPFC_POST_STAGE_PORT_READY == |
| 7906 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7907 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7908 | msleep(10); |
| 7909 | } |
| 7910 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7911 | /* |
| 7912 | * If there was a port error during POST, then don't proceed with |
| 7913 | * other register reads as the data may not be valid. Just exit. |
| 7914 | */ |
| 7915 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7917 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7918 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7919 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7920 | portsmphr_reg.word0, |
| 7921 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7922 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7923 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7924 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7925 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7926 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7927 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7928 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7929 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7930 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7931 | "2534 Device Info: SLIFamily=0x%x, " |
| 7932 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7933 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7934 | bf_get(lpfc_sli_intf_sli_family, |
| 7935 | &phba->sli4_hba.sli_intf), |
| 7936 | bf_get(lpfc_sli_intf_slirev, |
| 7937 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7938 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7939 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7940 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7941 | &phba->sli4_hba.sli_intf), |
| 7942 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7943 | &phba->sli4_hba.sli_intf), |
| 7944 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7945 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7946 | /* |
| 7947 | * Check for other Port errors during the initialization |
| 7948 | * process. Fail the load if the port did not come up |
| 7949 | * correctly. |
| 7950 | */ |
| 7951 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7952 | &phba->sli4_hba.sli_intf); |
| 7953 | switch (if_type) { |
| 7954 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7955 | phba->sli4_hba.ue_mask_lo = |
| 7956 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7957 | phba->sli4_hba.ue_mask_hi = |
| 7958 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7959 | uerrlo_reg.word0 = |
| 7960 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7961 | uerrhi_reg.word0 = |
| 7962 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7963 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7964 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7965 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7966 | "1422 Unrecoverable Error " |
| 7967 | "Detected during POST " |
| 7968 | "uerr_lo_reg=0x%x, " |
| 7969 | "uerr_hi_reg=0x%x, " |
| 7970 | "ue_mask_lo_reg=0x%x, " |
| 7971 | "ue_mask_hi_reg=0x%x\n", |
| 7972 | uerrlo_reg.word0, |
| 7973 | uerrhi_reg.word0, |
| 7974 | phba->sli4_hba.ue_mask_lo, |
| 7975 | phba->sli4_hba.ue_mask_hi); |
| 7976 | port_error = -ENODEV; |
| 7977 | } |
| 7978 | break; |
| 7979 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7980 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7981 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7982 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7983 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7984 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7985 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7986 | phba->work_status[0] = |
| 7987 | readl(phba->sli4_hba.u.if_type2. |
| 7988 | ERR1regaddr); |
| 7989 | phba->work_status[1] = |
| 7990 | readl(phba->sli4_hba.u.if_type2. |
| 7991 | ERR2regaddr); |
| 7992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7993 | "2888 Unrecoverable port error " |
| 7994 | "following POST: port status reg " |
| 7995 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7996 | "error 1=0x%x, error 2=0x%x\n", |
| 7997 | reg_data.word0, |
| 7998 | portsmphr_reg.word0, |
| 7999 | phba->work_status[0], |
| 8000 | phba->work_status[1]); |
| 8001 | port_error = -ENODEV; |
| 8002 | } |
| 8003 | break; |
| 8004 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8005 | default: |
| 8006 | break; |
| 8007 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8008 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8009 | return port_error; |
| 8010 | } |
| 8011 | |
| 8012 | /** |
| 8013 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 8014 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8015 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8016 | * |
| 8017 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 8018 | * memory map. |
| 8019 | **/ |
| 8020 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8021 | 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] | 8022 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8023 | switch (if_type) { |
| 8024 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8025 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 8026 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 8027 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 8028 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 8029 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 8030 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 8031 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 8032 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 8033 | phba->sli4_hba.SLIINTFregaddr = |
| 8034 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8035 | break; |
| 8036 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8037 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8038 | phba->sli4_hba.conf_regs_memmap_p + |
| 8039 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8040 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8041 | phba->sli4_hba.conf_regs_memmap_p + |
| 8042 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8043 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8044 | phba->sli4_hba.conf_regs_memmap_p + |
| 8045 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8046 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8047 | phba->sli4_hba.conf_regs_memmap_p + |
| 8048 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8049 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8050 | phba->sli4_hba.conf_regs_memmap_p + |
| 8051 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8052 | phba->sli4_hba.SLIINTFregaddr = |
| 8053 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8054 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8055 | phba->sli4_hba.conf_regs_memmap_p + |
| 8056 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8057 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8058 | phba->sli4_hba.conf_regs_memmap_p + |
| 8059 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8060 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8061 | phba->sli4_hba.conf_regs_memmap_p + |
| 8062 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8063 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8064 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8065 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8066 | phba->sli4_hba.MQDBregaddr = |
| 8067 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8068 | phba->sli4_hba.BMBXregaddr = |
| 8069 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8070 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8071 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8072 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8073 | phba->sli4_hba.conf_regs_memmap_p + |
| 8074 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8075 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8076 | phba->sli4_hba.conf_regs_memmap_p + |
| 8077 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8078 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8079 | phba->sli4_hba.conf_regs_memmap_p + |
| 8080 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8081 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8082 | phba->sli4_hba.conf_regs_memmap_p + |
| 8083 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8084 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8085 | phba->sli4_hba.conf_regs_memmap_p + |
| 8086 | LPFC_CTL_PORT_STA_OFFSET; |
| 8087 | phba->sli4_hba.PSMPHRregaddr = |
| 8088 | phba->sli4_hba.conf_regs_memmap_p + |
| 8089 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8090 | phba->sli4_hba.BMBXregaddr = |
| 8091 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8092 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8093 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8094 | default: |
| 8095 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8096 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8097 | if_type); |
| 8098 | break; |
| 8099 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | /** |
| 8103 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8104 | * @phba: pointer to lpfc hba data structure. |
| 8105 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8106 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8107 | **/ |
| 8108 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8109 | 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] | 8110 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8111 | switch (if_type) { |
| 8112 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8113 | phba->sli4_hba.PSMPHRregaddr = |
| 8114 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8115 | LPFC_SLIPORT_IF0_SMPHR; |
| 8116 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8117 | LPFC_HST_ISR0; |
| 8118 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8119 | LPFC_HST_IMR0; |
| 8120 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8121 | LPFC_HST_ISCR0; |
| 8122 | break; |
| 8123 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8124 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8125 | LPFC_IF6_RQ_DOORBELL; |
| 8126 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8127 | LPFC_IF6_WQ_DOORBELL; |
| 8128 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8129 | LPFC_IF6_CQ_DOORBELL; |
| 8130 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8131 | LPFC_IF6_EQ_DOORBELL; |
| 8132 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8133 | LPFC_IF6_MQ_DOORBELL; |
| 8134 | break; |
| 8135 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8136 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8137 | default: |
| 8138 | dev_err(&phba->pcidev->dev, |
| 8139 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8140 | if_type); |
| 8141 | break; |
| 8142 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8143 | } |
| 8144 | |
| 8145 | /** |
| 8146 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8147 | * @phba: pointer to lpfc hba data structure. |
| 8148 | * @vf: virtual function number |
| 8149 | * |
| 8150 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8151 | * based on the given viftual function number, @vf. |
| 8152 | * |
| 8153 | * Return 0 if successful, otherwise -ENODEV. |
| 8154 | **/ |
| 8155 | static int |
| 8156 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8157 | { |
| 8158 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8159 | return -ENODEV; |
| 8160 | |
| 8161 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8162 | vf * LPFC_VFR_PAGE_SIZE + |
| 8163 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8164 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8165 | vf * LPFC_VFR_PAGE_SIZE + |
| 8166 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8167 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8168 | vf * LPFC_VFR_PAGE_SIZE + |
| 8169 | LPFC_EQCQ_DOORBELL); |
| 8170 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8171 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8172 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8173 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8174 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8175 | return 0; |
| 8176 | } |
| 8177 | |
| 8178 | /** |
| 8179 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8180 | * @phba: pointer to lpfc hba data structure. |
| 8181 | * |
| 8182 | * This routine is invoked to create the bootstrap mailbox |
| 8183 | * region consistent with the SLI-4 interface spec. This |
| 8184 | * routine allocates all memory necessary to communicate |
| 8185 | * mailbox commands to the port and sets up all alignment |
| 8186 | * needs. No locks are expected to be held when calling |
| 8187 | * this routine. |
| 8188 | * |
| 8189 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8190 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8191 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8192 | **/ |
| 8193 | static int |
| 8194 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8195 | { |
| 8196 | uint32_t bmbx_size; |
| 8197 | struct lpfc_dmabuf *dmabuf; |
| 8198 | struct dma_address *dma_address; |
| 8199 | uint32_t pa_addr; |
| 8200 | uint64_t phys_addr; |
| 8201 | |
| 8202 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8203 | if (!dmabuf) |
| 8204 | return -ENOMEM; |
| 8205 | |
| 8206 | /* |
| 8207 | * The bootstrap mailbox region is comprised of 2 parts |
| 8208 | * plus an alignment restriction of 16 bytes. |
| 8209 | */ |
| 8210 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8211 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8212 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8213 | if (!dmabuf->virt) { |
| 8214 | kfree(dmabuf); |
| 8215 | return -ENOMEM; |
| 8216 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8217 | |
| 8218 | /* |
| 8219 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8220 | * operations are simple later. The mailbox dma address is required |
| 8221 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8222 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8223 | * command to the port. |
| 8224 | */ |
| 8225 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8226 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8227 | |
| 8228 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8229 | LPFC_ALIGN_16_BYTE); |
| 8230 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8231 | LPFC_ALIGN_16_BYTE); |
| 8232 | |
| 8233 | /* |
| 8234 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8235 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8236 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8237 | * the 30-bit address is the high or low address. |
| 8238 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8239 | * clean on 32 bit machines. |
| 8240 | */ |
| 8241 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8242 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8243 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8244 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8245 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8246 | |
| 8247 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8248 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8249 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8250 | return 0; |
| 8251 | } |
| 8252 | |
| 8253 | /** |
| 8254 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8255 | * @phba: pointer to lpfc hba data structure. |
| 8256 | * |
| 8257 | * This routine is invoked to teardown the bootstrap mailbox |
| 8258 | * region and release all host resources. This routine requires |
| 8259 | * the caller to ensure all mailbox commands recovered, no |
| 8260 | * additional mailbox comands are sent, and interrupts are disabled |
| 8261 | * before calling this routine. |
| 8262 | * |
| 8263 | **/ |
| 8264 | static void |
| 8265 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8266 | { |
| 8267 | dma_free_coherent(&phba->pcidev->dev, |
| 8268 | phba->sli4_hba.bmbx.bmbx_size, |
| 8269 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8270 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8271 | |
| 8272 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8273 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8274 | } |
| 8275 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8276 | static const char * const lpfc_topo_to_str[] = { |
| 8277 | "Loop then P2P", |
| 8278 | "Loopback", |
| 8279 | "P2P Only", |
| 8280 | "Unsupported", |
| 8281 | "Loop Only", |
| 8282 | "Unsupported", |
| 8283 | "P2P then Loop", |
| 8284 | }; |
| 8285 | |
| 8286 | /** |
| 8287 | * lpfc_map_topology - Map the topology read from READ_CONFIG |
| 8288 | * @phba: pointer to lpfc hba data structure. |
| 8289 | * @rdconf: pointer to read config data |
| 8290 | * |
| 8291 | * This routine is invoked to map the topology values as read |
| 8292 | * from the read config mailbox command. If the persistent |
| 8293 | * topology feature is supported, the firmware will provide the |
| 8294 | * saved topology information to be used in INIT_LINK |
| 8295 | * |
| 8296 | **/ |
| 8297 | #define LINK_FLAGS_DEF 0x0 |
| 8298 | #define LINK_FLAGS_P2P 0x1 |
| 8299 | #define LINK_FLAGS_LOOP 0x2 |
| 8300 | static void |
| 8301 | lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config) |
| 8302 | { |
| 8303 | u8 ptv, tf, pt; |
| 8304 | |
| 8305 | ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config); |
| 8306 | tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config); |
| 8307 | pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config); |
| 8308 | |
| 8309 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8310 | "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x", |
| 8311 | ptv, tf, pt); |
| 8312 | if (!ptv) { |
| 8313 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8314 | "2019 FW does not support persistent topology " |
| 8315 | "Using driver parameter defined value [%s]", |
| 8316 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8317 | return; |
| 8318 | } |
| 8319 | /* FW supports persistent topology - override module parameter value */ |
| 8320 | phba->hba_flag |= HBA_PERSISTENT_TOPO; |
| 8321 | switch (phba->pcidev->device) { |
| 8322 | case PCI_DEVICE_ID_LANCER_G7_FC: |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8323 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 8324 | if (!tf) { |
| 8325 | phba->cfg_topology = ((pt == LINK_FLAGS_LOOP) |
| 8326 | ? FLAGS_TOPOLOGY_MODE_LOOP |
| 8327 | : FLAGS_TOPOLOGY_MODE_PT_PT); |
| 8328 | } else { |
| 8329 | phba->hba_flag &= ~HBA_PERSISTENT_TOPO; |
| 8330 | } |
| 8331 | break; |
| 8332 | default: /* G5 */ |
| 8333 | if (tf) { |
| 8334 | /* If topology failover set - pt is '0' or '1' */ |
| 8335 | phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP : |
| 8336 | FLAGS_TOPOLOGY_MODE_LOOP_PT); |
| 8337 | } else { |
| 8338 | phba->cfg_topology = ((pt == LINK_FLAGS_P2P) |
| 8339 | ? FLAGS_TOPOLOGY_MODE_PT_PT |
| 8340 | : FLAGS_TOPOLOGY_MODE_LOOP); |
| 8341 | } |
| 8342 | break; |
| 8343 | } |
| 8344 | if (phba->hba_flag & HBA_PERSISTENT_TOPO) { |
| 8345 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8346 | "2020 Using persistent topology value [%s]", |
| 8347 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8348 | } else { |
| 8349 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8350 | "2021 Invalid topology values from FW " |
| 8351 | "Using driver parameter defined value [%s]", |
| 8352 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8353 | } |
| 8354 | } |
| 8355 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8356 | /** |
| 8357 | * lpfc_sli4_read_config - Get the config parameters. |
| 8358 | * @phba: pointer to lpfc hba data structure. |
| 8359 | * |
| 8360 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8361 | * The configuration parameters are used to set the base and maximum values |
| 8362 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8363 | * allocation for the port. |
| 8364 | * |
| 8365 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8366 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8367 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8368 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8369 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8370 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8371 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8372 | { |
| 8373 | LPFC_MBOXQ_t *pmb; |
| 8374 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8375 | union lpfc_sli4_cfg_shdr *shdr; |
| 8376 | uint32_t shdr_status, shdr_add_status; |
| 8377 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8378 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8379 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8380 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8381 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8382 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8383 | |
| 8384 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8385 | if (!pmb) { |
| 8386 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8387 | "2011 Unable to allocate memory for issuing " |
| 8388 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8389 | return -ENOMEM; |
| 8390 | } |
| 8391 | |
| 8392 | lpfc_read_config(phba, pmb); |
| 8393 | |
| 8394 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8395 | if (rc != MBX_SUCCESS) { |
| 8396 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8397 | "2012 Mailbox failed , mbxCmd x%x " |
| 8398 | "READ_CONFIG, mbxStatus x%x\n", |
| 8399 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8400 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 8401 | rc = -EIO; |
| 8402 | } else { |
| 8403 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8404 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8405 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8406 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8407 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8408 | phba->sli4_hba.lnk_info.lnk_no = |
| 8409 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8410 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8411 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8412 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8413 | phba->sli4_hba.lnk_info.lnk_no); |
| 8414 | } else |
| 8415 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8416 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8417 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8418 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8419 | phba->bbcredit_support = 1; |
| 8420 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8421 | } |
| 8422 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8423 | phba->sli4_hba.conf_trunk = |
| 8424 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8425 | phba->sli4_hba.extents_in_use = |
| 8426 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8427 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8428 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8429 | /* Reduce resource usage in kdump environment */ |
| 8430 | if (is_kdump_kernel() && |
| 8431 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8432 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8433 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8434 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8435 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8436 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8437 | /* Limit the max we support */ |
| 8438 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8439 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8440 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8441 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8442 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8443 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8444 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8445 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8446 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8447 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8448 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8449 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8450 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8451 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8452 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8453 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8454 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8455 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8456 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8457 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8458 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8459 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8460 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8461 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8462 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8463 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8464 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8465 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | phba->max_vports = phba->max_vpi; |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8467 | lpfc_map_topology(phba, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8468 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8469 | "2003 cfg params Extents? %d " |
| 8470 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8471 | "VPI(B:%d M:%d) " |
| 8472 | "VFI(B:%d M:%d) " |
| 8473 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8474 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8475 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8476 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8477 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8478 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8479 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8480 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8481 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8482 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8483 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8484 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8485 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8486 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8487 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8488 | phba->sli4_hba.max_cfg_param.max_rq); |
| 8489 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8490 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8491 | * Calculate queue resources based on how |
| 8492 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8493 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8494 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8495 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8496 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8497 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8498 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8499 | /* |
| 8500 | * Whats left after this can go toward NVME / FCP. |
| 8501 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8502 | * plus one extra. When configured for |
| 8503 | * NVMET, FCP io channel WQs are not created. |
| 8504 | */ |
| 8505 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8506 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8507 | /* Check to see if there is enough for NVME */ |
| 8508 | if ((phba->cfg_irq_chann > qmin) || |
| 8509 | (phba->cfg_hdw_queue > qmin)) { |
| 8510 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8511 | "2005 Reducing Queues: " |
| 8512 | "WQ %d CQ %d EQ %d: min %d: " |
| 8513 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8514 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8515 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8516 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8517 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8518 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8519 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8520 | if (phba->cfg_irq_chann > qmin) |
| 8521 | phba->cfg_irq_chann = qmin; |
| 8522 | if (phba->cfg_hdw_queue > qmin) |
| 8523 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8524 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8525 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8526 | |
| 8527 | if (rc) |
| 8528 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8529 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8530 | /* Update link speed if forced link speed is supported */ |
| 8531 | 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] | 8532 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8533 | forced_link_speed = |
| 8534 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8535 | if (forced_link_speed) { |
| 8536 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8537 | |
| 8538 | switch (forced_link_speed) { |
| 8539 | case LINK_SPEED_1G: |
| 8540 | phba->cfg_link_speed = |
| 8541 | LPFC_USER_LINK_SPEED_1G; |
| 8542 | break; |
| 8543 | case LINK_SPEED_2G: |
| 8544 | phba->cfg_link_speed = |
| 8545 | LPFC_USER_LINK_SPEED_2G; |
| 8546 | break; |
| 8547 | case LINK_SPEED_4G: |
| 8548 | phba->cfg_link_speed = |
| 8549 | LPFC_USER_LINK_SPEED_4G; |
| 8550 | break; |
| 8551 | case LINK_SPEED_8G: |
| 8552 | phba->cfg_link_speed = |
| 8553 | LPFC_USER_LINK_SPEED_8G; |
| 8554 | break; |
| 8555 | case LINK_SPEED_10G: |
| 8556 | phba->cfg_link_speed = |
| 8557 | LPFC_USER_LINK_SPEED_10G; |
| 8558 | break; |
| 8559 | case LINK_SPEED_16G: |
| 8560 | phba->cfg_link_speed = |
| 8561 | LPFC_USER_LINK_SPEED_16G; |
| 8562 | break; |
| 8563 | case LINK_SPEED_32G: |
| 8564 | phba->cfg_link_speed = |
| 8565 | LPFC_USER_LINK_SPEED_32G; |
| 8566 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8567 | case LINK_SPEED_64G: |
| 8568 | phba->cfg_link_speed = |
| 8569 | LPFC_USER_LINK_SPEED_64G; |
| 8570 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8571 | case 0xffff: |
| 8572 | phba->cfg_link_speed = |
| 8573 | LPFC_USER_LINK_SPEED_AUTO; |
| 8574 | break; |
| 8575 | default: |
| 8576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8577 | "0047 Unrecognized link " |
| 8578 | "speed : %d\n", |
| 8579 | forced_link_speed); |
| 8580 | phba->cfg_link_speed = |
| 8581 | LPFC_USER_LINK_SPEED_AUTO; |
| 8582 | } |
| 8583 | } |
| 8584 | } |
| 8585 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8586 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8587 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8588 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8589 | if (phba->cfg_hba_queue_depth > length) { |
| 8590 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8591 | "3361 HBA queue depth changed from %d to %d\n", |
| 8592 | phba->cfg_hba_queue_depth, length); |
| 8593 | phba->cfg_hba_queue_depth = length; |
| 8594 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8595 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8596 | 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] | 8597 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8598 | goto read_cfg_out; |
| 8599 | |
| 8600 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8601 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8602 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8603 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8604 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8605 | length, LPFC_SLI4_MBX_EMBED); |
| 8606 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8607 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8608 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8609 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8610 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8611 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8612 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8613 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8614 | "3026 Mailbox failed , mbxCmd x%x " |
| 8615 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8616 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8617 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8618 | goto read_cfg_out; |
| 8619 | } |
| 8620 | |
| 8621 | /* search for fc_fcoe resrouce descriptor */ |
| 8622 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8623 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8624 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8625 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8626 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8627 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8628 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8629 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8630 | goto read_cfg_out; |
| 8631 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8632 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8633 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8634 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8635 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8636 | phba->sli4_hba.iov.pf_number = |
| 8637 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8638 | phba->sli4_hba.iov.vf_number = |
| 8639 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8640 | break; |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8645 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8646 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8647 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8648 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8649 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8651 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8652 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8653 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8654 | |
| 8655 | read_cfg_out: |
| 8656 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8657 | return rc; |
| 8658 | } |
| 8659 | |
| 8660 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8661 | * 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] | 8662 | * @phba: pointer to lpfc hba data structure. |
| 8663 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8664 | * This routine is invoked to setup the port-side endian order when |
| 8665 | * the port if_type is 0. This routine has no function for other |
| 8666 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8667 | * |
| 8668 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8669 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8670 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8671 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8672 | **/ |
| 8673 | static int |
| 8674 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8675 | { |
| 8676 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8677 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8678 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8679 | HOST_ENDIAN_HIGH_WORD1}; |
| 8680 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8681 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8682 | switch (if_type) { |
| 8683 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8684 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8685 | GFP_KERNEL); |
| 8686 | if (!mboxq) { |
| 8687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8688 | "0492 Unable to allocate memory for " |
| 8689 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8690 | "command\n"); |
| 8691 | return -ENOMEM; |
| 8692 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8693 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8694 | /* |
| 8695 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8696 | * two words to contain special data values and no other data. |
| 8697 | */ |
| 8698 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8699 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8700 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8701 | if (rc != MBX_SUCCESS) { |
| 8702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8703 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8704 | "failed with status x%x\n", |
| 8705 | rc); |
| 8706 | rc = -EIO; |
| 8707 | } |
| 8708 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8709 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8710 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8711 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8712 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8713 | default: |
| 8714 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8715 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8716 | return rc; |
| 8717 | } |
| 8718 | |
| 8719 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8720 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8721 | * @phba: pointer to lpfc hba data structure. |
| 8722 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8723 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8724 | * 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] | 8725 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8726 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8727 | * |
| 8728 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8729 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8730 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8731 | **/ |
| 8732 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8733 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8734 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8735 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8736 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8737 | * device parameters |
| 8738 | */ |
| 8739 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8740 | if (phba->nvmet_support) { |
James Smart | 97a9ed3 | 2019-10-18 14:18:17 -0700 | [diff] [blame] | 8741 | if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq) |
| 8742 | phba->cfg_nvmet_mrq = phba->cfg_hdw_queue; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8743 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8744 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8745 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8746 | |
| 8747 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8748 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8749 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8750 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8751 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8752 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8753 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8754 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8755 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8756 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8757 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8758 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8759 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8760 | } |
| 8761 | |
| 8762 | static int |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8763 | lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8764 | { |
| 8765 | struct lpfc_queue *qdesc; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8766 | u32 wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8767 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8768 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8769 | cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ); |
| 8770 | /* Create Fast Path IO CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8771 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8772 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8773 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8774 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8775 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8776 | |
| 8777 | else |
| 8778 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8779 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8780 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8781 | if (!qdesc) { |
| 8782 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8783 | "0499 Failed allocate fast-path IO CQ (%d)\n", idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8784 | return 1; |
| 8785 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8786 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8787 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8788 | qdesc->chann = cpu; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8789 | phba->sli4_hba.hdwq[idx].io_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8790 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8791 | /* Create Fast Path IO WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8792 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8793 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8794 | wqesize = (phba->fcp_embed_io) ? |
| 8795 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8796 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8797 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8798 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8799 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8800 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8801 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8802 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8803 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8804 | if (!qdesc) { |
| 8805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8806 | "0503 Failed allocate fast-path IO WQ (%d)\n", |
| 8807 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8808 | return 1; |
| 8809 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8810 | qdesc->hdwq = idx; |
| 8811 | qdesc->chann = cpu; |
| 8812 | phba->sli4_hba.hdwq[idx].io_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8813 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8814 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8815 | } |
| 8816 | |
| 8817 | /** |
| 8818 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8819 | * @phba: pointer to lpfc hba data structure. |
| 8820 | * |
| 8821 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8822 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8823 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8824 | * we just use some constant number as place holder. |
| 8825 | * |
| 8826 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8827 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8828 | * -ENOMEM - No availble memory |
| 8829 | * -EIO - The mailbox failed to complete successfully. |
| 8830 | **/ |
| 8831 | int |
| 8832 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8833 | { |
| 8834 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8835 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8836 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8837 | struct lpfc_vector_map_info *cpup; |
| 8838 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8839 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8840 | |
| 8841 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8842 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8843 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8844 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8845 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8846 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8847 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8848 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8849 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8850 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8851 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8852 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8853 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8854 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8855 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8856 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8857 | phba->sli4_hba.hdwq = kcalloc( |
| 8858 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8859 | GFP_KERNEL); |
| 8860 | if (!phba->sli4_hba.hdwq) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8862 | "6427 Failed allocate memory for " |
| 8863 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8864 | goto out_error; |
| 8865 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8866 | /* Prepare hardware queues to take IO buffers */ |
| 8867 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8868 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8869 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8870 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8871 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 8872 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 8873 | qp->get_io_bufs = 0; |
| 8874 | qp->put_io_bufs = 0; |
| 8875 | qp->total_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8876 | spin_lock_init(&qp->abts_io_buf_list_lock); |
| 8877 | INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8878 | qp->abts_scsi_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8879 | qp->abts_nvme_io_bufs = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8880 | INIT_LIST_HEAD(&qp->sgl_list); |
| 8881 | INIT_LIST_HEAD(&qp->cmd_rsp_buf_list); |
| 8882 | spin_lock_init(&qp->hdwq_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8883 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8884 | } |
| 8885 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8886 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8887 | if (phba->nvmet_support) { |
| 8888 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8889 | phba->cfg_nvmet_mrq, |
| 8890 | sizeof(struct lpfc_queue *), |
| 8891 | GFP_KERNEL); |
| 8892 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8894 | "3121 Fail allocate memory for " |
| 8895 | "fast-path CQ set array\n"); |
| 8896 | goto out_error; |
| 8897 | } |
| 8898 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8899 | phba->cfg_nvmet_mrq, |
| 8900 | sizeof(struct lpfc_queue *), |
| 8901 | GFP_KERNEL); |
| 8902 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8903 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8904 | "3122 Fail allocate memory for " |
| 8905 | "fast-path RQ set hdr array\n"); |
| 8906 | goto out_error; |
| 8907 | } |
| 8908 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8909 | phba->cfg_nvmet_mrq, |
| 8910 | sizeof(struct lpfc_queue *), |
| 8911 | GFP_KERNEL); |
| 8912 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8913 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8914 | "3124 Fail allocate memory for " |
| 8915 | "fast-path RQ set data array\n"); |
| 8916 | goto out_error; |
| 8917 | } |
| 8918 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8919 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8920 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8921 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8922 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8923 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8924 | for_each_present_cpu(cpu) { |
| 8925 | /* We only want to create 1 EQ per vector, even though |
| 8926 | * multiple CPUs might be using that vector. so only |
| 8927 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8928 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8929 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8930 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8931 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8932 | |
| 8933 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 8934 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8935 | |
| 8936 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8937 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8938 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8939 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8940 | if (!qdesc) { |
| 8941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8942 | "0497 Failed allocate EQ (%d)\n", |
| 8943 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8944 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8945 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8946 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8947 | qdesc->hdwq = cpup->hdwq; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 8948 | qdesc->chann = cpu; /* First CPU this EQ is affinitized to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8949 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8950 | |
| 8951 | /* Save the allocated EQ in the Hardware Queue */ |
| 8952 | qp->hba_eq = qdesc; |
| 8953 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8954 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 8955 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8956 | } |
| 8957 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8958 | /* Now we need to populate the other Hardware Queues, that share |
| 8959 | * an IRQ vector, with the associated EQ ptr. |
| 8960 | */ |
| 8961 | for_each_present_cpu(cpu) { |
| 8962 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8963 | |
| 8964 | /* Check for EQ already allocated in previous loop */ |
| 8965 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 8966 | continue; |
| 8967 | |
| 8968 | /* Check for multiple CPUs per hdwq */ |
| 8969 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8970 | if (qp->hba_eq) |
| 8971 | continue; |
| 8972 | |
| 8973 | /* We need to share an EQ for this hdwq */ |
| 8974 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 8975 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 8976 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 8977 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8978 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8979 | /* Allocate IO Path SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8980 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8981 | if (lpfc_alloc_io_wq_cq(phba, idx)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8982 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8983 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8984 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8985 | if (phba->nvmet_support) { |
| 8986 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 8987 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 8988 | LPFC_FIND_BY_HDWQ); |
| 8989 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8990 | LPFC_DEFAULT_PAGE_SIZE, |
| 8991 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8992 | phba->sli4_hba.cq_ecount, |
| 8993 | cpu); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8994 | if (!qdesc) { |
| 8995 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8996 | "3142 Failed allocate NVME " |
| 8997 | "CQ Set (%d)\n", idx); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8998 | goto out_error; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8999 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9000 | qdesc->qe_valid = 1; |
| 9001 | qdesc->hdwq = idx; |
| 9002 | qdesc->chann = cpu; |
| 9003 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9004 | } |
| 9005 | } |
| 9006 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9007 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9008 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9009 | */ |
| 9010 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9011 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9012 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9013 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9014 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9015 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9016 | if (!qdesc) { |
| 9017 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9018 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9019 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9020 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9021 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9022 | phba->sli4_hba.mbx_cq = qdesc; |
| 9023 | |
| 9024 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9025 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9026 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9027 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9028 | if (!qdesc) { |
| 9029 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9030 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9031 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9032 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9033 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9034 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9035 | phba->sli4_hba.els_cq = qdesc; |
| 9036 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9037 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9038 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9039 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9040 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9041 | |
| 9042 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9043 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9044 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9045 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9046 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9047 | if (!qdesc) { |
| 9048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9049 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9050 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9051 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9052 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9053 | phba->sli4_hba.mbx_wq = qdesc; |
| 9054 | |
| 9055 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9056 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9057 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9058 | |
| 9059 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9060 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9061 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9062 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9063 | if (!qdesc) { |
| 9064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9065 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9066 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9067 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9068 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9069 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9070 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9071 | |
| 9072 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9073 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9074 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9075 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9076 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9077 | if (!qdesc) { |
| 9078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9079 | "6079 Failed allocate NVME LS CQ\n"); |
| 9080 | goto out_error; |
| 9081 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9082 | qdesc->chann = cpu; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9083 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9084 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9085 | |
| 9086 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9087 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9088 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9089 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9090 | if (!qdesc) { |
| 9091 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9092 | "6080 Failed allocate NVME LS WQ\n"); |
| 9093 | goto out_error; |
| 9094 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9095 | qdesc->chann = cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9096 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9097 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9098 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9099 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9100 | /* |
| 9101 | * Create Receive Queue (RQ) |
| 9102 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9103 | |
| 9104 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9105 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9106 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9107 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9108 | if (!qdesc) { |
| 9109 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9110 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9111 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9112 | } |
| 9113 | phba->sli4_hba.hdr_rq = qdesc; |
| 9114 | |
| 9115 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9116 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9117 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9118 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9119 | if (!qdesc) { |
| 9120 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9121 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9122 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9123 | } |
| 9124 | phba->sli4_hba.dat_rq = qdesc; |
| 9125 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9126 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9127 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9128 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9129 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9130 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9131 | /* Create NVMET Receive Queue for header */ |
| 9132 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9133 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9134 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9135 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9136 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9137 | if (!qdesc) { |
| 9138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9139 | "3146 Failed allocate " |
| 9140 | "receive HRQ\n"); |
| 9141 | goto out_error; |
| 9142 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9143 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9144 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9145 | |
| 9146 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9147 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9148 | GFP_KERNEL, |
| 9149 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9150 | if (qdesc->rqbp == NULL) { |
| 9151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9152 | "6131 Failed allocate " |
| 9153 | "Header RQBP\n"); |
| 9154 | goto out_error; |
| 9155 | } |
| 9156 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9157 | /* Put list in known state in case driver load fails. */ |
| 9158 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9159 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9160 | /* Create NVMET Receive Queue for data */ |
| 9161 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9162 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9163 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9164 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9165 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9166 | if (!qdesc) { |
| 9167 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9168 | "3156 Failed allocate " |
| 9169 | "receive DRQ\n"); |
| 9170 | goto out_error; |
| 9171 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9172 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9173 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9174 | } |
| 9175 | } |
| 9176 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9177 | /* Clear NVME stats */ |
| 9178 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9179 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9180 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9181 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9182 | } |
| 9183 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9184 | |
| 9185 | /* Clear SCSI stats */ |
| 9186 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9187 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9188 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9189 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9190 | } |
| 9191 | } |
| 9192 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9193 | return 0; |
| 9194 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9195 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9196 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9197 | return -ENOMEM; |
| 9198 | } |
| 9199 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9200 | static inline void |
| 9201 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9202 | { |
| 9203 | if (*qp != NULL) { |
| 9204 | lpfc_sli4_queue_free(*qp); |
| 9205 | *qp = NULL; |
| 9206 | } |
| 9207 | } |
| 9208 | |
| 9209 | static inline void |
| 9210 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9211 | { |
| 9212 | int idx; |
| 9213 | |
| 9214 | if (*qs == NULL) |
| 9215 | return; |
| 9216 | |
| 9217 | for (idx = 0; idx < max; idx++) |
| 9218 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9219 | |
| 9220 | kfree(*qs); |
| 9221 | *qs = NULL; |
| 9222 | } |
| 9223 | |
| 9224 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9225 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9226 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9227 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9228 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9229 | uint32_t idx; |
| 9230 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9231 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9232 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9233 | /* Loop thru all Hardware Queues */ |
| 9234 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9235 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9236 | lpfc_sli4_queue_free(hdwq[idx].io_cq); |
| 9237 | lpfc_sli4_queue_free(hdwq[idx].io_wq); |
James Smart | 821bc88 | 2020-01-27 16:23:05 -0800 | [diff] [blame] | 9238 | hdwq[idx].hba_eq = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9239 | hdwq[idx].io_cq = NULL; |
| 9240 | hdwq[idx].io_wq = NULL; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9241 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 9242 | lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]); |
| 9243 | lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9244 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9245 | /* Loop thru all IRQ vectors */ |
| 9246 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9247 | /* Free the EQ corresponding to the IRQ vector */ |
| 9248 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9249 | lpfc_sli4_queue_free(eq); |
| 9250 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9251 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9252 | } |
| 9253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9254 | /** |
| 9255 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9256 | * @phba: pointer to lpfc hba data structure. |
| 9257 | * |
| 9258 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9259 | * operation. |
| 9260 | * |
| 9261 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9262 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9263 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9264 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9265 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9266 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9267 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9268 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9269 | /* |
| 9270 | * Set FREE_INIT before beginning to free the queues. |
| 9271 | * Wait until the users of queues to acknowledge to |
| 9272 | * release queues by clearing FREE_WAIT. |
| 9273 | */ |
| 9274 | spin_lock_irq(&phba->hbalock); |
| 9275 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9276 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9277 | spin_unlock_irq(&phba->hbalock); |
| 9278 | msleep(20); |
| 9279 | spin_lock_irq(&phba->hbalock); |
| 9280 | } |
| 9281 | spin_unlock_irq(&phba->hbalock); |
| 9282 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 9283 | lpfc_sli4_cleanup_poll_list(phba); |
| 9284 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9285 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9286 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9287 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9288 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9289 | if (phba->nvmet_support) { |
| 9290 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9291 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9292 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9293 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9294 | phba->cfg_nvmet_mrq); |
| 9295 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9296 | phba->cfg_nvmet_mrq); |
| 9297 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9298 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9299 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9300 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9301 | |
| 9302 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9303 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9304 | |
| 9305 | /* Release ELS work queue */ |
| 9306 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9307 | |
| 9308 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9309 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9310 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9311 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9312 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9313 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9314 | |
| 9315 | /* Release NVME LS complete queue */ |
| 9316 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9317 | |
| 9318 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9319 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9320 | |
| 9321 | /* Everything on this list has been freed */ |
| 9322 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9323 | |
| 9324 | /* Done with freeing the queues */ |
| 9325 | spin_lock_irq(&phba->hbalock); |
| 9326 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9327 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9328 | } |
| 9329 | |
| 9330 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9331 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9332 | { |
| 9333 | struct lpfc_rqb *rqbp; |
| 9334 | struct lpfc_dmabuf *h_buf; |
| 9335 | struct rqb_dmabuf *rqb_buffer; |
| 9336 | |
| 9337 | rqbp = rq->rqbp; |
| 9338 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9339 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9340 | struct lpfc_dmabuf, list); |
| 9341 | |
| 9342 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9343 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9344 | rqbp->buffer_count--; |
| 9345 | } |
| 9346 | return 1; |
| 9347 | } |
| 9348 | |
| 9349 | static int |
| 9350 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9351 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9352 | int qidx, uint32_t qtype) |
| 9353 | { |
| 9354 | struct lpfc_sli_ring *pring; |
| 9355 | int rc; |
| 9356 | |
| 9357 | if (!eq || !cq || !wq) { |
| 9358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9359 | "6085 Fast-path %s (%d) not allocated\n", |
| 9360 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9361 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9362 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9363 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9364 | /* create the Cq first */ |
| 9365 | rc = lpfc_cq_create(phba, cq, eq, |
| 9366 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9367 | if (rc) { |
| 9368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9369 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9370 | qidx, (uint32_t)rc); |
| 9371 | return rc; |
| 9372 | } |
| 9373 | |
| 9374 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9375 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9376 | if (cq_map) |
| 9377 | *cq_map = cq->queue_id; |
| 9378 | |
| 9379 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9380 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9381 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9382 | |
| 9383 | /* create the wq */ |
| 9384 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9385 | if (rc) { |
| 9386 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9387 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9388 | qidx, (uint32_t)rc); |
| 9389 | /* no need to tear down cq - caller will do so */ |
| 9390 | return rc; |
| 9391 | } |
| 9392 | |
| 9393 | /* Bind this CQ/WQ to the NVME ring */ |
| 9394 | pring = wq->pring; |
| 9395 | pring->sli.sli4.wqp = (void *)wq; |
| 9396 | cq->pring = pring; |
| 9397 | |
| 9398 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9399 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9400 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9401 | } else { |
| 9402 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9403 | if (rc) { |
| 9404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9405 | "0539 Failed setup of slow-path MQ: " |
| 9406 | "rc = 0x%x\n", rc); |
| 9407 | /* no need to tear down cq - caller will do so */ |
| 9408 | return rc; |
| 9409 | } |
| 9410 | |
| 9411 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9412 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9413 | phba->sli4_hba.mbx_wq->queue_id, |
| 9414 | phba->sli4_hba.mbx_cq->queue_id); |
| 9415 | } |
| 9416 | |
| 9417 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9418 | } |
| 9419 | |
| 9420 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9421 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9422 | * @phba: pointer to lpfc hba data structure. |
| 9423 | * |
| 9424 | * This routine will populate the cq_lookup table by all |
| 9425 | * available CQ queue_id's. |
| 9426 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9427 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9428 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9429 | { |
| 9430 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9431 | int qidx; |
| 9432 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9433 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9434 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9435 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9436 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9437 | /* Get the EQ corresponding to the IRQ vector */ |
| 9438 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9439 | if (!eq) |
| 9440 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9441 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9442 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9443 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9444 | continue; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9445 | if (childq->subtype == LPFC_IO) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9446 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9447 | childq; |
| 9448 | } |
| 9449 | } |
| 9450 | } |
| 9451 | |
| 9452 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9453 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9454 | * @phba: pointer to lpfc hba data structure. |
| 9455 | * |
| 9456 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9457 | * operation. |
| 9458 | * |
| 9459 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9460 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9461 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9462 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9463 | **/ |
| 9464 | int |
| 9465 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9466 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9467 | uint32_t shdr_status, shdr_add_status; |
| 9468 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9469 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9470 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9471 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9472 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9473 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9474 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9475 | |
| 9476 | /* Check for dual-ULP support */ |
| 9477 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9478 | if (!mboxq) { |
| 9479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9480 | "3249 Unable to allocate memory for " |
| 9481 | "QUERY_FW_CFG mailbox command\n"); |
| 9482 | return -ENOMEM; |
| 9483 | } |
| 9484 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9485 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9486 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9487 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9488 | length, LPFC_SLI4_MBX_EMBED); |
| 9489 | |
| 9490 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9491 | |
| 9492 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9493 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9494 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9495 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9496 | if (shdr_status || shdr_add_status || rc) { |
| 9497 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9498 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9499 | "x%x add_status x%x, mbx status x%x\n", |
| 9500 | shdr_status, shdr_add_status, rc); |
| 9501 | if (rc != MBX_TIMEOUT) |
| 9502 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9503 | rc = -ENXIO; |
| 9504 | goto out_error; |
| 9505 | } |
| 9506 | |
| 9507 | phba->sli4_hba.fw_func_mode = |
| 9508 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9509 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9510 | 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] | 9511 | phba->sli4_hba.physical_port = |
| 9512 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9513 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9514 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9515 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9516 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9517 | |
| 9518 | if (rc != MBX_TIMEOUT) |
| 9519 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9520 | |
| 9521 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9522 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9523 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9524 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9525 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9526 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9527 | if (!qp) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9529 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9530 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9531 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9532 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9533 | |
| 9534 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9535 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9536 | /* Create HBA Event Queues (EQs) in order */ |
| 9537 | for_each_present_cpu(cpu) { |
| 9538 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9539 | |
| 9540 | /* Look for the CPU thats using that vector with |
| 9541 | * LPFC_CPU_FIRST_IRQ set. |
| 9542 | */ |
| 9543 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9544 | continue; |
| 9545 | if (qidx != cpup->eq) |
| 9546 | continue; |
| 9547 | |
| 9548 | /* Create an EQ for that vector */ |
| 9549 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9550 | phba->cfg_fcp_imax); |
| 9551 | if (rc) { |
| 9552 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9553 | "0523 Failed setup of fast-path" |
| 9554 | " EQ (%d), rc = 0x%x\n", |
| 9555 | cpup->eq, (uint32_t)rc); |
| 9556 | goto out_destroy; |
| 9557 | } |
| 9558 | |
| 9559 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9560 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9561 | qp[cpup->hdwq].hba_eq; |
| 9562 | |
| 9563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9564 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9565 | cpup->eq, |
| 9566 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9567 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9568 | } |
| 9569 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9570 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9571 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9572 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9573 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9574 | |
| 9575 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9576 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9577 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9578 | qp[qidx].io_cq, |
| 9579 | qp[qidx].io_wq, |
| 9580 | &phba->sli4_hba.hdwq[qidx].io_cq_map, |
| 9581 | qidx, |
| 9582 | LPFC_IO); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9583 | if (rc) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9585 | "0535 Failed to setup fastpath " |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9586 | "IO WQ/CQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9587 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9588 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9589 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9590 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9591 | |
| 9592 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9593 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9594 | */ |
| 9595 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9596 | /* Set up slow-path MBOX CQ/MQ */ |
| 9597 | |
| 9598 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9599 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9600 | "0528 %s not allocated\n", |
| 9601 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9602 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9603 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9604 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9605 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9606 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9607 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9608 | phba->sli4_hba.mbx_cq, |
| 9609 | phba->sli4_hba.mbx_wq, |
| 9610 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9611 | if (rc) { |
| 9612 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9613 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9614 | (uint32_t)rc); |
| 9615 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9616 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9617 | if (phba->nvmet_support) { |
| 9618 | if (!phba->sli4_hba.nvmet_cqset) { |
| 9619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9620 | "3165 Fast-path NVME CQ Set " |
| 9621 | "array not allocated\n"); |
| 9622 | rc = -ENOMEM; |
| 9623 | goto out_destroy; |
| 9624 | } |
| 9625 | if (phba->cfg_nvmet_mrq > 1) { |
| 9626 | rc = lpfc_cq_create_set(phba, |
| 9627 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9628 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9629 | LPFC_WCQ, LPFC_NVMET); |
| 9630 | if (rc) { |
| 9631 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9632 | "3164 Failed setup of NVME CQ " |
| 9633 | "Set, rc = 0x%x\n", |
| 9634 | (uint32_t)rc); |
| 9635 | goto out_destroy; |
| 9636 | } |
| 9637 | } else { |
| 9638 | /* Set up NVMET Receive Complete Queue */ |
| 9639 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9640 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9641 | LPFC_WCQ, LPFC_NVMET); |
| 9642 | if (rc) { |
| 9643 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9644 | "6089 Failed setup NVMET CQ: " |
| 9645 | "rc = 0x%x\n", (uint32_t)rc); |
| 9646 | goto out_destroy; |
| 9647 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9648 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9649 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9650 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9651 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9652 | "parent eq-id=%d\n", |
| 9653 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9654 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9655 | } |
| 9656 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9657 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9658 | /* Set up slow-path ELS WQ/CQ */ |
| 9659 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9660 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9661 | "0530 ELS %s not allocated\n", |
| 9662 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9663 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9664 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9665 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9666 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9667 | phba->sli4_hba.els_cq, |
| 9668 | phba->sli4_hba.els_wq, |
| 9669 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9670 | if (rc) { |
| 9671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9672 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9673 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9674 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9675 | } |
| 9676 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9677 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9678 | phba->sli4_hba.els_wq->queue_id, |
| 9679 | phba->sli4_hba.els_cq->queue_id); |
| 9680 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9681 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9682 | /* Set up NVME LS Complete Queue */ |
| 9683 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 9684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9685 | "6091 LS %s not allocated\n", |
| 9686 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9687 | rc = -ENOMEM; |
| 9688 | goto out_destroy; |
| 9689 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9690 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9691 | phba->sli4_hba.nvmels_cq, |
| 9692 | phba->sli4_hba.nvmels_wq, |
| 9693 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9694 | if (rc) { |
| 9695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9696 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9697 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9698 | goto out_destroy; |
| 9699 | } |
| 9700 | |
| 9701 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9702 | "6096 ELS WQ setup: wq-id=%d, " |
| 9703 | "parent cq-id=%d\n", |
| 9704 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9705 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9706 | } |
| 9707 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9708 | /* |
| 9709 | * Create NVMET Receive Queue (RQ) |
| 9710 | */ |
| 9711 | if (phba->nvmet_support) { |
| 9712 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9713 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9714 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 9715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9716 | "6130 MRQ CQ Queues not " |
| 9717 | "allocated\n"); |
| 9718 | rc = -ENOMEM; |
| 9719 | goto out_destroy; |
| 9720 | } |
| 9721 | if (phba->cfg_nvmet_mrq > 1) { |
| 9722 | rc = lpfc_mrq_create(phba, |
| 9723 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9724 | phba->sli4_hba.nvmet_mrq_data, |
| 9725 | phba->sli4_hba.nvmet_cqset, |
| 9726 | LPFC_NVMET); |
| 9727 | if (rc) { |
| 9728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9729 | "6098 Failed setup of NVMET " |
| 9730 | "MRQ: rc = 0x%x\n", |
| 9731 | (uint32_t)rc); |
| 9732 | goto out_destroy; |
| 9733 | } |
| 9734 | |
| 9735 | } else { |
| 9736 | rc = lpfc_rq_create(phba, |
| 9737 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9738 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9739 | phba->sli4_hba.nvmet_cqset[0], |
| 9740 | LPFC_NVMET); |
| 9741 | if (rc) { |
| 9742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9743 | "6057 Failed setup of NVMET " |
| 9744 | "Receive Queue: rc = 0x%x\n", |
| 9745 | (uint32_t)rc); |
| 9746 | goto out_destroy; |
| 9747 | } |
| 9748 | |
| 9749 | lpfc_printf_log( |
| 9750 | phba, KERN_INFO, LOG_INIT, |
| 9751 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9752 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9753 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9754 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9755 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9756 | |
| 9757 | } |
| 9758 | } |
| 9759 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9760 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 9761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9762 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9763 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9764 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9765 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9766 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9767 | 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] | 9768 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9769 | if (rc) { |
| 9770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9771 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9772 | "rc = 0x%x\n", (uint32_t)rc); |
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 | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9775 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9776 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9777 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9778 | "parent cq-id=%d\n", |
| 9779 | phba->sli4_hba.hdr_rq->queue_id, |
| 9780 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9781 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9782 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9783 | if (phba->cfg_fcp_imax) |
| 9784 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9785 | else |
| 9786 | usdelay = 0; |
| 9787 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9788 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9789 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9790 | 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] | 9791 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9792 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9793 | if (phba->sli4_hba.cq_max) { |
| 9794 | kfree(phba->sli4_hba.cq_lookup); |
| 9795 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9796 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9797 | if (!phba->sli4_hba.cq_lookup) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9798 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9799 | "0549 Failed setup of CQ Lookup table: " |
| 9800 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9801 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9802 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9803 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9804 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9805 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9806 | return 0; |
| 9807 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9808 | out_destroy: |
| 9809 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9810 | out_error: |
| 9811 | return rc; |
| 9812 | } |
| 9813 | |
| 9814 | /** |
| 9815 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9816 | * @phba: pointer to lpfc hba data structure. |
| 9817 | * |
| 9818 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9819 | * operation. |
| 9820 | * |
| 9821 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9822 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9823 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9824 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9825 | **/ |
| 9826 | void |
| 9827 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9828 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9829 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9830 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9831 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9832 | |
| 9833 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9834 | if (phba->sli4_hba.mbx_wq) |
| 9835 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9836 | |
| 9837 | /* Unset NVME LS work queue */ |
| 9838 | if (phba->sli4_hba.nvmels_wq) |
| 9839 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9840 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9841 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9842 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9843 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9844 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9845 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9846 | if (phba->sli4_hba.hdr_rq) |
| 9847 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9848 | phba->sli4_hba.dat_rq); |
| 9849 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9850 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9851 | if (phba->sli4_hba.mbx_cq) |
| 9852 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9853 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9854 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9855 | if (phba->sli4_hba.els_cq) |
| 9856 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9857 | |
| 9858 | /* Unset NVME LS complete queue */ |
| 9859 | if (phba->sli4_hba.nvmels_cq) |
| 9860 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9861 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9862 | if (phba->nvmet_support) { |
| 9863 | /* Unset NVMET MRQ queue */ |
| 9864 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9865 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9866 | lpfc_rq_destroy( |
| 9867 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9868 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9869 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9870 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9871 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9872 | /* Unset NVMET CQ Set complete queue */ |
| 9873 | if (phba->sli4_hba.nvmet_cqset) { |
| 9874 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9875 | lpfc_cq_destroy( |
| 9876 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9877 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9878 | } |
| 9879 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9880 | /* Unset fast-path SLI4 queues */ |
| 9881 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9882 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9883 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9884 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9885 | qp = &phba->sli4_hba.hdwq[qidx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9886 | lpfc_wq_destroy(phba, qp->io_wq); |
| 9887 | lpfc_cq_destroy(phba, qp->io_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9888 | } |
| 9889 | /* Loop thru all IRQ vectors */ |
| 9890 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 9891 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 9892 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 9893 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9894 | } |
| 9895 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9896 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9897 | kfree(phba->sli4_hba.cq_lookup); |
| 9898 | phba->sli4_hba.cq_lookup = NULL; |
| 9899 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9900 | } |
| 9901 | |
| 9902 | /** |
| 9903 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9904 | * @phba: pointer to lpfc hba data structure. |
| 9905 | * |
| 9906 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9907 | * events. The body of the completion queue event is a completion queue entry |
| 9908 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9909 | * the following HBA completion queue events for the worker thread to process: |
| 9910 | * - Mailbox asynchronous events |
| 9911 | * - Receive queue completion unsolicited events |
| 9912 | * Later, this can be used for all the slow-path events. |
| 9913 | * |
| 9914 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9915 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9916 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9917 | **/ |
| 9918 | static int |
| 9919 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9920 | { |
| 9921 | struct lpfc_cq_event *cq_event; |
| 9922 | int i; |
| 9923 | |
| 9924 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9925 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9926 | if (!cq_event) |
| 9927 | goto out_pool_create_fail; |
| 9928 | list_add_tail(&cq_event->list, |
| 9929 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9930 | } |
| 9931 | return 0; |
| 9932 | |
| 9933 | out_pool_create_fail: |
| 9934 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9935 | return -ENOMEM; |
| 9936 | } |
| 9937 | |
| 9938 | /** |
| 9939 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9940 | * @phba: pointer to lpfc hba data structure. |
| 9941 | * |
| 9942 | * This routine is invoked to free the pool of completion queue events at |
| 9943 | * driver unload time. Note that, it is the responsibility of the driver |
| 9944 | * cleanup routine to free all the outstanding completion-queue events |
| 9945 | * allocated from this pool back into the pool before invoking this routine |
| 9946 | * to destroy the pool. |
| 9947 | **/ |
| 9948 | static void |
| 9949 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9950 | { |
| 9951 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9952 | |
| 9953 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9954 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9955 | list_del(&cq_event->list); |
| 9956 | kfree(cq_event); |
| 9957 | } |
| 9958 | } |
| 9959 | |
| 9960 | /** |
| 9961 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9962 | * @phba: pointer to lpfc hba data structure. |
| 9963 | * |
| 9964 | * This routine is the lock free version of the API invoked to allocate a |
| 9965 | * completion-queue event from the free pool. |
| 9966 | * |
| 9967 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9968 | * NULL otherwise. |
| 9969 | **/ |
| 9970 | struct lpfc_cq_event * |
| 9971 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9972 | { |
| 9973 | struct lpfc_cq_event *cq_event = NULL; |
| 9974 | |
| 9975 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9976 | struct lpfc_cq_event, list); |
| 9977 | return cq_event; |
| 9978 | } |
| 9979 | |
| 9980 | /** |
| 9981 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9982 | * @phba: pointer to lpfc hba data structure. |
| 9983 | * |
| 9984 | * This routine is the lock version of the API invoked to allocate a |
| 9985 | * completion-queue event from the free pool. |
| 9986 | * |
| 9987 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9988 | * NULL otherwise. |
| 9989 | **/ |
| 9990 | struct lpfc_cq_event * |
| 9991 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9992 | { |
| 9993 | struct lpfc_cq_event *cq_event; |
| 9994 | unsigned long iflags; |
| 9995 | |
| 9996 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9997 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9998 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9999 | return cq_event; |
| 10000 | } |
| 10001 | |
| 10002 | /** |
| 10003 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10004 | * @phba: pointer to lpfc hba data structure. |
| 10005 | * @cq_event: pointer to the completion queue event to be freed. |
| 10006 | * |
| 10007 | * This routine is the lock free version of the API invoked to release a |
| 10008 | * completion-queue event back into the free pool. |
| 10009 | **/ |
| 10010 | void |
| 10011 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10012 | struct lpfc_cq_event *cq_event) |
| 10013 | { |
| 10014 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 10015 | } |
| 10016 | |
| 10017 | /** |
| 10018 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10019 | * @phba: pointer to lpfc hba data structure. |
| 10020 | * @cq_event: pointer to the completion queue event to be freed. |
| 10021 | * |
| 10022 | * This routine is the lock version of the API invoked to release a |
| 10023 | * completion-queue event back into the free pool. |
| 10024 | **/ |
| 10025 | void |
| 10026 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10027 | struct lpfc_cq_event *cq_event) |
| 10028 | { |
| 10029 | unsigned long iflags; |
| 10030 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10031 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 10032 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10033 | } |
| 10034 | |
| 10035 | /** |
| 10036 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 10037 | * @phba: pointer to lpfc hba data structure. |
| 10038 | * |
| 10039 | * This routine is to free all the pending completion-queue events to the |
| 10040 | * back into the free pool for device reset. |
| 10041 | **/ |
| 10042 | static void |
| 10043 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10044 | { |
| 10045 | LIST_HEAD(cqelist); |
| 10046 | struct lpfc_cq_event *cqe; |
| 10047 | unsigned long iflags; |
| 10048 | |
| 10049 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 10050 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10051 | /* Pending FCP XRI abort events */ |
| 10052 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10053 | &cqelist); |
| 10054 | /* Pending ELS XRI abort events */ |
| 10055 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10056 | &cqelist); |
| 10057 | /* Pending asynnc events */ |
| 10058 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10059 | &cqelist); |
| 10060 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10061 | |
| 10062 | while (!list_empty(&cqelist)) { |
| 10063 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 10064 | lpfc_sli4_cq_event_release(phba, cqe); |
| 10065 | } |
| 10066 | } |
| 10067 | |
| 10068 | /** |
| 10069 | * lpfc_pci_function_reset - Reset pci function. |
| 10070 | * @phba: pointer to lpfc hba data structure. |
| 10071 | * |
| 10072 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10073 | * all resources assigned to the PCI function which originates this request. |
| 10074 | * |
| 10075 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10076 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10077 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10078 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10079 | **/ |
| 10080 | int |
| 10081 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10082 | { |
| 10083 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10084 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10085 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10086 | uint32_t rdy_chk; |
| 10087 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10088 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10089 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10090 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10091 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10092 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10093 | switch (if_type) { |
| 10094 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10095 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10096 | GFP_KERNEL); |
| 10097 | if (!mboxq) { |
| 10098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10099 | "0494 Unable to allocate memory for " |
| 10100 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10101 | "command\n"); |
| 10102 | return -ENOMEM; |
| 10103 | } |
| 10104 | |
| 10105 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10106 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10107 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10108 | LPFC_SLI4_MBX_EMBED); |
| 10109 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10110 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10111 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10112 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10113 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10114 | &shdr->response); |
| 10115 | if (rc != MBX_TIMEOUT) |
| 10116 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10117 | if (shdr_status || shdr_add_status || rc) { |
| 10118 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10119 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10120 | "failed with status x%x add_status x%x," |
| 10121 | " mbx status x%x\n", |
| 10122 | shdr_status, shdr_add_status, rc); |
| 10123 | rc = -ENXIO; |
| 10124 | } |
| 10125 | break; |
| 10126 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10127 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10128 | wait: |
| 10129 | /* |
| 10130 | * Poll the Port Status Register and wait for RDY for |
| 10131 | * up to 30 seconds. If the port doesn't respond, treat |
| 10132 | * it as an error. |
| 10133 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10134 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10135 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10136 | STATUSregaddr, ®_data.word0)) { |
| 10137 | rc = -ENODEV; |
| 10138 | goto out; |
| 10139 | } |
| 10140 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10141 | break; |
| 10142 | msleep(20); |
| 10143 | } |
| 10144 | |
| 10145 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10146 | phba->work_status[0] = readl( |
| 10147 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10148 | phba->work_status[1] = readl( |
| 10149 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10151 | "2890 Port not ready, port status reg " |
| 10152 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10153 | reg_data.word0, |
| 10154 | phba->work_status[0], |
| 10155 | phba->work_status[1]); |
| 10156 | rc = -ENODEV; |
| 10157 | goto out; |
| 10158 | } |
| 10159 | |
| 10160 | if (!port_reset) { |
| 10161 | /* |
| 10162 | * Reset the port now |
| 10163 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10164 | reg_data.word0 = 0; |
| 10165 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10166 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10167 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10168 | LPFC_SLIPORT_INIT_PORT); |
| 10169 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10170 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10171 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10172 | pci_read_config_word(phba->pcidev, |
| 10173 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10174 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10175 | port_reset = 1; |
| 10176 | msleep(20); |
| 10177 | goto wait; |
| 10178 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10179 | rc = -ENODEV; |
| 10180 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10181 | } |
| 10182 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10183 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10184 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10185 | default: |
| 10186 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10187 | } |
| 10188 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10189 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10190 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10191 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10193 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10194 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10195 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10196 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10197 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10198 | return rc; |
| 10199 | } |
| 10200 | |
| 10201 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10202 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10203 | * @phba: pointer to lpfc hba data structure. |
| 10204 | * |
| 10205 | * This routine is invoked to set up the PCI device memory space for device |
| 10206 | * with SLI-4 interface spec. |
| 10207 | * |
| 10208 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10209 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10210 | * other values - error |
| 10211 | **/ |
| 10212 | static int |
| 10213 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10214 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10215 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10216 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10217 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10218 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10219 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10220 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10221 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10222 | |
| 10223 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10224 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10225 | if (error) |
| 10226 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10227 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10228 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10229 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10230 | /* |
| 10231 | * The BARs and register set definitions and offset locations are |
| 10232 | * dependent on the if_type. |
| 10233 | */ |
| 10234 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10235 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10236 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10237 | } |
| 10238 | |
| 10239 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10240 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10241 | LPFC_SLI_INTF_VALID) { |
| 10242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10243 | "2894 SLI_INTF reg contents invalid " |
| 10244 | "sli_intf reg 0x%x\n", |
| 10245 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10246 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10247 | } |
| 10248 | |
| 10249 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10250 | /* |
| 10251 | * Get the bus address of SLI4 device Bar regions and the |
| 10252 | * number of bytes required by each mapping. The mapping of the |
| 10253 | * particular PCI BARs regions is dependent on the type of |
| 10254 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10255 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10256 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10257 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10258 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10259 | |
| 10260 | /* |
| 10261 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10262 | * addr |
| 10263 | */ |
| 10264 | phba->sli4_hba.conf_regs_memmap_p = |
| 10265 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10266 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10267 | dev_printk(KERN_ERR, &pdev->dev, |
| 10268 | "ioremap failed for SLI4 PCI config " |
| 10269 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10270 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10271 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10272 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10273 | /* Set up BAR0 PCI config space register memory map */ |
| 10274 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10275 | } else { |
| 10276 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10277 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10278 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10279 | dev_printk(KERN_ERR, &pdev->dev, |
| 10280 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10281 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10282 | } |
| 10283 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10284 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10285 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10286 | dev_printk(KERN_ERR, &pdev->dev, |
| 10287 | "ioremap failed for SLI4 PCI config " |
| 10288 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10289 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10290 | } |
| 10291 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10292 | } |
| 10293 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10294 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10295 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10296 | /* |
| 10297 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10298 | * kernel virtual address and setup the registers. |
| 10299 | */ |
| 10300 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10301 | PCI_64BIT_BAR2); |
| 10302 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10303 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10304 | ioremap(phba->pci_bar1_map, |
| 10305 | bar1map_len); |
| 10306 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10307 | dev_err(&pdev->dev, |
| 10308 | "ioremap failed for SLI4 HBA " |
| 10309 | "control registers.\n"); |
| 10310 | error = -ENOMEM; |
| 10311 | goto out_iounmap_conf; |
| 10312 | } |
| 10313 | phba->pci_bar2_memmap_p = |
| 10314 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10315 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10316 | } else { |
| 10317 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10318 | goto out_iounmap_conf; |
| 10319 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10320 | } |
| 10321 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10322 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10323 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10324 | /* |
| 10325 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10326 | * virtual address and setup the registers. |
| 10327 | */ |
| 10328 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10329 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10330 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10331 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10332 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10333 | dev_err(&pdev->dev, |
| 10334 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10335 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10336 | goto out_iounmap_conf; |
| 10337 | } |
| 10338 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10339 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10340 | } |
| 10341 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10342 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10343 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10344 | /* |
| 10345 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10346 | * a kernel virtual address and setup the registers. |
| 10347 | */ |
| 10348 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10349 | PCI_64BIT_BAR4); |
| 10350 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10351 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10352 | ioremap(phba->pci_bar2_map, |
| 10353 | bar2map_len); |
| 10354 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10355 | dev_err(&pdev->dev, |
| 10356 | "ioremap failed for SLI4 HBA" |
| 10357 | " doorbell registers.\n"); |
| 10358 | error = -ENOMEM; |
| 10359 | goto out_iounmap_ctrl; |
| 10360 | } |
| 10361 | phba->pci_bar4_memmap_p = |
| 10362 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10363 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10364 | if (error) |
| 10365 | goto out_iounmap_all; |
| 10366 | } else { |
| 10367 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10368 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10369 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10370 | } |
| 10371 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10372 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10373 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10374 | /* |
| 10375 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10376 | * virtual address and setup the registers. |
| 10377 | */ |
| 10378 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10379 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10380 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10381 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10382 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10383 | dev_err(&pdev->dev, |
| 10384 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10385 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10386 | goto out_iounmap_ctrl; |
| 10387 | } |
| 10388 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10389 | } |
| 10390 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10391 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10392 | switch (if_type) { |
| 10393 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10394 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10395 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10396 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10397 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10398 | break; |
| 10399 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10400 | 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] | 10401 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10402 | 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] | 10403 | break; |
| 10404 | default: |
| 10405 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10406 | } |
| 10407 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10408 | return 0; |
| 10409 | |
| 10410 | out_iounmap_all: |
| 10411 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10412 | out_iounmap_ctrl: |
| 10413 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10414 | out_iounmap_conf: |
| 10415 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10416 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10417 | return error; |
| 10418 | } |
| 10419 | |
| 10420 | /** |
| 10421 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10422 | * @phba: pointer to lpfc hba data structure. |
| 10423 | * |
| 10424 | * This routine is invoked to unset the PCI device memory space for device |
| 10425 | * with SLI-4 interface spec. |
| 10426 | **/ |
| 10427 | static void |
| 10428 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10429 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10430 | uint32_t if_type; |
| 10431 | 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] | 10432 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10433 | switch (if_type) { |
| 10434 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10435 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10436 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10437 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10438 | break; |
| 10439 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10440 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10441 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10442 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10443 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10444 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
James Smart | 0b43919 | 2019-12-18 15:58:05 -0800 | [diff] [blame] | 10445 | if (phba->sli4_hba.dpp_regs_memmap_p) |
| 10446 | iounmap(phba->sli4_hba.dpp_regs_memmap_p); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10447 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10448 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10449 | default: |
| 10450 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10451 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10452 | if_type); |
| 10453 | break; |
| 10454 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10455 | } |
| 10456 | |
| 10457 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10458 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10459 | * @phba: pointer to lpfc hba data structure. |
| 10460 | * |
| 10461 | * 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] | 10462 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10463 | * |
| 10464 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10465 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10466 | * other values - error |
| 10467 | **/ |
| 10468 | static int |
| 10469 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10470 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10471 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10472 | LPFC_MBOXQ_t *pmb; |
| 10473 | |
| 10474 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10475 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10476 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10477 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10478 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10479 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10480 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10481 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10482 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10483 | /* |
| 10484 | * Assign MSI-X vectors to interrupt handlers |
| 10485 | */ |
| 10486 | |
| 10487 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10488 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10489 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10490 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10491 | if (rc) { |
| 10492 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10493 | "0421 MSI-X slow-path request_irq failed " |
| 10494 | "(%d)\n", rc); |
| 10495 | goto msi_fail_out; |
| 10496 | } |
| 10497 | |
| 10498 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10499 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10500 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10501 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10502 | |
| 10503 | if (rc) { |
| 10504 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10505 | "0429 MSI-X fast-path request_irq failed " |
| 10506 | "(%d)\n", rc); |
| 10507 | goto irq_fail_out; |
| 10508 | } |
| 10509 | |
| 10510 | /* |
| 10511 | * Configure HBA MSI-X attention conditions to messages |
| 10512 | */ |
| 10513 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10514 | |
| 10515 | if (!pmb) { |
| 10516 | rc = -ENOMEM; |
| 10517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10518 | "0474 Unable to allocate memory for issuing " |
| 10519 | "MBOX_CONFIG_MSI command\n"); |
| 10520 | goto mem_fail_out; |
| 10521 | } |
| 10522 | rc = lpfc_config_msi(phba, pmb); |
| 10523 | if (rc) |
| 10524 | goto mbx_fail_out; |
| 10525 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10526 | if (rc != MBX_SUCCESS) { |
| 10527 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10528 | "0351 Config MSI mailbox command failed, " |
| 10529 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10530 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10531 | goto mbx_fail_out; |
| 10532 | } |
| 10533 | |
| 10534 | /* Free memory allocated for mailbox command */ |
| 10535 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10536 | return rc; |
| 10537 | |
| 10538 | mbx_fail_out: |
| 10539 | /* Free memory allocated for mailbox command */ |
| 10540 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10541 | |
| 10542 | mem_fail_out: |
| 10543 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10544 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10545 | |
| 10546 | irq_fail_out: |
| 10547 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10548 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10549 | |
| 10550 | msi_fail_out: |
| 10551 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10552 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10553 | |
| 10554 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10555 | return rc; |
| 10556 | } |
| 10557 | |
| 10558 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10559 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10560 | * @phba: pointer to lpfc hba data structure. |
| 10561 | * |
| 10562 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10563 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10564 | * enable the MSI vector. The device driver is responsible for calling the |
| 10565 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10566 | * is done in this function. |
| 10567 | * |
| 10568 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10569 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10570 | * other values - error |
| 10571 | */ |
| 10572 | static int |
| 10573 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10574 | { |
| 10575 | int rc; |
| 10576 | |
| 10577 | rc = pci_enable_msi(phba->pcidev); |
| 10578 | if (!rc) |
| 10579 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10580 | "0462 PCI enable MSI mode success.\n"); |
| 10581 | else { |
| 10582 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10583 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10584 | return rc; |
| 10585 | } |
| 10586 | |
| 10587 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10588 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10589 | if (rc) { |
| 10590 | pci_disable_msi(phba->pcidev); |
| 10591 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10592 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10593 | } |
| 10594 | return rc; |
| 10595 | } |
| 10596 | |
| 10597 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10598 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10599 | * @phba: pointer to lpfc hba data structure. |
| 10600 | * |
| 10601 | * This routine is invoked to enable device interrupt and associate driver's |
| 10602 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10603 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10604 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10605 | * mode which is supported by the platform, kernel, and device in the order |
| 10606 | * of: |
| 10607 | * MSI-X -> MSI -> IRQ. |
| 10608 | * |
| 10609 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10610 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10611 | * other values - error |
| 10612 | **/ |
| 10613 | static uint32_t |
| 10614 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10615 | { |
| 10616 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10617 | int retval; |
| 10618 | |
| 10619 | if (cfg_mode == 2) { |
| 10620 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10621 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10622 | if (!retval) { |
| 10623 | /* Now, try to enable MSI-X interrupt mode */ |
| 10624 | retval = lpfc_sli_enable_msix(phba); |
| 10625 | if (!retval) { |
| 10626 | /* Indicate initialization to MSI-X mode */ |
| 10627 | phba->intr_type = MSIX; |
| 10628 | intr_mode = 2; |
| 10629 | } |
| 10630 | } |
| 10631 | } |
| 10632 | |
| 10633 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10634 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10635 | retval = lpfc_sli_enable_msi(phba); |
| 10636 | if (!retval) { |
| 10637 | /* Indicate initialization to MSI mode */ |
| 10638 | phba->intr_type = MSI; |
| 10639 | intr_mode = 1; |
| 10640 | } |
| 10641 | } |
| 10642 | |
| 10643 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10644 | if (phba->intr_type == NONE) { |
| 10645 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10646 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10647 | if (!retval) { |
| 10648 | /* Indicate initialization to INTx mode */ |
| 10649 | phba->intr_type = INTx; |
| 10650 | intr_mode = 0; |
| 10651 | } |
| 10652 | } |
| 10653 | return intr_mode; |
| 10654 | } |
| 10655 | |
| 10656 | /** |
| 10657 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10658 | * @phba: pointer to lpfc hba data structure. |
| 10659 | * |
| 10660 | * This routine is invoked to disable device interrupt and disassociate the |
| 10661 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10662 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10663 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10664 | **/ |
| 10665 | static void |
| 10666 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10667 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10668 | int nr_irqs, i; |
| 10669 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10670 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10671 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10672 | else |
| 10673 | nr_irqs = 1; |
| 10674 | |
| 10675 | for (i = 0; i < nr_irqs; i++) |
| 10676 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10677 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10678 | |
| 10679 | /* Reset interrupt management states */ |
| 10680 | phba->intr_type = NONE; |
| 10681 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10682 | } |
| 10683 | |
| 10684 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10685 | * 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] | 10686 | * @phba: pointer to lpfc hba data structure. |
| 10687 | * @id: EQ vector index or Hardware Queue index |
| 10688 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10689 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10690 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10691 | */ |
| 10692 | static uint16_t |
| 10693 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10694 | { |
| 10695 | struct lpfc_vector_map_info *cpup; |
| 10696 | int cpu; |
| 10697 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10698 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10699 | for_each_present_cpu(cpu) { |
| 10700 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10701 | |
| 10702 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10703 | * using the same vector, so select the one with |
| 10704 | * LPFC_CPU_FIRST_IRQ set. |
| 10705 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10706 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10707 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10708 | (cpup->eq == id)) |
| 10709 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10710 | |
| 10711 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10712 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10713 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10714 | } |
| 10715 | return 0; |
| 10716 | } |
| 10717 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10718 | #ifdef CONFIG_X86 |
| 10719 | /** |
| 10720 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10721 | * @phba: pointer to lpfc hba data structure. |
| 10722 | * @cpu: CPU map index |
| 10723 | * @phys_id: CPU package physical id |
| 10724 | * @core_id: CPU core id |
| 10725 | */ |
| 10726 | static int |
| 10727 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10728 | uint16_t phys_id, uint16_t core_id) |
| 10729 | { |
| 10730 | struct lpfc_vector_map_info *cpup; |
| 10731 | int idx; |
| 10732 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10733 | for_each_present_cpu(idx) { |
| 10734 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10735 | /* Does the cpup match the one we are looking for */ |
| 10736 | if ((cpup->phys_id == phys_id) && |
| 10737 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10738 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10739 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10740 | } |
| 10741 | return 0; |
| 10742 | } |
| 10743 | #endif |
| 10744 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10745 | /* |
| 10746 | * lpfc_assign_eq_map_info - Assigns eq for vector_map structure |
| 10747 | * @phba: pointer to lpfc hba data structure. |
| 10748 | * @eqidx: index for eq and irq vector |
| 10749 | * @flag: flags to set for vector_map structure |
| 10750 | * @cpu: cpu used to index vector_map structure |
| 10751 | * |
| 10752 | * The routine assigns eq info into vector_map structure |
| 10753 | */ |
| 10754 | static inline void |
| 10755 | lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag, |
| 10756 | unsigned int cpu) |
| 10757 | { |
| 10758 | struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10759 | struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx); |
| 10760 | |
| 10761 | cpup->eq = eqidx; |
| 10762 | cpup->flag |= flag; |
| 10763 | |
| 10764 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10765 | "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n", |
| 10766 | cpu, eqhdl->irq, cpup->eq, cpup->flag); |
| 10767 | } |
| 10768 | |
| 10769 | /** |
| 10770 | * lpfc_cpu_map_array_init - Initialize cpu_map structure |
| 10771 | * @phba: pointer to lpfc hba data structure. |
| 10772 | * |
| 10773 | * The routine initializes the cpu_map array structure |
| 10774 | */ |
| 10775 | static void |
| 10776 | lpfc_cpu_map_array_init(struct lpfc_hba *phba) |
| 10777 | { |
| 10778 | struct lpfc_vector_map_info *cpup; |
| 10779 | struct lpfc_eq_intr_info *eqi; |
| 10780 | int cpu; |
| 10781 | |
| 10782 | for_each_possible_cpu(cpu) { |
| 10783 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10784 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10785 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10786 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10787 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10788 | cpup->flag = 0; |
| 10789 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu); |
| 10790 | INIT_LIST_HEAD(&eqi->list); |
| 10791 | eqi->icnt = 0; |
| 10792 | } |
| 10793 | } |
| 10794 | |
| 10795 | /** |
| 10796 | * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure |
| 10797 | * @phba: pointer to lpfc hba data structure. |
| 10798 | * |
| 10799 | * The routine initializes the hba_eq_hdl array structure |
| 10800 | */ |
| 10801 | static void |
| 10802 | lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) |
| 10803 | { |
| 10804 | struct lpfc_hba_eq_hdl *eqhdl; |
| 10805 | int i; |
| 10806 | |
| 10807 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 10808 | eqhdl = lpfc_get_eq_hdl(i); |
| 10809 | eqhdl->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10810 | eqhdl->phba = phba; |
| 10811 | } |
| 10812 | } |
| 10813 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10814 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10815 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10816 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10817 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10818 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10819 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10820 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10821 | * In addition, the CPU to IO channel mapping will be calculated |
| 10822 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10823 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10824 | static void |
| 10825 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10826 | { |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10827 | int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10828 | int max_phys_id, min_phys_id; |
| 10829 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10830 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10831 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10832 | #ifdef CONFIG_X86 |
| 10833 | struct cpuinfo_x86 *cpuinfo; |
| 10834 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10835 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10836 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10837 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10838 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10839 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10840 | |
| 10841 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10842 | for_each_present_cpu(cpu) { |
| 10843 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10844 | #ifdef CONFIG_X86 |
| 10845 | cpuinfo = &cpu_data(cpu); |
| 10846 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10847 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10848 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10849 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10850 | #else |
| 10851 | /* No distinction between CPUs for other platforms */ |
| 10852 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10853 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10854 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10855 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10856 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10857 | "3328 CPU %d physid %d coreid %d flag x%x\n", |
| 10858 | cpu, cpup->phys_id, cpup->core_id, cpup->flag); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10859 | |
| 10860 | if (cpup->phys_id > max_phys_id) |
| 10861 | max_phys_id = cpup->phys_id; |
| 10862 | if (cpup->phys_id < min_phys_id) |
| 10863 | min_phys_id = cpup->phys_id; |
| 10864 | |
| 10865 | if (cpup->core_id > max_core_id) |
| 10866 | max_core_id = cpup->core_id; |
| 10867 | if (cpup->core_id < min_core_id) |
| 10868 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10869 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10870 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10871 | /* After looking at each irq vector assigned to this pcidev, its |
| 10872 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10873 | * Next we will set any unassigned (unaffinitized) cpu map |
| 10874 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10875 | */ |
| 10876 | first_cpu = cpumask_first(cpu_present_mask); |
| 10877 | start_cpu = first_cpu; |
| 10878 | |
| 10879 | for_each_present_cpu(cpu) { |
| 10880 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10881 | |
| 10882 | /* Is this CPU entry unassigned */ |
| 10883 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10884 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 10885 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10886 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10887 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10888 | * phys_id as cpup. start_cpu will start where we |
| 10889 | * left off so all unassigned entries don't get assgined |
| 10890 | * the IRQ of the first entry. |
| 10891 | */ |
| 10892 | new_cpu = start_cpu; |
| 10893 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10894 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10895 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10896 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10897 | (new_cpup->phys_id == cpup->phys_id)) |
| 10898 | goto found_same; |
| 10899 | new_cpu = cpumask_next( |
| 10900 | new_cpu, cpu_present_mask); |
| 10901 | if (new_cpu == nr_cpumask_bits) |
| 10902 | new_cpu = first_cpu; |
| 10903 | } |
| 10904 | /* At this point, we leave the CPU as unassigned */ |
| 10905 | continue; |
| 10906 | found_same: |
| 10907 | /* We found a matching phys_id, so copy the IRQ info */ |
| 10908 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10909 | |
| 10910 | /* Bump start_cpu to the next slot to minmize the |
| 10911 | * chance of having multiple unassigned CPU entries |
| 10912 | * selecting the same IRQ. |
| 10913 | */ |
| 10914 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10915 | if (start_cpu == nr_cpumask_bits) |
| 10916 | start_cpu = first_cpu; |
| 10917 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10918 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10919 | "3337 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10920 | "eq %d from peer cpu %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10921 | "phys_id (%d)\n", |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10922 | cpu, cpup->eq, new_cpu, |
| 10923 | cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10924 | } |
| 10925 | } |
| 10926 | |
| 10927 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 10928 | start_cpu = first_cpu; |
| 10929 | |
| 10930 | for_each_present_cpu(cpu) { |
| 10931 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10932 | |
| 10933 | /* Is this entry unassigned */ |
| 10934 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10935 | /* Mark it as IRQ not assigned by the kernel */ |
| 10936 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10937 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10938 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10939 | * as the cpup. start_cpu will start where we |
| 10940 | * left off so all unassigned entries don't get |
| 10941 | * assigned the IRQ of the first entry. |
| 10942 | */ |
| 10943 | new_cpu = start_cpu; |
| 10944 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10945 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10946 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10947 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10948 | goto found_any; |
| 10949 | new_cpu = cpumask_next( |
| 10950 | new_cpu, cpu_present_mask); |
| 10951 | if (new_cpu == nr_cpumask_bits) |
| 10952 | new_cpu = first_cpu; |
| 10953 | } |
| 10954 | /* We should never leave an entry unassigned */ |
| 10955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10956 | "3339 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10957 | "eq %d UNASSIGNED\n", |
| 10958 | cpup->hdwq, cpup->eq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10959 | continue; |
| 10960 | found_any: |
| 10961 | /* We found an available entry, copy the IRQ info */ |
| 10962 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10963 | |
| 10964 | /* Bump start_cpu to the next slot to minmize the |
| 10965 | * chance of having multiple unassigned CPU entries |
| 10966 | * selecting the same IRQ. |
| 10967 | */ |
| 10968 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10969 | if (start_cpu == nr_cpumask_bits) |
| 10970 | start_cpu = first_cpu; |
| 10971 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10972 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10973 | "3338 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10974 | "eq %d from peer cpu %d (%d/%d)\n", |
| 10975 | cpu, cpup->eq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10976 | new_cpup->phys_id, new_cpup->core_id); |
| 10977 | } |
| 10978 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10979 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10980 | /* Assign hdwq indices that are unique across all cpus in the map |
| 10981 | * that are also FIRST_CPUs. |
| 10982 | */ |
| 10983 | idx = 0; |
| 10984 | for_each_present_cpu(cpu) { |
| 10985 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10986 | |
| 10987 | /* Only FIRST IRQs get a hdwq index assignment. */ |
| 10988 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 10989 | continue; |
| 10990 | |
| 10991 | /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */ |
| 10992 | cpup->hdwq = idx; |
| 10993 | idx++; |
| 10994 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10995 | "3333 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10996 | "hdwq %d eq %d flg x%x\n", |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10997 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10998 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10999 | } |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11000 | /* Associate a hdwq with each cpu_map entry |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11001 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 11002 | * hardware queues then CPUs. For that case we will just round-robin |
| 11003 | * the available hardware queues as they get assigned to CPUs. |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11004 | * The next_idx is the idx from the FIRST_CPU loop above to account |
| 11005 | * for irq_chann < hdwq. The idx is used for round-robin assignments |
| 11006 | * and needs to start at 0. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11007 | */ |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11008 | next_idx = idx; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11009 | start_cpu = 0; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11010 | idx = 0; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11011 | for_each_present_cpu(cpu) { |
| 11012 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11013 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11014 | /* FIRST cpus are already mapped. */ |
| 11015 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 11016 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11017 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11018 | /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq |
| 11019 | * of the unassigned cpus to the next idx so that all |
| 11020 | * hdw queues are fully utilized. |
| 11021 | */ |
| 11022 | if (next_idx < phba->cfg_hdw_queue) { |
| 11023 | cpup->hdwq = next_idx; |
| 11024 | next_idx++; |
| 11025 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11026 | } |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11027 | |
| 11028 | /* Not a First CPU and all hdw_queues are used. Reuse a |
| 11029 | * Hardware Queue for another CPU, so be smart about it |
| 11030 | * and pick one that has its IRQ/EQ mapped to the same phys_id |
| 11031 | * (CPU package) and core_id. |
| 11032 | */ |
| 11033 | new_cpu = start_cpu; |
| 11034 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11035 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11036 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11037 | new_cpup->phys_id == cpup->phys_id && |
| 11038 | new_cpup->core_id == cpup->core_id) { |
| 11039 | goto found_hdwq; |
| 11040 | } |
| 11041 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11042 | if (new_cpu == nr_cpumask_bits) |
| 11043 | new_cpu = first_cpu; |
| 11044 | } |
| 11045 | |
| 11046 | /* If we can't match both phys_id and core_id, |
| 11047 | * settle for just a phys_id match. |
| 11048 | */ |
| 11049 | new_cpu = start_cpu; |
| 11050 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11051 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11052 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11053 | new_cpup->phys_id == cpup->phys_id) |
| 11054 | goto found_hdwq; |
| 11055 | |
| 11056 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11057 | if (new_cpu == nr_cpumask_bits) |
| 11058 | new_cpu = first_cpu; |
| 11059 | } |
| 11060 | |
| 11061 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 11062 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 11063 | idx++; |
| 11064 | goto logit; |
| 11065 | found_hdwq: |
| 11066 | /* We found an available entry, copy the IRQ info */ |
| 11067 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11068 | if (start_cpu == nr_cpumask_bits) |
| 11069 | start_cpu = first_cpu; |
| 11070 | cpup->hdwq = new_cpup->hdwq; |
| 11071 | logit: |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11073 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11074 | "hdwq %d eq %d flg x%x\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11075 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11076 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11077 | } |
| 11078 | |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11079 | /* |
| 11080 | * Initialize the cpu_map slots for not-present cpus in case |
| 11081 | * a cpu is hot-added. Perform a simple hdwq round robin assignment. |
| 11082 | */ |
| 11083 | idx = 0; |
| 11084 | for_each_possible_cpu(cpu) { |
| 11085 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11086 | if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) |
| 11087 | continue; |
| 11088 | |
| 11089 | cpup->hdwq = idx++ % phba->cfg_hdw_queue; |
| 11090 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11091 | "3340 Set Affinity: not present " |
| 11092 | "CPU %d hdwq %d\n", |
| 11093 | cpu, cpup->hdwq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11094 | } |
| 11095 | |
| 11096 | /* The cpu_map array will be used later during initialization |
| 11097 | * when EQ / CQ / WQs are allocated and configured. |
| 11098 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11099 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11100 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11101 | |
| 11102 | /** |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11103 | * lpfc_cpuhp_get_eq |
| 11104 | * |
| 11105 | * @phba: pointer to lpfc hba data structure. |
| 11106 | * @cpu: cpu going offline |
| 11107 | * @eqlist: |
| 11108 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11109 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11110 | lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu, |
| 11111 | struct list_head *eqlist) |
| 11112 | { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11113 | const struct cpumask *maskp; |
| 11114 | struct lpfc_queue *eq; |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11115 | struct cpumask *tmp; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11116 | u16 idx; |
| 11117 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11118 | tmp = kzalloc(cpumask_size(), GFP_KERNEL); |
| 11119 | if (!tmp) |
| 11120 | return -ENOMEM; |
| 11121 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11122 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11123 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 11124 | if (!maskp) |
| 11125 | continue; |
| 11126 | /* |
| 11127 | * if irq is not affinitized to the cpu going |
| 11128 | * then we don't need to poll the eq attached |
| 11129 | * to it. |
| 11130 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11131 | if (!cpumask_and(tmp, maskp, cpumask_of(cpu))) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11132 | continue; |
| 11133 | /* get the cpus that are online and are affini- |
| 11134 | * tized to this irq vector. If the count is |
| 11135 | * more than 1 then cpuhp is not going to shut- |
| 11136 | * down this vector. Since this cpu has not |
| 11137 | * gone offline yet, we need >1. |
| 11138 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11139 | cpumask_and(tmp, maskp, cpu_online_mask); |
| 11140 | if (cpumask_weight(tmp) > 1) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11141 | continue; |
| 11142 | |
| 11143 | /* Now that we have an irq to shutdown, get the eq |
| 11144 | * mapped to this irq. Note: multiple hdwq's in |
| 11145 | * the software can share an eq, but eventually |
| 11146 | * only eq will be mapped to this vector |
| 11147 | */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11148 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 11149 | list_add(&eq->_poll_list, eqlist); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11150 | } |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11151 | kfree(tmp); |
| 11152 | return 0; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11153 | } |
| 11154 | |
| 11155 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11156 | { |
| 11157 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11158 | return; |
| 11159 | |
| 11160 | cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state, |
| 11161 | &phba->cpuhp); |
| 11162 | /* |
| 11163 | * unregistering the instance doesn't stop the polling |
| 11164 | * timer. Wait for the poll timer to retire. |
| 11165 | */ |
| 11166 | synchronize_rcu(); |
| 11167 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 11168 | } |
| 11169 | |
| 11170 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11171 | { |
| 11172 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 11173 | return; |
| 11174 | |
| 11175 | __lpfc_cpuhp_remove(phba); |
| 11176 | } |
| 11177 | |
| 11178 | static void lpfc_cpuhp_add(struct lpfc_hba *phba) |
| 11179 | { |
| 11180 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11181 | return; |
| 11182 | |
| 11183 | rcu_read_lock(); |
| 11184 | |
| 11185 | if (!list_empty(&phba->poll_list)) { |
| 11186 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
| 11187 | mod_timer(&phba->cpuhp_poll_timer, |
| 11188 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 11189 | } |
| 11190 | |
| 11191 | rcu_read_unlock(); |
| 11192 | |
| 11193 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, |
| 11194 | &phba->cpuhp); |
| 11195 | } |
| 11196 | |
| 11197 | static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval) |
| 11198 | { |
| 11199 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 11200 | *retval = -EAGAIN; |
| 11201 | return true; |
| 11202 | } |
| 11203 | |
| 11204 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11205 | *retval = 0; |
| 11206 | return true; |
| 11207 | } |
| 11208 | |
| 11209 | /* proceed with the hotplug */ |
| 11210 | return false; |
| 11211 | } |
| 11212 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11213 | /** |
| 11214 | * lpfc_irq_set_aff - set IRQ affinity |
| 11215 | * @eqhdl: EQ handle |
| 11216 | * @cpu: cpu to set affinity |
| 11217 | * |
| 11218 | **/ |
| 11219 | static inline void |
| 11220 | lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu) |
| 11221 | { |
| 11222 | cpumask_clear(&eqhdl->aff_mask); |
| 11223 | cpumask_set_cpu(cpu, &eqhdl->aff_mask); |
| 11224 | irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 11225 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 11226 | } |
| 11227 | |
| 11228 | /** |
| 11229 | * lpfc_irq_clear_aff - clear IRQ affinity |
| 11230 | * @eqhdl: EQ handle |
| 11231 | * |
| 11232 | **/ |
| 11233 | static inline void |
| 11234 | lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl) |
| 11235 | { |
| 11236 | cpumask_clear(&eqhdl->aff_mask); |
| 11237 | irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 11238 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 11239 | } |
| 11240 | |
| 11241 | /** |
| 11242 | * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event |
| 11243 | * @phba: pointer to HBA context object. |
| 11244 | * @cpu: cpu going offline/online |
| 11245 | * @offline: true, cpu is going offline. false, cpu is coming online. |
| 11246 | * |
| 11247 | * If cpu is going offline, we'll try our best effort to find the next |
| 11248 | * online cpu on the phba's NUMA node and migrate all offlining IRQ affinities. |
| 11249 | * |
| 11250 | * If cpu is coming online, reaffinitize the IRQ back to the onlineng cpu. |
| 11251 | * |
| 11252 | * Note: Call only if cfg_irq_numa is enabled, otherwise rely on |
| 11253 | * PCI_IRQ_AFFINITY to auto-manage IRQ affinity. |
| 11254 | * |
| 11255 | **/ |
| 11256 | static void |
| 11257 | lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline) |
| 11258 | { |
| 11259 | struct lpfc_vector_map_info *cpup; |
| 11260 | struct cpumask *aff_mask; |
| 11261 | unsigned int cpu_select, cpu_next, idx; |
| 11262 | const struct cpumask *numa_mask; |
| 11263 | |
| 11264 | if (!phba->cfg_irq_numa) |
| 11265 | return; |
| 11266 | |
| 11267 | numa_mask = &phba->sli4_hba.numa_mask; |
| 11268 | |
| 11269 | if (!cpumask_test_cpu(cpu, numa_mask)) |
| 11270 | return; |
| 11271 | |
| 11272 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11273 | |
| 11274 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11275 | return; |
| 11276 | |
| 11277 | if (offline) { |
| 11278 | /* Find next online CPU on NUMA node */ |
| 11279 | cpu_next = cpumask_next_wrap(cpu, numa_mask, cpu, true); |
| 11280 | cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu_next); |
| 11281 | |
| 11282 | /* Found a valid CPU */ |
| 11283 | if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) { |
| 11284 | /* Go through each eqhdl and ensure offlining |
| 11285 | * cpu aff_mask is migrated |
| 11286 | */ |
| 11287 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11288 | aff_mask = lpfc_get_aff_mask(idx); |
| 11289 | |
| 11290 | /* Migrate affinity */ |
| 11291 | if (cpumask_test_cpu(cpu, aff_mask)) |
| 11292 | lpfc_irq_set_aff(lpfc_get_eq_hdl(idx), |
| 11293 | cpu_select); |
| 11294 | } |
| 11295 | } else { |
| 11296 | /* Rely on irqbalance if no online CPUs left on NUMA */ |
| 11297 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) |
| 11298 | lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx)); |
| 11299 | } |
| 11300 | } else { |
| 11301 | /* Migrate affinity back to this CPU */ |
| 11302 | lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu); |
| 11303 | } |
| 11304 | } |
| 11305 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11306 | static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node) |
| 11307 | { |
| 11308 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11309 | struct lpfc_queue *eq, *next; |
| 11310 | LIST_HEAD(eqlist); |
| 11311 | int retval; |
| 11312 | |
| 11313 | if (!phba) { |
| 11314 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11315 | return 0; |
| 11316 | } |
| 11317 | |
| 11318 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11319 | return retval; |
| 11320 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11321 | lpfc_irq_rebalance(phba, cpu, true); |
| 11322 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame^] | 11323 | retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist); |
| 11324 | if (retval) |
| 11325 | return retval; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11326 | |
| 11327 | /* start polling on these eq's */ |
| 11328 | list_for_each_entry_safe(eq, next, &eqlist, _poll_list) { |
| 11329 | list_del_init(&eq->_poll_list); |
| 11330 | lpfc_sli4_start_polling(eq); |
| 11331 | } |
| 11332 | |
| 11333 | return 0; |
| 11334 | } |
| 11335 | |
| 11336 | static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node) |
| 11337 | { |
| 11338 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11339 | struct lpfc_queue *eq, *next; |
| 11340 | unsigned int n; |
| 11341 | int retval; |
| 11342 | |
| 11343 | if (!phba) { |
| 11344 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11345 | return 0; |
| 11346 | } |
| 11347 | |
| 11348 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11349 | return retval; |
| 11350 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11351 | lpfc_irq_rebalance(phba, cpu, false); |
| 11352 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11353 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) { |
| 11354 | n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ); |
| 11355 | if (n == cpu) |
| 11356 | lpfc_sli4_stop_polling(eq); |
| 11357 | } |
| 11358 | |
| 11359 | return 0; |
| 11360 | } |
| 11361 | |
| 11362 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11363 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 11364 | * @phba: pointer to lpfc hba data structure. |
| 11365 | * |
| 11366 | * 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] | 11367 | * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them |
| 11368 | * to cpus on the system. |
| 11369 | * |
| 11370 | * When cfg_irq_numa is enabled, the adapter will only allocate vectors for |
| 11371 | * the number of cpus on the same numa node as this adapter. The vectors are |
| 11372 | * allocated without requesting OS affinity mapping. A vector will be |
| 11373 | * allocated and assigned to each online and offline cpu. If the cpu is |
| 11374 | * online, then affinity will be set to that cpu. If the cpu is offline, then |
| 11375 | * affinity will be set to the nearest peer cpu within the numa node that is |
| 11376 | * online. If there are no online cpus within the numa node, affinity is not |
| 11377 | * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping |
| 11378 | * is consistent with the way cpu online/offline is handled when cfg_irq_numa is |
| 11379 | * configured. |
| 11380 | * |
| 11381 | * If numa mode is not enabled and there is more than 1 vector allocated, then |
| 11382 | * the driver relies on the managed irq interface where the OS assigns vector to |
| 11383 | * cpu affinity. The driver will then use that affinity mapping to setup its |
| 11384 | * cpu mapping table. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11385 | * |
| 11386 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11387 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11388 | * other values - error |
| 11389 | **/ |
| 11390 | static int |
| 11391 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11392 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11393 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11394 | char *name; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11395 | const struct cpumask *numa_mask = NULL; |
| 11396 | unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids; |
| 11397 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11398 | const struct cpumask *maskp; |
| 11399 | bool first; |
| 11400 | unsigned int flags = PCI_IRQ_MSIX; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11401 | |
| 11402 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11403 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11404 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11405 | if (phba->cfg_irq_numa) { |
| 11406 | numa_mask = &phba->sli4_hba.numa_mask; |
| 11407 | cpu_cnt = cpumask_weight(numa_mask); |
| 11408 | vectors = min(phba->cfg_irq_chann, cpu_cnt); |
| 11409 | |
| 11410 | /* cpu: iterates over numa_mask including offline or online |
| 11411 | * cpu_select: iterates over online numa_mask to set affinity |
| 11412 | */ |
| 11413 | cpu = cpumask_first(numa_mask); |
| 11414 | cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu); |
| 11415 | } else { |
| 11416 | flags |= PCI_IRQ_AFFINITY; |
| 11417 | } |
| 11418 | |
| 11419 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11420 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11421 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11422 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11423 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11424 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11425 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11426 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11427 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11428 | for (index = 0; index < vectors; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11429 | eqhdl = lpfc_get_eq_hdl(index); |
| 11430 | name = eqhdl->handler_name; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11431 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11432 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11433 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11434 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11435 | eqhdl->idx = index; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11436 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11437 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11438 | name, eqhdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11439 | if (rc) { |
| 11440 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11441 | "0486 MSI-X fast-path (%d) " |
| 11442 | "request_irq failed (%d)\n", index, rc); |
| 11443 | goto cfg_fail_out; |
| 11444 | } |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11445 | |
| 11446 | eqhdl->irq = pci_irq_vector(phba->pcidev, index); |
| 11447 | |
| 11448 | if (phba->cfg_irq_numa) { |
| 11449 | /* If found a neighboring online cpu, set affinity */ |
| 11450 | if (cpu_select < nr_cpu_ids) |
| 11451 | lpfc_irq_set_aff(eqhdl, cpu_select); |
| 11452 | |
| 11453 | /* Assign EQ to cpu_map */ |
| 11454 | lpfc_assign_eq_map_info(phba, index, |
| 11455 | LPFC_CPU_FIRST_IRQ, |
| 11456 | cpu); |
| 11457 | |
| 11458 | /* Iterate to next offline or online cpu in numa_mask */ |
| 11459 | cpu = cpumask_next(cpu, numa_mask); |
| 11460 | |
| 11461 | /* Find next online cpu in numa_mask to set affinity */ |
| 11462 | cpu_select = lpfc_next_online_numa_cpu(numa_mask, cpu); |
| 11463 | } else if (vectors == 1) { |
| 11464 | cpu = cpumask_first(cpu_present_mask); |
| 11465 | lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ, |
| 11466 | cpu); |
| 11467 | } else { |
| 11468 | maskp = pci_irq_get_affinity(phba->pcidev, index); |
| 11469 | |
| 11470 | first = true; |
| 11471 | /* Loop through all CPUs associated with vector index */ |
| 11472 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
| 11473 | /* If this is the first CPU thats assigned to |
| 11474 | * this vector, set LPFC_CPU_FIRST_IRQ. |
| 11475 | */ |
| 11476 | lpfc_assign_eq_map_info(phba, index, |
| 11477 | first ? |
| 11478 | LPFC_CPU_FIRST_IRQ : 0, |
| 11479 | cpu); |
| 11480 | if (first) |
| 11481 | first = false; |
| 11482 | } |
| 11483 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11484 | } |
| 11485 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11486 | if (vectors != phba->cfg_irq_chann) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11487 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11488 | "3238 Reducing IO channels to match number of " |
| 11489 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11490 | phba->cfg_irq_chann, vectors); |
| 11491 | if (phba->cfg_irq_chann > vectors) |
| 11492 | phba->cfg_irq_chann = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11493 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11494 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11495 | return rc; |
| 11496 | |
| 11497 | cfg_fail_out: |
| 11498 | /* free the irq already requested */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11499 | for (--index; index >= 0; index--) { |
| 11500 | eqhdl = lpfc_get_eq_hdl(index); |
| 11501 | lpfc_irq_clear_aff(eqhdl); |
| 11502 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11503 | free_irq(eqhdl->irq, eqhdl); |
| 11504 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11505 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11506 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11507 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11508 | |
| 11509 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11510 | return rc; |
| 11511 | } |
| 11512 | |
| 11513 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11514 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11515 | * @phba: pointer to lpfc hba data structure. |
| 11516 | * |
| 11517 | * 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] | 11518 | * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is |
| 11519 | * called to enable the MSI vector. The device driver is responsible for |
| 11520 | * calling the request_irq() to register MSI vector with a interrupt the |
| 11521 | * handler, which is done in this function. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11522 | * |
| 11523 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11524 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11525 | * other values - error |
| 11526 | **/ |
| 11527 | static int |
| 11528 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11529 | { |
| 11530 | int rc, index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11531 | unsigned int cpu; |
| 11532 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11533 | |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11534 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1, |
| 11535 | PCI_IRQ_MSI | PCI_IRQ_AFFINITY); |
| 11536 | if (rc > 0) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11537 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11538 | "0487 PCI enable MSI mode success.\n"); |
| 11539 | else { |
| 11540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11541 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11542 | return rc ? rc : -1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11543 | } |
| 11544 | |
| 11545 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11546 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11547 | if (rc) { |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11548 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11549 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11550 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11551 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11552 | } |
| 11553 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11554 | eqhdl = lpfc_get_eq_hdl(0); |
| 11555 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11556 | |
| 11557 | cpu = cpumask_first(cpu_present_mask); |
| 11558 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu); |
| 11559 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11560 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11561 | eqhdl = lpfc_get_eq_hdl(index); |
| 11562 | eqhdl->idx = index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11563 | } |
| 11564 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11565 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11566 | } |
| 11567 | |
| 11568 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11569 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11570 | * @phba: pointer to lpfc hba data structure. |
| 11571 | * |
| 11572 | * This routine is invoked to enable device interrupt and associate driver's |
| 11573 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11574 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11575 | * the driver will try to fallback from the configured interrupt mode to an |
| 11576 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11577 | * the order of: |
| 11578 | * MSI-X -> MSI -> IRQ. |
| 11579 | * |
| 11580 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11581 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11582 | * other values - error |
| 11583 | **/ |
| 11584 | static uint32_t |
| 11585 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11586 | { |
| 11587 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11588 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11589 | |
| 11590 | if (cfg_mode == 2) { |
| 11591 | /* Preparation before conf_msi mbox cmd */ |
| 11592 | retval = 0; |
| 11593 | if (!retval) { |
| 11594 | /* Now, try to enable MSI-X interrupt mode */ |
| 11595 | retval = lpfc_sli4_enable_msix(phba); |
| 11596 | if (!retval) { |
| 11597 | /* Indicate initialization to MSI-X mode */ |
| 11598 | phba->intr_type = MSIX; |
| 11599 | intr_mode = 2; |
| 11600 | } |
| 11601 | } |
| 11602 | } |
| 11603 | |
| 11604 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11605 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11606 | retval = lpfc_sli4_enable_msi(phba); |
| 11607 | if (!retval) { |
| 11608 | /* Indicate initialization to MSI mode */ |
| 11609 | phba->intr_type = MSI; |
| 11610 | intr_mode = 1; |
| 11611 | } |
| 11612 | } |
| 11613 | |
| 11614 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11615 | if (phba->intr_type == NONE) { |
| 11616 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11617 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11618 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11619 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11620 | unsigned int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11621 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11622 | /* Indicate initialization to INTx mode */ |
| 11623 | phba->intr_type = INTx; |
| 11624 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11625 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11626 | eqhdl = lpfc_get_eq_hdl(0); |
| 11627 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11628 | |
| 11629 | cpu = cpumask_first(cpu_present_mask); |
| 11630 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, |
| 11631 | cpu); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11632 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11633 | eqhdl = lpfc_get_eq_hdl(idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11634 | eqhdl->idx = idx; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11635 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11636 | } |
| 11637 | } |
| 11638 | return intr_mode; |
| 11639 | } |
| 11640 | |
| 11641 | /** |
| 11642 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11643 | * @phba: pointer to lpfc hba data structure. |
| 11644 | * |
| 11645 | * This routine is invoked to disable device interrupt and disassociate |
| 11646 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11647 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11648 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11649 | **/ |
| 11650 | static void |
| 11651 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11652 | { |
| 11653 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11654 | if (phba->intr_type == MSIX) { |
| 11655 | int index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11656 | struct lpfc_hba_eq_hdl *eqhdl; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11657 | |
| 11658 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11659 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11660 | eqhdl = lpfc_get_eq_hdl(index); |
| 11661 | lpfc_irq_clear_aff(eqhdl); |
| 11662 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11663 | free_irq(eqhdl->irq, eqhdl); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11664 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11665 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11666 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11667 | } |
| 11668 | |
| 11669 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11670 | |
| 11671 | /* Reset interrupt management states */ |
| 11672 | phba->intr_type = NONE; |
| 11673 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11674 | } |
| 11675 | |
| 11676 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11677 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11678 | * @phba: pointer to lpfc hba data structure. |
| 11679 | * |
| 11680 | * This routine is invoked to unset the HBA device initialization steps to |
| 11681 | * a device with SLI-3 interface spec. |
| 11682 | **/ |
| 11683 | static void |
| 11684 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11685 | { |
| 11686 | struct lpfc_vport *vport = phba->pport; |
| 11687 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11688 | |
| 11689 | spin_lock_irq(shost->host_lock); |
| 11690 | vport->load_flag |= FC_UNLOADING; |
| 11691 | spin_unlock_irq(shost->host_lock); |
| 11692 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11693 | kfree(phba->vpi_bmask); |
| 11694 | kfree(phba->vpi_ids); |
| 11695 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11696 | lpfc_stop_hba_timers(phba); |
| 11697 | |
| 11698 | phba->pport->work_port_events = 0; |
| 11699 | |
| 11700 | lpfc_sli_hba_down(phba); |
| 11701 | |
| 11702 | lpfc_sli_brdrestart(phba); |
| 11703 | |
| 11704 | lpfc_sli_disable_intr(phba); |
| 11705 | |
| 11706 | return; |
| 11707 | } |
| 11708 | |
| 11709 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11710 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11711 | * @phba: Pointer to HBA context object. |
| 11712 | * |
| 11713 | * This function is called in the SLI4 code path to wait for completion |
| 11714 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11715 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11716 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11717 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11718 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11719 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11720 | * the rest of the driver unload resource release. |
| 11721 | **/ |
| 11722 | static void |
| 11723 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11724 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11725 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11726 | int idx, ccnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11727 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11728 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11729 | int nvmet_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11730 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11731 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11732 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11733 | * here to give the HBA time to complete the IO and get entries |
| 11734 | * into the abts lists. |
| 11735 | */ |
| 11736 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11737 | |
| 11738 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11739 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11740 | lpfc_nvme_wait_for_io_drain(phba); |
| 11741 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11742 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11743 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11744 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11745 | io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list); |
| 11746 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11747 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11748 | } |
| 11749 | if (ccnt) |
| 11750 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11751 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11752 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11753 | nvmet_xri_cmpl = |
| 11754 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11755 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11756 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11757 | while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11758 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11759 | if (!nvmet_xri_cmpl) |
| 11760 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11761 | "6424 NVMET XRI exchange busy " |
| 11762 | "wait time: %d seconds.\n", |
| 11763 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11764 | if (!io_xri_cmpl) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11765 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11766 | "6100 IO XRI exchange busy " |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11767 | "wait time: %d seconds.\n", |
| 11768 | wait_time/1000); |
| 11769 | if (!els_xri_cmpl) |
| 11770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11771 | "2878 ELS XRI exchange busy " |
| 11772 | "wait time: %d seconds.\n", |
| 11773 | wait_time/1000); |
| 11774 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11775 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11776 | } else { |
| 11777 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11778 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11779 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11780 | |
| 11781 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11782 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11783 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11784 | io_xri_cmpl = list_empty( |
| 11785 | &qp->lpfc_abts_io_buf_list); |
| 11786 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11787 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11788 | } |
| 11789 | if (ccnt) |
| 11790 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11791 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11792 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11793 | nvmet_xri_cmpl = list_empty( |
| 11794 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11795 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11796 | els_xri_cmpl = |
| 11797 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11798 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11799 | } |
| 11800 | } |
| 11801 | |
| 11802 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11803 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11804 | * @phba: Pointer to HBA context object. |
| 11805 | * |
| 11806 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11807 | * function. The caller is not required to hold any lock. This routine |
| 11808 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11809 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11810 | * free any pending commands. |
| 11811 | **/ |
| 11812 | static void |
| 11813 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11814 | { |
| 11815 | int wait_cnt = 0; |
| 11816 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11817 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11818 | |
| 11819 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11820 | if (phba->pport) |
| 11821 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11822 | |
| 11823 | /* |
| 11824 | * Gracefully wait out the potential current outstanding asynchronous |
| 11825 | * mailbox command. |
| 11826 | */ |
| 11827 | |
| 11828 | /* First, block any pending async mailbox command from posted */ |
| 11829 | spin_lock_irq(&phba->hbalock); |
| 11830 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11831 | spin_unlock_irq(&phba->hbalock); |
| 11832 | /* Now, trying to wait it out if we can */ |
| 11833 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11834 | msleep(10); |
| 11835 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11836 | break; |
| 11837 | } |
| 11838 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11839 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11840 | spin_lock_irq(&phba->hbalock); |
| 11841 | mboxq = phba->sli.mbox_active; |
| 11842 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11843 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11844 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11845 | phba->sli.mbox_active = NULL; |
| 11846 | spin_unlock_irq(&phba->hbalock); |
| 11847 | } |
| 11848 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11849 | /* Abort all iocbs associated with the hba */ |
| 11850 | lpfc_sli_hba_iocb_abort(phba); |
| 11851 | |
| 11852 | /* Wait for completion of device XRI exchange busy */ |
| 11853 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 11854 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11855 | /* per-phba callback de-registration for hotplug event */ |
| 11856 | lpfc_cpuhp_remove(phba); |
| 11857 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11858 | /* Disable PCI subsystem interrupt */ |
| 11859 | lpfc_sli4_disable_intr(phba); |
| 11860 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11861 | /* Disable SR-IOV if enabled */ |
| 11862 | if (phba->cfg_sriov_nr_virtfn) |
| 11863 | pci_disable_sriov(pdev); |
| 11864 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11865 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11866 | kthread_stop(phba->worker_thread); |
| 11867 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11868 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11869 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11870 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11871 | /* Unset the queues shared with the hardware then release all |
| 11872 | * allocated resources. |
| 11873 | */ |
| 11874 | lpfc_sli4_queue_unset(phba); |
| 11875 | lpfc_sli4_queue_destroy(phba); |
| 11876 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11877 | /* Reset SLI4 HBA FCoE function */ |
| 11878 | lpfc_pci_function_reset(phba); |
| 11879 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11880 | /* Free RAS DMA memory */ |
| 11881 | if (phba->ras_fwlog.ras_enabled) |
| 11882 | lpfc_sli4_ras_dma_free(phba); |
| 11883 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11884 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 11885 | if (phba->pport) |
| 11886 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11887 | } |
| 11888 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11889 | /** |
| 11890 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 11891 | * @phba: Pointer to HBA context object. |
| 11892 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11893 | * |
| 11894 | * This function is called in the SLI4 code path to read the port's |
| 11895 | * sli4 capabilities. |
| 11896 | * |
| 11897 | * This function may be be called from any context that can block-wait |
| 11898 | * for the completion. The expectation is that this routine is called |
| 11899 | * typically from probe_one or from the online routine. |
| 11900 | **/ |
| 11901 | int |
| 11902 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11903 | { |
| 11904 | int rc; |
| 11905 | struct lpfc_mqe *mqe; |
| 11906 | struct lpfc_pc_sli4_params *sli4_params; |
| 11907 | uint32_t mbox_tmo; |
| 11908 | |
| 11909 | rc = 0; |
| 11910 | mqe = &mboxq->u.mqe; |
| 11911 | |
| 11912 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11913 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11914 | if (!phba->sli4_hba.intr_enable) |
| 11915 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 11916 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11917 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11918 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11919 | } |
| 11920 | |
| 11921 | if (unlikely(rc)) |
| 11922 | return 1; |
| 11923 | |
| 11924 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11925 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 11926 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 11927 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 11928 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 11929 | &mqe->un.sli4_params); |
| 11930 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 11931 | &mqe->un.sli4_params); |
| 11932 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 11933 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 11934 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 11935 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 11936 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 11937 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 11938 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 11939 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 11940 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 11941 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 11942 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 11943 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 11944 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 11945 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 11946 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 11947 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 11948 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 11949 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 11950 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 11951 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 11952 | 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] | 11953 | |
| 11954 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11955 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11956 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11957 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11958 | return rc; |
| 11959 | } |
| 11960 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11961 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11962 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 11963 | * @phba: Pointer to HBA context object. |
| 11964 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11965 | * |
| 11966 | * This function is called in the SLI4 code path to read the port's |
| 11967 | * sli4 capabilities. |
| 11968 | * |
| 11969 | * This function may be be called from any context that can block-wait |
| 11970 | * for the completion. The expectation is that this routine is called |
| 11971 | * typically from probe_one or from the online routine. |
| 11972 | **/ |
| 11973 | int |
| 11974 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11975 | { |
| 11976 | int rc; |
| 11977 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 11978 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11979 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11980 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11981 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11982 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 11983 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11984 | /* |
| 11985 | * By default, the driver assumes the SLI4 port requires RPI |
| 11986 | * header postings. The SLI4_PARAM response will correct this |
| 11987 | * assumption. |
| 11988 | */ |
| 11989 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 11990 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11991 | /* Read the port's SLI4 Config Parameters */ |
| 11992 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 11993 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 11994 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11995 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 11996 | length, LPFC_SLI4_MBX_EMBED); |
| 11997 | if (!phba->sli4_hba.intr_enable) |
| 11998 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11999 | else { |
| 12000 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 12001 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 12002 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12003 | if (unlikely(rc)) |
| 12004 | return rc; |
| 12005 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 12006 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 12007 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 12008 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 12009 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 12010 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 12011 | mbx_sli4_parameters); |
| 12012 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 12013 | mbx_sli4_parameters); |
| 12014 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 12015 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 12016 | else |
| 12017 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 12018 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 12019 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12020 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12021 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 12022 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 12023 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 12024 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12025 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 12026 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 12027 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 12028 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 12029 | sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12030 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 12031 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12032 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12033 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 12034 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12035 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 12036 | 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] | 12037 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 12038 | /* Check for Extended Pre-Registered SGL support */ |
| 12039 | phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters); |
| 12040 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12041 | /* Check for firmware nvme support */ |
| 12042 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 12043 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12044 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12045 | if (rc) { |
| 12046 | /* Save this to indicate the Firmware supports NVME */ |
| 12047 | sli4_params->nvme = 1; |
| 12048 | |
| 12049 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 12050 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 12051 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 12052 | "6133 Disabling NVME support: " |
| 12053 | "FC4 type not supported: x%x\n", |
| 12054 | phba->cfg_enable_fc4_type); |
| 12055 | goto fcponly; |
| 12056 | } |
| 12057 | } else { |
| 12058 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 12059 | sli4_params->nvme = 0; |
| 12060 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 12062 | "6101 Disabling NVME support: Not " |
| 12063 | "supported by firmware (%d %d) x%x\n", |
| 12064 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 12065 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 12066 | phba->cfg_enable_fc4_type); |
| 12067 | fcponly: |
| 12068 | phba->nvme_support = 0; |
| 12069 | phba->nvmet_support = 0; |
| 12070 | phba->cfg_nvmet_mrq = 0; |
James Smart | 6a224b4 | 2019-08-14 16:56:57 -0700 | [diff] [blame] | 12071 | phba->cfg_nvme_seg_cnt = 0; |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12072 | |
| 12073 | /* If no FC4 type support, move to just SCSI support */ |
| 12074 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 12075 | return -ENODEV; |
| 12076 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 12077 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12078 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12079 | |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12080 | /* 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] | 12081 | * accommodate 512K and 1M IOs in a single nvme buf. |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12082 | */ |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 12083 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12084 | phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12085 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12086 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 12087 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 12088 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 12089 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12090 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12091 | /* |
| 12092 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 12093 | * lpfc_suppress_rsp module parameter must be set (default). |
| 12094 | * In SLI4-Parameters Descriptor: |
| 12095 | * Extended Inline Buffers (XIB) must be supported. |
| 12096 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 12097 | * (double negative). |
| 12098 | */ |
| 12099 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 12100 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12101 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12102 | else |
| 12103 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12104 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 12105 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 12106 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 12107 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12108 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 12109 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 12110 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 12111 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12112 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12113 | * Check whether the adapter supports an embedded copy of the |
| 12114 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 12115 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12116 | */ |
| 12117 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 12118 | phba->fcp_embed_io = 1; |
| 12119 | else |
| 12120 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12121 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12122 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12123 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12124 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12125 | phba->cfg_enable_pbde, |
| 12126 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 12127 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12128 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12129 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 12130 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 12131 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 12132 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12133 | exp_wqcq_pages = false; |
| 12134 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12135 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 12136 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12137 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12138 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 12139 | phba->enab_exp_wqcq_pages = 1; |
| 12140 | else |
| 12141 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12142 | /* |
| 12143 | * Check if the SLI port supports MDS Diagnostics |
| 12144 | */ |
| 12145 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 12146 | phba->mds_diags_support = 1; |
| 12147 | else |
| 12148 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12149 | |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 12150 | /* |
| 12151 | * Check if the SLI port supports NSLER |
| 12152 | */ |
| 12153 | if (bf_get(cfg_nsler, mbx_sli4_parameters)) |
| 12154 | phba->nsler = 1; |
| 12155 | else |
| 12156 | phba->nsler = 0; |
| 12157 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12158 | return 0; |
| 12159 | } |
| 12160 | |
| 12161 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12162 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 12163 | * @pdev: pointer to PCI device |
| 12164 | * @pid: pointer to PCI device identifier |
| 12165 | * |
| 12166 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 12167 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12168 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12169 | * information of the device and driver to see if the driver state that it can |
| 12170 | * support this kind of device. If the match is successful, the driver core |
| 12171 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 12172 | * does all the initialization that it needs to do to handle the HBA properly. |
| 12173 | * |
| 12174 | * Return code |
| 12175 | * 0 - driver can claim the device |
| 12176 | * negative value - driver can not claim the device |
| 12177 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12178 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12179 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12180 | { |
| 12181 | struct lpfc_hba *phba; |
| 12182 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12183 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12184 | int error; |
| 12185 | uint32_t cfg_mode, intr_mode; |
| 12186 | |
| 12187 | /* Allocate memory for HBA structure */ |
| 12188 | phba = lpfc_hba_alloc(pdev); |
| 12189 | if (!phba) |
| 12190 | return -ENOMEM; |
| 12191 | |
| 12192 | /* Perform generic PCI device enabling operation */ |
| 12193 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12194 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12195 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12196 | |
| 12197 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 12198 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 12199 | if (error) |
| 12200 | goto out_disable_pci_dev; |
| 12201 | |
| 12202 | /* Set up SLI-3 specific device PCI memory space */ |
| 12203 | error = lpfc_sli_pci_mem_setup(phba); |
| 12204 | if (error) { |
| 12205 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12206 | "1402 Failed to set up pci memory space.\n"); |
| 12207 | goto out_disable_pci_dev; |
| 12208 | } |
| 12209 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12210 | /* Set up SLI-3 specific device driver resources */ |
| 12211 | error = lpfc_sli_driver_resource_setup(phba); |
| 12212 | if (error) { |
| 12213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12214 | "1404 Failed to set up driver resource.\n"); |
| 12215 | goto out_unset_pci_mem_s3; |
| 12216 | } |
| 12217 | |
| 12218 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12219 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12220 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 12221 | if (error) { |
| 12222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12223 | "1405 Failed to initialize iocb list.\n"); |
| 12224 | goto out_unset_driver_resource_s3; |
| 12225 | } |
| 12226 | |
| 12227 | /* Set up common device driver resources */ |
| 12228 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12229 | if (error) { |
| 12230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12231 | "1406 Failed to set up driver resource.\n"); |
| 12232 | goto out_free_iocb_list; |
| 12233 | } |
| 12234 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12235 | /* Get the default values for Model Name and Description */ |
| 12236 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12237 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12238 | /* Create SCSI host to the physical port */ |
| 12239 | error = lpfc_create_shost(phba); |
| 12240 | if (error) { |
| 12241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12242 | "1407 Failed to create scsi host.\n"); |
| 12243 | goto out_unset_driver_resource; |
| 12244 | } |
| 12245 | |
| 12246 | /* Configure sysfs attributes */ |
| 12247 | vport = phba->pport; |
| 12248 | error = lpfc_alloc_sysfs_attr(vport); |
| 12249 | if (error) { |
| 12250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12251 | "1476 Failed to allocate sysfs attr\n"); |
| 12252 | goto out_destroy_shost; |
| 12253 | } |
| 12254 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12255 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12256 | /* Now, trying to enable interrupt and bring up the device */ |
| 12257 | cfg_mode = phba->cfg_use_msi; |
| 12258 | while (true) { |
| 12259 | /* Put device to a known state before enabling interrupt */ |
| 12260 | lpfc_stop_port(phba); |
| 12261 | /* Configure and enable interrupt */ |
| 12262 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 12263 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12264 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12265 | "0431 Failed to enable interrupt.\n"); |
| 12266 | error = -ENODEV; |
| 12267 | goto out_free_sysfs_attr; |
| 12268 | } |
| 12269 | /* SLI-3 HBA setup */ |
| 12270 | if (lpfc_sli_hba_setup(phba)) { |
| 12271 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12272 | "1477 Failed to set up hba\n"); |
| 12273 | error = -ENODEV; |
| 12274 | goto out_remove_device; |
| 12275 | } |
| 12276 | |
| 12277 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 12278 | msleep(50); |
| 12279 | /* Check active interrupts on message signaled interrupts */ |
| 12280 | if (intr_mode == 0 || |
| 12281 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 12282 | /* Log the current active interrupt mode */ |
| 12283 | phba->intr_mode = intr_mode; |
| 12284 | lpfc_log_intr_mode(phba, intr_mode); |
| 12285 | break; |
| 12286 | } else { |
| 12287 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12288 | "0447 Configure interrupt mode (%d) " |
| 12289 | "failed active interrupt test.\n", |
| 12290 | intr_mode); |
| 12291 | /* Disable the current interrupt mode */ |
| 12292 | lpfc_sli_disable_intr(phba); |
| 12293 | /* Try next level of interrupt mode */ |
| 12294 | cfg_mode = --intr_mode; |
| 12295 | } |
| 12296 | } |
| 12297 | |
| 12298 | /* Perform post initialization setup */ |
| 12299 | lpfc_post_init_setup(phba); |
| 12300 | |
| 12301 | /* Check if there are static vports to be created. */ |
| 12302 | lpfc_create_static_vport(phba); |
| 12303 | |
| 12304 | return 0; |
| 12305 | |
| 12306 | out_remove_device: |
| 12307 | lpfc_unset_hba(phba); |
| 12308 | out_free_sysfs_attr: |
| 12309 | lpfc_free_sysfs_attr(vport); |
| 12310 | out_destroy_shost: |
| 12311 | lpfc_destroy_shost(phba); |
| 12312 | out_unset_driver_resource: |
| 12313 | lpfc_unset_driver_resource_phase2(phba); |
| 12314 | out_free_iocb_list: |
| 12315 | lpfc_free_iocb_list(phba); |
| 12316 | out_unset_driver_resource_s3: |
| 12317 | lpfc_sli_driver_resource_unset(phba); |
| 12318 | out_unset_pci_mem_s3: |
| 12319 | lpfc_sli_pci_mem_unset(phba); |
| 12320 | out_disable_pci_dev: |
| 12321 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12322 | if (shost) |
| 12323 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12324 | out_free_phba: |
| 12325 | lpfc_hba_free(phba); |
| 12326 | return error; |
| 12327 | } |
| 12328 | |
| 12329 | /** |
| 12330 | * 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] | 12331 | * @pdev: pointer to PCI device |
| 12332 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12333 | * This routine is to be called to disattach a device with SLI-3 interface |
| 12334 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12335 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12336 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12337 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12338 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12339 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12340 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12341 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12342 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12343 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12344 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12345 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 12346 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12347 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12348 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12349 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12350 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12351 | lpfc_free_sysfs_attr(vport); |
| 12352 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12353 | /* Release all the vports against this physical port */ |
| 12354 | vports = lpfc_create_vport_work_array(phba); |
| 12355 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12356 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12357 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12358 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12359 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12360 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12361 | lpfc_destroy_vport_work_array(phba, vports); |
| 12362 | |
| 12363 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12364 | fc_remove_host(shost); |
| 12365 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 12366 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 12367 | lpfc_cleanup(vport); |
| 12368 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12369 | /* |
| 12370 | * Bring down the SLI Layer. This step disable all interrupts, |
| 12371 | * clears the rings, discards all mailbox commands, and resets |
| 12372 | * the HBA. |
| 12373 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12374 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 12375 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12376 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12377 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12378 | kthread_stop(phba->worker_thread); |
| 12379 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12380 | lpfc_sli_brdrestart(phba); |
| 12381 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 12382 | kfree(phba->vpi_bmask); |
| 12383 | kfree(phba->vpi_ids); |
| 12384 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12385 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12386 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12387 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12388 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12389 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12390 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12391 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12392 | /* Disable SR-IOV if enabled */ |
| 12393 | if (phba->cfg_sriov_nr_virtfn) |
| 12394 | pci_disable_sriov(pdev); |
| 12395 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12396 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12397 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12398 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12399 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12400 | |
| 12401 | /* |
| 12402 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 12403 | * corresponding pools here. |
| 12404 | */ |
| 12405 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12406 | lpfc_free_iocb_list(phba); |
| 12407 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12408 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12409 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12410 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 12411 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12412 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12413 | /* Free resources associated with SLI2 interface */ |
| 12414 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12415 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12416 | |
| 12417 | /* unmap adapter SLIM and Control Registers */ |
| 12418 | iounmap(phba->ctrl_regs_memmap_p); |
| 12419 | iounmap(phba->slim_memmap_p); |
| 12420 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12421 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12422 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 12423 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12424 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12425 | } |
| 12426 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12427 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12428 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12429 | * @pdev: pointer to PCI device |
| 12430 | * @msg: power management message |
| 12431 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12432 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12433 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 12434 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 12435 | * worker thread for the device, turning off device's interrupt and DMA, |
| 12436 | * and bring the device offline. Note that as the driver implements the |
| 12437 | * minimum PM requirements to a power-aware driver's PM support for the |
| 12438 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12439 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 12440 | * fully reinitialize its device during resume() method call, the driver will |
| 12441 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 12442 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12443 | * |
| 12444 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12445 | * 0 - driver suspended the device |
| 12446 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12447 | **/ |
| 12448 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12449 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12450 | { |
| 12451 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12452 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12453 | |
| 12454 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12455 | "0473 PCI device Power Management suspend.\n"); |
| 12456 | |
| 12457 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12458 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12459 | lpfc_offline(phba); |
| 12460 | kthread_stop(phba->worker_thread); |
| 12461 | |
| 12462 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12463 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12464 | |
| 12465 | /* Save device state to PCI config space */ |
| 12466 | pci_save_state(pdev); |
| 12467 | pci_set_power_state(pdev, PCI_D3hot); |
| 12468 | |
| 12469 | return 0; |
| 12470 | } |
| 12471 | |
| 12472 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12473 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12474 | * @pdev: pointer to PCI device |
| 12475 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12476 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12477 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12478 | * invokes this method, it restores the device's PCI config space state and |
| 12479 | * fully reinitializes the device and brings it online. Note that as the |
| 12480 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12481 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12482 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12483 | * driver will fully reinitialize its device during resume() method call, |
| 12484 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12485 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12486 | * |
| 12487 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12488 | * 0 - driver suspended the device |
| 12489 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12490 | **/ |
| 12491 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12492 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12493 | { |
| 12494 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12495 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12496 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12497 | int error; |
| 12498 | |
| 12499 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12500 | "0452 PCI device Power Management resume.\n"); |
| 12501 | |
| 12502 | /* Restore device state from PCI config space */ |
| 12503 | pci_set_power_state(pdev, PCI_D0); |
| 12504 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12505 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12506 | /* |
| 12507 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12508 | * device saved_state flag, need to save the restored state again. |
| 12509 | */ |
| 12510 | pci_save_state(pdev); |
| 12511 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12512 | if (pdev->is_busmaster) |
| 12513 | pci_set_master(pdev); |
| 12514 | |
| 12515 | /* Startup the kernel thread for this host adapter. */ |
| 12516 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12517 | "lpfc_worker_%d", phba->brd_no); |
| 12518 | if (IS_ERR(phba->worker_thread)) { |
| 12519 | error = PTR_ERR(phba->worker_thread); |
| 12520 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12521 | "0434 PM resume failed to start worker " |
| 12522 | "thread: error=x%x.\n", error); |
| 12523 | return error; |
| 12524 | } |
| 12525 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12526 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12527 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12528 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12530 | "0430 PM resume Failed to enable interrupt\n"); |
| 12531 | return -EIO; |
| 12532 | } else |
| 12533 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12534 | |
| 12535 | /* Restart HBA and bring it online */ |
| 12536 | lpfc_sli_brdrestart(phba); |
| 12537 | lpfc_online(phba); |
| 12538 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12539 | /* Log the current active interrupt mode */ |
| 12540 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12541 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12542 | return 0; |
| 12543 | } |
| 12544 | |
| 12545 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12546 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12547 | * @phba: pointer to lpfc hba data structure. |
| 12548 | * |
| 12549 | * 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] | 12550 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12551 | **/ |
| 12552 | static void |
| 12553 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12554 | { |
| 12555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12556 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12557 | |
| 12558 | /* |
| 12559 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12560 | * and let the SCSI mid-layer to retry them to recover. |
| 12561 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12562 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12563 | } |
| 12564 | |
| 12565 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12566 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12567 | * @phba: pointer to lpfc hba data structure. |
| 12568 | * |
| 12569 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12570 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12571 | * pending I/Os. |
| 12572 | **/ |
| 12573 | static void |
| 12574 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12575 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12576 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12577 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12578 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12579 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12580 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12581 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12582 | /* Block all SCSI devices' I/Os on the host */ |
| 12583 | lpfc_scsi_dev_block(phba); |
| 12584 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12585 | /* 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] | 12586 | lpfc_sli_flush_io_rings(phba); |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12587 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12588 | /* stop all timers */ |
| 12589 | lpfc_stop_hba_timers(phba); |
| 12590 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12591 | /* Disable interrupt and pci device */ |
| 12592 | lpfc_sli_disable_intr(phba); |
| 12593 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12594 | } |
| 12595 | |
| 12596 | /** |
| 12597 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12598 | * @phba: pointer to lpfc hba data structure. |
| 12599 | * |
| 12600 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12601 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12602 | * pending I/Os. |
| 12603 | **/ |
| 12604 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12605 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12606 | { |
| 12607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12608 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12609 | /* Block all SCSI devices' I/Os on the host */ |
| 12610 | lpfc_scsi_dev_block(phba); |
| 12611 | |
| 12612 | /* stop all timers */ |
| 12613 | lpfc_stop_hba_timers(phba); |
| 12614 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12615 | /* Clean up all driver's outstanding SCSI I/Os */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12616 | lpfc_sli_flush_io_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12617 | } |
| 12618 | |
| 12619 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12620 | * 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] | 12621 | * @pdev: pointer to PCI device. |
| 12622 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12623 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12624 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12625 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12626 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12627 | * When this function is invoked, it will need to stop all the I/Os and |
| 12628 | * interrupt(s) to the device. Once that is done, it will return |
| 12629 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12630 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12631 | * |
| 12632 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12633 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12634 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12635 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12636 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12637 | static pci_ers_result_t |
| 12638 | 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] | 12639 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12640 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12641 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12642 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12643 | switch (state) { |
| 12644 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12645 | /* Non-fatal error, prepare for recovery */ |
| 12646 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12647 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12648 | case pci_channel_io_frozen: |
| 12649 | /* Fatal error, prepare for slot reset */ |
| 12650 | lpfc_sli_prep_dev_for_reset(phba); |
| 12651 | return PCI_ERS_RESULT_NEED_RESET; |
| 12652 | case pci_channel_io_perm_failure: |
| 12653 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12654 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12655 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12656 | default: |
| 12657 | /* Unknown state, prepare and request slot reset */ |
| 12658 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12659 | "0472 Unknown PCI error state: x%x\n", state); |
| 12660 | lpfc_sli_prep_dev_for_reset(phba); |
| 12661 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12662 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12663 | } |
| 12664 | |
| 12665 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12666 | * 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] | 12667 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12668 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12669 | * This routine is called from the PCI subsystem for error handling to |
| 12670 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12671 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12672 | * During the PCI subsystem error recovery, after driver returns |
| 12673 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12674 | * recovery and then call this routine before calling the .resume method |
| 12675 | * to recover the device. This function will initialize the HBA device, |
| 12676 | * enable the interrupt, but it will just put the HBA to offline state |
| 12677 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12678 | * |
| 12679 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12680 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12681 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12682 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12683 | static pci_ers_result_t |
| 12684 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12685 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12686 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12687 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12688 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12689 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12690 | |
| 12691 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12692 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12693 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12694 | "PCI device after reset.\n"); |
| 12695 | return PCI_ERS_RESULT_DISCONNECT; |
| 12696 | } |
| 12697 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12698 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12699 | |
| 12700 | /* |
| 12701 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12702 | * device saved_state flag, need to save the restored state again. |
| 12703 | */ |
| 12704 | pci_save_state(pdev); |
| 12705 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12706 | if (pdev->is_busmaster) |
| 12707 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12708 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12709 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12710 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12711 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12712 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12713 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12714 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12715 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12717 | "0427 Cannot re-enable interrupt after " |
| 12718 | "slot reset.\n"); |
| 12719 | return PCI_ERS_RESULT_DISCONNECT; |
| 12720 | } else |
| 12721 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12722 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12723 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12724 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12725 | lpfc_offline(phba); |
| 12726 | lpfc_sli_brdrestart(phba); |
| 12727 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12728 | /* Log the current active interrupt mode */ |
| 12729 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12730 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12731 | return PCI_ERS_RESULT_RECOVERED; |
| 12732 | } |
| 12733 | |
| 12734 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12735 | * 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] | 12736 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12737 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12738 | * This routine is called from the PCI subsystem for error handling to device |
| 12739 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12740 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12741 | * error recovery. After this call, traffic can start to flow from this device |
| 12742 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12743 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12744 | static void |
| 12745 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12746 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12747 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12748 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12749 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12750 | /* 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] | 12751 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12752 | } |
| 12753 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12754 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12755 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12756 | * @phba: pointer to lpfc hba data structure. |
| 12757 | * |
| 12758 | * returns the number of ELS/CT IOCBs to reserve |
| 12759 | **/ |
| 12760 | int |
| 12761 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12762 | { |
| 12763 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12764 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12765 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12766 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12767 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12768 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12769 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12770 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12771 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12772 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12773 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12774 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12775 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12776 | else if (max_xri <= 2048) |
| 12777 | return 200; |
| 12778 | else |
| 12779 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12780 | } else |
| 12781 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12782 | } |
| 12783 | |
| 12784 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12785 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12786 | * @phba: pointer to lpfc hba data structure. |
| 12787 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12788 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12789 | **/ |
| 12790 | int |
| 12791 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12792 | { |
| 12793 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12794 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12795 | if (phba->nvmet_support) |
| 12796 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12797 | return max_xri; |
| 12798 | } |
| 12799 | |
| 12800 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12801 | static int |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12802 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12803 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12804 | const struct firmware *fw) |
| 12805 | { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12806 | int rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12807 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12808 | /* Three cases: (1) FW was not supported on the detected adapter. |
| 12809 | * (2) FW update has been locked out administratively. |
| 12810 | * (3) Some other error during FW update. |
| 12811 | * In each case, an unmaskable message is written to the console |
| 12812 | * for admin diagnosis. |
| 12813 | */ |
| 12814 | if (offset == ADD_STATUS_FW_NOT_SUPPORTED || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12815 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12816 | magic_number != MAGIC_NUMBER_G6) || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12817 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12818 | magic_number != MAGIC_NUMBER_G7)) { |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12820 | "3030 This firmware version is not supported on" |
| 12821 | " this HBA model. Device:%x Magic:%x Type:%x " |
| 12822 | "ID:%x Size %d %zd\n", |
| 12823 | phba->pcidev->device, magic_number, ftype, fid, |
| 12824 | fsize, fw->size); |
| 12825 | rc = -EINVAL; |
| 12826 | } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) { |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12828 | "3021 Firmware downloads have been prohibited " |
| 12829 | "by a system configuration setting on " |
| 12830 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12831 | "%zd\n", |
| 12832 | phba->pcidev->device, magic_number, ftype, fid, |
| 12833 | fsize, fw->size); |
| 12834 | rc = -EACCES; |
| 12835 | } else { |
| 12836 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12837 | "3022 FW Download failed. Add Status x%x " |
| 12838 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12839 | "%zd\n", |
| 12840 | offset, phba->pcidev->device, magic_number, |
| 12841 | ftype, fid, fsize, fw->size); |
| 12842 | rc = -EIO; |
| 12843 | } |
| 12844 | return rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12845 | } |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12846 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12847 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12848 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12849 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12850 | * @context: pointer to firmware image returned from request_firmware. |
| 12851 | * @ret: return value this routine provides to the caller. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12852 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12853 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12854 | static void |
| 12855 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12856 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12857 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12858 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12859 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12860 | struct list_head dma_buffer_list; |
| 12861 | int i, rc = 0; |
| 12862 | struct lpfc_dmabuf *dmabuf, *next; |
| 12863 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12864 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12865 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12866 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12867 | if (!fw) { |
| 12868 | rc = -ENXIO; |
| 12869 | goto out; |
| 12870 | } |
| 12871 | image = (struct lpfc_grp_hdr *)fw->data; |
| 12872 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12873 | magic_number = be32_to_cpu(image->magic_number); |
| 12874 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12875 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12876 | fsize = be32_to_cpu(image->size); |
| 12877 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12878 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12879 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12880 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12882 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12883 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12884 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12885 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 12886 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 12887 | GFP_KERNEL); |
| 12888 | if (!dmabuf) { |
| 12889 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12890 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12891 | } |
| 12892 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 12893 | SLI4_PAGE_SIZE, |
| 12894 | &dmabuf->phys, |
| 12895 | GFP_KERNEL); |
| 12896 | if (!dmabuf->virt) { |
| 12897 | kfree(dmabuf); |
| 12898 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12899 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12900 | } |
| 12901 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 12902 | } |
| 12903 | while (offset < fw->size) { |
| 12904 | temp_offset = offset; |
| 12905 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12906 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12907 | memcpy(dmabuf->virt, |
| 12908 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12909 | fw->size - temp_offset); |
| 12910 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12911 | break; |
| 12912 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12913 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 12914 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12915 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12916 | } |
| 12917 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 12918 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12919 | if (rc) { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12920 | rc = lpfc_log_write_firmware_error(phba, offset, |
| 12921 | magic_number, |
| 12922 | ftype, |
| 12923 | fid, |
| 12924 | fsize, |
| 12925 | fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12926 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12927 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12928 | } |
| 12929 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12930 | } else |
| 12931 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12932 | "3029 Skipped Firmware update, Current " |
| 12933 | "Version:%s New Version:%s\n", |
| 12934 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12935 | |
| 12936 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12937 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 12938 | list_del(&dmabuf->list); |
| 12939 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 12940 | dmabuf->virt, dmabuf->phys); |
| 12941 | kfree(dmabuf); |
| 12942 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12943 | release_firmware(fw); |
| 12944 | out: |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12945 | if (rc < 0) |
| 12946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12947 | "3062 Firmware update error, status %d.\n", rc); |
| 12948 | else |
| 12949 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12950 | "3024 Firmware update success: size %d.\n", rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12951 | } |
| 12952 | |
| 12953 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12954 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 12955 | * @phba: pointer to lpfc hba data structure. |
| 12956 | * |
| 12957 | * This routine is called to perform Linux generic firmware upgrade on device |
| 12958 | * that supports such feature. |
| 12959 | **/ |
| 12960 | int |
| 12961 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 12962 | { |
| 12963 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 12964 | int ret; |
| 12965 | const struct firmware *fw; |
| 12966 | |
| 12967 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12968 | 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] | 12969 | LPFC_SLI_INTF_IF_TYPE_2) |
| 12970 | return -EPERM; |
| 12971 | |
| 12972 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 12973 | |
| 12974 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 12975 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 12976 | file_name, &phba->pcidev->dev, |
| 12977 | GFP_KERNEL, (void *)phba, |
| 12978 | lpfc_write_firmware); |
| 12979 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 12980 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 12981 | if (!ret) |
| 12982 | lpfc_write_firmware(fw, (void *)phba); |
| 12983 | } else { |
| 12984 | ret = -EINVAL; |
| 12985 | } |
| 12986 | |
| 12987 | return ret; |
| 12988 | } |
| 12989 | |
| 12990 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12991 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 12992 | * @pdev: pointer to PCI device |
| 12993 | * @pid: pointer to PCI device identifier |
| 12994 | * |
| 12995 | * This routine is called from the kernel's PCI subsystem to device with |
| 12996 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12997 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12998 | * information of the device and driver to see if the driver state that it |
| 12999 | * can support this kind of device. If the match is successful, the driver |
| 13000 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 13001 | * it does all the initialization that it needs to do to handle the HBA |
| 13002 | * properly. |
| 13003 | * |
| 13004 | * Return code |
| 13005 | * 0 - driver can claim the device |
| 13006 | * negative value - driver can not claim the device |
| 13007 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13008 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13009 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13010 | { |
| 13011 | struct lpfc_hba *phba; |
| 13012 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13013 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13014 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13015 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13016 | |
| 13017 | /* Allocate memory for HBA structure */ |
| 13018 | phba = lpfc_hba_alloc(pdev); |
| 13019 | if (!phba) |
| 13020 | return -ENOMEM; |
| 13021 | |
| 13022 | /* Perform generic PCI device enabling operation */ |
| 13023 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13024 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13025 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13026 | |
| 13027 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 13028 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 13029 | if (error) |
| 13030 | goto out_disable_pci_dev; |
| 13031 | |
| 13032 | /* Set up SLI-4 specific device PCI memory space */ |
| 13033 | error = lpfc_sli4_pci_mem_setup(phba); |
| 13034 | if (error) { |
| 13035 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13036 | "1410 Failed to set up pci memory space.\n"); |
| 13037 | goto out_disable_pci_dev; |
| 13038 | } |
| 13039 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13040 | /* Set up SLI-4 Specific device driver resources */ |
| 13041 | error = lpfc_sli4_driver_resource_setup(phba); |
| 13042 | if (error) { |
| 13043 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13044 | "1412 Failed to set up driver resource.\n"); |
| 13045 | goto out_unset_pci_mem_s4; |
| 13046 | } |
| 13047 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13048 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 13049 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13050 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13051 | /* Set up common device driver resources */ |
| 13052 | error = lpfc_setup_driver_resource_phase2(phba); |
| 13053 | if (error) { |
| 13054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13055 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13056 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13057 | } |
| 13058 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13059 | /* Get the default values for Model Name and Description */ |
| 13060 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 13061 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13062 | /* Now, trying to enable interrupt and bring up the device */ |
| 13063 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13064 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13065 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13066 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13067 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13068 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13069 | /* Init cpu_map array */ |
| 13070 | lpfc_cpu_map_array_init(phba); |
| 13071 | |
| 13072 | /* Init hba_eq_hdl array */ |
| 13073 | lpfc_hba_eq_hdl_array_init(phba); |
| 13074 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13075 | /* Configure and enable interrupt */ |
| 13076 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 13077 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13079 | "0426 Failed to enable interrupt.\n"); |
| 13080 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13081 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13082 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13083 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13084 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13085 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13086 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13087 | if (phba->nvmet_support) |
| 13088 | phba->cfg_nvmet_mrq = 1; |
| 13089 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13090 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13091 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13092 | |
| 13093 | /* Create SCSI host to the physical port */ |
| 13094 | error = lpfc_create_shost(phba); |
| 13095 | if (error) { |
| 13096 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13097 | "1415 Failed to create scsi host.\n"); |
| 13098 | goto out_disable_intr; |
| 13099 | } |
| 13100 | vport = phba->pport; |
| 13101 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 13102 | |
| 13103 | /* Configure sysfs attributes */ |
| 13104 | error = lpfc_alloc_sysfs_attr(vport); |
| 13105 | if (error) { |
| 13106 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13107 | "1416 Failed to allocate sysfs attr\n"); |
| 13108 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13109 | } |
| 13110 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13111 | /* Set up SLI-4 HBA */ |
| 13112 | if (lpfc_sli4_hba_setup(phba)) { |
| 13113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13114 | "1421 Failed to set up hba\n"); |
| 13115 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13116 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13117 | } |
| 13118 | |
| 13119 | /* Log the current active interrupt mode */ |
| 13120 | phba->intr_mode = intr_mode; |
| 13121 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13122 | |
| 13123 | /* Perform post initialization setup */ |
| 13124 | lpfc_post_init_setup(phba); |
| 13125 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13126 | /* NVME support in FW earlier in the driver load corrects the |
| 13127 | * FC4 type making a check for nvme_support unnecessary. |
| 13128 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13129 | if (phba->nvmet_support == 0) { |
| 13130 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13131 | /* Create NVME binding with nvme_fc_transport. This |
| 13132 | * ensures the vport is initialized. If the localport |
| 13133 | * create fails, it should not unload the driver to |
| 13134 | * support field issues. |
| 13135 | */ |
| 13136 | error = lpfc_nvme_create_localport(vport); |
| 13137 | if (error) { |
| 13138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13139 | "6004 NVME registration " |
| 13140 | "failed, error x%x\n", |
| 13141 | error); |
| 13142 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13143 | } |
| 13144 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13145 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13146 | /* check for firmware upgrade or downgrade */ |
| 13147 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 13148 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13149 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 13150 | /* Check if there are static vports to be created. */ |
| 13151 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13152 | |
| 13153 | /* Enable RAS FW log support */ |
| 13154 | lpfc_sli4_ras_setup(phba); |
| 13155 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13156 | INIT_LIST_HEAD(&phba->poll_list); |
| 13157 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp); |
| 13158 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13159 | return 0; |
| 13160 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13161 | out_free_sysfs_attr: |
| 13162 | lpfc_free_sysfs_attr(vport); |
| 13163 | out_destroy_shost: |
| 13164 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13165 | out_disable_intr: |
| 13166 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13167 | out_unset_driver_resource: |
| 13168 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13169 | out_unset_driver_resource_s4: |
| 13170 | lpfc_sli4_driver_resource_unset(phba); |
| 13171 | out_unset_pci_mem_s4: |
| 13172 | lpfc_sli4_pci_mem_unset(phba); |
| 13173 | out_disable_pci_dev: |
| 13174 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13175 | if (shost) |
| 13176 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13177 | out_free_phba: |
| 13178 | lpfc_hba_free(phba); |
| 13179 | return error; |
| 13180 | } |
| 13181 | |
| 13182 | /** |
| 13183 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 13184 | * @pdev: pointer to PCI device |
| 13185 | * |
| 13186 | * This routine is called from the kernel's PCI subsystem to device with |
| 13187 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13188 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 13189 | * device to be removed from the PCI subsystem properly. |
| 13190 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13191 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13192 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 13193 | { |
| 13194 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13195 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 13196 | struct lpfc_vport **vports; |
| 13197 | struct lpfc_hba *phba = vport->phba; |
| 13198 | int i; |
| 13199 | |
| 13200 | /* Mark the device unloading flag */ |
| 13201 | spin_lock_irq(&phba->hbalock); |
| 13202 | vport->load_flag |= FC_UNLOADING; |
| 13203 | spin_unlock_irq(&phba->hbalock); |
| 13204 | |
| 13205 | /* Free the HBA sysfs attributes */ |
| 13206 | lpfc_free_sysfs_attr(vport); |
| 13207 | |
| 13208 | /* Release all the vports against this physical port */ |
| 13209 | vports = lpfc_create_vport_work_array(phba); |
| 13210 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13211 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 13212 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 13213 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13214 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13215 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13216 | lpfc_destroy_vport_work_array(phba, vports); |
| 13217 | |
| 13218 | /* Remove FC host and then SCSI host with the physical port */ |
| 13219 | fc_remove_host(shost); |
| 13220 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13221 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13222 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 13223 | * localports are destroyed after to cleanup all transport memory. |
| 13224 | */ |
| 13225 | lpfc_cleanup(vport); |
| 13226 | lpfc_nvmet_destroy_targetport(phba); |
| 13227 | lpfc_nvme_destroy_localport(vport); |
| 13228 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 13229 | /* De-allocate multi-XRI pools */ |
| 13230 | if (phba->cfg_xri_rebalancing) |
| 13231 | lpfc_destroy_multixri_pools(phba); |
| 13232 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 13233 | /* |
| 13234 | * Bring down the SLI Layer. This step disables all interrupts, |
| 13235 | * clears the rings, discards all mailbox commands, and resets |
| 13236 | * the HBA FCoE function. |
| 13237 | */ |
| 13238 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13239 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 13240 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13241 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13242 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13243 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13244 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 13245 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13246 | * buffers are released to their corresponding pools here. |
| 13247 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13248 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13249 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13250 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13251 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 13252 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13253 | lpfc_sli4_driver_resource_unset(phba); |
| 13254 | |
| 13255 | /* Unmap adapter Control and Doorbell registers */ |
| 13256 | lpfc_sli4_pci_mem_unset(phba); |
| 13257 | |
| 13258 | /* Release PCI resources and disable device's PCI function */ |
| 13259 | scsi_host_put(shost); |
| 13260 | lpfc_disable_pci_dev(phba); |
| 13261 | |
| 13262 | /* Finally, free the driver's device data structure */ |
| 13263 | lpfc_hba_free(phba); |
| 13264 | |
| 13265 | return; |
| 13266 | } |
| 13267 | |
| 13268 | /** |
| 13269 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 13270 | * @pdev: pointer to PCI device |
| 13271 | * @msg: power management message |
| 13272 | * |
| 13273 | * This routine is called from the kernel's PCI subsystem to support system |
| 13274 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 13275 | * this method, it quiesces the device by stopping the driver's worker |
| 13276 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 13277 | * the device offline. Note that as the driver implements the minimum PM |
| 13278 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 13279 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 13280 | * method call will be treated as SUSPEND and the driver will fully |
| 13281 | * reinitialize its device during resume() method call, the driver will set |
| 13282 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 13283 | * according to the @msg provided by the PM. |
| 13284 | * |
| 13285 | * Return code |
| 13286 | * 0 - driver suspended the device |
| 13287 | * Error otherwise |
| 13288 | **/ |
| 13289 | static int |
| 13290 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 13291 | { |
| 13292 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13293 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13294 | |
| 13295 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13296 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13297 | |
| 13298 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13299 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13300 | lpfc_offline(phba); |
| 13301 | kthread_stop(phba->worker_thread); |
| 13302 | |
| 13303 | /* Disable interrupt from device */ |
| 13304 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13305 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13306 | |
| 13307 | /* Save device state to PCI config space */ |
| 13308 | pci_save_state(pdev); |
| 13309 | pci_set_power_state(pdev, PCI_D3hot); |
| 13310 | |
| 13311 | return 0; |
| 13312 | } |
| 13313 | |
| 13314 | /** |
| 13315 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 13316 | * @pdev: pointer to PCI device |
| 13317 | * |
| 13318 | * This routine is called from the kernel's PCI subsystem to support system |
| 13319 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 13320 | * this method, it restores the device's PCI config space state and fully |
| 13321 | * reinitializes the device and brings it online. Note that as the driver |
| 13322 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 13323 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 13324 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 13325 | * will fully reinitialize its device during resume() method call, the device |
| 13326 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 13327 | * state. |
| 13328 | * |
| 13329 | * Return code |
| 13330 | * 0 - driver suspended the device |
| 13331 | * Error otherwise |
| 13332 | **/ |
| 13333 | static int |
| 13334 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 13335 | { |
| 13336 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13337 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13338 | uint32_t intr_mode; |
| 13339 | int error; |
| 13340 | |
| 13341 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13342 | "0292 PCI device Power Management resume.\n"); |
| 13343 | |
| 13344 | /* Restore device state from PCI config space */ |
| 13345 | pci_set_power_state(pdev, PCI_D0); |
| 13346 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 13347 | |
| 13348 | /* |
| 13349 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13350 | * device saved_state flag, need to save the restored state again. |
| 13351 | */ |
| 13352 | pci_save_state(pdev); |
| 13353 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13354 | if (pdev->is_busmaster) |
| 13355 | pci_set_master(pdev); |
| 13356 | |
| 13357 | /* Startup the kernel thread for this host adapter. */ |
| 13358 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 13359 | "lpfc_worker_%d", phba->brd_no); |
| 13360 | if (IS_ERR(phba->worker_thread)) { |
| 13361 | error = PTR_ERR(phba->worker_thread); |
| 13362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13363 | "0293 PM resume failed to start worker " |
| 13364 | "thread: error=x%x.\n", error); |
| 13365 | return error; |
| 13366 | } |
| 13367 | |
| 13368 | /* Configure and enable interrupt */ |
| 13369 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13370 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13372 | "0294 PM resume Failed to enable interrupt\n"); |
| 13373 | return -EIO; |
| 13374 | } else |
| 13375 | phba->intr_mode = intr_mode; |
| 13376 | |
| 13377 | /* Restart HBA and bring it online */ |
| 13378 | lpfc_sli_brdrestart(phba); |
| 13379 | lpfc_online(phba); |
| 13380 | |
| 13381 | /* Log the current active interrupt mode */ |
| 13382 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13383 | |
| 13384 | return 0; |
| 13385 | } |
| 13386 | |
| 13387 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13388 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 13389 | * @phba: pointer to lpfc hba data structure. |
| 13390 | * |
| 13391 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 13392 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 13393 | **/ |
| 13394 | static void |
| 13395 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 13396 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13397 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13398 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 13399 | /* |
| 13400 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 13401 | * and let the SCSI mid-layer to retry them to recover. |
| 13402 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 13403 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13404 | } |
| 13405 | |
| 13406 | /** |
| 13407 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 13408 | * @phba: pointer to lpfc hba data structure. |
| 13409 | * |
| 13410 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 13411 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 13412 | * pending I/Os. |
| 13413 | **/ |
| 13414 | static void |
| 13415 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 13416 | { |
| 13417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13418 | "2826 PCI channel disable preparing for reset\n"); |
| 13419 | |
| 13420 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13421 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13422 | |
| 13423 | /* Block all SCSI devices' I/Os on the host */ |
| 13424 | lpfc_scsi_dev_block(phba); |
| 13425 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13426 | /* Flush all driver's outstanding I/Os as we are to reset */ |
| 13427 | lpfc_sli_flush_io_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 13428 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13429 | /* stop all timers */ |
| 13430 | lpfc_stop_hba_timers(phba); |
| 13431 | |
| 13432 | /* Disable interrupt and pci device */ |
| 13433 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13434 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13435 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13436 | } |
| 13437 | |
| 13438 | /** |
| 13439 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 13440 | * @phba: pointer to lpfc hba data structure. |
| 13441 | * |
| 13442 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 13443 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 13444 | * pending I/Os. |
| 13445 | **/ |
| 13446 | static void |
| 13447 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 13448 | { |
| 13449 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13450 | "2827 PCI channel permanent disable for failure\n"); |
| 13451 | |
| 13452 | /* Block all SCSI devices' I/Os on the host */ |
| 13453 | lpfc_scsi_dev_block(phba); |
| 13454 | |
| 13455 | /* stop all timers */ |
| 13456 | lpfc_stop_hba_timers(phba); |
| 13457 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13458 | /* Clean up all driver's outstanding I/Os */ |
| 13459 | lpfc_sli_flush_io_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13460 | } |
| 13461 | |
| 13462 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13463 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 13464 | * @pdev: pointer to PCI device. |
| 13465 | * @state: the current PCI connection state. |
| 13466 | * |
| 13467 | * This routine is called from the PCI subsystem for error handling to device |
| 13468 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 13469 | * after a PCI bus error affecting this device has been detected. When this |
| 13470 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 13471 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 13472 | * for the PCI subsystem to perform proper recovery as desired. |
| 13473 | * |
| 13474 | * Return codes |
| 13475 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13476 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13477 | **/ |
| 13478 | static pci_ers_result_t |
| 13479 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 13480 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13481 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13482 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13483 | |
| 13484 | switch (state) { |
| 13485 | case pci_channel_io_normal: |
| 13486 | /* Non-fatal error, prepare for recovery */ |
| 13487 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13488 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13489 | case pci_channel_io_frozen: |
| 13490 | /* Fatal error, prepare for slot reset */ |
| 13491 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13492 | return PCI_ERS_RESULT_NEED_RESET; |
| 13493 | case pci_channel_io_perm_failure: |
| 13494 | /* Permanent failure, prepare for device down */ |
| 13495 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13496 | return PCI_ERS_RESULT_DISCONNECT; |
| 13497 | default: |
| 13498 | /* Unknown state, prepare and request slot reset */ |
| 13499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13500 | "2825 Unknown PCI error state: x%x\n", state); |
| 13501 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13502 | return PCI_ERS_RESULT_NEED_RESET; |
| 13503 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13504 | } |
| 13505 | |
| 13506 | /** |
| 13507 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13508 | * @pdev: pointer to PCI device. |
| 13509 | * |
| 13510 | * This routine is called from the PCI subsystem for error handling to device |
| 13511 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13512 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13513 | * PCI subsystem error recovery, after the driver returns |
| 13514 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13515 | * recovery and then call this routine before calling the .resume method to |
| 13516 | * recover the device. This function will initialize the HBA device, enable |
| 13517 | * the interrupt, but it will just put the HBA to offline state without |
| 13518 | * passing any I/O traffic. |
| 13519 | * |
| 13520 | * Return codes |
| 13521 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13522 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13523 | */ |
| 13524 | static pci_ers_result_t |
| 13525 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13526 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13527 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13528 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13529 | struct lpfc_sli *psli = &phba->sli; |
| 13530 | uint32_t intr_mode; |
| 13531 | |
| 13532 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13533 | if (pci_enable_device_mem(pdev)) { |
| 13534 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13535 | "PCI device after reset.\n"); |
| 13536 | return PCI_ERS_RESULT_DISCONNECT; |
| 13537 | } |
| 13538 | |
| 13539 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13540 | |
| 13541 | /* |
| 13542 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13543 | * device saved_state flag, need to save the restored state again. |
| 13544 | */ |
| 13545 | pci_save_state(pdev); |
| 13546 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13547 | if (pdev->is_busmaster) |
| 13548 | pci_set_master(pdev); |
| 13549 | |
| 13550 | spin_lock_irq(&phba->hbalock); |
| 13551 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13552 | spin_unlock_irq(&phba->hbalock); |
| 13553 | |
| 13554 | /* Configure and enable interrupt */ |
| 13555 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13556 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13558 | "2824 Cannot re-enable interrupt after " |
| 13559 | "slot reset.\n"); |
| 13560 | return PCI_ERS_RESULT_DISCONNECT; |
| 13561 | } else |
| 13562 | phba->intr_mode = intr_mode; |
| 13563 | |
| 13564 | /* Log the current active interrupt mode */ |
| 13565 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13566 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13567 | return PCI_ERS_RESULT_RECOVERED; |
| 13568 | } |
| 13569 | |
| 13570 | /** |
| 13571 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13572 | * @pdev: pointer to PCI device |
| 13573 | * |
| 13574 | * This routine is called from the PCI subsystem for error handling to device |
| 13575 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13576 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13577 | * error recovery. After this call, traffic can start to flow from this device |
| 13578 | * again. |
| 13579 | **/ |
| 13580 | static void |
| 13581 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13582 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13583 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13584 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13585 | |
| 13586 | /* |
| 13587 | * In case of slot reset, as function reset is performed through |
| 13588 | * mailbox command which needs DMA to be enabled, this operation |
| 13589 | * has to be moved to the io resume phase. Taking device offline |
| 13590 | * will perform the necessary cleanup. |
| 13591 | */ |
| 13592 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13593 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13594 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13595 | lpfc_offline(phba); |
| 13596 | lpfc_sli_brdrestart(phba); |
| 13597 | /* Bring the device back online */ |
| 13598 | lpfc_online(phba); |
| 13599 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13600 | } |
| 13601 | |
| 13602 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13603 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13604 | * @pdev: pointer to PCI device |
| 13605 | * @pid: pointer to PCI device identifier |
| 13606 | * |
| 13607 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13608 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13609 | * at PCI device-specific information of the device and driver to see if the |
| 13610 | * driver state that it can support this kind of device. If the match is |
| 13611 | * successful, the driver core invokes this routine. This routine dispatches |
| 13612 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13613 | * do all the initialization that it needs to do to handle the HBA device |
| 13614 | * properly. |
| 13615 | * |
| 13616 | * Return code |
| 13617 | * 0 - driver can claim the device |
| 13618 | * negative value - driver can not claim the device |
| 13619 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13620 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13621 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13622 | { |
| 13623 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13624 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13625 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13626 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13627 | return -ENODEV; |
| 13628 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13629 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13630 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13631 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13632 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13633 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13634 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13635 | return rc; |
| 13636 | } |
| 13637 | |
| 13638 | /** |
| 13639 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13640 | * @pdev: pointer to PCI device |
| 13641 | * |
| 13642 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13643 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13644 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13645 | * remove routine, which will perform all the necessary cleanup for the |
| 13646 | * device to be removed from the PCI subsystem properly. |
| 13647 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13648 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13649 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13650 | { |
| 13651 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13652 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13653 | |
| 13654 | switch (phba->pci_dev_grp) { |
| 13655 | case LPFC_PCI_DEV_LP: |
| 13656 | lpfc_pci_remove_one_s3(pdev); |
| 13657 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13658 | case LPFC_PCI_DEV_OC: |
| 13659 | lpfc_pci_remove_one_s4(pdev); |
| 13660 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13661 | default: |
| 13662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13663 | "1424 Invalid PCI device group: 0x%x\n", |
| 13664 | phba->pci_dev_grp); |
| 13665 | break; |
| 13666 | } |
| 13667 | return; |
| 13668 | } |
| 13669 | |
| 13670 | /** |
| 13671 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 13672 | * @pdev: pointer to PCI device |
| 13673 | * @msg: power management message |
| 13674 | * |
| 13675 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13676 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13677 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13678 | * suspend the device. |
| 13679 | * |
| 13680 | * Return code |
| 13681 | * 0 - driver suspended the device |
| 13682 | * Error otherwise |
| 13683 | **/ |
| 13684 | static int |
| 13685 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 13686 | { |
| 13687 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13688 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13689 | int rc = -ENODEV; |
| 13690 | |
| 13691 | switch (phba->pci_dev_grp) { |
| 13692 | case LPFC_PCI_DEV_LP: |
| 13693 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 13694 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13695 | case LPFC_PCI_DEV_OC: |
| 13696 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 13697 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13698 | default: |
| 13699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13700 | "1425 Invalid PCI device group: 0x%x\n", |
| 13701 | phba->pci_dev_grp); |
| 13702 | break; |
| 13703 | } |
| 13704 | return rc; |
| 13705 | } |
| 13706 | |
| 13707 | /** |
| 13708 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 13709 | * @pdev: pointer to PCI device |
| 13710 | * |
| 13711 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13712 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13713 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13714 | * resume the device. |
| 13715 | * |
| 13716 | * Return code |
| 13717 | * 0 - driver suspended the device |
| 13718 | * Error otherwise |
| 13719 | **/ |
| 13720 | static int |
| 13721 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 13722 | { |
| 13723 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13724 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13725 | int rc = -ENODEV; |
| 13726 | |
| 13727 | switch (phba->pci_dev_grp) { |
| 13728 | case LPFC_PCI_DEV_LP: |
| 13729 | rc = lpfc_pci_resume_one_s3(pdev); |
| 13730 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13731 | case LPFC_PCI_DEV_OC: |
| 13732 | rc = lpfc_pci_resume_one_s4(pdev); |
| 13733 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13734 | default: |
| 13735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13736 | "1426 Invalid PCI device group: 0x%x\n", |
| 13737 | phba->pci_dev_grp); |
| 13738 | break; |
| 13739 | } |
| 13740 | return rc; |
| 13741 | } |
| 13742 | |
| 13743 | /** |
| 13744 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13745 | * @pdev: pointer to PCI device. |
| 13746 | * @state: the current PCI connection state. |
| 13747 | * |
| 13748 | * This routine is registered to the PCI subsystem for error handling. This |
| 13749 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13750 | * this device has been detected. When this routine is invoked, it dispatches |
| 13751 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13752 | * routine, which will perform the proper error detected operation. |
| 13753 | * |
| 13754 | * Return codes |
| 13755 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13756 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13757 | **/ |
| 13758 | static pci_ers_result_t |
| 13759 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13760 | { |
| 13761 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13762 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13763 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13764 | |
| 13765 | switch (phba->pci_dev_grp) { |
| 13766 | case LPFC_PCI_DEV_LP: |
| 13767 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13768 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13769 | case LPFC_PCI_DEV_OC: |
| 13770 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13771 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13772 | default: |
| 13773 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13774 | "1427 Invalid PCI device group: 0x%x\n", |
| 13775 | phba->pci_dev_grp); |
| 13776 | break; |
| 13777 | } |
| 13778 | return rc; |
| 13779 | } |
| 13780 | |
| 13781 | /** |
| 13782 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13783 | * @pdev: pointer to PCI device. |
| 13784 | * |
| 13785 | * This routine is registered to the PCI subsystem for error handling. This |
| 13786 | * function is called after PCI bus has been reset to restart the PCI card |
| 13787 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13788 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13789 | * routine, which will perform the proper device reset. |
| 13790 | * |
| 13791 | * Return codes |
| 13792 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13793 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13794 | **/ |
| 13795 | static pci_ers_result_t |
| 13796 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13797 | { |
| 13798 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13799 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13800 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13801 | |
| 13802 | switch (phba->pci_dev_grp) { |
| 13803 | case LPFC_PCI_DEV_LP: |
| 13804 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13805 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13806 | case LPFC_PCI_DEV_OC: |
| 13807 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13808 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13809 | default: |
| 13810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13811 | "1428 Invalid PCI device group: 0x%x\n", |
| 13812 | phba->pci_dev_grp); |
| 13813 | break; |
| 13814 | } |
| 13815 | return rc; |
| 13816 | } |
| 13817 | |
| 13818 | /** |
| 13819 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13820 | * @pdev: pointer to PCI device |
| 13821 | * |
| 13822 | * This routine is registered to the PCI subsystem for error handling. It |
| 13823 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13824 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13825 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13826 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13827 | **/ |
| 13828 | static void |
| 13829 | lpfc_io_resume(struct pci_dev *pdev) |
| 13830 | { |
| 13831 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13832 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13833 | |
| 13834 | switch (phba->pci_dev_grp) { |
| 13835 | case LPFC_PCI_DEV_LP: |
| 13836 | lpfc_io_resume_s3(pdev); |
| 13837 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13838 | case LPFC_PCI_DEV_OC: |
| 13839 | lpfc_io_resume_s4(pdev); |
| 13840 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13841 | default: |
| 13842 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13843 | "1429 Invalid PCI device group: 0x%x\n", |
| 13844 | phba->pci_dev_grp); |
| 13845 | break; |
| 13846 | } |
| 13847 | return; |
| 13848 | } |
| 13849 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13850 | /** |
| 13851 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13852 | * @phba: pointer to lpfc hba data structure. |
| 13853 | * |
| 13854 | * This routine checks to see if OAS is supported for this adapter. If |
| 13855 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13856 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13857 | * is destroyed. |
| 13858 | * |
| 13859 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13860 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13861 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13862 | { |
| 13863 | |
| 13864 | if (!phba->cfg_EnableXLane) |
| 13865 | return; |
| 13866 | |
| 13867 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13868 | phba->cfg_fof = 1; |
| 13869 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13870 | phba->cfg_fof = 0; |
Saurav Girepunje | c3e5aac | 2019-10-27 01:17:17 +0530 | [diff] [blame] | 13871 | mempool_destroy(phba->device_data_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13872 | phba->device_data_mem_pool = NULL; |
| 13873 | } |
| 13874 | |
| 13875 | return; |
| 13876 | } |
| 13877 | |
| 13878 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13879 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13880 | * @phba: pointer to lpfc hba data structure. |
| 13881 | * |
| 13882 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13883 | * function through which RAS support enablement is to be done. |
| 13884 | **/ |
| 13885 | void |
| 13886 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 13887 | { |
| 13888 | switch (phba->pcidev->device) { |
| 13889 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 13890 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 13891 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 13892 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 13893 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13894 | phba->ras_fwlog.ras_enabled = true; |
| 13895 | else |
| 13896 | phba->ras_fwlog.ras_enabled = false; |
| 13897 | break; |
| 13898 | default: |
| 13899 | phba->ras_fwlog.ras_hwsupport = false; |
| 13900 | } |
| 13901 | } |
| 13902 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13903 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13904 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 13905 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 13906 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 13907 | .error_detected = lpfc_io_error_detected, |
| 13908 | .slot_reset = lpfc_io_slot_reset, |
| 13909 | .resume = lpfc_io_resume, |
| 13910 | }; |
| 13911 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13912 | static struct pci_driver lpfc_driver = { |
| 13913 | .name = LPFC_DRIVER_NAME, |
| 13914 | .id_table = lpfc_id_table, |
| 13915 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13916 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 13917 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 13918 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13919 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13920 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13921 | }; |
| 13922 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13923 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 13924 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13925 | }; |
| 13926 | |
| 13927 | static struct miscdevice lpfc_mgmt_dev = { |
| 13928 | .minor = MISC_DYNAMIC_MINOR, |
| 13929 | .name = "lpfcmgmt", |
| 13930 | .fops = &lpfc_mgmt_fop, |
| 13931 | }; |
| 13932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13934 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13935 | * |
| 13936 | * This routine is to be invoked when the lpfc module is loaded into the |
| 13937 | * kernel. The special kernel macro module_init() is used to indicate the |
| 13938 | * role of this routine to the kernel as lpfc module entry point. |
| 13939 | * |
| 13940 | * Return codes |
| 13941 | * 0 - successful |
| 13942 | * -ENOMEM - FC attach transport failed |
| 13943 | * all others - failed |
| 13944 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13945 | static int __init |
| 13946 | lpfc_init(void) |
| 13947 | { |
| 13948 | int error = 0; |
| 13949 | |
| 13950 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 13951 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13952 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13953 | error = misc_register(&lpfc_mgmt_dev); |
| 13954 | if (error) |
| 13955 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 13956 | "misc_register returned with status %d", error); |
| 13957 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13958 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 13959 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13960 | lpfc_transport_template = |
| 13961 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13962 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13963 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13964 | lpfc_vport_transport_template = |
| 13965 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 13966 | if (lpfc_vport_transport_template == NULL) { |
| 13967 | fc_release_transport(lpfc_transport_template); |
| 13968 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13969 | } |
James Smart | 5fd1108 | 2018-03-05 12:04:04 -0800 | [diff] [blame] | 13970 | lpfc_nvme_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 13971 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13972 | |
| 13973 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 13974 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13975 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13976 | error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, |
| 13977 | "lpfc/sli4:online", |
| 13978 | lpfc_cpu_online, lpfc_cpu_offline); |
| 13979 | if (error < 0) |
| 13980 | goto cpuhp_failure; |
| 13981 | lpfc_cpuhp_state = error; |
| 13982 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13983 | error = pci_register_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13984 | if (error) |
| 13985 | goto unwind; |
| 13986 | |
| 13987 | return error; |
| 13988 | |
| 13989 | unwind: |
| 13990 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| 13991 | cpuhp_failure: |
| 13992 | fc_release_transport(lpfc_transport_template); |
| 13993 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13994 | |
| 13995 | return error; |
| 13996 | } |
| 13997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13999 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14000 | * |
| 14001 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 14002 | * The special kernel macro module_exit() is used to indicate the role of |
| 14003 | * this routine to the kernel as lpfc module exit point. |
| 14004 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14005 | static void __exit |
| 14006 | lpfc_exit(void) |
| 14007 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14008 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14009 | pci_unregister_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14010 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14011 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14012 | fc_release_transport(lpfc_vport_transport_template); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 14013 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14014 | } |
| 14015 | |
| 14016 | module_init(lpfc_init); |
| 14017 | module_exit(lpfc_exit); |
| 14018 | MODULE_LICENSE("GPL"); |
| 14019 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 14020 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14021 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |