| 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> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 43 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include <scsi/scsi_device.h> |
| 45 | #include <scsi/scsi_host.h> |
| 46 | #include <scsi/scsi_transport_fc.h> |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 47 | #include <scsi/scsi_tcq.h> |
| 48 | #include <scsi/fc/fc_fs.h> |
| 49 | |
| 50 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 51 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 52 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | #include "lpfc_hw.h" |
| 54 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 55 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 56 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 59 | #include "lpfc_scsi.h" |
| 60 | #include "lpfc_nvme.h" |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 61 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 62 | #include "lpfc_logmsg.h" |
| 63 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 64 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 66 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 67 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 68 | char *_dump_buf_data; |
| 69 | unsigned long _dump_buf_data_order; |
| 70 | char *_dump_buf_dif; |
| 71 | unsigned long _dump_buf_dif_order; |
| 72 | spinlock_t _dump_buf_lock; |
| 73 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 74 | /* Used when mapping IRQ vectors in a driver centric manner */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 75 | uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 76 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 77 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 78 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 79 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 80 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 81 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 82 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 83 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 84 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 85 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 86 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 87 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 88 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 89 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 90 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 91 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 92 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 93 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 94 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 95 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 96 | static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 97 | |
| 98 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 99 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 101 | #define LPFC_NVMET_BUF_POST 254 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 104 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 105 | * @phba: pointer to lpfc hba data structure. |
| 106 | * |
| 107 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 108 | * mailbox command. It retrieves the revision information from the HBA and |
| 109 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 110 | * configuration of the HBA. |
| 111 | * |
| 112 | * Return codes: |
| 113 | * 0 - success. |
| 114 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 115 | * Any other value - indicates an error. |
| 116 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 118 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | { |
| 120 | lpfc_vpd_t *vp = &phba->vpd; |
| 121 | int i = 0, rc; |
| 122 | LPFC_MBOXQ_t *pmb; |
| 123 | MAILBOX_t *mb; |
| 124 | char *lpfc_vpd_data = NULL; |
| 125 | uint16_t offset = 0; |
| 126 | static char licensed[56] = |
| 127 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 128 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 129 | |
| 130 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 131 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 132 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 133 | return -ENOMEM; |
| 134 | } |
| 135 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 136 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 137 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 138 | |
| 139 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 140 | if (init_key) { |
| 141 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 142 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 143 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 144 | *ptext = cpu_to_be32(*ptext); |
| 145 | init_key = 0; |
| 146 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | |
| 148 | lpfc_read_nv(phba, pmb); |
| 149 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 150 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 151 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 152 | sizeof (licensed)); |
| 153 | |
| 154 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 155 | |
| 156 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 157 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 158 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | "error, mbxCmd x%x READ_NVPARM, " |
| 160 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | mb->mbxCommand, mb->mbxStatus); |
| 162 | mempool_free(pmb, phba->mbox_mem_pool); |
| 163 | return -ERESTART; |
| 164 | } |
| 165 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 166 | sizeof(phba->wwnn)); |
| 167 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 168 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 171 | /* |
| 172 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 173 | * which was already set in lpfc_get_cfgparam() |
| 174 | */ |
| 175 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 176 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | /* Setup and issue mailbox READ REV command */ |
| 178 | lpfc_read_rev(phba, pmb); |
| 179 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 180 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 181 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 182 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | mb->mbxCommand, mb->mbxStatus); |
| 185 | mempool_free( pmb, phba->mbox_mem_pool); |
| 186 | return -ERESTART; |
| 187 | } |
| 188 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 189 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 190 | /* |
| 191 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 192 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 194 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 197 | "0440 Adapter failed to init, READ_REV has " |
| 198 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | mempool_free(pmb, phba->mbox_mem_pool); |
| 200 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | } |
| 202 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 203 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 204 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 205 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 206 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 209 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 210 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 211 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 212 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 213 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 214 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 216 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 217 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 218 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 219 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 220 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 221 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 222 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 223 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 224 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | /* If the sli feature level is less then 9, we must |
| 227 | * tear down all RPIs and VPIs on link down if NPIV |
| 228 | * is enabled. |
| 229 | */ |
| 230 | if (vp->rev.feaLevelHigh < 9) |
| 231 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 232 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 234 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 235 | sizeof (phba->RandomData)); |
| 236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 239 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 240 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 242 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 244 | |
| 245 | if (rc != MBX_SUCCESS) { |
| 246 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 247 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 250 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 252 | /* dump mem may return a zero when finished or we got a |
| 253 | * mailbox error, either way we are done. |
| 254 | */ |
| 255 | if (mb->un.varDmp.word_cnt == 0) |
| 256 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 257 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 258 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 259 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 260 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 261 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 263 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 264 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 265 | |
| 266 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | out_free_mbox: |
| 268 | mempool_free(pmb, phba->mbox_mem_pool); |
| 269 | return 0; |
| 270 | } |
| 271 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 272 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 273 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 274 | * @phba: pointer to lpfc hba data structure. |
| 275 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 276 | * |
| 277 | * This is the completion handler for driver's configuring asynchronous event |
| 278 | * mailbox command to the device. If the mailbox command returns successfully, |
| 279 | * it will set internal async event support flag to 1; otherwise, it will |
| 280 | * set internal async event support flag to 0. |
| 281 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 282 | static void |
| 283 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 284 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 285 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 286 | phba->temp_sensor_support = 1; |
| 287 | else |
| 288 | phba->temp_sensor_support = 0; |
| 289 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 290 | return; |
| 291 | } |
| 292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 294 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 295 | * @phba: pointer to lpfc hba data structure. |
| 296 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 297 | * |
| 298 | * This is the completion handler for dump mailbox command for getting |
| 299 | * wake up parameters. When this command complete, the response contain |
| 300 | * Option rom version of the HBA. This function translate the version number |
| 301 | * into a human readable string and store it in OptionROMVersion. |
| 302 | **/ |
| 303 | static void |
| 304 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 305 | { |
| 306 | struct prog_id *prg; |
| 307 | uint32_t prog_id_word; |
| 308 | char dist = ' '; |
| 309 | /* character array used for decoding dist type. */ |
| 310 | char dist_char[] = "nabx"; |
| 311 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 312 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 313 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 314 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 315 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 316 | |
| 317 | prg = (struct prog_id *) &prog_id_word; |
| 318 | |
| 319 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 320 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 321 | |
| 322 | /* Decode the Option rom version word to a readable string */ |
| 323 | if (prg->dist < 4) |
| 324 | dist = dist_char[prg->dist]; |
| 325 | |
| 326 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 327 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 328 | prg->ver, prg->rev, prg->lev); |
| 329 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 330 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 331 | prg->ver, prg->rev, prg->lev, |
| 332 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 333 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | |
| 337 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 338 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 339 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 340 | * @vport: pointer to lpfc vport data structure. |
| 341 | * |
| 342 | * |
| 343 | * Return codes |
| 344 | * None. |
| 345 | **/ |
| 346 | void |
| 347 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 348 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 349 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 350 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 351 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 352 | /* If the soft name exists then update it using the service params */ |
| 353 | if (vport->phba->cfg_soft_wwnn) |
| 354 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 355 | vport->fc_sparam.nodeName.u.wwn); |
| 356 | if (vport->phba->cfg_soft_wwpn) |
| 357 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 358 | vport->fc_sparam.portName.u.wwn); |
| 359 | |
| 360 | /* |
| 361 | * If the name is empty or there exists a soft name |
| 362 | * then copy the service params name, otherwise use the fc name |
| 363 | */ |
| 364 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 365 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 366 | sizeof(struct lpfc_name)); |
| 367 | else |
| 368 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 369 | sizeof(struct lpfc_name)); |
| 370 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 371 | /* |
| 372 | * If the port name has changed, then set the Param changes flag |
| 373 | * to unreg the login |
| 374 | */ |
| 375 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 376 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 377 | sizeof(struct lpfc_name))) |
| 378 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 379 | |
| 380 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 381 | vport->phba->cfg_soft_wwpn || |
| 382 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 383 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 384 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 385 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 386 | vport->vport_flag &= ~FAWWPN_SET; |
| 387 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 388 | vport->vport_flag |= FAWWPN_SET; |
| 389 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 390 | else |
| 391 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 392 | sizeof(struct lpfc_name)); |
| 393 | } |
| 394 | |
| 395 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 396 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 397 | * @phba: pointer to lpfc hba data structure. |
| 398 | * |
| 399 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 400 | * command call. It performs all internal resource and state setups on the |
| 401 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 402 | * ELS ring timers, etc. |
| 403 | * |
| 404 | * Return codes |
| 405 | * 0 - success. |
| 406 | * Any other value - error. |
| 407 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 412 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | LPFC_MBOXQ_t *pmb; |
| 414 | MAILBOX_t *mb; |
| 415 | struct lpfc_dmabuf *mp; |
| 416 | struct lpfc_sli *psli = &phba->sli; |
| 417 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 418 | int i, j; |
| 419 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 420 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 421 | spin_lock_irq(&phba->hbalock); |
| 422 | /* |
| 423 | * If the Config port completed correctly the HBA is not |
| 424 | * over heated any more. |
| 425 | */ |
| 426 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 427 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 428 | spin_unlock_irq(&phba->hbalock); |
| 429 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 430 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 431 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 432 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | return -ENOMEM; |
| 434 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 435 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 438 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 439 | if (rc) { |
| 440 | mempool_free(pmb, phba->mbox_mem_pool); |
| 441 | return -ENOMEM; |
| 442 | } |
| 443 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 444 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 445 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 447 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 448 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 449 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 450 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 451 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 452 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 453 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 454 | kfree(mp); |
| 455 | return -EIO; |
| 456 | } |
| 457 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 458 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 459 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 460 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 462 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 463 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 464 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 465 | |
| 466 | /* Update the fc_host data structures with new wwn. */ |
| 467 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 468 | 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] | 469 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 470 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 471 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 472 | /* This should be consolidated into parse_vpd ? - mr */ |
| 473 | if (phba->SerialNumber[0] == 0) { |
| 474 | uint8_t *outptr; |
| 475 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 476 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 477 | for (i = 0; i < 12; i++) { |
| 478 | status = *outptr++; |
| 479 | j = ((status & 0xf0) >> 4); |
| 480 | if (j <= 9) |
| 481 | phba->SerialNumber[i] = |
| 482 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 483 | else |
| 484 | phba->SerialNumber[i] = |
| 485 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 486 | i++; |
| 487 | j = (status & 0xf); |
| 488 | if (j <= 9) |
| 489 | phba->SerialNumber[i] = |
| 490 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 491 | else |
| 492 | phba->SerialNumber[i] = |
| 493 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 494 | } |
| 495 | } |
| 496 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 497 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 498 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 500 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 501 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 504 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | mempool_free( pmb, phba->mbox_mem_pool); |
| 506 | return -EIO; |
| 507 | } |
| 508 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 509 | /* Check if the port is disabled */ |
| 510 | lpfc_sli_read_link_ste(phba); |
| 511 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 512 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 513 | i = (mb->un.varRdConfig.max_xri + 1); |
| 514 | if (phba->cfg_hba_queue_depth > i) { |
| 515 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 516 | "3359 HBA queue depth changed from %d to %d\n", |
| 517 | phba->cfg_hba_queue_depth, i); |
| 518 | phba->cfg_hba_queue_depth = i; |
| 519 | } |
| 520 | |
| 521 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 522 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 523 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 524 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 525 | "3360 LUN queue depth changed from %d to %d\n", |
| 526 | phba->pport->cfg_lun_queue_depth, i); |
| 527 | phba->pport->cfg_lun_queue_depth = i; |
| 528 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 529 | |
| 530 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 531 | |
| 532 | /* Get the default values for Model Name and Description */ |
| 533 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 534 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 535 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 537 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 538 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 539 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 540 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 541 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | |
| 543 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 544 | if (phba->sli_rev != 3) |
| 545 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 546 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 547 | /* |
| 548 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 549 | */ |
| 550 | if (phba->intr_type == MSIX) { |
| 551 | rc = lpfc_config_msi(phba, pmb); |
| 552 | if (rc) { |
| 553 | mempool_free(pmb, phba->mbox_mem_pool); |
| 554 | return -EIO; |
| 555 | } |
| 556 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 557 | if (rc != MBX_SUCCESS) { |
| 558 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 559 | "0352 Config MSI mailbox command " |
| 560 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 561 | pmb->u.mb.mbxCommand, |
| 562 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 563 | mempool_free(pmb, phba->mbox_mem_pool); |
| 564 | return -EIO; |
| 565 | } |
| 566 | } |
| 567 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 568 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 569 | /* Initialize ERATT handling flag */ |
| 570 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 571 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 573 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 574 | spin_unlock_irq(&phba->hbalock); |
| 575 | return -EIO; |
| 576 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 577 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 578 | if (psli->num_rings > 0) |
| 579 | status |= HC_R0INT_ENA; |
| 580 | if (psli->num_rings > 1) |
| 581 | status |= HC_R1INT_ENA; |
| 582 | if (psli->num_rings > 2) |
| 583 | status |= HC_R2INT_ENA; |
| 584 | if (psli->num_rings > 3) |
| 585 | status |= HC_R3INT_ENA; |
| 586 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 587 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 588 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 589 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 590 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 591 | writel(status, phba->HCregaddr); |
| 592 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 593 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 595 | /* Set up ring-0 (ELS) timer */ |
| 596 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 597 | mod_timer(&vport->els_tmofunc, |
| 598 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 599 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 600 | mod_timer(&phba->hb_tmofunc, |
| 601 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 602 | phba->hb_outstanding = 0; |
| 603 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 604 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 605 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 606 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 608 | if (phba->hba_flag & LINK_DISABLED) { |
| 609 | lpfc_printf_log(phba, |
| 610 | KERN_ERR, LOG_INIT, |
| 611 | "2598 Adapter Link is disabled.\n"); |
| 612 | lpfc_down_link(phba, pmb); |
| 613 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 614 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 615 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 616 | lpfc_printf_log(phba, |
| 617 | KERN_ERR, LOG_INIT, |
| 618 | "2599 Adapter failed to issue DOWN_LINK" |
| 619 | " mbox command rc 0x%x\n", rc); |
| 620 | |
| 621 | mempool_free(pmb, phba->mbox_mem_pool); |
| 622 | return -EIO; |
| 623 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 624 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 625 | mempool_free(pmb, phba->mbox_mem_pool); |
| 626 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 627 | if (rc) |
| 628 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | } |
| 630 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 631 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 632 | if (!pmb) { |
| 633 | phba->link_state = LPFC_HBA_ERROR; |
| 634 | return -ENOMEM; |
| 635 | } |
| 636 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 637 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 638 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 639 | pmb->vport = phba->pport; |
| 640 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 642 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 643 | lpfc_printf_log(phba, |
| 644 | KERN_ERR, |
| 645 | LOG_INIT, |
| 646 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 647 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 648 | rc); |
| 649 | mempool_free(pmb, phba->mbox_mem_pool); |
| 650 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 651 | |
| 652 | /* Get Option rom version */ |
| 653 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 654 | if (!pmb) { |
| 655 | phba->link_state = LPFC_HBA_ERROR; |
| 656 | return -ENOMEM; |
| 657 | } |
| 658 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 659 | lpfc_dump_wakeup_param(phba, pmb); |
| 660 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 661 | pmb->vport = phba->pport; |
| 662 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 663 | |
| 664 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 666 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 667 | mempool_free(pmb, phba->mbox_mem_pool); |
| 668 | } |
| 669 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 670 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 671 | } |
| 672 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 673 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 674 | * lpfc_hba_init_link - Initialize the FC link |
| 675 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 676 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 677 | * |
| 678 | * This routine will issue the INIT_LINK mailbox command call. |
| 679 | * It is available to other drivers through the lpfc_hba data |
| 680 | * structure for use as a delayed link up mechanism with the |
| 681 | * module parameter lpfc_suppress_link_up. |
| 682 | * |
| 683 | * Return code |
| 684 | * 0 - success |
| 685 | * Any other value - error |
| 686 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 687 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 688 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 689 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 690 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 695 | * @phba: pointer to lpfc hba data structure. |
| 696 | * @fc_topology: desired fc topology. |
| 697 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 698 | * |
| 699 | * This routine will issue the INIT_LINK mailbox command call. |
| 700 | * It is available to other drivers through the lpfc_hba data |
| 701 | * structure for use as a delayed link up mechanism with the |
| 702 | * module parameter lpfc_suppress_link_up. |
| 703 | * |
| 704 | * Return code |
| 705 | * 0 - success |
| 706 | * Any other value - error |
| 707 | **/ |
| 708 | int |
| 709 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 710 | uint32_t flag) |
| 711 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 712 | struct lpfc_vport *vport = phba->pport; |
| 713 | LPFC_MBOXQ_t *pmb; |
| 714 | MAILBOX_t *mb; |
| 715 | int rc; |
| 716 | |
| 717 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 718 | if (!pmb) { |
| 719 | phba->link_state = LPFC_HBA_ERROR; |
| 720 | return -ENOMEM; |
| 721 | } |
| 722 | mb = &pmb->u.mb; |
| 723 | pmb->vport = vport; |
| 724 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 725 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 726 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 727 | !(phba->lmt & LMT_1Gb)) || |
| 728 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 729 | !(phba->lmt & LMT_2Gb)) || |
| 730 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 731 | !(phba->lmt & LMT_4Gb)) || |
| 732 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 733 | !(phba->lmt & LMT_8Gb)) || |
| 734 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 735 | !(phba->lmt & LMT_10Gb)) || |
| 736 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 737 | !(phba->lmt & LMT_16Gb)) || |
| 738 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 739 | !(phba->lmt & LMT_32Gb)) || |
| 740 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 741 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 742 | /* Reset link speed to auto */ |
| 743 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 744 | "1302 Invalid speed for this board:%d " |
| 745 | "Reset link speed to auto.\n", |
| 746 | phba->cfg_link_speed); |
| 747 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 748 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 749 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 750 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 751 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 752 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 753 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 754 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 755 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 756 | "0498 Adapter failed to init, mbxCmd x%x " |
| 757 | "INIT_LINK, mbxStatus x%x\n", |
| 758 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 759 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 760 | /* Clear all interrupt enable conditions */ |
| 761 | writel(0, phba->HCregaddr); |
| 762 | readl(phba->HCregaddr); /* flush */ |
| 763 | /* Clear all pending interrupts */ |
| 764 | writel(0xffffffff, phba->HAregaddr); |
| 765 | readl(phba->HAregaddr); /* flush */ |
| 766 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 767 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 768 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 769 | mempool_free(pmb, phba->mbox_mem_pool); |
| 770 | return -EIO; |
| 771 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 772 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 773 | if (flag == MBX_POLL) |
| 774 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 781 | * @phba: pointer to lpfc hba data structure. |
| 782 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 783 | * |
| 784 | * This routine will issue the DOWN_LINK mailbox command call. |
| 785 | * It is available to other drivers through the lpfc_hba data |
| 786 | * structure for use to stop the link. |
| 787 | * |
| 788 | * Return code |
| 789 | * 0 - success |
| 790 | * Any other value - error |
| 791 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 792 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 793 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 794 | { |
| 795 | LPFC_MBOXQ_t *pmb; |
| 796 | int rc; |
| 797 | |
| 798 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 799 | if (!pmb) { |
| 800 | phba->link_state = LPFC_HBA_ERROR; |
| 801 | return -ENOMEM; |
| 802 | } |
| 803 | |
| 804 | lpfc_printf_log(phba, |
| 805 | KERN_ERR, LOG_INIT, |
| 806 | "0491 Adapter Link is disabled.\n"); |
| 807 | lpfc_down_link(phba, pmb); |
| 808 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 809 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 810 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 811 | lpfc_printf_log(phba, |
| 812 | KERN_ERR, LOG_INIT, |
| 813 | "2522 Adapter failed to issue DOWN_LINK" |
| 814 | " mbox command rc 0x%x\n", rc); |
| 815 | |
| 816 | mempool_free(pmb, phba->mbox_mem_pool); |
| 817 | return -EIO; |
| 818 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 819 | if (flag == MBX_POLL) |
| 820 | mempool_free(pmb, phba->mbox_mem_pool); |
| 821 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 826 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 827 | * @phba: pointer to lpfc HBA data structure. |
| 828 | * |
| 829 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 830 | * bringing down the SLI Layer. |
| 831 | * |
| 832 | * Return codes |
| 833 | * 0 - success. |
| 834 | * Any other value - error. |
| 835 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 836 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 837 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 839 | struct lpfc_vport **vports; |
| 840 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 841 | |
| 842 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 843 | /* Disable interrupts */ |
| 844 | writel(0, phba->HCregaddr); |
| 845 | readl(phba->HCregaddr); /* flush */ |
| 846 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 848 | if (phba->pport->load_flag & FC_UNLOADING) |
| 849 | lpfc_cleanup_discovery_resources(phba->pport); |
| 850 | else { |
| 851 | vports = lpfc_create_vport_work_array(phba); |
| 852 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 853 | for (i = 0; i <= phba->max_vports && |
| 854 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 855 | lpfc_cleanup_discovery_resources(vports[i]); |
| 856 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 857 | } |
| 858 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | } |
| 860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 861 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 862 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 863 | * rspiocb which got deferred |
| 864 | * |
| 865 | * @phba: pointer to lpfc HBA data structure. |
| 866 | * |
| 867 | * This routine will cleanup completed slow path events after HBA is reset |
| 868 | * when bringing down the SLI Layer. |
| 869 | * |
| 870 | * |
| 871 | * Return codes |
| 872 | * void. |
| 873 | **/ |
| 874 | static void |
| 875 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 876 | { |
| 877 | struct lpfc_iocbq *rspiocbq; |
| 878 | struct hbq_dmabuf *dmabuf; |
| 879 | struct lpfc_cq_event *cq_event; |
| 880 | |
| 881 | spin_lock_irq(&phba->hbalock); |
| 882 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 883 | spin_unlock_irq(&phba->hbalock); |
| 884 | |
| 885 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 886 | /* Get the response iocb from the head of work queue */ |
| 887 | spin_lock_irq(&phba->hbalock); |
| 888 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 889 | cq_event, struct lpfc_cq_event, list); |
| 890 | spin_unlock_irq(&phba->hbalock); |
| 891 | |
| 892 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 893 | case CQE_CODE_COMPL_WQE: |
| 894 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 895 | cq_event); |
| 896 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 897 | break; |
| 898 | case CQE_CODE_RECEIVE: |
| 899 | case CQE_CODE_RECEIVE_V1: |
| 900 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 901 | cq_event); |
| 902 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 908 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 909 | * @phba: pointer to lpfc HBA data structure. |
| 910 | * |
| 911 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 912 | * when bringing down the SLI Layer. |
| 913 | * |
| 914 | * |
| 915 | * Return codes |
| 916 | * void. |
| 917 | **/ |
| 918 | static void |
| 919 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 920 | { |
| 921 | struct lpfc_sli *psli = &phba->sli; |
| 922 | struct lpfc_sli_ring *pring; |
| 923 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 924 | LIST_HEAD(buflist); |
| 925 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 926 | |
| 927 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 928 | lpfc_sli_hbqbuf_free_all(phba); |
| 929 | else { |
| 930 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 931 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 932 | spin_lock_irq(&phba->hbalock); |
| 933 | list_splice_init(&pring->postbufq, &buflist); |
| 934 | spin_unlock_irq(&phba->hbalock); |
| 935 | |
| 936 | count = 0; |
| 937 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 938 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 939 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 940 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 941 | kfree(mp); |
| 942 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 943 | |
| 944 | spin_lock_irq(&phba->hbalock); |
| 945 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 946 | spin_unlock_irq(&phba->hbalock); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 952 | * @phba: pointer to lpfc HBA data structure. |
| 953 | * |
| 954 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 955 | * down the SLI Layer. |
| 956 | * |
| 957 | * Return codes |
| 958 | * void |
| 959 | **/ |
| 960 | static void |
| 961 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 962 | { |
| 963 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 964 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 965 | struct lpfc_sli_ring *pring; |
| 966 | LIST_HEAD(completions); |
| 967 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 968 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 969 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 970 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 971 | for (i = 0; i < psli->num_rings; i++) { |
| 972 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 973 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 974 | /* At this point in time the HBA is either reset or DOA |
| 975 | * Nothing should be on txcmplq as it will |
| 976 | * NEVER complete. |
| 977 | */ |
| 978 | list_splice_init(&pring->txcmplq, &completions); |
| 979 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 980 | spin_unlock_irq(&phba->hbalock); |
| 981 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 982 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 983 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 984 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 985 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 986 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 987 | return; |
| 988 | } |
| 989 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 990 | pring = qp->pring; |
| 991 | if (!pring) |
| 992 | continue; |
| 993 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 994 | list_for_each_entry_safe(piocb, next_iocb, |
| 995 | &pring->txcmplq, list) |
| 996 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 997 | list_splice_init(&pring->txcmplq, &completions); |
| 998 | pring->txcmplq_cnt = 0; |
| 999 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1000 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1001 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1002 | /* Cancel all the IOCBs from the completions list */ |
| 1003 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 1004 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1008 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1009 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1010 | * @phba: pointer to lpfc HBA data structure. |
| 1011 | * |
| 1012 | * This routine will do uninitialization after the HBA is reset when bring |
| 1013 | * down the SLI Layer. |
| 1014 | * |
| 1015 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1016 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1017 | * Any other value - error. |
| 1018 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1019 | static int |
| 1020 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1021 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1022 | lpfc_hba_free_post_buf(phba); |
| 1023 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1024 | return 0; |
| 1025 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1026 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1027 | /** |
| 1028 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1029 | * @phba: pointer to lpfc HBA data structure. |
| 1030 | * |
| 1031 | * This routine will do uninitialization after the HBA is reset when bring |
| 1032 | * down the SLI Layer. |
| 1033 | * |
| 1034 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1035 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1036 | * Any other value - error. |
| 1037 | **/ |
| 1038 | static int |
| 1039 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1040 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1041 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1042 | struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1043 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1044 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1045 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1046 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1047 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1048 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1049 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1050 | |
| 1051 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1052 | lpfc_hba_clean_txcmplq(phba); |
| 1053 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1054 | /* At this point in time the HBA is either reset or DOA. Either |
| 1055 | * 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] | 1056 | * 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] | 1057 | * driver is unloading or reposted if the driver is restarting |
| 1058 | * the port. |
| 1059 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1060 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1061 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1062 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | * list. |
| 1064 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1065 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1066 | list_for_each_entry(sglq_entry, |
| 1067 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1068 | sglq_entry->state = SGL_FREED; |
| 1069 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1070 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1071 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1072 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1073 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1074 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1075 | |
| 1076 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1077 | * list. |
| 1078 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1079 | cnt = 0; |
| 1080 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1081 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1082 | |
| 1083 | spin_lock(&qp->abts_scsi_buf_list_lock); |
| 1084 | list_splice_init(&qp->lpfc_abts_scsi_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1085 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1086 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1087 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1088 | psb->pCmd = NULL; |
| 1089 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1090 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1091 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1092 | spin_lock(&qp->io_buf_list_put_lock); |
| 1093 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1094 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
| 1095 | qp->abts_scsi_io_bufs = 0; |
| 1096 | spin_unlock(&qp->io_buf_list_put_lock); |
| 1097 | spin_unlock(&qp->abts_scsi_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1098 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1099 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1100 | spin_lock(&qp->abts_nvme_buf_list_lock); |
| 1101 | list_splice_init(&qp->lpfc_abts_nvme_buf_list, |
| 1102 | &nvme_aborts); |
| 1103 | list_for_each_entry_safe(psb, psb_next, &nvme_aborts, |
| 1104 | list) { |
| 1105 | psb->pCmd = NULL; |
| 1106 | psb->status = IOSTAT_SUCCESS; |
| 1107 | cnt++; |
| 1108 | } |
| 1109 | spin_lock(&qp->io_buf_list_put_lock); |
| 1110 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
| 1111 | qp->abts_nvme_io_bufs = 0; |
| 1112 | list_splice_init(&nvme_aborts, |
| 1113 | &qp->lpfc_io_buf_list_put); |
| 1114 | spin_unlock(&qp->io_buf_list_put_lock); |
| 1115 | spin_unlock(&qp->abts_nvme_buf_list_lock); |
| 1116 | |
| 1117 | } |
| 1118 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1119 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1120 | |
| 1121 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1122 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1123 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1124 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1125 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1126 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
| 1127 | ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1128 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1129 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1130 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1131 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1132 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1133 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1138 | * @phba: pointer to lpfc HBA data structure. |
| 1139 | * |
| 1140 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1141 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1142 | * |
| 1143 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1144 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1145 | * Any other value - error. |
| 1146 | **/ |
| 1147 | int |
| 1148 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1149 | { |
| 1150 | return (*phba->lpfc_hba_down_post)(phba); |
| 1151 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1152 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1153 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1154 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1156 | * |
| 1157 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1158 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1159 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1160 | * event will be used by the worker thread to invoke the actual timeout |
| 1161 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1162 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1163 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1164 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1165 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1166 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1167 | { |
| 1168 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1169 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1170 | unsigned long iflag; |
| 1171 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1172 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1173 | |
| 1174 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1175 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1176 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1177 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1178 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1179 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1180 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1181 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1182 | if (!tmo_posted) |
| 1183 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1184 | return; |
| 1185 | } |
| 1186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1188 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1189 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1190 | * |
| 1191 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1192 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1193 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1194 | * event will be used by the worker thread to invoke the actual timeout |
| 1195 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1196 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1197 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1198 | **/ |
| 1199 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1200 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1201 | { |
| 1202 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1203 | unsigned long iflag; |
| 1204 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1205 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1206 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1207 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1208 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1209 | else |
| 1210 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1211 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1212 | |
| 1213 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1214 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1218 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | * @phba: pointer to lpfc hba data structure. |
| 1220 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1221 | * |
| 1222 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1223 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1224 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1225 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1226 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1227 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1228 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1229 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1230 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1231 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1232 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1233 | static void |
| 1234 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1235 | { |
| 1236 | unsigned long drvr_flag; |
| 1237 | |
| 1238 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1239 | phba->hb_outstanding = 0; |
| 1240 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1241 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1242 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1243 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1244 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1245 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1246 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1247 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1248 | jiffies + |
| 1249 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1253 | static void |
| 1254 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1255 | { |
| 1256 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1257 | struct lpfc_hba, eq_delay_work); |
| 1258 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1259 | struct lpfc_queue *eq, *eq_next; |
| 1260 | unsigned char *eqcnt = NULL; |
| 1261 | uint32_t usdelay; |
| 1262 | int i; |
| 1263 | |
| 1264 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1265 | return; |
| 1266 | |
| 1267 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1268 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1269 | goto requeue; |
| 1270 | |
| 1271 | eqcnt = kcalloc(num_possible_cpus(), sizeof(unsigned char), |
| 1272 | GFP_KERNEL); |
| 1273 | if (!eqcnt) |
| 1274 | goto requeue; |
| 1275 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 1276 | /* Loop thru all IRQ vectors */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1277 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 1278 | /* Get the EQ corresponding to the IRQ vector */ |
| 1279 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1280 | if (eq && eqcnt[eq->last_cpu] < 2) |
| 1281 | eqcnt[eq->last_cpu]++; |
| 1282 | continue; |
| 1283 | } |
| 1284 | |
| 1285 | for_each_present_cpu(i) { |
| 1286 | if (phba->cfg_irq_chann > 1 && eqcnt[i] < 2) |
| 1287 | continue; |
| 1288 | |
| 1289 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
| 1290 | |
| 1291 | usdelay = (eqi->icnt / LPFC_IMAX_THRESHOLD) * |
| 1292 | LPFC_EQ_DELAY_STEP; |
| 1293 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1294 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1295 | |
| 1296 | eqi->icnt = 0; |
| 1297 | |
| 1298 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
| 1299 | if (eq->last_cpu != i) { |
| 1300 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1301 | eq->last_cpu); |
| 1302 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1303 | continue; |
| 1304 | } |
| 1305 | if (usdelay != eq->q_mode) |
| 1306 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1307 | usdelay); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | kfree(eqcnt); |
| 1312 | |
| 1313 | requeue: |
| 1314 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1315 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1316 | } |
| 1317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1318 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1319 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1320 | * @phba: pointer to lpfc hba data structure. |
| 1321 | * |
| 1322 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1323 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1324 | **/ |
| 1325 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1326 | { |
| 1327 | u32 i; |
| 1328 | u32 hwq_count; |
| 1329 | |
| 1330 | hwq_count = phba->cfg_hdw_queue; |
| 1331 | for (i = 0; i < hwq_count; i++) { |
| 1332 | /* Adjust XRIs in private pool */ |
| 1333 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1334 | |
| 1335 | /* Adjust high watermark */ |
| 1336 | lpfc_adjust_high_watermark(phba, i); |
| 1337 | |
| 1338 | #ifdef LPFC_MXP_STAT |
| 1339 | /* Snapshot pbl, pvt and busy count */ |
| 1340 | lpfc_snapshot_mxp(phba, i); |
| 1341 | #endif |
| 1342 | } |
| 1343 | } |
| 1344 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1345 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1346 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1347 | * @phba: pointer to lpfc hba data structure. |
| 1348 | * |
| 1349 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1350 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1351 | * handler performs any periodic operations needed for the device. If such |
| 1352 | * periodic event has already been attended to either in the interrupt handler |
| 1353 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1354 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1355 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1356 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1357 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1358 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1359 | * to offline. |
| 1360 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1361 | void |
| 1362 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1363 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1364 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1365 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1366 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1367 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1368 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1369 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1370 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1371 | if (phba->cfg_xri_rebalancing) { |
| 1372 | /* Multi-XRI pools handler */ |
| 1373 | lpfc_hb_mxp_handler(phba); |
| 1374 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1375 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1376 | vports = lpfc_create_vport_work_array(phba); |
| 1377 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1378 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1379 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1380 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1381 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1382 | lpfc_destroy_vport_work_array(phba, vports); |
| 1383 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1384 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1385 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1386 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1387 | return; |
| 1388 | |
| 1389 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1390 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1391 | if (time_after(phba->last_completion_time + |
| 1392 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1393 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1394 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1395 | if (!phba->hb_outstanding) |
| 1396 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1397 | jiffies + |
| 1398 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1399 | else |
| 1400 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1401 | jiffies + |
| 1402 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1403 | return; |
| 1404 | } |
| 1405 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1406 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1407 | if (phba->elsbuf_cnt && |
| 1408 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1409 | spin_lock_irq(&phba->hbalock); |
| 1410 | list_splice_init(&phba->elsbuf, &completions); |
| 1411 | phba->elsbuf_cnt = 0; |
| 1412 | phba->elsbuf_prev_cnt = 0; |
| 1413 | spin_unlock_irq(&phba->hbalock); |
| 1414 | |
| 1415 | while (!list_empty(&completions)) { |
| 1416 | list_remove_head(&completions, buf_ptr, |
| 1417 | struct lpfc_dmabuf, list); |
| 1418 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1419 | kfree(buf_ptr); |
| 1420 | } |
| 1421 | } |
| 1422 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1423 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1424 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1425 | if (phba->cfg_enable_hba_heartbeat) { |
| 1426 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1427 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1428 | (list_empty(&psli->mboxq))) { |
| 1429 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1430 | GFP_KERNEL); |
| 1431 | if (!pmboxq) { |
| 1432 | mod_timer(&phba->hb_tmofunc, |
| 1433 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1434 | msecs_to_jiffies(1000 * |
| 1435 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1436 | return; |
| 1437 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1438 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1439 | lpfc_heart_beat(phba, pmboxq); |
| 1440 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1441 | pmboxq->vport = phba->pport; |
| 1442 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1443 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1444 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1445 | if (retval != MBX_BUSY && |
| 1446 | retval != MBX_SUCCESS) { |
| 1447 | mempool_free(pmboxq, |
| 1448 | phba->mbox_mem_pool); |
| 1449 | mod_timer(&phba->hb_tmofunc, |
| 1450 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1451 | msecs_to_jiffies(1000 * |
| 1452 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | phba->skipped_hb = 0; |
| 1456 | phba->hb_outstanding = 1; |
| 1457 | } else if (time_before_eq(phba->last_completion_time, |
| 1458 | phba->skipped_hb)) { |
| 1459 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1460 | "2857 Last completion time not " |
| 1461 | " updated in %d ms\n", |
| 1462 | jiffies_to_msecs(jiffies |
| 1463 | - phba->last_completion_time)); |
| 1464 | } else |
| 1465 | phba->skipped_hb = jiffies; |
| 1466 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 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 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1471 | } else { |
| 1472 | /* |
| 1473 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1474 | * we need to give the hb mailbox cmd a chance to |
| 1475 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1476 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1477 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1478 | "0459 Adapter heartbeat still out" |
| 1479 | "standing:last compl time was %d ms.\n", |
| 1480 | jiffies_to_msecs(jiffies |
| 1481 | - phba->last_completion_time)); |
| 1482 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1483 | jiffies + |
| 1484 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1485 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1486 | } else { |
| 1487 | mod_timer(&phba->hb_tmofunc, |
| 1488 | jiffies + |
| 1489 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1493 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1494 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1495 | * @phba: pointer to lpfc hba data structure. |
| 1496 | * |
| 1497 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1498 | * other than Port Error 6 has been detected. |
| 1499 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1500 | static void |
| 1501 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1502 | { |
| 1503 | struct lpfc_sli *psli = &phba->sli; |
| 1504 | |
| 1505 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1506 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1507 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1508 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1509 | |
| 1510 | lpfc_offline(phba); |
| 1511 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1512 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1513 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1514 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1515 | lpfc_hba_down_post(phba); |
| 1516 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1517 | lpfc_unblock_mgmt_io(phba); |
| 1518 | phba->link_state = LPFC_HBA_ERROR; |
| 1519 | return; |
| 1520 | } |
| 1521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1522 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1523 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1524 | * @phba: pointer to lpfc hba data structure. |
| 1525 | * |
| 1526 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1527 | * other than Port Error 6 has been detected. |
| 1528 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1529 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1530 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1531 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1532 | spin_lock_irq(&phba->hbalock); |
| 1533 | phba->link_state = LPFC_HBA_ERROR; |
| 1534 | spin_unlock_irq(&phba->hbalock); |
| 1535 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1536 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1537 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1538 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1539 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1543 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1544 | * @phba: pointer to lpfc hba data structure. |
| 1545 | * |
| 1546 | * This routine is invoked to handle the deferred HBA hardware error |
| 1547 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1548 | * and another ER bit in the host status register. The driver will |
| 1549 | * wait until the ER1 bit clears before handling the error condition. |
| 1550 | **/ |
| 1551 | static void |
| 1552 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1553 | { |
| 1554 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1555 | struct lpfc_sli *psli = &phba->sli; |
| 1556 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1557 | /* If the pci channel is offline, ignore possible errors, |
| 1558 | * since we cannot communicate with the pci card anyway. |
| 1559 | */ |
| 1560 | if (pci_channel_offline(phba->pcidev)) { |
| 1561 | spin_lock_irq(&phba->hbalock); |
| 1562 | phba->hba_flag &= ~DEFER_ERATT; |
| 1563 | spin_unlock_irq(&phba->hbalock); |
| 1564 | return; |
| 1565 | } |
| 1566 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1568 | "0479 Deferred Adapter Hardware Error " |
| 1569 | "Data: x%x x%x x%x\n", |
| 1570 | phba->work_hs, |
| 1571 | phba->work_status[0], phba->work_status[1]); |
| 1572 | |
| 1573 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1574 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1575 | spin_unlock_irq(&phba->hbalock); |
| 1576 | |
| 1577 | |
| 1578 | /* |
| 1579 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1580 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1581 | * SCSI layer retry it after re-establishing link. |
| 1582 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1583 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1584 | |
| 1585 | /* |
| 1586 | * There was a firmware error. Take the hba offline and then |
| 1587 | * attempt to restart it. |
| 1588 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1589 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1590 | lpfc_offline(phba); |
| 1591 | |
| 1592 | /* Wait for the ER1 bit to clear.*/ |
| 1593 | while (phba->work_hs & HS_FFER1) { |
| 1594 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1595 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1596 | phba->work_hs = UNPLUG_ERR ; |
| 1597 | break; |
| 1598 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1599 | /* If driver is unloading let the worker thread continue */ |
| 1600 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1601 | phba->work_hs = 0; |
| 1602 | break; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * This is to ptrotect against a race condition in which |
| 1608 | * first write to the host attention register clear the |
| 1609 | * host status register. |
| 1610 | */ |
| 1611 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1612 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1613 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1614 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1615 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1616 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1617 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1618 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1619 | } |
| 1620 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1621 | static void |
| 1622 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1623 | { |
| 1624 | struct lpfc_board_event_header board_event; |
| 1625 | struct Scsi_Host *shost; |
| 1626 | |
| 1627 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1628 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1629 | shost = lpfc_shost_from_vport(phba->pport); |
| 1630 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1631 | sizeof(board_event), |
| 1632 | (char *) &board_event, |
| 1633 | LPFC_NL_VENDOR_ID); |
| 1634 | } |
| 1635 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1636 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1637 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1638 | * @phba: pointer to lpfc hba data structure. |
| 1639 | * |
| 1640 | * This routine is invoked to handle the following HBA hardware error |
| 1641 | * conditions: |
| 1642 | * 1 - HBA error attention interrupt |
| 1643 | * 2 - DMA ring index out of range |
| 1644 | * 3 - Mailbox command came back as unknown |
| 1645 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1646 | static void |
| 1647 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1651 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1652 | unsigned long temperature; |
| 1653 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1654 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1656 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1657 | * since we cannot communicate with the pci card anyway. |
| 1658 | */ |
| 1659 | if (pci_channel_offline(phba->pcidev)) { |
| 1660 | spin_lock_irq(&phba->hbalock); |
| 1661 | phba->hba_flag &= ~DEFER_ERATT; |
| 1662 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1663 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1666 | /* If resets are disabled then leave the HBA alone and return */ |
| 1667 | if (!phba->cfg_enable_hba_reset) |
| 1668 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1669 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1670 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1671 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1672 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1673 | if (phba->hba_flag & DEFER_ERATT) |
| 1674 | lpfc_handle_deferred_eratt(phba); |
| 1675 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1676 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1677 | if (phba->work_hs & HS_FFER6) |
| 1678 | /* Re-establishing Link */ |
| 1679 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1680 | "1301 Re-establishing Link " |
| 1681 | "Data: x%x x%x x%x\n", |
| 1682 | phba->work_hs, phba->work_status[0], |
| 1683 | phba->work_status[1]); |
| 1684 | if (phba->work_hs & HS_FFER8) |
| 1685 | /* Device Zeroization */ |
| 1686 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1687 | "2861 Host Authentication device " |
| 1688 | "zeroization Data:x%x x%x x%x\n", |
| 1689 | phba->work_hs, phba->work_status[0], |
| 1690 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1691 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1692 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1693 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1694 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | |
| 1696 | /* |
| 1697 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1698 | * That could cause the I/Os dropped by the firmware. |
| 1699 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1700 | * retry it after re-establishing link. |
| 1701 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1702 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1703 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | /* |
| 1705 | * There was a firmware error. Take the hba offline and then |
| 1706 | * attempt to restart it. |
| 1707 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1708 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1710 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1712 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | return; |
| 1714 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1715 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1716 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1717 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1718 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1719 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1720 | temp_event_data.data = (uint32_t)temperature; |
| 1721 | |
| 1722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1723 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1724 | "(%ld), taking this port offline " |
| 1725 | "Data: x%x x%x x%x\n", |
| 1726 | temperature, phba->work_hs, |
| 1727 | phba->work_status[0], phba->work_status[1]); |
| 1728 | |
| 1729 | shost = lpfc_shost_from_vport(phba->pport); |
| 1730 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1731 | sizeof(temp_event_data), |
| 1732 | (char *) &temp_event_data, |
| 1733 | SCSI_NL_VID_TYPE_PCI |
| 1734 | | PCI_VENDOR_ID_EMULEX); |
| 1735 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1736 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1737 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1738 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1739 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1740 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | } else { |
| 1742 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1743 | * failure is a value other than FFER6. Do not call the offline |
| 1744 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | */ |
| 1746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1747 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1749 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | phba->work_status[0], phba->work_status[1]); |
| 1751 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1752 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1753 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1755 | sizeof(event_data), (char *) &event_data, |
| 1756 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1757 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1758 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1759 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1760 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | } |
| 1762 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1763 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1764 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1765 | * @phba: pointer to lpfc hba data structure. |
| 1766 | * @mbx_action: flag for mailbox shutdown action. |
| 1767 | * |
| 1768 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1769 | * response to port status register polling attention. It waits for port |
| 1770 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1771 | * During this process, interrupt vectors are freed and later requested |
| 1772 | * for handling possible port resource change. |
| 1773 | **/ |
| 1774 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1775 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1776 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1777 | { |
| 1778 | int rc; |
| 1779 | uint32_t intr_mode; |
| 1780 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1781 | 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] | 1782 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1783 | /* |
| 1784 | * On error status condition, driver need to wait for port |
| 1785 | * ready before performing reset. |
| 1786 | */ |
| 1787 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1788 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1789 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1790 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1791 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1792 | /* need reset: attempt for port recovery */ |
| 1793 | if (en_rn_msg) |
| 1794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1795 | "2887 Reset Needed: Attempting Port " |
| 1796 | "Recovery...\n"); |
| 1797 | lpfc_offline_prep(phba, mbx_action); |
| 1798 | lpfc_offline(phba); |
| 1799 | /* release interrupt for possible resource change */ |
| 1800 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1801 | rc = lpfc_sli_brdrestart(phba); |
| 1802 | if (rc) { |
| 1803 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1804 | "6309 Failed to restart board\n"); |
| 1805 | return rc; |
| 1806 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1807 | /* request and enable interrupt */ |
| 1808 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1809 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1811 | "3175 Failed to enable interrupt\n"); |
| 1812 | return -EIO; |
| 1813 | } |
| 1814 | phba->intr_mode = intr_mode; |
| 1815 | rc = lpfc_online(phba); |
| 1816 | if (rc == 0) |
| 1817 | lpfc_unblock_mgmt_io(phba); |
| 1818 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1819 | return rc; |
| 1820 | } |
| 1821 | |
| 1822 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1823 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1824 | * @phba: pointer to lpfc hba data structure. |
| 1825 | * |
| 1826 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1827 | * conditions. |
| 1828 | **/ |
| 1829 | static void |
| 1830 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1831 | { |
| 1832 | struct lpfc_vport *vport = phba->pport; |
| 1833 | uint32_t event_data; |
| 1834 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1835 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1836 | struct lpfc_register portstat_reg = {0}; |
| 1837 | uint32_t reg_err1, reg_err2; |
| 1838 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1839 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1840 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1841 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1842 | struct lpfc_register portsmphr_reg; |
| 1843 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1844 | |
| 1845 | /* If the pci channel is offline, ignore possible errors, since |
| 1846 | * we cannot communicate with the pci card anyway. |
| 1847 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1848 | if (pci_channel_offline(phba->pcidev)) { |
| 1849 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1850 | "3166 pci channel is offline\n"); |
| 1851 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1852 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1853 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1854 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1855 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1856 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1857 | switch (if_type) { |
| 1858 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1859 | pci_rd_rc1 = lpfc_readl( |
| 1860 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1861 | &uerrlo_reg); |
| 1862 | pci_rd_rc2 = lpfc_readl( |
| 1863 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1864 | &uemasklo_reg); |
| 1865 | /* consider PCI bus read error as pci_channel_offline */ |
| 1866 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1867 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1868 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1869 | lpfc_sli4_offline_eratt(phba); |
| 1870 | return; |
| 1871 | } |
| 1872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1873 | "7623 Checking UE recoverable"); |
| 1874 | |
| 1875 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1876 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1877 | &portsmphr_reg.word0)) |
| 1878 | continue; |
| 1879 | |
| 1880 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1881 | &portsmphr_reg); |
| 1882 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1883 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1884 | break; |
| 1885 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1886 | msleep(1000); |
| 1887 | } |
| 1888 | |
| 1889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1890 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1891 | smphr_port_status, i); |
| 1892 | |
| 1893 | /* Recoverable UE, reset the HBA device */ |
| 1894 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1895 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1896 | for (i = 0; i < 20; i++) { |
| 1897 | msleep(1000); |
| 1898 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1899 | &portsmphr_reg.word0) && |
| 1900 | (LPFC_POST_STAGE_PORT_READY == |
| 1901 | bf_get(lpfc_port_smphr_port_status, |
| 1902 | &portsmphr_reg))) { |
| 1903 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1904 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1905 | if (rc == 0) |
| 1906 | return; |
| 1907 | lpfc_printf_log(phba, |
| 1908 | KERN_ERR, LOG_INIT, |
| 1909 | "4215 Failed to recover UE"); |
| 1910 | break; |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1915 | "7624 Firmware not ready: Failing UE recovery," |
| 1916 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1917 | lpfc_sli4_offline_eratt(phba); |
| 1918 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1919 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1920 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1921 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1922 | pci_rd_rc1 = lpfc_readl( |
| 1923 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1924 | &portstat_reg.word0); |
| 1925 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1926 | if (pci_rd_rc1 == -EIO) { |
| 1927 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1928 | "3151 PCI bus read access failure: x%x\n", |
| 1929 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1930 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1931 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1932 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1933 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1934 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1935 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1937 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1938 | "taking port offline Data: x%x x%x\n", |
| 1939 | reg_err1, reg_err2); |
| 1940 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1941 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1942 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1943 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1944 | temp_event_data.data = 0xFFFFFFFF; |
| 1945 | |
| 1946 | shost = lpfc_shost_from_vport(phba->pport); |
| 1947 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1948 | sizeof(temp_event_data), |
| 1949 | (char *)&temp_event_data, |
| 1950 | SCSI_NL_VID_TYPE_PCI |
| 1951 | | PCI_VENDOR_ID_EMULEX); |
| 1952 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1953 | spin_lock_irq(&phba->hbalock); |
| 1954 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1955 | spin_unlock_irq(&phba->hbalock); |
| 1956 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1957 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1958 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1959 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1960 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1962 | "3143 Port Down: Firmware Update " |
| 1963 | "Detected\n"); |
| 1964 | en_rn_msg = false; |
| 1965 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1966 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1968 | "3144 Port Down: Debug Dump\n"); |
| 1969 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1970 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1972 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1973 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1974 | /* If resets are disabled then leave the HBA alone and return */ |
| 1975 | if (!phba->cfg_enable_hba_reset) |
| 1976 | return; |
| 1977 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1978 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1979 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1980 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1981 | if (rc == 0) { |
| 1982 | /* don't report event on forced debug dump */ |
| 1983 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1984 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1985 | return; |
| 1986 | else |
| 1987 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1988 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1989 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1991 | "3152 Unrecoverable error, bring the port " |
| 1992 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1993 | lpfc_sli4_offline_eratt(phba); |
| 1994 | break; |
| 1995 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1996 | default: |
| 1997 | break; |
| 1998 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1999 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2000 | "3123 Report dump event to upper layer\n"); |
| 2001 | /* Send an internal error event to mgmt application */ |
| 2002 | lpfc_board_errevt_to_mgmt(phba); |
| 2003 | |
| 2004 | event_data = FC_REG_DUMP_EVENT; |
| 2005 | shost = lpfc_shost_from_vport(vport); |
| 2006 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2007 | sizeof(event_data), (char *) &event_data, |
| 2008 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2013 | * @phba: pointer to lpfc HBA data structure. |
| 2014 | * |
| 2015 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2016 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2017 | * |
| 2018 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2019 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2020 | * Any other value - error. |
| 2021 | **/ |
| 2022 | void |
| 2023 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2024 | { |
| 2025 | (*phba->lpfc_handle_eratt)(phba); |
| 2026 | } |
| 2027 | |
| 2028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2029 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2030 | * @phba: pointer to lpfc hba data structure. |
| 2031 | * |
| 2032 | * 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] | 2033 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2034 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2035 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2036 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | struct lpfc_vport *vport = phba->pport; |
| 2039 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2040 | LPFC_MBOXQ_t *pmb; |
| 2041 | volatile uint32_t control; |
| 2042 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2043 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2044 | |
| 2045 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2046 | if (!pmb) { |
| 2047 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2048 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2049 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | |
| 2051 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2052 | if (!mp) { |
| 2053 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2055 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | |
| 2057 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2058 | if (!mp->virt) { |
| 2059 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2061 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2063 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2064 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | |
| 2066 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2067 | lpfc_read_topology(phba, pmb, mp); |
| 2068 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2070 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2071 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2072 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2073 | if (rc == MBX_NOT_FINISHED) { |
| 2074 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2075 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2076 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | |
| 2078 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | writel(HA_LATT, phba->HAregaddr); |
| 2081 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | |
| 2084 | return; |
| 2085 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2086 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2087 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2088 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | lpfc_handle_latt_free_mp: |
| 2090 | kfree(mp); |
| 2091 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2092 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | lpfc_handle_latt_err_exit: |
| 2094 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2095 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2097 | control = readl(phba->HCregaddr); |
| 2098 | control |= HC_LAINT_ENA; |
| 2099 | writel(control, phba->HCregaddr); |
| 2100 | readl(phba->HCregaddr); /* flush */ |
| 2101 | |
| 2102 | /* Clear Link Attention in HA REG */ |
| 2103 | writel(HA_LATT, phba->HAregaddr); |
| 2104 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2105 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2109 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2110 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2111 | |
| 2112 | return; |
| 2113 | } |
| 2114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2116 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2117 | * @phba: pointer to lpfc hba data structure. |
| 2118 | * @vpd: pointer to the vital product data. |
| 2119 | * @len: length of the vital product data in bytes. |
| 2120 | * |
| 2121 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2122 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2123 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2124 | * |
| 2125 | * Return codes |
| 2126 | * 0 - pointer to the VPD passed in is NULL |
| 2127 | * 1 - success |
| 2128 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2129 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2130 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | { |
| 2132 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2133 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | int i, j; |
| 2135 | int finished = 0; |
| 2136 | int index = 0; |
| 2137 | |
| 2138 | if (!vpd) |
| 2139 | return 0; |
| 2140 | |
| 2141 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2142 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2143 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2145 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2146 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | switch (vpd[index]) { |
| 2148 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2149 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | index += 1; |
| 2151 | lenlo = vpd[index]; |
| 2152 | index += 1; |
| 2153 | lenhi = vpd[index]; |
| 2154 | index += 1; |
| 2155 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2156 | index += i; |
| 2157 | break; |
| 2158 | case 0x90: |
| 2159 | index += 1; |
| 2160 | lenlo = vpd[index]; |
| 2161 | index += 1; |
| 2162 | lenhi = vpd[index]; |
| 2163 | index += 1; |
| 2164 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2165 | if (Length > len - index) |
| 2166 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | while (Length > 0) { |
| 2168 | /* Look for Serial Number */ |
| 2169 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2170 | index += 2; |
| 2171 | i = vpd[index]; |
| 2172 | index += 1; |
| 2173 | j = 0; |
| 2174 | Length -= (3+i); |
| 2175 | while(i--) { |
| 2176 | phba->SerialNumber[j++] = vpd[index++]; |
| 2177 | if (j == 31) |
| 2178 | break; |
| 2179 | } |
| 2180 | phba->SerialNumber[j] = 0; |
| 2181 | continue; |
| 2182 | } |
| 2183 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2184 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2185 | index += 2; |
| 2186 | i = vpd[index]; |
| 2187 | index += 1; |
| 2188 | j = 0; |
| 2189 | Length -= (3+i); |
| 2190 | while(i--) { |
| 2191 | phba->ModelDesc[j++] = vpd[index++]; |
| 2192 | if (j == 255) |
| 2193 | break; |
| 2194 | } |
| 2195 | phba->ModelDesc[j] = 0; |
| 2196 | continue; |
| 2197 | } |
| 2198 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2199 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2200 | index += 2; |
| 2201 | i = vpd[index]; |
| 2202 | index += 1; |
| 2203 | j = 0; |
| 2204 | Length -= (3+i); |
| 2205 | while(i--) { |
| 2206 | phba->ModelName[j++] = vpd[index++]; |
| 2207 | if (j == 79) |
| 2208 | break; |
| 2209 | } |
| 2210 | phba->ModelName[j] = 0; |
| 2211 | continue; |
| 2212 | } |
| 2213 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2214 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2215 | index += 2; |
| 2216 | i = vpd[index]; |
| 2217 | index += 1; |
| 2218 | j = 0; |
| 2219 | Length -= (3+i); |
| 2220 | while(i--) { |
| 2221 | phba->ProgramType[j++] = vpd[index++]; |
| 2222 | if (j == 255) |
| 2223 | break; |
| 2224 | } |
| 2225 | phba->ProgramType[j] = 0; |
| 2226 | continue; |
| 2227 | } |
| 2228 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2229 | phba->vpd_flag |= VPD_PORT; |
| 2230 | index += 2; |
| 2231 | i = vpd[index]; |
| 2232 | index += 1; |
| 2233 | j = 0; |
| 2234 | Length -= (3+i); |
| 2235 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2236 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2237 | (phba->sli4_hba.pport_name_sta == |
| 2238 | LPFC_SLI4_PPNAME_GET)) { |
| 2239 | j++; |
| 2240 | index++; |
| 2241 | } else |
| 2242 | phba->Port[j++] = vpd[index++]; |
| 2243 | if (j == 19) |
| 2244 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2246 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2247 | (phba->sli4_hba.pport_name_sta == |
| 2248 | LPFC_SLI4_PPNAME_NON)) |
| 2249 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | continue; |
| 2251 | } |
| 2252 | else { |
| 2253 | index += 2; |
| 2254 | i = vpd[index]; |
| 2255 | index += 1; |
| 2256 | index += i; |
| 2257 | Length -= (3 + i); |
| 2258 | } |
| 2259 | } |
| 2260 | finished = 0; |
| 2261 | break; |
| 2262 | case 0x78: |
| 2263 | finished = 1; |
| 2264 | break; |
| 2265 | default: |
| 2266 | index ++; |
| 2267 | break; |
| 2268 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2270 | |
| 2271 | return(1); |
| 2272 | } |
| 2273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2275 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2276 | * @phba: pointer to lpfc hba data structure. |
| 2277 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2278 | * @descp: pointer to the data structure to hold the derived description. |
| 2279 | * |
| 2280 | * This routine retrieves HBA's description based on its registered PCI device |
| 2281 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2282 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2283 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2284 | * function returns, the @mdp will be filled with the model name. |
| 2285 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2287 | 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] | 2288 | { |
| 2289 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2290 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2291 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2292 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2293 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2294 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2295 | char *name; |
| 2296 | char *bus; |
| 2297 | char *function; |
| 2298 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2299 | |
| 2300 | if (mdp && mdp[0] != '\0' |
| 2301 | && descp && descp[0] != '\0') |
| 2302 | return; |
| 2303 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2304 | if (phba->lmt & LMT_64Gb) |
| 2305 | max_speed = 64; |
| 2306 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2307 | max_speed = 32; |
| 2308 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2309 | max_speed = 16; |
| 2310 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2311 | max_speed = 10; |
| 2312 | else if (phba->lmt & LMT_8Gb) |
| 2313 | max_speed = 8; |
| 2314 | else if (phba->lmt & LMT_4Gb) |
| 2315 | max_speed = 4; |
| 2316 | else if (phba->lmt & LMT_2Gb) |
| 2317 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2318 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2319 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2320 | else |
| 2321 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | |
| 2323 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2325 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2326 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2327 | m = (typeof(m)){"LP6000", "PCI", |
| 2328 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2329 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | case PCI_DEVICE_ID_SUPERFLY: |
| 2331 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2332 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2334 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2335 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | break; |
| 2337 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2338 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2339 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | break; |
| 2341 | case PCI_DEVICE_ID_CENTAUR: |
| 2342 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2343 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2345 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2346 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2347 | break; |
| 2348 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2349 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2350 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | break; |
| 2352 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2353 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2354 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | break; |
| 2356 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2357 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2358 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | break; |
| 2360 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2361 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2362 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | break; |
| 2364 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2365 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2366 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | break; |
| 2368 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2369 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2370 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | break; |
| 2372 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2373 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2374 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2376 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2377 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2378 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2381 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2382 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2383 | break; |
| 2384 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2385 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2386 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2387 | break; |
| 2388 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2389 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2390 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2391 | break; |
| 2392 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2393 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2394 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2395 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2396 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2397 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | break; |
| 2399 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2400 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2401 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | break; |
| 2403 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2404 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2406 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2407 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2408 | break; |
| 2409 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2410 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2411 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2412 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2413 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2414 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | break; |
| 2416 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2417 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | break; |
| 2419 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2420 | m = (typeof(m)){"LP101", "PCI-X", |
| 2421 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | break; |
| 2423 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2424 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2425 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2426 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2427 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2428 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2429 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2430 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2431 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2432 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2433 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2434 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2435 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2436 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2437 | break; |
| 2438 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2439 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2440 | break; |
| 2441 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2442 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2443 | break; |
| 2444 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2445 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2446 | break; |
| 2447 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2448 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2449 | break; |
| 2450 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2451 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2452 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2453 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2454 | m = (typeof(m)){"LP21000", "PCIe", |
| 2455 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2456 | GE = 1; |
| 2457 | break; |
| 2458 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2459 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2460 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2461 | break; |
| 2462 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2463 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2464 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2465 | break; |
| 2466 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2467 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2468 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2469 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2470 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2471 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2472 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2473 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2474 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2475 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2476 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2477 | break; |
| 2478 | case PCI_DEVICE_ID_FALCON: |
| 2479 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2480 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2481 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2482 | case PCI_DEVICE_ID_BALIUS: |
| 2483 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2484 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2485 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2486 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2487 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2488 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2489 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2490 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2491 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2492 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2493 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2494 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2495 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2496 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2497 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2498 | oneConnect = 1; |
| 2499 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2500 | "Obsolete, Unsupported FCoE"}; |
| 2501 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2502 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2503 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2504 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2505 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2506 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2507 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2508 | case PCI_DEVICE_ID_SKYHAWK: |
| 2509 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2510 | oneConnect = 1; |
| 2511 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2512 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2513 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2514 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2515 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2516 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2517 | |
| 2518 | if (mdp && mdp[0] == '\0') |
| 2519 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2520 | /* |
| 2521 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2522 | * and we put the port number on the end |
| 2523 | */ |
| 2524 | if (descp && descp[0] == '\0') { |
| 2525 | if (oneConnect) |
| 2526 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2527 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2528 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2529 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2530 | else if (max_speed == 0) |
| 2531 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2532 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2533 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2534 | else |
| 2535 | snprintf(descp, 255, |
| 2536 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2537 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2538 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2539 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | } |
| 2541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2543 | * 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] | 2544 | * @phba: pointer to lpfc hba data structure. |
| 2545 | * @pring: pointer to a IOCB ring. |
| 2546 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2547 | * |
| 2548 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2549 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2550 | * |
| 2551 | * Return codes |
| 2552 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2553 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2554 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2555 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | { |
| 2557 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2558 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2559 | struct lpfc_dmabuf *mp1, *mp2; |
| 2560 | |
| 2561 | cnt += pring->missbufcnt; |
| 2562 | |
| 2563 | /* While there are buffers to post */ |
| 2564 | while (cnt > 0) { |
| 2565 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2566 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2567 | if (iocb == NULL) { |
| 2568 | pring->missbufcnt = cnt; |
| 2569 | return cnt; |
| 2570 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | icmd = &iocb->iocb; |
| 2572 | |
| 2573 | /* 2 buffers can be posted per command */ |
| 2574 | /* Allocate buffer to post */ |
| 2575 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2576 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2577 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2578 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2579 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2580 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | pring->missbufcnt = cnt; |
| 2582 | return cnt; |
| 2583 | } |
| 2584 | |
| 2585 | INIT_LIST_HEAD(&mp1->list); |
| 2586 | /* Allocate buffer to post */ |
| 2587 | if (cnt > 1) { |
| 2588 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2589 | if (mp2) |
| 2590 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2591 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2592 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2593 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2594 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2595 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2596 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | pring->missbufcnt = cnt; |
| 2598 | return cnt; |
| 2599 | } |
| 2600 | |
| 2601 | INIT_LIST_HEAD(&mp2->list); |
| 2602 | } else { |
| 2603 | mp2 = NULL; |
| 2604 | } |
| 2605 | |
| 2606 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2607 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2608 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2609 | icmd->ulpBdeCount = 1; |
| 2610 | cnt--; |
| 2611 | if (mp2) { |
| 2612 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2613 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2614 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2615 | cnt--; |
| 2616 | icmd->ulpBdeCount = 2; |
| 2617 | } |
| 2618 | |
| 2619 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2620 | icmd->ulpLe = 1; |
| 2621 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2622 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2623 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2625 | kfree(mp1); |
| 2626 | cnt++; |
| 2627 | if (mp2) { |
| 2628 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2629 | kfree(mp2); |
| 2630 | cnt++; |
| 2631 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2632 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | return cnt; |
| 2635 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2637 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | } |
| 2640 | pring->missbufcnt = 0; |
| 2641 | return 0; |
| 2642 | } |
| 2643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2644 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2645 | * 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] | 2646 | * @phba: pointer to lpfc hba data structure. |
| 2647 | * |
| 2648 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2649 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2650 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2651 | * |
| 2652 | * Return codes |
| 2653 | * 0 - success (currently always success) |
| 2654 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2656 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | { |
| 2658 | struct lpfc_sli *psli = &phba->sli; |
| 2659 | |
| 2660 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2661 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | /* Ring 2 - FCP no buffers needed */ |
| 2663 | |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
| 2667 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2669 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2670 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2671 | * @HashResultPointer: pointer to an array as hash table. |
| 2672 | * |
| 2673 | * This routine sets up the initial values to the array of hash table entries |
| 2674 | * for the LC HBAs. |
| 2675 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2676 | static void |
| 2677 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2678 | { |
| 2679 | HashResultPointer[0] = 0x67452301; |
| 2680 | HashResultPointer[1] = 0xEFCDAB89; |
| 2681 | HashResultPointer[2] = 0x98BADCFE; |
| 2682 | HashResultPointer[3] = 0x10325476; |
| 2683 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2684 | } |
| 2685 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2687 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2688 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2689 | * @HashWorkingPointer: pointer to an working hash table. |
| 2690 | * |
| 2691 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2692 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2693 | * The results are putting back to the initial hash table, returned through |
| 2694 | * the @HashResultPointer as the result hash table. |
| 2695 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | static void |
| 2697 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2698 | { |
| 2699 | int t; |
| 2700 | uint32_t TEMP; |
| 2701 | uint32_t A, B, C, D, E; |
| 2702 | t = 16; |
| 2703 | do { |
| 2704 | HashWorkingPointer[t] = |
| 2705 | S(1, |
| 2706 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2707 | 8] ^ |
| 2708 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2709 | } while (++t <= 79); |
| 2710 | t = 0; |
| 2711 | A = HashResultPointer[0]; |
| 2712 | B = HashResultPointer[1]; |
| 2713 | C = HashResultPointer[2]; |
| 2714 | D = HashResultPointer[3]; |
| 2715 | E = HashResultPointer[4]; |
| 2716 | |
| 2717 | do { |
| 2718 | if (t < 20) { |
| 2719 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2720 | } else if (t < 40) { |
| 2721 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2722 | } else if (t < 60) { |
| 2723 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2724 | } else { |
| 2725 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2726 | } |
| 2727 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2728 | E = D; |
| 2729 | D = C; |
| 2730 | C = S(30, B); |
| 2731 | B = A; |
| 2732 | A = TEMP; |
| 2733 | } while (++t <= 79); |
| 2734 | |
| 2735 | HashResultPointer[0] += A; |
| 2736 | HashResultPointer[1] += B; |
| 2737 | HashResultPointer[2] += C; |
| 2738 | HashResultPointer[3] += D; |
| 2739 | HashResultPointer[4] += E; |
| 2740 | |
| 2741 | } |
| 2742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2744 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2745 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2746 | * @HashWorking: pointer to the entry of the working hash array. |
| 2747 | * |
| 2748 | * This routine calculates the working hash array referred by @HashWorking |
| 2749 | * from the challenge random numbers associated with the host, referred by |
| 2750 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2751 | * array and returned by reference through @HashWorking. |
| 2752 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | static void |
| 2754 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2755 | { |
| 2756 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2757 | } |
| 2758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2760 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | * @phba: pointer to lpfc hba data structure. |
| 2762 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2763 | * |
| 2764 | * This routine performs the special handling for LC HBA initialization. |
| 2765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | void |
| 2767 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2768 | { |
| 2769 | int t; |
| 2770 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2771 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2773 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | if (!HashWorking) |
| 2775 | return; |
| 2776 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2777 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2778 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2779 | |
| 2780 | for (t = 0; t < 7; t++) |
| 2781 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2782 | |
| 2783 | lpfc_sha_init(hbainit); |
| 2784 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2785 | kfree(HashWorking); |
| 2786 | } |
| 2787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2789 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2790 | * @vport: pointer to a virtual N_Port data structure. |
| 2791 | * |
| 2792 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2793 | * It invokes the discovery state machine to perform necessary state |
| 2794 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2795 | * the physical port is treated as @vport 0. |
| 2796 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2797 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2798 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2800 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2802 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2804 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2805 | lpfc_port_link_failure(vport); |
| 2806 | |
| 2807 | 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] | 2808 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2809 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2810 | NLP_STE_UNUSED_NODE); |
| 2811 | if (!ndlp) |
| 2812 | continue; |
| 2813 | spin_lock_irq(&phba->ndlp_lock); |
| 2814 | NLP_SET_FREE_REQ(ndlp); |
| 2815 | spin_unlock_irq(&phba->ndlp_lock); |
| 2816 | /* Trigger the release of the ndlp memory */ |
| 2817 | lpfc_nlp_put(ndlp); |
| 2818 | continue; |
| 2819 | } |
| 2820 | spin_lock_irq(&phba->ndlp_lock); |
| 2821 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2822 | /* The ndlp should not be in memory free mode already */ |
| 2823 | spin_unlock_irq(&phba->ndlp_lock); |
| 2824 | continue; |
| 2825 | } else |
| 2826 | /* Indicate request for freeing ndlp memory */ |
| 2827 | NLP_SET_FREE_REQ(ndlp); |
| 2828 | spin_unlock_irq(&phba->ndlp_lock); |
| 2829 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2830 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2831 | ndlp->nlp_DID == Fabric_DID) { |
| 2832 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2833 | lpfc_nlp_put(ndlp); |
| 2834 | continue; |
| 2835 | } |
| 2836 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2837 | /* take care of nodes in unused state before the state |
| 2838 | * machine taking action. |
| 2839 | */ |
| 2840 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2841 | lpfc_nlp_put(ndlp); |
| 2842 | continue; |
| 2843 | } |
| 2844 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2845 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2846 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2847 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2848 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2849 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2850 | NLP_EVT_DEVICE_RM); |
| 2851 | } |
| 2852 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2853 | /* At this point, ALL ndlp's should be gone |
| 2854 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2855 | * Lets wait for this to happen, if needed. |
| 2856 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2857 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2858 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2859 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2860 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2861 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2862 | &vport->fc_nodes, nlp_listp) { |
| 2863 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2864 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2865 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2866 | "usgmap:x%x refcnt:%d\n", |
| 2867 | ndlp->nlp_DID, (void *)ndlp, |
| 2868 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2869 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2870 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2871 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2872 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2873 | |
| 2874 | /* Wait for any activity on ndlps to settle */ |
| 2875 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2876 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2877 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | } |
| 2879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2880 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2881 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2882 | * @vport: pointer to a virtual N_Port data structure. |
| 2883 | * |
| 2884 | * This routine stops all the timers associated with a @vport. This function |
| 2885 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2886 | * port is treated as @vport 0. |
| 2887 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2888 | void |
| 2889 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2890 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2891 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2892 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2893 | lpfc_can_disctmo(vport); |
| 2894 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | } |
| 2896 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2897 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2898 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2899 | * @phba: pointer to lpfc hba data structure. |
| 2900 | * |
| 2901 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2902 | * caller of this routine should already hold the host lock. |
| 2903 | **/ |
| 2904 | void |
| 2905 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2906 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2907 | /* Clear pending FCF rediscovery wait flag */ |
| 2908 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2909 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2910 | /* Now, try to stop the timer */ |
| 2911 | del_timer(&phba->fcf.redisc_wait); |
| 2912 | } |
| 2913 | |
| 2914 | /** |
| 2915 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2916 | * @phba: pointer to lpfc hba data structure. |
| 2917 | * |
| 2918 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2919 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2920 | * lock held before proceeding with disabling the timer and clearing the |
| 2921 | * wait timer pendig flag. |
| 2922 | **/ |
| 2923 | void |
| 2924 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2925 | { |
| 2926 | spin_lock_irq(&phba->hbalock); |
| 2927 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2928 | /* FCF rediscovery timer already fired or stopped */ |
| 2929 | spin_unlock_irq(&phba->hbalock); |
| 2930 | return; |
| 2931 | } |
| 2932 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2933 | /* Clear failover in progress flags */ |
| 2934 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2935 | spin_unlock_irq(&phba->hbalock); |
| 2936 | } |
| 2937 | |
| 2938 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2939 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2940 | * @phba: pointer to lpfc hba data structure. |
| 2941 | * |
| 2942 | * This routine stops all the timers associated with a HBA. This function is |
| 2943 | * invoked before either putting a HBA offline or unloading the driver. |
| 2944 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2945 | void |
| 2946 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 2948 | if (phba->pport) |
| 2949 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 2950 | cancel_delayed_work_sync(&phba->eq_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2951 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2952 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2953 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2954 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2955 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2956 | del_timer_sync(&phba->rrq_tmr); |
| 2957 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2958 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2959 | phba->hb_outstanding = 0; |
| 2960 | |
| 2961 | switch (phba->pci_dev_grp) { |
| 2962 | case LPFC_PCI_DEV_LP: |
| 2963 | /* Stop any LightPulse device specific driver timers */ |
| 2964 | del_timer_sync(&phba->fcp_poll_timer); |
| 2965 | break; |
| 2966 | case LPFC_PCI_DEV_OC: |
| 2967 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2968 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2969 | break; |
| 2970 | default: |
| 2971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2972 | "0297 Invalid device group (x%x)\n", |
| 2973 | phba->pci_dev_grp); |
| 2974 | break; |
| 2975 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | } |
| 2978 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2979 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2980 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2981 | * @phba: pointer to lpfc hba data structure. |
| 2982 | * |
| 2983 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2984 | * management interface is marked as blocked, all the user space access to |
| 2985 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2986 | * all be blocked. The HBA is set to block the management interface when the |
| 2987 | * driver prepares the HBA interface for online or offline. |
| 2988 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2989 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2990 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2991 | { |
| 2992 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2993 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2994 | unsigned long timeout; |
| 2995 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2996 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2997 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2998 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2999 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3000 | return; |
| 3001 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3002 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3003 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3004 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3005 | /* Determine how long we might wait for the active mailbox |
| 3006 | * command to be gracefully completed by firmware. |
| 3007 | */ |
| 3008 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3009 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3010 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3011 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3012 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3013 | /* Wait for the outstnading mailbox command to complete */ |
| 3014 | while (phba->sli.mbox_active) { |
| 3015 | /* Check active mailbox complete status every 2ms */ |
| 3016 | msleep(2); |
| 3017 | if (time_after(jiffies, timeout)) { |
| 3018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3019 | "2813 Mgmt IO is Blocked %x " |
| 3020 | "- mbox cmd %x still active\n", |
| 3021 | phba->sli.sli_flag, actcmd); |
| 3022 | break; |
| 3023 | } |
| 3024 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3027 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3028 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3029 | * @phba: pointer to lpfc hba data structure. |
| 3030 | * |
| 3031 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3032 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3033 | * is to fixup the temporary rpi assignments. |
| 3034 | **/ |
| 3035 | void |
| 3036 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3037 | { |
| 3038 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3039 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3040 | int i, rpi; |
| 3041 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3042 | |
| 3043 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3044 | return; |
| 3045 | |
| 3046 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3047 | if (vports == NULL) |
| 3048 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3049 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3050 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3051 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3052 | continue; |
| 3053 | |
| 3054 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3055 | &vports[i]->fc_nodes, |
| 3056 | nlp_listp) { |
| 3057 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3058 | continue; |
| 3059 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3060 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3061 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3062 | NLP_CLR_NODE_ACT(ndlp); |
| 3063 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3064 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3065 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3066 | ndlp->nlp_rpi = rpi; |
| 3067 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3068 | "0009 rpi:%x DID:%x " |
| 3069 | "flg:%x map:%x %p\n", ndlp->nlp_rpi, |
| 3070 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3071 | ndlp->nlp_usg_map, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3072 | } |
| 3073 | } |
| 3074 | lpfc_destroy_vport_work_array(phba, vports); |
| 3075 | } |
| 3076 | |
| 3077 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3078 | * lpfc_create_expedite_pool - create expedite pool |
| 3079 | * @phba: pointer to lpfc hba data structure. |
| 3080 | * |
| 3081 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3082 | * to expedite pool. Mark them as expedite. |
| 3083 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3084 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3085 | { |
| 3086 | struct lpfc_sli4_hdw_queue *qp; |
| 3087 | struct lpfc_io_buf *lpfc_ncmd; |
| 3088 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3089 | struct lpfc_epd_pool *epd_pool; |
| 3090 | unsigned long iflag; |
| 3091 | |
| 3092 | epd_pool = &phba->epd_pool; |
| 3093 | qp = &phba->sli4_hba.hdwq[0]; |
| 3094 | |
| 3095 | spin_lock_init(&epd_pool->lock); |
| 3096 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3097 | spin_lock(&epd_pool->lock); |
| 3098 | INIT_LIST_HEAD(&epd_pool->list); |
| 3099 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3100 | &qp->lpfc_io_buf_list_put, list) { |
| 3101 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3102 | lpfc_ncmd->expedite = true; |
| 3103 | qp->put_io_bufs--; |
| 3104 | epd_pool->count++; |
| 3105 | if (epd_pool->count >= XRI_BATCH) |
| 3106 | break; |
| 3107 | } |
| 3108 | spin_unlock(&epd_pool->lock); |
| 3109 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3110 | } |
| 3111 | |
| 3112 | /** |
| 3113 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3114 | * @phba: pointer to lpfc hba data structure. |
| 3115 | * |
| 3116 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3117 | * of HWQ 0. Clear the mark. |
| 3118 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3119 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3120 | { |
| 3121 | struct lpfc_sli4_hdw_queue *qp; |
| 3122 | struct lpfc_io_buf *lpfc_ncmd; |
| 3123 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3124 | struct lpfc_epd_pool *epd_pool; |
| 3125 | unsigned long iflag; |
| 3126 | |
| 3127 | epd_pool = &phba->epd_pool; |
| 3128 | qp = &phba->sli4_hba.hdwq[0]; |
| 3129 | |
| 3130 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3131 | spin_lock(&epd_pool->lock); |
| 3132 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3133 | &epd_pool->list, list) { |
| 3134 | list_move_tail(&lpfc_ncmd->list, |
| 3135 | &qp->lpfc_io_buf_list_put); |
| 3136 | lpfc_ncmd->flags = false; |
| 3137 | qp->put_io_bufs++; |
| 3138 | epd_pool->count--; |
| 3139 | } |
| 3140 | spin_unlock(&epd_pool->lock); |
| 3141 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3146 | * @phba: pointer to lpfc hba data structure. |
| 3147 | * |
| 3148 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3149 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3150 | * Initialized. |
| 3151 | **/ |
| 3152 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3153 | { |
| 3154 | u32 i, j; |
| 3155 | u32 hwq_count; |
| 3156 | u32 count_per_hwq; |
| 3157 | struct lpfc_io_buf *lpfc_ncmd; |
| 3158 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3159 | unsigned long iflag; |
| 3160 | struct lpfc_sli4_hdw_queue *qp; |
| 3161 | struct lpfc_multixri_pool *multixri_pool; |
| 3162 | struct lpfc_pbl_pool *pbl_pool; |
| 3163 | struct lpfc_pvt_pool *pvt_pool; |
| 3164 | |
| 3165 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3166 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3167 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3168 | phba->sli4_hba.io_xri_cnt); |
| 3169 | |
| 3170 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3171 | lpfc_create_expedite_pool(phba); |
| 3172 | |
| 3173 | hwq_count = phba->cfg_hdw_queue; |
| 3174 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3175 | |
| 3176 | for (i = 0; i < hwq_count; i++) { |
| 3177 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3178 | |
| 3179 | if (!multixri_pool) { |
| 3180 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3181 | "1238 Failed to allocate memory for " |
| 3182 | "multixri_pool\n"); |
| 3183 | |
| 3184 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3185 | lpfc_destroy_expedite_pool(phba); |
| 3186 | |
| 3187 | j = 0; |
| 3188 | while (j < i) { |
| 3189 | qp = &phba->sli4_hba.hdwq[j]; |
| 3190 | kfree(qp->p_multixri_pool); |
| 3191 | j++; |
| 3192 | } |
| 3193 | phba->cfg_xri_rebalancing = 0; |
| 3194 | return; |
| 3195 | } |
| 3196 | |
| 3197 | qp = &phba->sli4_hba.hdwq[i]; |
| 3198 | qp->p_multixri_pool = multixri_pool; |
| 3199 | |
| 3200 | multixri_pool->xri_limit = count_per_hwq; |
| 3201 | multixri_pool->rrb_next_hwqid = i; |
| 3202 | |
| 3203 | /* Deal with public free xri pool */ |
| 3204 | pbl_pool = &multixri_pool->pbl_pool; |
| 3205 | spin_lock_init(&pbl_pool->lock); |
| 3206 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3207 | spin_lock(&pbl_pool->lock); |
| 3208 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3209 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3210 | &qp->lpfc_io_buf_list_put, list) { |
| 3211 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3212 | qp->put_io_bufs--; |
| 3213 | pbl_pool->count++; |
| 3214 | } |
| 3215 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3216 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3217 | pbl_pool->count, i); |
| 3218 | spin_unlock(&pbl_pool->lock); |
| 3219 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3220 | |
| 3221 | /* Deal with private free xri pool */ |
| 3222 | pvt_pool = &multixri_pool->pvt_pool; |
| 3223 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3224 | pvt_pool->low_watermark = XRI_BATCH; |
| 3225 | spin_lock_init(&pvt_pool->lock); |
| 3226 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3227 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3228 | pvt_pool->count = 0; |
| 3229 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | /** |
| 3234 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3235 | * @phba: pointer to lpfc hba data structure. |
| 3236 | * |
| 3237 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3238 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3239 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3240 | { |
| 3241 | u32 i; |
| 3242 | u32 hwq_count; |
| 3243 | struct lpfc_io_buf *lpfc_ncmd; |
| 3244 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3245 | unsigned long iflag; |
| 3246 | struct lpfc_sli4_hdw_queue *qp; |
| 3247 | struct lpfc_multixri_pool *multixri_pool; |
| 3248 | struct lpfc_pbl_pool *pbl_pool; |
| 3249 | struct lpfc_pvt_pool *pvt_pool; |
| 3250 | |
| 3251 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3252 | lpfc_destroy_expedite_pool(phba); |
| 3253 | |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3254 | if (!(phba->pport->load_flag & FC_UNLOADING)) { |
| 3255 | lpfc_sli_flush_fcp_rings(phba); |
| 3256 | |
| 3257 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3258 | lpfc_sli_flush_nvme_rings(phba); |
| 3259 | } |
| 3260 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3261 | hwq_count = phba->cfg_hdw_queue; |
| 3262 | |
| 3263 | for (i = 0; i < hwq_count; i++) { |
| 3264 | qp = &phba->sli4_hba.hdwq[i]; |
| 3265 | multixri_pool = qp->p_multixri_pool; |
| 3266 | if (!multixri_pool) |
| 3267 | continue; |
| 3268 | |
| 3269 | qp->p_multixri_pool = NULL; |
| 3270 | |
| 3271 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3272 | |
| 3273 | /* Deal with public free xri pool */ |
| 3274 | pbl_pool = &multixri_pool->pbl_pool; |
| 3275 | spin_lock(&pbl_pool->lock); |
| 3276 | |
| 3277 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3278 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3279 | pbl_pool->count, i); |
| 3280 | |
| 3281 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3282 | &pbl_pool->list, list) { |
| 3283 | list_move_tail(&lpfc_ncmd->list, |
| 3284 | &qp->lpfc_io_buf_list_put); |
| 3285 | qp->put_io_bufs++; |
| 3286 | pbl_pool->count--; |
| 3287 | } |
| 3288 | |
| 3289 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3290 | pbl_pool->count = 0; |
| 3291 | |
| 3292 | spin_unlock(&pbl_pool->lock); |
| 3293 | |
| 3294 | /* Deal with private free xri pool */ |
| 3295 | pvt_pool = &multixri_pool->pvt_pool; |
| 3296 | spin_lock(&pvt_pool->lock); |
| 3297 | |
| 3298 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3299 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3300 | pvt_pool->count, i); |
| 3301 | |
| 3302 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3303 | &pvt_pool->list, list) { |
| 3304 | list_move_tail(&lpfc_ncmd->list, |
| 3305 | &qp->lpfc_io_buf_list_put); |
| 3306 | qp->put_io_bufs++; |
| 3307 | pvt_pool->count--; |
| 3308 | } |
| 3309 | |
| 3310 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3311 | pvt_pool->count = 0; |
| 3312 | |
| 3313 | spin_unlock(&pvt_pool->lock); |
| 3314 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3315 | |
| 3316 | kfree(multixri_pool); |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3321 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3322 | * @phba: pointer to lpfc hba data structure. |
| 3323 | * |
| 3324 | * This routine initializes the HBA and brings a HBA online. During this |
| 3325 | * process, the management interface is blocked to prevent user space access |
| 3326 | * to the HBA interfering with the driver initialization. |
| 3327 | * |
| 3328 | * Return codes |
| 3329 | * 0 - successful |
| 3330 | * 1 - failed |
| 3331 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3333 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3335 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3336 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3337 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3338 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | if (!phba) |
| 3341 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3342 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3343 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | return 0; |
| 3346 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3347 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3348 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3349 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3350 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3352 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3353 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3354 | lpfc_unblock_mgmt_io(phba); |
| 3355 | return 1; |
| 3356 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3357 | spin_lock_irq(&phba->hbalock); |
| 3358 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3359 | vpis_cleared = true; |
| 3360 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3361 | |
| 3362 | /* Reestablish the local initiator port. |
| 3363 | * The offline process destroyed the previous lport. |
| 3364 | */ |
| 3365 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3366 | !phba->nvmet_support) { |
| 3367 | error = lpfc_nvme_create_localport(phba->pport); |
| 3368 | if (error) |
| 3369 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3370 | "6132 NVME restore reg failed " |
| 3371 | "on nvmei error x%x\n", error); |
| 3372 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3373 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3374 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3375 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3376 | lpfc_unblock_mgmt_io(phba); |
| 3377 | return 1; |
| 3378 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3379 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3381 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3382 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3383 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3384 | struct Scsi_Host *shost; |
| 3385 | shost = lpfc_shost_from_vport(vports[i]); |
| 3386 | spin_lock_irq(shost->host_lock); |
| 3387 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3388 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3389 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3390 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3391 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3392 | if ((vpis_cleared) && |
| 3393 | (vports[i]->port_type != |
| 3394 | LPFC_PHYSICAL_PORT)) |
| 3395 | vports[i]->vpi = 0; |
| 3396 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3397 | spin_unlock_irq(shost->host_lock); |
| 3398 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3399 | } |
| 3400 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3402 | if (phba->cfg_xri_rebalancing) |
| 3403 | lpfc_create_multixri_pools(phba); |
| 3404 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3405 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | return 0; |
| 3407 | } |
| 3408 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3409 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3410 | * 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] | 3411 | * @phba: pointer to lpfc hba data structure. |
| 3412 | * |
| 3413 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3414 | * HBA's management interface is marked as not blocked, all the user space |
| 3415 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3416 | * interface will be allowed. The HBA is set to block the management interface |
| 3417 | * when the driver prepares the HBA interface for online or offline and then |
| 3418 | * set to unblock the management interface afterwards. |
| 3419 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3420 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3421 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3422 | { |
| 3423 | unsigned long iflag; |
| 3424 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3426 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3427 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3428 | } |
| 3429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3430 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3431 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3432 | * @phba: pointer to lpfc hba data structure. |
| 3433 | * |
| 3434 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3435 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3436 | * queue to make it ready to be brought offline. |
| 3437 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3438 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3439 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3440 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3441 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3442 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3443 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3444 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3445 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3447 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3448 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3450 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | |
| 3452 | lpfc_linkdown(phba); |
| 3453 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3454 | /* Issue an unreg_login to all nodes on all vports */ |
| 3455 | vports = lpfc_create_vport_work_array(phba); |
| 3456 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3457 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3458 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3459 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3460 | shost = lpfc_shost_from_vport(vports[i]); |
| 3461 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3462 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3463 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3464 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3465 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3466 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3467 | shost = lpfc_shost_from_vport(vports[i]); |
| 3468 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3469 | &vports[i]->fc_nodes, |
| 3470 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3471 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3472 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3473 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3474 | continue; |
| 3475 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3476 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3477 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3478 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3479 | NULL, NLP_EVT_DEVICE_RM); |
| 3480 | } |
| 3481 | spin_lock_irq(shost->host_lock); |
| 3482 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3483 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3484 | /* |
| 3485 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3486 | * RPI. Get a new RPI when the adapter port |
| 3487 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3488 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3489 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3490 | lpfc_printf_vlog(ndlp->vport, |
| 3491 | KERN_INFO, LOG_NODE, |
| 3492 | "0011 lpfc_offline: " |
| 3493 | "ndlp:x%p did %x " |
| 3494 | "usgmap:x%x rpi:%x\n", |
| 3495 | ndlp, ndlp->nlp_DID, |
| 3496 | ndlp->nlp_usg_map, |
| 3497 | ndlp->nlp_rpi); |
| 3498 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3499 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3500 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3501 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3502 | } |
| 3503 | } |
| 3504 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3505 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3506 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3507 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3508 | |
| 3509 | if (phba->wq) |
| 3510 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3511 | } |
| 3512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3513 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3514 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3515 | * @phba: pointer to lpfc hba data structure. |
| 3516 | * |
| 3517 | * This routine actually brings a HBA offline. It stops all the timers |
| 3518 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3519 | * marks the HBA as in offline state for the upper layer protocol. |
| 3520 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3521 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3522 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3523 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3524 | struct Scsi_Host *shost; |
| 3525 | struct lpfc_vport **vports; |
| 3526 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3527 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3528 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3529 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3530 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3531 | /* stop port and all timers associated with this hba */ |
| 3532 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3533 | |
| 3534 | /* Tear down the local and target port registrations. The |
| 3535 | * nvme transports need to cleanup. |
| 3536 | */ |
| 3537 | lpfc_nvmet_destroy_targetport(phba); |
| 3538 | lpfc_nvme_destroy_localport(phba->pport); |
| 3539 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3540 | vports = lpfc_create_vport_work_array(phba); |
| 3541 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3542 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3543 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3544 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3545 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3546 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3548 | now. */ |
| 3549 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3550 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3551 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3552 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3553 | vports = lpfc_create_vport_work_array(phba); |
| 3554 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3555 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3556 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3557 | spin_lock_irq(shost->host_lock); |
| 3558 | vports[i]->work_port_events = 0; |
| 3559 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3560 | spin_unlock_irq(shost->host_lock); |
| 3561 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3562 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3563 | |
| 3564 | if (phba->cfg_xri_rebalancing) |
| 3565 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3566 | } |
| 3567 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3568 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3569 | * 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] | 3570 | * @phba: pointer to lpfc hba data structure. |
| 3571 | * |
| 3572 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3573 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3574 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3575 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3576 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3577 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3579 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3581 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3582 | return; |
| 3583 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3584 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3585 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3586 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3587 | |
| 3588 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3589 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3590 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3591 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3592 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3593 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3594 | kfree(sb); |
| 3595 | phba->total_scsi_bufs--; |
| 3596 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3597 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3598 | |
| 3599 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3600 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3601 | list) { |
| 3602 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3603 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3604 | sb->dma_handle); |
| 3605 | kfree(sb); |
| 3606 | phba->total_scsi_bufs--; |
| 3607 | } |
| 3608 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3609 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3610 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3611 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3612 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3613 | * 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] | 3614 | * @phba: pointer to lpfc hba data structure. |
| 3615 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3616 | * 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] | 3617 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3618 | * the internal resources before the device is removed from the system. |
| 3619 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3620 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3621 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3622 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3623 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3624 | struct lpfc_sli4_hdw_queue *qp; |
| 3625 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3626 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3627 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3628 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3629 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3630 | spin_lock(&qp->io_buf_list_put_lock); |
| 3631 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3632 | &qp->lpfc_io_buf_list_put, |
| 3633 | list) { |
| 3634 | list_del(&lpfc_ncmd->list); |
| 3635 | qp->put_io_bufs--; |
| 3636 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3637 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3638 | kfree(lpfc_ncmd); |
| 3639 | qp->total_io_bufs--; |
| 3640 | } |
| 3641 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3642 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3643 | spin_lock(&qp->io_buf_list_get_lock); |
| 3644 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3645 | &qp->lpfc_io_buf_list_get, |
| 3646 | list) { |
| 3647 | list_del(&lpfc_ncmd->list); |
| 3648 | qp->get_io_bufs--; |
| 3649 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3650 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3651 | kfree(lpfc_ncmd); |
| 3652 | qp->total_io_bufs--; |
| 3653 | } |
| 3654 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3655 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3656 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3657 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3658 | /** |
| 3659 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3660 | * @phba: pointer to lpfc hba data structure. |
| 3661 | * |
| 3662 | * This routine first calculates the sizes of the current els and allocated |
| 3663 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3664 | * XRIs assigned due to port function reset. During port initialization, the |
| 3665 | * current els and allocated scsi sgl lists are 0s. |
| 3666 | * |
| 3667 | * Return codes |
| 3668 | * 0 - successful (for now, it always returns 0) |
| 3669 | **/ |
| 3670 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3671 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3672 | { |
| 3673 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3674 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3675 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3676 | int rc; |
| 3677 | |
| 3678 | /* |
| 3679 | * update on pci function's els xri-sgl list |
| 3680 | */ |
| 3681 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3682 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3683 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3684 | /* els xri-sgl expanded */ |
| 3685 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3686 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3687 | "3157 ELS xri-sgl count increased from " |
| 3688 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3689 | els_xri_cnt); |
| 3690 | /* allocate the additional els sgls */ |
| 3691 | for (i = 0; i < xri_cnt; i++) { |
| 3692 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3693 | GFP_KERNEL); |
| 3694 | if (sglq_entry == NULL) { |
| 3695 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3696 | "2562 Failure to allocate an " |
| 3697 | "ELS sgl entry:%d\n", i); |
| 3698 | rc = -ENOMEM; |
| 3699 | goto out_free_mem; |
| 3700 | } |
| 3701 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3702 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3703 | &sglq_entry->phys); |
| 3704 | if (sglq_entry->virt == NULL) { |
| 3705 | kfree(sglq_entry); |
| 3706 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3707 | "2563 Failure to allocate an " |
| 3708 | "ELS mbuf:%d\n", i); |
| 3709 | rc = -ENOMEM; |
| 3710 | goto out_free_mem; |
| 3711 | } |
| 3712 | sglq_entry->sgl = sglq_entry->virt; |
| 3713 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3714 | sglq_entry->state = SGL_FREED; |
| 3715 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3716 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3717 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3718 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3719 | list_splice_init(&els_sgl_list, |
| 3720 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3721 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3722 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3723 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3724 | /* els xri-sgl shrinked */ |
| 3725 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3726 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3727 | "3158 ELS xri-sgl count decreased from " |
| 3728 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3729 | els_xri_cnt); |
| 3730 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3731 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3732 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3733 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3734 | /* release extra els sgls from list */ |
| 3735 | for (i = 0; i < xri_cnt; i++) { |
| 3736 | list_remove_head(&els_sgl_list, |
| 3737 | sglq_entry, struct lpfc_sglq, list); |
| 3738 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3739 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3740 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3741 | kfree(sglq_entry); |
| 3742 | } |
| 3743 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3744 | list_splice_init(&els_sgl_list, |
| 3745 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3746 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3747 | spin_unlock_irq(&phba->hbalock); |
| 3748 | } else |
| 3749 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3750 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3751 | els_xri_cnt); |
| 3752 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3753 | |
| 3754 | /* update xris to els sgls on the list */ |
| 3755 | sglq_entry = NULL; |
| 3756 | sglq_entry_next = NULL; |
| 3757 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3758 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3759 | lxri = lpfc_sli4_next_xritag(phba); |
| 3760 | if (lxri == NO_XRI) { |
| 3761 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3762 | "2400 Failed to allocate xri for " |
| 3763 | "ELS sgl\n"); |
| 3764 | rc = -ENOMEM; |
| 3765 | goto out_free_mem; |
| 3766 | } |
| 3767 | sglq_entry->sli4_lxritag = lxri; |
| 3768 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3769 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3770 | return 0; |
| 3771 | |
| 3772 | out_free_mem: |
| 3773 | lpfc_free_els_sgl_list(phba); |
| 3774 | return rc; |
| 3775 | } |
| 3776 | |
| 3777 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3778 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3779 | * @phba: pointer to lpfc hba data structure. |
| 3780 | * |
| 3781 | * This routine first calculates the sizes of the current els and allocated |
| 3782 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3783 | * XRIs assigned due to port function reset. During port initialization, the |
| 3784 | * current els and allocated scsi sgl lists are 0s. |
| 3785 | * |
| 3786 | * Return codes |
| 3787 | * 0 - successful (for now, it always returns 0) |
| 3788 | **/ |
| 3789 | int |
| 3790 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3791 | { |
| 3792 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3793 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3794 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3795 | LIST_HEAD(nvmet_sgl_list); |
| 3796 | int rc; |
| 3797 | |
| 3798 | /* |
| 3799 | * update on pci function's nvmet xri-sgl list |
| 3800 | */ |
| 3801 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3802 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3803 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3804 | 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] | 3805 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3806 | /* els xri-sgl expanded */ |
| 3807 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3808 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3809 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3810 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3811 | /* allocate the additional nvmet sgls */ |
| 3812 | for (i = 0; i < xri_cnt; i++) { |
| 3813 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3814 | GFP_KERNEL); |
| 3815 | if (sglq_entry == NULL) { |
| 3816 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3817 | "6303 Failure to allocate an " |
| 3818 | "NVMET sgl entry:%d\n", i); |
| 3819 | rc = -ENOMEM; |
| 3820 | goto out_free_mem; |
| 3821 | } |
| 3822 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3823 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3824 | &sglq_entry->phys); |
| 3825 | if (sglq_entry->virt == NULL) { |
| 3826 | kfree(sglq_entry); |
| 3827 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3828 | "6304 Failure to allocate an " |
| 3829 | "NVMET buf:%d\n", i); |
| 3830 | rc = -ENOMEM; |
| 3831 | goto out_free_mem; |
| 3832 | } |
| 3833 | sglq_entry->sgl = sglq_entry->virt; |
| 3834 | memset(sglq_entry->sgl, 0, |
| 3835 | phba->cfg_sg_dma_buf_size); |
| 3836 | sglq_entry->state = SGL_FREED; |
| 3837 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3838 | } |
| 3839 | spin_lock_irq(&phba->hbalock); |
| 3840 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3841 | list_splice_init(&nvmet_sgl_list, |
| 3842 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3843 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3844 | spin_unlock_irq(&phba->hbalock); |
| 3845 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3846 | /* nvmet xri-sgl shrunk */ |
| 3847 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3848 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3849 | "6305 NVMET xri-sgl count decreased from " |
| 3850 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3851 | nvmet_xri_cnt); |
| 3852 | spin_lock_irq(&phba->hbalock); |
| 3853 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3854 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3855 | &nvmet_sgl_list); |
| 3856 | /* release extra nvmet sgls from list */ |
| 3857 | for (i = 0; i < xri_cnt; i++) { |
| 3858 | list_remove_head(&nvmet_sgl_list, |
| 3859 | sglq_entry, struct lpfc_sglq, list); |
| 3860 | if (sglq_entry) { |
| 3861 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3862 | sglq_entry->phys); |
| 3863 | kfree(sglq_entry); |
| 3864 | } |
| 3865 | } |
| 3866 | list_splice_init(&nvmet_sgl_list, |
| 3867 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3868 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3869 | spin_unlock_irq(&phba->hbalock); |
| 3870 | } else |
| 3871 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3872 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3873 | nvmet_xri_cnt); |
| 3874 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3875 | |
| 3876 | /* update xris to nvmet sgls on the list */ |
| 3877 | sglq_entry = NULL; |
| 3878 | sglq_entry_next = NULL; |
| 3879 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3880 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3881 | lxri = lpfc_sli4_next_xritag(phba); |
| 3882 | if (lxri == NO_XRI) { |
| 3883 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3884 | "6307 Failed to allocate xri for " |
| 3885 | "NVMET sgl\n"); |
| 3886 | rc = -ENOMEM; |
| 3887 | goto out_free_mem; |
| 3888 | } |
| 3889 | sglq_entry->sli4_lxritag = lxri; |
| 3890 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3891 | } |
| 3892 | return 0; |
| 3893 | |
| 3894 | out_free_mem: |
| 3895 | lpfc_free_nvmet_sgl_list(phba); |
| 3896 | return rc; |
| 3897 | } |
| 3898 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3899 | int |
| 3900 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3901 | { |
| 3902 | LIST_HEAD(blist); |
| 3903 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3904 | struct lpfc_io_buf *lpfc_cmd; |
| 3905 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3906 | int idx, cnt, xri, inserted; |
| 3907 | |
| 3908 | cnt = 0; |
| 3909 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3910 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3911 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 3912 | spin_lock(&qp->io_buf_list_put_lock); |
| 3913 | |
| 3914 | /* Take everything off the get and put lists */ |
| 3915 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 3916 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 3917 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 3918 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 3919 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 3920 | qp->get_io_bufs = 0; |
| 3921 | qp->put_io_bufs = 0; |
| 3922 | qp->total_io_bufs = 0; |
| 3923 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3924 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 3925 | } |
| 3926 | |
| 3927 | /* |
| 3928 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 3929 | * This is because POST_SGL takes a sequential range of XRIs |
| 3930 | * to post to the firmware. |
| 3931 | */ |
| 3932 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3933 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3934 | if (!lpfc_cmd) |
| 3935 | return cnt; |
| 3936 | if (idx == 0) { |
| 3937 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3938 | continue; |
| 3939 | } |
| 3940 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 3941 | inserted = 0; |
| 3942 | prev_iobufp = NULL; |
| 3943 | list_for_each_entry(iobufp, cbuf, list) { |
| 3944 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 3945 | if (prev_iobufp) |
| 3946 | list_add(&lpfc_cmd->list, |
| 3947 | &prev_iobufp->list); |
| 3948 | else |
| 3949 | list_add(&lpfc_cmd->list, cbuf); |
| 3950 | inserted = 1; |
| 3951 | break; |
| 3952 | } |
| 3953 | prev_iobufp = iobufp; |
| 3954 | } |
| 3955 | if (!inserted) |
| 3956 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3957 | } |
| 3958 | return cnt; |
| 3959 | } |
| 3960 | |
| 3961 | int |
| 3962 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3963 | { |
| 3964 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3965 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3966 | int idx, cnt; |
| 3967 | |
| 3968 | qp = phba->sli4_hba.hdwq; |
| 3969 | cnt = 0; |
| 3970 | while (!list_empty(cbuf)) { |
| 3971 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3972 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3973 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3974 | if (!lpfc_cmd) |
| 3975 | return cnt; |
| 3976 | cnt++; |
| 3977 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 3978 | lpfc_cmd->hdwq_no = idx; |
| 3979 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3980 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 3981 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 3982 | spin_lock(&qp->io_buf_list_put_lock); |
| 3983 | list_add_tail(&lpfc_cmd->list, |
| 3984 | &qp->lpfc_io_buf_list_put); |
| 3985 | qp->put_io_bufs++; |
| 3986 | qp->total_io_bufs++; |
| 3987 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3988 | } |
| 3989 | } |
| 3990 | return cnt; |
| 3991 | } |
| 3992 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3993 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3994 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3995 | * @phba: pointer to lpfc hba data structure. |
| 3996 | * |
| 3997 | * This routine first calculates the sizes of the current els and allocated |
| 3998 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3999 | * XRIs assigned due to port function reset. During port initialization, the |
| 4000 | * current els and allocated scsi sgl lists are 0s. |
| 4001 | * |
| 4002 | * Return codes |
| 4003 | * 0 - successful (for now, it always returns 0) |
| 4004 | **/ |
| 4005 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4006 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4007 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4008 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4009 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4010 | uint16_t io_xri_cnt, io_xri_max; |
| 4011 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4012 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4013 | |
| 4014 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4015 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4016 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4017 | |
| 4018 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4019 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4020 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4021 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4022 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4023 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4024 | "6074 Current allocated XRI sgl count:%d, " |
| 4025 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4026 | phba->sli4_hba.io_xri_cnt, |
| 4027 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4028 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4029 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4030 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4031 | 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] | 4032 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4033 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4034 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4035 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4036 | for (i = 0; i < io_xri_cnt; i++) { |
| 4037 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4038 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4039 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4040 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4041 | lpfc_ncmd->data, |
| 4042 | lpfc_ncmd->dma_handle); |
| 4043 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4044 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4045 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4046 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4047 | } |
| 4048 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4049 | /* update xris associated to remaining allocated nvme buffers */ |
| 4050 | lpfc_ncmd = NULL; |
| 4051 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4052 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4053 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4054 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4055 | lxri = lpfc_sli4_next_xritag(phba); |
| 4056 | if (lxri == NO_XRI) { |
| 4057 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4058 | "6075 Failed to allocate xri for " |
| 4059 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4060 | rc = -ENOMEM; |
| 4061 | goto out_free_mem; |
| 4062 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4063 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4064 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4065 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4066 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4067 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4068 | |
| 4069 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4070 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4071 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4072 | } |
| 4073 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4074 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4075 | * 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] | 4076 | * @vport: The virtual port for which this call being executed. |
| 4077 | * @num_to_allocate: The requested number of buffers to allocate. |
| 4078 | * |
| 4079 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4080 | * the nvme buffer contains all the necessary information needed to initiate |
| 4081 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4082 | * them on a list, it post them to the port by using SGL block post. |
| 4083 | * |
| 4084 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4085 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4086 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4087 | **/ |
| 4088 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4089 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4090 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4091 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4092 | struct lpfc_iocbq *pwqeq; |
| 4093 | uint16_t iotag, lxri = 0; |
| 4094 | int bcnt, num_posted; |
| 4095 | LIST_HEAD(prep_nblist); |
| 4096 | LIST_HEAD(post_nblist); |
| 4097 | LIST_HEAD(nvme_nblist); |
| 4098 | |
| 4099 | /* Sanity check to ensure our sizing is right for both SCSI and NVME */ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4100 | if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4101 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Arnd Bergmann | f996861 | 2019-03-04 20:39:09 +0100 | [diff] [blame] | 4102 | "6426 Common buffer size %zd exceeds %d\n", |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4103 | sizeof(struct lpfc_io_buf), |
| 4104 | LPFC_COMMON_IO_BUF_SZ); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4105 | return 0; |
| 4106 | } |
| 4107 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4108 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4109 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 4110 | lpfc_ncmd = kzalloc(LPFC_COMMON_IO_BUF_SZ, GFP_KERNEL); |
| 4111 | if (!lpfc_ncmd) |
| 4112 | break; |
| 4113 | /* |
| 4114 | * Get memory from the pci pool to map the virt space to |
| 4115 | * pci bus space for an I/O. The DMA buffer includes the |
| 4116 | * number of SGE's necessary to support the sg_tablesize. |
| 4117 | */ |
| 4118 | lpfc_ncmd->data = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 4119 | GFP_KERNEL, |
| 4120 | &lpfc_ncmd->dma_handle); |
| 4121 | if (!lpfc_ncmd->data) { |
| 4122 | kfree(lpfc_ncmd); |
| 4123 | break; |
| 4124 | } |
| 4125 | memset(lpfc_ncmd->data, 0, phba->cfg_sg_dma_buf_size); |
| 4126 | |
| 4127 | /* |
| 4128 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 4129 | * to be sure. |
| 4130 | */ |
| 4131 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4132 | (((unsigned long)(lpfc_ncmd->data) & |
| 4133 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
| 4134 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 4135 | "3369 Memory alignment err: addr=%lx\n", |
| 4136 | (unsigned long)lpfc_ncmd->data); |
| 4137 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4138 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4139 | kfree(lpfc_ncmd); |
| 4140 | break; |
| 4141 | } |
| 4142 | |
| 4143 | lxri = lpfc_sli4_next_xritag(phba); |
| 4144 | if (lxri == NO_XRI) { |
| 4145 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4146 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4147 | kfree(lpfc_ncmd); |
| 4148 | break; |
| 4149 | } |
| 4150 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4151 | |
| 4152 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4153 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4154 | if (iotag == 0) { |
| 4155 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4156 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4157 | kfree(lpfc_ncmd); |
| 4158 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, |
| 4159 | "6121 Failed to allocate IOTAG for" |
| 4160 | " XRI:0x%x\n", lxri); |
| 4161 | lpfc_sli4_free_xri(phba, lxri); |
| 4162 | break; |
| 4163 | } |
| 4164 | pwqeq->sli4_lxritag = lxri; |
| 4165 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4166 | pwqeq->context1 = lpfc_ncmd; |
| 4167 | |
| 4168 | /* Initialize local short-hand pointers. */ |
| 4169 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4170 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4171 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4172 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4173 | |
| 4174 | /* add the nvme buffer to a post list */ |
| 4175 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4176 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4177 | } |
| 4178 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4179 | "6114 Allocate %d out of %d requested new NVME " |
| 4180 | "buffers\n", bcnt, num_to_alloc); |
| 4181 | |
| 4182 | /* post the list of nvme buffer sgls to port if available */ |
| 4183 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4184 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4185 | phba, &post_nblist, bcnt); |
| 4186 | else |
| 4187 | num_posted = 0; |
| 4188 | |
| 4189 | return num_posted; |
| 4190 | } |
| 4191 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4192 | static uint64_t |
| 4193 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4194 | { |
| 4195 | uint64_t wwn; |
| 4196 | int rc; |
| 4197 | LPFC_MBOXQ_t *mboxq; |
| 4198 | MAILBOX_t *mb; |
| 4199 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4200 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4201 | GFP_KERNEL); |
| 4202 | if (!mboxq) |
| 4203 | return (uint64_t)-1; |
| 4204 | |
| 4205 | /* First get WWN of HBA instance */ |
| 4206 | lpfc_read_nv(phba, mboxq); |
| 4207 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4208 | if (rc != MBX_SUCCESS) { |
| 4209 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4210 | "6019 Mailbox failed , mbxCmd x%x " |
| 4211 | "READ_NV, mbxStatus x%x\n", |
| 4212 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4213 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4214 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4215 | return (uint64_t) -1; |
| 4216 | } |
| 4217 | mb = &mboxq->u.mb; |
| 4218 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4219 | /* wwn is WWPN of HBA instance */ |
| 4220 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4221 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4222 | return be64_to_cpu(wwn); |
| 4223 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4224 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4225 | } |
| 4226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4227 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4228 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4229 | * @phba: pointer to lpfc hba data structure. |
| 4230 | * @instance: a unique integer ID to this FC port. |
| 4231 | * @dev: pointer to the device data structure. |
| 4232 | * |
| 4233 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4234 | * can be created on top of either a physical port or a virtual port provided |
| 4235 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4236 | * and associates the FC port created before adding the shost into the SCSI |
| 4237 | * layer. |
| 4238 | * |
| 4239 | * Return codes |
| 4240 | * @vport - pointer to the virtual N_Port data structure. |
| 4241 | * NULL - port create failed. |
| 4242 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4244 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4245 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4246 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4247 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4248 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4249 | int i; |
| 4250 | uint64_t wwn; |
| 4251 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4252 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4253 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4254 | if (lpfc_no_hba_reset_cnt) { |
| 4255 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4256 | dev == &phba->pcidev->dev) { |
| 4257 | /* Reset the port first */ |
| 4258 | lpfc_sli_brdrestart(phba); |
| 4259 | rc = lpfc_sli_chipset_init(phba); |
| 4260 | if (rc) |
| 4261 | return NULL; |
| 4262 | } |
| 4263 | wwn = lpfc_get_wwpn(phba); |
| 4264 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4265 | |
| 4266 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4267 | if (wwn == lpfc_no_hba_reset[i]) { |
| 4268 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4269 | "6020 Setting use_no_reset port=%llx\n", |
| 4270 | wwn); |
| 4271 | use_no_reset_hba = true; |
| 4272 | break; |
| 4273 | } |
| 4274 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4275 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4276 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4277 | if (dev != &phba->pcidev->dev) { |
| 4278 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 4279 | sizeof(struct lpfc_vport)); |
| 4280 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4281 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4282 | shost = scsi_host_alloc(&lpfc_template, |
| 4283 | sizeof(struct lpfc_vport)); |
| 4284 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4285 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4286 | sizeof(struct lpfc_vport)); |
| 4287 | } |
| 4288 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 4289 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4290 | sizeof(struct lpfc_vport)); |
| 4291 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | if (!shost) |
| 4293 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4294 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4295 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4296 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4297 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4298 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4299 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4300 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4301 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4302 | /* Adjust value in vport */ |
| 4303 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4305 | shost->unique_id = instance; |
| 4306 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4307 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | shost->this_id = -1; |
| 4309 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4310 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4311 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4312 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) |
| 4313 | shost->nr_hw_queues = phba->cfg_hdw_queue; |
| 4314 | else |
| 4315 | shost->nr_hw_queues = phba->sli4_hba.num_present_cpu; |
| 4316 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4317 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4318 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 4319 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4320 | } else |
| 4321 | /* SLI-3 has a limited number of hardware queues (3), |
| 4322 | * thus there is only one for FCP processing. |
| 4323 | */ |
| 4324 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4325 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4326 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | * Set initial can_queue value since 0 is no longer supported and |
| 4328 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4329 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4330 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4331 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4332 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4333 | shost->transportt = lpfc_vport_transport_template; |
| 4334 | vport->port_type = LPFC_NPIV_PORT; |
| 4335 | } else { |
| 4336 | shost->transportt = lpfc_transport_template; |
| 4337 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4338 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4339 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4340 | /* Initialize all internally managed lists. */ |
| 4341 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4342 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4343 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4344 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4345 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4346 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4347 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4348 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4349 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4350 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4351 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | if (error) |
| 4353 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4354 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4355 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4357 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4358 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4359 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | out_put_shost: |
| 4361 | scsi_host_put(shost); |
| 4362 | out: |
| 4363 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4364 | } |
| 4365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4367 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4368 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4369 | * |
| 4370 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4371 | * resources associated with the port are released. |
| 4372 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4373 | void |
| 4374 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4375 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4376 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4377 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4378 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4379 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4380 | fc_remove_host(shost); |
| 4381 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4382 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4383 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4385 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4386 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4387 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4388 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4389 | } |
| 4390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4392 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4393 | * |
| 4394 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4395 | * uses the kernel idr facility to perform the task. |
| 4396 | * |
| 4397 | * Return codes: |
| 4398 | * instance - a unique integer ID allocated as the new instance. |
| 4399 | * -1 - lpfc get instance failed. |
| 4400 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4401 | int |
| 4402 | lpfc_get_instance(void) |
| 4403 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4404 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4406 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4407 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4408 | } |
| 4409 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4410 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4411 | * 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] | 4412 | * @shost: pointer to SCSI host data structure. |
| 4413 | * @time: elapsed time of the scan in jiffies. |
| 4414 | * |
| 4415 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4416 | * whether the scan host is finished. |
| 4417 | * |
| 4418 | * Note: there is no scan_start function as adapter initialization will have |
| 4419 | * asynchronously kicked off the link initialization. |
| 4420 | * |
| 4421 | * Return codes |
| 4422 | * 0 - SCSI host scan is not over yet. |
| 4423 | * 1 - SCSI host scan is over. |
| 4424 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4425 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4426 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4428 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4429 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4430 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4431 | spin_lock_irq(shost->host_lock); |
| 4432 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4433 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4434 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4435 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4436 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4437 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4438 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4439 | "0461 Scanning longer than 30 " |
| 4440 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4441 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4442 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4443 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4444 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4445 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4446 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4447 | "0465 Link down longer than 15 " |
| 4448 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4449 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4451 | } |
| 4452 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4453 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4454 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4456 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4457 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
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 ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4460 | goto finished; |
| 4461 | |
| 4462 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4463 | |
| 4464 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4465 | spin_unlock_irq(shost->host_lock); |
| 4466 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4467 | } |
| 4468 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4469 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4470 | { |
| 4471 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4472 | struct lpfc_hba *phba = vport->phba; |
| 4473 | |
| 4474 | fc_host_supported_speeds(shost) = 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4475 | if (phba->lmt & LMT_128Gb) |
| 4476 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4477 | if (phba->lmt & LMT_64Gb) |
| 4478 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4479 | if (phba->lmt & LMT_32Gb) |
| 4480 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4481 | if (phba->lmt & LMT_16Gb) |
| 4482 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4483 | if (phba->lmt & LMT_10Gb) |
| 4484 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4485 | if (phba->lmt & LMT_8Gb) |
| 4486 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4487 | if (phba->lmt & LMT_4Gb) |
| 4488 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4489 | if (phba->lmt & LMT_2Gb) |
| 4490 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4491 | if (phba->lmt & LMT_1Gb) |
| 4492 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4493 | } |
| 4494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4496 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4497 | * @shost: pointer to SCSI host data structure. |
| 4498 | * |
| 4499 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4500 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4501 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4502 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4503 | { |
| 4504 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4505 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4506 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4507 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4508 | */ |
| 4509 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4510 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4511 | 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] | 4512 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4513 | |
| 4514 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4515 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4516 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4517 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4518 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4519 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4520 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4521 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4522 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4523 | |
| 4524 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4525 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4526 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4527 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4528 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4529 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4530 | /* This value is also unchanging */ |
| 4531 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4533 | fc_host_active_fc4s(shost)[2] = 1; |
| 4534 | fc_host_active_fc4s(shost)[7] = 1; |
| 4535 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4536 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4537 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4538 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4539 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4540 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4542 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4543 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4544 | * @phba: pointer to lpfc hba data structure. |
| 4545 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4546 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4547 | * from generating interrupts and stops the device driver's timers for the |
| 4548 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4549 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4550 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4551 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4552 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4553 | /* Clear all interrupt enable conditions */ |
| 4554 | writel(0, phba->HCregaddr); |
| 4555 | readl(phba->HCregaddr); /* flush */ |
| 4556 | /* Clear all pending interrupts */ |
| 4557 | writel(0xffffffff, phba->HAregaddr); |
| 4558 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4559 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4560 | /* Reset some HBA SLI setup states */ |
| 4561 | lpfc_stop_hba_timers(phba); |
| 4562 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4563 | } |
| 4564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4565 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4566 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4567 | * @phba: pointer to lpfc hba data structure. |
| 4568 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4569 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4570 | * from generating interrupts and stops the device driver's timers for the |
| 4571 | * device. |
| 4572 | **/ |
| 4573 | static void |
| 4574 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4575 | { |
| 4576 | /* Reset some HBA SLI4 setup states */ |
| 4577 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4578 | if (phba->pport) |
| 4579 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4580 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | /** |
| 4584 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4585 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4586 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4587 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4588 | * the API jump table function pointer from the lpfc_hba struct. |
| 4589 | **/ |
| 4590 | void |
| 4591 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4592 | { |
| 4593 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4594 | |
| 4595 | if (phba->wq) |
| 4596 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4600 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4601 | * @phba: Pointer to hba for which this call is being executed. |
| 4602 | * |
| 4603 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4604 | **/ |
| 4605 | void |
| 4606 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4607 | { |
| 4608 | unsigned long fcf_redisc_wait_tmo = |
| 4609 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4610 | /* Start fcf rediscovery wait period timer */ |
| 4611 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4612 | spin_lock_irq(&phba->hbalock); |
| 4613 | /* Allow action to new fcf asynchronous event */ |
| 4614 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4615 | /* Mark the FCF rediscovery pending state */ |
| 4616 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4617 | spin_unlock_irq(&phba->hbalock); |
| 4618 | } |
| 4619 | |
| 4620 | /** |
| 4621 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4622 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4623 | * |
| 4624 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4625 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4626 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4627 | * list, and then worker thread shall be waked up for processing from the |
| 4628 | * worker thread context. |
| 4629 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4630 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4631 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4632 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4633 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4634 | |
| 4635 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4636 | spin_lock_irq(&phba->hbalock); |
| 4637 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4638 | spin_unlock_irq(&phba->hbalock); |
| 4639 | return; |
| 4640 | } |
| 4641 | /* Clear FCF rediscovery timer pending flag */ |
| 4642 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4643 | /* FCF rediscovery event to worker thread */ |
| 4644 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4645 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4646 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4647 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4648 | /* wake up worker thread */ |
| 4649 | lpfc_worker_wake_up(phba); |
| 4650 | } |
| 4651 | |
| 4652 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4653 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4654 | * @phba: pointer to lpfc hba data structure. |
| 4655 | * @acqe_link: pointer to the async link completion queue entry. |
| 4656 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4657 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4658 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4659 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4660 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4661 | struct lpfc_acqe_link *acqe_link) |
| 4662 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4663 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4664 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4665 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4666 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4667 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4668 | break; |
| 4669 | default: |
| 4670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4671 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4673 | break; |
| 4674 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | /** |
| 4678 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4679 | * @phba: pointer to lpfc hba data structure. |
| 4680 | * @acqe_link: pointer to the async link completion queue entry. |
| 4681 | * |
| 4682 | * This routine is to parse the SLI4 link attention type and translate it |
| 4683 | * into the base driver's link attention type coding. |
| 4684 | * |
| 4685 | * Return: Link attention type in terms of base driver's coding. |
| 4686 | **/ |
| 4687 | static uint8_t |
| 4688 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4689 | struct lpfc_acqe_link *acqe_link) |
| 4690 | { |
| 4691 | uint8_t att_type; |
| 4692 | |
| 4693 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4694 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4695 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4696 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4697 | break; |
| 4698 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4699 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4700 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4701 | break; |
| 4702 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4703 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4704 | break; |
| 4705 | default: |
| 4706 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4707 | "0399 Invalid link attention type: x%x\n", |
| 4708 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4709 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4710 | break; |
| 4711 | } |
| 4712 | return att_type; |
| 4713 | } |
| 4714 | |
| 4715 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4716 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4717 | * @phba: pointer to lpfc hba data structure. |
| 4718 | * |
| 4719 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4720 | * |
| 4721 | * Return: link speed in terms of Mbps. |
| 4722 | **/ |
| 4723 | uint32_t |
| 4724 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4725 | { |
| 4726 | uint32_t link_speed; |
| 4727 | |
| 4728 | if (!lpfc_is_link_up(phba)) |
| 4729 | return 0; |
| 4730 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4731 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4732 | switch (phba->fc_linkspeed) { |
| 4733 | case LPFC_LINK_SPEED_1GHZ: |
| 4734 | link_speed = 1000; |
| 4735 | break; |
| 4736 | case LPFC_LINK_SPEED_2GHZ: |
| 4737 | link_speed = 2000; |
| 4738 | break; |
| 4739 | case LPFC_LINK_SPEED_4GHZ: |
| 4740 | link_speed = 4000; |
| 4741 | break; |
| 4742 | case LPFC_LINK_SPEED_8GHZ: |
| 4743 | link_speed = 8000; |
| 4744 | break; |
| 4745 | case LPFC_LINK_SPEED_10GHZ: |
| 4746 | link_speed = 10000; |
| 4747 | break; |
| 4748 | case LPFC_LINK_SPEED_16GHZ: |
| 4749 | link_speed = 16000; |
| 4750 | break; |
| 4751 | default: |
| 4752 | link_speed = 0; |
| 4753 | } |
| 4754 | } else { |
| 4755 | if (phba->sli4_hba.link_state.logical_speed) |
| 4756 | link_speed = |
| 4757 | phba->sli4_hba.link_state.logical_speed; |
| 4758 | else |
| 4759 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4760 | } |
| 4761 | return link_speed; |
| 4762 | } |
| 4763 | |
| 4764 | /** |
| 4765 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4766 | * @phba: pointer to lpfc hba data structure. |
| 4767 | * @evt_code: asynchronous event code. |
| 4768 | * @speed_code: asynchronous event link speed code. |
| 4769 | * |
| 4770 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4771 | * value of Mbps for the link speed. |
| 4772 | * |
| 4773 | * Return: link speed in terms of Mbps. |
| 4774 | **/ |
| 4775 | static uint32_t |
| 4776 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4777 | uint8_t speed_code) |
| 4778 | { |
| 4779 | uint32_t port_speed; |
| 4780 | |
| 4781 | switch (evt_code) { |
| 4782 | case LPFC_TRAILER_CODE_LINK: |
| 4783 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4784 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4785 | port_speed = 0; |
| 4786 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4787 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4788 | port_speed = 10; |
| 4789 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4790 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4791 | port_speed = 100; |
| 4792 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4793 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4794 | port_speed = 1000; |
| 4795 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4796 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4797 | port_speed = 10000; |
| 4798 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4799 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4800 | port_speed = 20000; |
| 4801 | break; |
| 4802 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4803 | port_speed = 25000; |
| 4804 | break; |
| 4805 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4806 | port_speed = 40000; |
| 4807 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4808 | default: |
| 4809 | port_speed = 0; |
| 4810 | } |
| 4811 | break; |
| 4812 | case LPFC_TRAILER_CODE_FC: |
| 4813 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4814 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4815 | port_speed = 0; |
| 4816 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4817 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4818 | port_speed = 1000; |
| 4819 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4820 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4821 | port_speed = 2000; |
| 4822 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4823 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4824 | port_speed = 4000; |
| 4825 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4826 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4827 | port_speed = 8000; |
| 4828 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4829 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4830 | port_speed = 10000; |
| 4831 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4832 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4833 | port_speed = 16000; |
| 4834 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4835 | case LPFC_FC_LA_SPEED_32G: |
| 4836 | port_speed = 32000; |
| 4837 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4838 | case LPFC_FC_LA_SPEED_64G: |
| 4839 | port_speed = 64000; |
| 4840 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4841 | case LPFC_FC_LA_SPEED_128G: |
| 4842 | port_speed = 128000; |
| 4843 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4844 | default: |
| 4845 | port_speed = 0; |
| 4846 | } |
| 4847 | break; |
| 4848 | default: |
| 4849 | port_speed = 0; |
| 4850 | } |
| 4851 | return port_speed; |
| 4852 | } |
| 4853 | |
| 4854 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4855 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4856 | * @phba: pointer to lpfc hba data structure. |
| 4857 | * @acqe_link: pointer to the async link completion queue entry. |
| 4858 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4859 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4860 | **/ |
| 4861 | static void |
| 4862 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4863 | struct lpfc_acqe_link *acqe_link) |
| 4864 | { |
| 4865 | struct lpfc_dmabuf *mp; |
| 4866 | LPFC_MBOXQ_t *pmb; |
| 4867 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4868 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4869 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4870 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4871 | |
| 4872 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4873 | 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] | 4874 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4875 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4876 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4877 | if (!pmb) { |
| 4878 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4879 | "0395 The mboxq allocation failed\n"); |
| 4880 | return; |
| 4881 | } |
| 4882 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4883 | if (!mp) { |
| 4884 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4885 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4886 | goto out_free_pmb; |
| 4887 | } |
| 4888 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4889 | if (!mp->virt) { |
| 4890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4891 | "0397 The mbuf allocation failed\n"); |
| 4892 | goto out_free_dmabuf; |
| 4893 | } |
| 4894 | |
| 4895 | /* Cleanup any outstanding ELS commands */ |
| 4896 | lpfc_els_flush_all_cmd(phba); |
| 4897 | |
| 4898 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4899 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4900 | |
| 4901 | /* Update link event statistics */ |
| 4902 | phba->sli.slistat.link_event++; |
| 4903 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4904 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4905 | lpfc_read_topology(phba, pmb, mp); |
| 4906 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4907 | pmb->vport = phba->pport; |
| 4908 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4909 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4910 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4911 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4912 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | phba->sli4_hba.link_state.duplex = |
| 4914 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4915 | phba->sli4_hba.link_state.status = |
| 4916 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4917 | phba->sli4_hba.link_state.type = |
| 4918 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4919 | phba->sli4_hba.link_state.number = |
| 4920 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4921 | phba->sli4_hba.link_state.fault = |
| 4922 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4923 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4924 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4925 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4926 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4927 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4928 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4929 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4930 | phba->sli4_hba.link_state.speed, |
| 4931 | phba->sli4_hba.link_state.topology, |
| 4932 | phba->sli4_hba.link_state.status, |
| 4933 | phba->sli4_hba.link_state.type, |
| 4934 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4935 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4936 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4937 | /* |
| 4938 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4939 | * topology info. Note: Optional for non FC-AL ports. |
| 4940 | */ |
| 4941 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4942 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4943 | if (rc == MBX_NOT_FINISHED) |
| 4944 | goto out_free_dmabuf; |
| 4945 | return; |
| 4946 | } |
| 4947 | /* |
| 4948 | * For FCoE Mode: fill in all the topology information we need and call |
| 4949 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4950 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4951 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4952 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4953 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4954 | mb->mbxStatus = MBX_SUCCESS; |
| 4955 | |
| 4956 | /* Parse port fault information field */ |
| 4957 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4958 | |
| 4959 | /* Parse and translate link attention fields */ |
| 4960 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4961 | la->eventTag = acqe_link->event_tag; |
| 4962 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4963 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4964 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4965 | |
| 4966 | /* Fake the the following irrelvant fields */ |
| 4967 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4968 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4969 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4970 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4971 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4972 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4973 | |
| 4974 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4975 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4976 | |
| 4977 | return; |
| 4978 | |
| 4979 | out_free_dmabuf: |
| 4980 | kfree(mp); |
| 4981 | out_free_pmb: |
| 4982 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4983 | } |
| 4984 | |
| 4985 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4986 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 4987 | * topology. |
| 4988 | * @phba: pointer to lpfc hba data structure. |
| 4989 | * @evt_code: asynchronous event code. |
| 4990 | * @speed_code: asynchronous event link speed code. |
| 4991 | * |
| 4992 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4993 | * value of Read topology link speed. |
| 4994 | * |
| 4995 | * Return: link speed in terms of Read topology. |
| 4996 | **/ |
| 4997 | static uint8_t |
| 4998 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 4999 | { |
| 5000 | uint8_t port_speed; |
| 5001 | |
| 5002 | switch (speed_code) { |
| 5003 | case LPFC_FC_LA_SPEED_1G: |
| 5004 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5005 | break; |
| 5006 | case LPFC_FC_LA_SPEED_2G: |
| 5007 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5008 | break; |
| 5009 | case LPFC_FC_LA_SPEED_4G: |
| 5010 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5011 | break; |
| 5012 | case LPFC_FC_LA_SPEED_8G: |
| 5013 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5014 | break; |
| 5015 | case LPFC_FC_LA_SPEED_16G: |
| 5016 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5017 | break; |
| 5018 | case LPFC_FC_LA_SPEED_32G: |
| 5019 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5020 | break; |
| 5021 | case LPFC_FC_LA_SPEED_64G: |
| 5022 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5023 | break; |
| 5024 | case LPFC_FC_LA_SPEED_128G: |
| 5025 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5026 | break; |
| 5027 | case LPFC_FC_LA_SPEED_256G: |
| 5028 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5029 | break; |
| 5030 | default: |
| 5031 | port_speed = 0; |
| 5032 | break; |
| 5033 | } |
| 5034 | |
| 5035 | return port_speed; |
| 5036 | } |
| 5037 | |
| 5038 | #define trunk_link_status(__idx)\ |
| 5039 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5040 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5041 | "Link up" : "Link down") : "NA" |
| 5042 | /* Did port __idx reported an error */ |
| 5043 | #define trunk_port_fault(__idx)\ |
| 5044 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5045 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5046 | |
| 5047 | static void |
| 5048 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5049 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5050 | { |
| 5051 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5052 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5053 | |
| 5054 | phba->sli4_hba.link_state.speed = |
| 5055 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5056 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5057 | |
| 5058 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5059 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5060 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5061 | phba->fc_linkspeed = |
| 5062 | lpfc_async_link_speed_to_read_top( |
| 5063 | phba, |
| 5064 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5065 | |
| 5066 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5067 | phba->trunk_link.link0.state = |
| 5068 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5069 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5070 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5071 | } |
| 5072 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5073 | phba->trunk_link.link1.state = |
| 5074 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5075 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5076 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5077 | } |
| 5078 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5079 | phba->trunk_link.link2.state = |
| 5080 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5081 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5082 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5083 | } |
| 5084 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5085 | phba->trunk_link.link3.state = |
| 5086 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5087 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5088 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5092 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5093 | "\tLogical speed:%d " |
| 5094 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5095 | phba->sli4_hba.link_state.speed, |
| 5096 | phba->sli4_hba.link_state.logical_speed, |
| 5097 | trunk_link_status(0), trunk_link_status(1), |
| 5098 | trunk_link_status(2), trunk_link_status(3)); |
| 5099 | |
| 5100 | if (port_fault) |
| 5101 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5102 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5103 | /* |
| 5104 | * SLI-4: We have only 0xA error codes |
| 5105 | * defined as of now. print an appropriate |
| 5106 | * message in case driver needs to be updated. |
| 5107 | */ |
| 5108 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5109 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5110 | trunk_port_fault(0), trunk_port_fault(1), |
| 5111 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5112 | } |
| 5113 | |
| 5114 | |
| 5115 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5116 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5117 | * @phba: pointer to lpfc hba data structure. |
| 5118 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5119 | * |
| 5120 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5121 | * that the event was received and then issue a read_topology mailbox command so |
| 5122 | * that the rest of the driver will treat it the same as SLI3. |
| 5123 | **/ |
| 5124 | static void |
| 5125 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5126 | { |
| 5127 | struct lpfc_dmabuf *mp; |
| 5128 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5129 | MAILBOX_t *mb; |
| 5130 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5131 | int rc; |
| 5132 | |
| 5133 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5134 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 5135 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5136 | "2895 Non FC link Event detected.(%d)\n", |
| 5137 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5138 | return; |
| 5139 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5140 | |
| 5141 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5142 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5143 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5144 | return; |
| 5145 | } |
| 5146 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5147 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5148 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5149 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5150 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5151 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5152 | phba->sli4_hba.link_state.topology = |
| 5153 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5154 | phba->sli4_hba.link_state.status = |
| 5155 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5156 | phba->sli4_hba.link_state.type = |
| 5157 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5158 | phba->sli4_hba.link_state.number = |
| 5159 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5160 | phba->sli4_hba.link_state.fault = |
| 5161 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5162 | |
| 5163 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5164 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5165 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5166 | else if (!phba->sli4_hba.conf_trunk) |
| 5167 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5168 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5169 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5170 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5171 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5172 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5173 | "%dMbps Fault:%d\n", |
| 5174 | phba->sli4_hba.link_state.speed, |
| 5175 | phba->sli4_hba.link_state.topology, |
| 5176 | phba->sli4_hba.link_state.status, |
| 5177 | phba->sli4_hba.link_state.type, |
| 5178 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5179 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5180 | phba->sli4_hba.link_state.fault); |
| 5181 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5182 | if (!pmb) { |
| 5183 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5184 | "2897 The mboxq allocation failed\n"); |
| 5185 | return; |
| 5186 | } |
| 5187 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5188 | if (!mp) { |
| 5189 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5190 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5191 | goto out_free_pmb; |
| 5192 | } |
| 5193 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5194 | if (!mp->virt) { |
| 5195 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5196 | "2899 The mbuf allocation failed\n"); |
| 5197 | goto out_free_dmabuf; |
| 5198 | } |
| 5199 | |
| 5200 | /* Cleanup any outstanding ELS commands */ |
| 5201 | lpfc_els_flush_all_cmd(phba); |
| 5202 | |
| 5203 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5204 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5205 | |
| 5206 | /* Update link event statistics */ |
| 5207 | phba->sli.slistat.link_event++; |
| 5208 | |
| 5209 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5210 | lpfc_read_topology(phba, pmb, mp); |
| 5211 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5212 | pmb->vport = phba->pport; |
| 5213 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5214 | 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] | 5215 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5216 | |
| 5217 | switch (phba->sli4_hba.link_state.status) { |
| 5218 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5219 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5220 | break; |
| 5221 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5222 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5223 | break; |
| 5224 | default: |
| 5225 | break; |
| 5226 | } |
| 5227 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5228 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5229 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5230 | mb->mbxStatus = MBX_SUCCESS; |
| 5231 | |
| 5232 | /* Parse port fault information field */ |
| 5233 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5234 | |
| 5235 | /* Parse and translate link attention fields */ |
| 5236 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5237 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5238 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5239 | if (phba->sli4_hba.link_state.status == |
| 5240 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5241 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5242 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5243 | } else { |
| 5244 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5245 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5246 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5247 | /* Invoke the mailbox command callback function */ |
| 5248 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5249 | |
| 5250 | return; |
| 5251 | } |
| 5252 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5253 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5254 | if (rc == MBX_NOT_FINISHED) |
| 5255 | goto out_free_dmabuf; |
| 5256 | return; |
| 5257 | |
| 5258 | out_free_dmabuf: |
| 5259 | kfree(mp); |
| 5260 | out_free_pmb: |
| 5261 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5262 | } |
| 5263 | |
| 5264 | /** |
| 5265 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5266 | * @phba: pointer to lpfc hba data structure. |
| 5267 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 5268 | * |
| 5269 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5270 | **/ |
| 5271 | static void |
| 5272 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5273 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5274 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5275 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5276 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5277 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5278 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5279 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5280 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5281 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5282 | struct lpfc_vport **vports; |
| 5283 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5284 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5285 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5286 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5287 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5288 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5289 | "x%08x SLI Event Type:%d\n", |
| 5290 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5291 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5292 | |
| 5293 | port_name = phba->Port[0]; |
| 5294 | if (port_name == 0x00) |
| 5295 | port_name = '?'; /* get port name is empty */ |
| 5296 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5297 | switch (evt_type) { |
| 5298 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5299 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5300 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5301 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5302 | |
| 5303 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5304 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5305 | acqe_sli->event_data1, port_name); |
| 5306 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5307 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5308 | shost = lpfc_shost_from_vport(phba->pport); |
| 5309 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5310 | sizeof(temp_event_data), |
| 5311 | (char *)&temp_event_data, |
| 5312 | SCSI_NL_VID_TYPE_PCI |
| 5313 | | PCI_VENDOR_ID_EMULEX); |
| 5314 | break; |
| 5315 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5316 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5317 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5318 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5319 | |
| 5320 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5321 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5322 | acqe_sli->event_data1, port_name); |
| 5323 | |
| 5324 | shost = lpfc_shost_from_vport(phba->pport); |
| 5325 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5326 | sizeof(temp_event_data), |
| 5327 | (char *)&temp_event_data, |
| 5328 | SCSI_NL_VID_TYPE_PCI |
| 5329 | | PCI_VENDOR_ID_EMULEX); |
| 5330 | break; |
| 5331 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5332 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5333 | &acqe_sli->event_data1; |
| 5334 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5335 | /* fetch the status for this port */ |
| 5336 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5337 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5338 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5339 | &misconfigured->theEvent); |
| 5340 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5341 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5342 | break; |
| 5343 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5344 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5345 | &misconfigured->theEvent); |
| 5346 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5347 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5348 | break; |
| 5349 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5350 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5351 | &misconfigured->theEvent); |
| 5352 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5353 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5354 | break; |
| 5355 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5356 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5357 | &misconfigured->theEvent); |
| 5358 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5359 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5360 | break; |
| 5361 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5362 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5363 | "3296 " |
| 5364 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5365 | "event: Invalid link %d", |
| 5366 | phba->sli4_hba.lnk_info.lnk_no); |
| 5367 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5368 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5369 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5370 | /* Skip if optic state unchanged */ |
| 5371 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5372 | return; |
| 5373 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5374 | switch (status) { |
| 5375 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5376 | sprintf(message, "Physical Link is functional"); |
| 5377 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5378 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5379 | sprintf(message, "Optics faulted/incorrectly " |
| 5380 | "installed/not installed - Reseat optics, " |
| 5381 | "if issue not resolved, replace."); |
| 5382 | break; |
| 5383 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5384 | sprintf(message, |
| 5385 | "Optics of two types installed - Remove one " |
| 5386 | "optic or install matching pair of optics."); |
| 5387 | break; |
| 5388 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5389 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5390 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5391 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5392 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5393 | sprintf(message, "Unqualified optics - Replace with " |
| 5394 | "Avago optics for Warranty and Technical " |
| 5395 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5396 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5397 | break; |
| 5398 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5399 | sprintf(message, "Uncertified optics - Replace with " |
| 5400 | "Avago-certified optics to enable link " |
| 5401 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5402 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5403 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5404 | default: |
| 5405 | /* firmware is reporting a status we don't know about */ |
| 5406 | sprintf(message, "Unknown event status x%02x", status); |
| 5407 | break; |
| 5408 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5409 | |
| 5410 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5411 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5412 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5413 | phba->lmt = 0; |
| 5414 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5415 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5416 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5417 | } |
| 5418 | vports = lpfc_create_vport_work_array(phba); |
| 5419 | if (vports != NULL) { |
| 5420 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5421 | i++) { |
| 5422 | shost = lpfc_shost_from_vport(vports[i]); |
| 5423 | lpfc_host_supported_speeds_set(shost); |
| 5424 | } |
| 5425 | } |
| 5426 | lpfc_destroy_vport_work_array(phba, vports); |
| 5427 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5428 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5429 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5430 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5431 | break; |
| 5432 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5433 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5434 | "3192 Remote DPort Test Initiated - " |
| 5435 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5436 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5437 | break; |
| 5438 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5439 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5440 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5441 | "x%08x SLI Event Type:%d\n", |
| 5442 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5443 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5444 | break; |
| 5445 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5449 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5450 | * @vport: pointer to vport data structure. |
| 5451 | * |
| 5452 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5453 | * response to a CVL event. |
| 5454 | * |
| 5455 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5456 | * return NULL. |
| 5457 | **/ |
| 5458 | static struct lpfc_nodelist * |
| 5459 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5460 | { |
| 5461 | struct lpfc_nodelist *ndlp; |
| 5462 | struct Scsi_Host *shost; |
| 5463 | struct lpfc_hba *phba; |
| 5464 | |
| 5465 | if (!vport) |
| 5466 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5467 | phba = vport->phba; |
| 5468 | if (!phba) |
| 5469 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5470 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5471 | if (!ndlp) { |
| 5472 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5473 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5474 | if (!ndlp) |
| 5475 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5476 | /* Set the node type */ |
| 5477 | ndlp->nlp_type |= NLP_FABRIC; |
| 5478 | /* Put ndlp onto node list */ |
| 5479 | lpfc_enqueue_node(vport, ndlp); |
| 5480 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5481 | /* re-setup ndlp without removing from node list */ |
| 5482 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5483 | if (!ndlp) |
| 5484 | return 0; |
| 5485 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5486 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5487 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5488 | return NULL; |
| 5489 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5490 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5491 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5492 | return NULL; |
| 5493 | shost = lpfc_shost_from_vport(vport); |
| 5494 | if (!shost) |
| 5495 | return NULL; |
| 5496 | lpfc_linkdown_port(vport); |
| 5497 | lpfc_cleanup_pending_mbox(vport); |
| 5498 | spin_lock_irq(shost->host_lock); |
| 5499 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5500 | spin_unlock_irq(shost->host_lock); |
| 5501 | |
| 5502 | return ndlp; |
| 5503 | } |
| 5504 | |
| 5505 | /** |
| 5506 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 5507 | * @vport: pointer to lpfc hba data structure. |
| 5508 | * |
| 5509 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5510 | * response to a FCF dead event. |
| 5511 | **/ |
| 5512 | static void |
| 5513 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5514 | { |
| 5515 | struct lpfc_vport **vports; |
| 5516 | int i; |
| 5517 | |
| 5518 | vports = lpfc_create_vport_work_array(phba); |
| 5519 | if (vports) |
| 5520 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5521 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5522 | lpfc_destroy_vport_work_array(phba, vports); |
| 5523 | } |
| 5524 | |
| 5525 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5526 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5527 | * @phba: pointer to lpfc hba data structure. |
| 5528 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 5529 | * |
| 5530 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5531 | **/ |
| 5532 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5533 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5534 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5535 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5536 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5537 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5538 | struct lpfc_vport *vport; |
| 5539 | struct lpfc_nodelist *ndlp; |
| 5540 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5541 | int active_vlink_present; |
| 5542 | struct lpfc_vport **vports; |
| 5543 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5544 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5545 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5546 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5547 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5548 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5549 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5550 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5551 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5552 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5553 | "2546 New FCF event, evt_tag:x%x, " |
| 5554 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5555 | acqe_fip->event_tag, |
| 5556 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5557 | else |
| 5558 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5559 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5560 | "2788 FCF param modified event, " |
| 5561 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5562 | acqe_fip->event_tag, |
| 5563 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5564 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5565 | /* |
| 5566 | * During period of FCF discovery, read the FCF |
| 5567 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5568 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5569 | */ |
| 5570 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5571 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5572 | "2779 Read FCF (x%x) for updating " |
| 5573 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5574 | acqe_fip->index); |
| 5575 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5576 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5577 | |
| 5578 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5579 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5580 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5581 | spin_unlock_irq(&phba->hbalock); |
| 5582 | break; |
| 5583 | } |
| 5584 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5585 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5586 | spin_unlock_irq(&phba->hbalock); |
| 5587 | break; |
| 5588 | } |
| 5589 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5590 | /* If the FCF has been in discovered state, do nothing. */ |
| 5591 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5592 | spin_unlock_irq(&phba->hbalock); |
| 5593 | break; |
| 5594 | } |
| 5595 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5596 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5597 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5598 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5599 | "2770 Start FCF table scan per async FCF " |
| 5600 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5601 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5602 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5603 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5604 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5605 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5606 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5607 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5608 | break; |
| 5609 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5610 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5611 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5612 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5613 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5614 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5615 | break; |
| 5616 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5617 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5618 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5619 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5620 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5621 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5622 | /* |
| 5623 | * If we are in the middle of FCF failover process, clear |
| 5624 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5625 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5626 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5627 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5628 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5629 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5630 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5631 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5632 | break; |
| 5633 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5634 | spin_unlock_irq(&phba->hbalock); |
| 5635 | |
| 5636 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5637 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5638 | break; |
| 5639 | |
| 5640 | /* |
| 5641 | * Otherwise, request the port to rediscover the entire FCF |
| 5642 | * table for a fast recovery from case that the current FCF |
| 5643 | * is no longer valid as we are not in the middle of FCF |
| 5644 | * failover process already. |
| 5645 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5646 | spin_lock_irq(&phba->hbalock); |
| 5647 | /* Mark the fast failover process in progress */ |
| 5648 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5649 | spin_unlock_irq(&phba->hbalock); |
| 5650 | |
| 5651 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5652 | "2771 Start FCF fast failover process due to " |
| 5653 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5654 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5655 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5656 | if (rc) { |
| 5657 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5658 | LOG_DISCOVERY, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5659 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5660 | "command failed, fail through to FCF " |
| 5661 | "dead event\n"); |
| 5662 | spin_lock_irq(&phba->hbalock); |
| 5663 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5664 | spin_unlock_irq(&phba->hbalock); |
| 5665 | /* |
| 5666 | * Last resort will fail over by treating this |
| 5667 | * as a link down to FCF registration. |
| 5668 | */ |
| 5669 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5670 | } else { |
| 5671 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5672 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5673 | /* |
| 5674 | * Handling fast FCF failover to a DEAD FCF event is |
| 5675 | * considered equalivant to receiving CVL to all vports. |
| 5676 | */ |
| 5677 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5678 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5679 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5680 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5681 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5682 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5683 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5684 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5685 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5686 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5687 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5688 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5689 | if (!ndlp) |
| 5690 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5691 | active_vlink_present = 0; |
| 5692 | |
| 5693 | vports = lpfc_create_vport_work_array(phba); |
| 5694 | if (vports) { |
| 5695 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5696 | i++) { |
| 5697 | if ((!(vports[i]->fc_flag & |
| 5698 | FC_VPORT_CVL_RCVD)) && |
| 5699 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5700 | active_vlink_present = 1; |
| 5701 | break; |
| 5702 | } |
| 5703 | } |
| 5704 | lpfc_destroy_vport_work_array(phba, vports); |
| 5705 | } |
| 5706 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5707 | /* |
| 5708 | * Don't re-instantiate if vport is marked for deletion. |
| 5709 | * If we are here first then vport_delete is going to wait |
| 5710 | * for discovery to complete. |
| 5711 | */ |
| 5712 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5713 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5714 | /* |
| 5715 | * If there are other active VLinks present, |
| 5716 | * re-instantiate the Vlink using FDISC. |
| 5717 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5718 | mod_timer(&ndlp->nlp_delayfunc, |
| 5719 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5720 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5721 | spin_lock_irq(shost->host_lock); |
| 5722 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5723 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5724 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5725 | vport->port_state = LPFC_FDISC; |
| 5726 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5727 | /* |
| 5728 | * Otherwise, we request port to rediscover |
| 5729 | * the entire FCF table for a fast recovery |
| 5730 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5731 | * is no longer valid if we are not already |
| 5732 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5733 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5734 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5735 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5736 | spin_unlock_irq(&phba->hbalock); |
| 5737 | break; |
| 5738 | } |
| 5739 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5740 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5741 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5742 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5743 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5744 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5745 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5746 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5747 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5748 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5749 | LOG_DISCOVERY, |
| 5750 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5751 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5752 | "through to CVL event\n"); |
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 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5755 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5756 | /* |
| 5757 | * Last resort will be re-try on the |
| 5758 | * the current registered FCF entry. |
| 5759 | */ |
| 5760 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5761 | } else |
| 5762 | /* |
| 5763 | * Reset FCF roundrobin bmask for new |
| 5764 | * discovery. |
| 5765 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5766 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5767 | } |
| 5768 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5769 | default: |
| 5770 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5771 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5772 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5773 | break; |
| 5774 | } |
| 5775 | } |
| 5776 | |
| 5777 | /** |
| 5778 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5779 | * @phba: pointer to lpfc hba data structure. |
| 5780 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5781 | * |
| 5782 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5783 | **/ |
| 5784 | static void |
| 5785 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5786 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5787 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5788 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5790 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5791 | "handled yet\n"); |
| 5792 | } |
| 5793 | |
| 5794 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5795 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5796 | * @phba: pointer to lpfc hba data structure. |
| 5797 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5798 | * |
| 5799 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5800 | * is an asynchronous notified of a logical link speed change. The Port |
| 5801 | * reports the logical link speed in units of 10Mbps. |
| 5802 | **/ |
| 5803 | static void |
| 5804 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5805 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5806 | { |
| 5807 | uint16_t prev_ll_spd; |
| 5808 | |
| 5809 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5810 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5811 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5812 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5813 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5814 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5815 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5816 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5817 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5818 | } |
| 5819 | |
| 5820 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5821 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5822 | * @phba: pointer to lpfc hba data structure. |
| 5823 | * |
| 5824 | * This routine is invoked by the worker thread to process all the pending |
| 5825 | * SLI4 asynchronous events. |
| 5826 | **/ |
| 5827 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5828 | { |
| 5829 | struct lpfc_cq_event *cq_event; |
| 5830 | |
| 5831 | /* First, declare the async event has been handled */ |
| 5832 | spin_lock_irq(&phba->hbalock); |
| 5833 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5834 | spin_unlock_irq(&phba->hbalock); |
| 5835 | /* Now, handle all the async events */ |
| 5836 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5837 | /* Get the first event from the head of the event queue */ |
| 5838 | spin_lock_irq(&phba->hbalock); |
| 5839 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5840 | cq_event, struct lpfc_cq_event, list); |
| 5841 | spin_unlock_irq(&phba->hbalock); |
| 5842 | /* Process the asynchronous event */ |
| 5843 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5844 | case LPFC_TRAILER_CODE_LINK: |
| 5845 | lpfc_sli4_async_link_evt(phba, |
| 5846 | &cq_event->cqe.acqe_link); |
| 5847 | break; |
| 5848 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5849 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5850 | break; |
| 5851 | case LPFC_TRAILER_CODE_DCBX: |
| 5852 | lpfc_sli4_async_dcbx_evt(phba, |
| 5853 | &cq_event->cqe.acqe_dcbx); |
| 5854 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5855 | case LPFC_TRAILER_CODE_GRP5: |
| 5856 | lpfc_sli4_async_grp5_evt(phba, |
| 5857 | &cq_event->cqe.acqe_grp5); |
| 5858 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5859 | case LPFC_TRAILER_CODE_FC: |
| 5860 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5861 | break; |
| 5862 | case LPFC_TRAILER_CODE_SLI: |
| 5863 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5864 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5865 | default: |
| 5866 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5867 | "1804 Invalid asynchrous event code: " |
| 5868 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5869 | &cq_event->cqe.mcqe_cmpl)); |
| 5870 | break; |
| 5871 | } |
| 5872 | /* Free the completion event processed to the free pool */ |
| 5873 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5878 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5879 | * @phba: pointer to lpfc hba data structure. |
| 5880 | * |
| 5881 | * This routine is invoked by the worker thread to process FCF table |
| 5882 | * rediscovery pending completion event. |
| 5883 | **/ |
| 5884 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5885 | { |
| 5886 | int rc; |
| 5887 | |
| 5888 | spin_lock_irq(&phba->hbalock); |
| 5889 | /* Clear FCF rediscovery timeout event */ |
| 5890 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5891 | /* Clear driver fast failover FCF record flag */ |
| 5892 | phba->fcf.failover_rec.flag = 0; |
| 5893 | /* Set state for FCF fast failover */ |
| 5894 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5895 | spin_unlock_irq(&phba->hbalock); |
| 5896 | |
| 5897 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5898 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5899 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5900 | 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] | 5901 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5902 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5903 | "2747 Issue FCF scan read FCF mailbox " |
| 5904 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5908 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5909 | * @phba: pointer to lpfc hba data structure. |
| 5910 | * @dev_grp: The HBA PCI-Device group number. |
| 5911 | * |
| 5912 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5913 | * API jump table entries. |
| 5914 | * |
| 5915 | * Return: 0 if success, otherwise -ENODEV |
| 5916 | **/ |
| 5917 | int |
| 5918 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5919 | { |
| 5920 | int rc; |
| 5921 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5922 | /* Set up lpfc PCI-device group */ |
| 5923 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5924 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5925 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5926 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5927 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5928 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5929 | /* Set up device INIT API function jump table */ |
| 5930 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5931 | if (rc) |
| 5932 | return -ENODEV; |
| 5933 | /* Set up SCSI API function jump table */ |
| 5934 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5935 | if (rc) |
| 5936 | return -ENODEV; |
| 5937 | /* Set up SLI API function jump table */ |
| 5938 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5939 | if (rc) |
| 5940 | return -ENODEV; |
| 5941 | /* Set up MBOX API function jump table */ |
| 5942 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5943 | if (rc) |
| 5944 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5945 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5946 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5950 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5951 | * @phba: pointer to lpfc hba data structure. |
| 5952 | * @intr_mode: active interrupt mode adopted. |
| 5953 | * |
| 5954 | * This routine it invoked to log the currently used active interrupt mode |
| 5955 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5956 | **/ |
| 5957 | 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] | 5958 | { |
| 5959 | switch (intr_mode) { |
| 5960 | case 0: |
| 5961 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5962 | "0470 Enable INTx interrupt mode.\n"); |
| 5963 | break; |
| 5964 | case 1: |
| 5965 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5966 | "0481 Enabled MSI interrupt mode.\n"); |
| 5967 | break; |
| 5968 | case 2: |
| 5969 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5970 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5971 | break; |
| 5972 | default: |
| 5973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5974 | "0482 Illegal interrupt mode.\n"); |
| 5975 | break; |
| 5976 | } |
| 5977 | return; |
| 5978 | } |
| 5979 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5980 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5981 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5982 | * @phba: pointer to lpfc hba data structure. |
| 5983 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5984 | * This routine is invoked to enable the PCI device that is common to all |
| 5985 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5986 | * |
| 5987 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5988 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5989 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5990 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5991 | static int |
| 5992 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5993 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5994 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5995 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5996 | /* Obtain PCI device reference */ |
| 5997 | if (!phba->pcidev) |
| 5998 | goto out_error; |
| 5999 | else |
| 6000 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6001 | /* Enable PCI device */ |
| 6002 | if (pci_enable_device_mem(pdev)) |
| 6003 | goto out_error; |
| 6004 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6005 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6006 | goto out_disable_device; |
| 6007 | /* Set up device as PCI master and save state for EEH */ |
| 6008 | pci_set_master(pdev); |
| 6009 | pci_try_set_mwi(pdev); |
| 6010 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6011 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6012 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6013 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6014 | pdev->needs_freset = 1; |
| 6015 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6016 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6017 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6018 | out_disable_device: |
| 6019 | pci_disable_device(pdev); |
| 6020 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 6021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6022 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6023 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6027 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6028 | * @phba: pointer to lpfc hba data structure. |
| 6029 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6030 | * This routine is invoked to disable the PCI device that is common to all |
| 6031 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6032 | **/ |
| 6033 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6034 | lpfc_disable_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 | return; |
| 6041 | else |
| 6042 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6043 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6044 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6045 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6046 | |
| 6047 | return; |
| 6048 | } |
| 6049 | |
| 6050 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6051 | * lpfc_reset_hba - Reset a hba |
| 6052 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6053 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6054 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6055 | * offline, performs a board restart, and then brings the board back |
| 6056 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6057 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6058 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6059 | void |
| 6060 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6061 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6062 | /* If resets are disabled then set error state and return. */ |
| 6063 | if (!phba->cfg_enable_hba_reset) { |
| 6064 | phba->link_state = LPFC_HBA_ERROR; |
| 6065 | return; |
| 6066 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6067 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 6068 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 6069 | else |
| 6070 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6071 | lpfc_offline(phba); |
| 6072 | lpfc_sli_brdrestart(phba); |
| 6073 | lpfc_online(phba); |
| 6074 | lpfc_unblock_mgmt_io(phba); |
| 6075 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6076 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6077 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6078 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6079 | * @phba: pointer to lpfc hba data structure. |
| 6080 | * |
| 6081 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6082 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6083 | * enable the number of virtual functions to the physical function. As |
| 6084 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6085 | * API call does not considered as an error condition for most of the device. |
| 6086 | **/ |
| 6087 | uint16_t |
| 6088 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6089 | { |
| 6090 | struct pci_dev *pdev = phba->pcidev; |
| 6091 | uint16_t nr_virtfn; |
| 6092 | int pos; |
| 6093 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6094 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6095 | if (pos == 0) |
| 6096 | return 0; |
| 6097 | |
| 6098 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6099 | return nr_virtfn; |
| 6100 | } |
| 6101 | |
| 6102 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6103 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6104 | * @phba: pointer to lpfc hba data structure. |
| 6105 | * @nr_vfn: number of virtual functions to be enabled. |
| 6106 | * |
| 6107 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6108 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6109 | * enable the number of virtual functions to the physical function. As |
| 6110 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6111 | * API call does not considered as an error condition for most of the device. |
| 6112 | **/ |
| 6113 | int |
| 6114 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6115 | { |
| 6116 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6117 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6118 | int rc; |
| 6119 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6120 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6121 | if (nr_vfn > max_nr_vfn) { |
| 6122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6123 | "3057 Requested vfs (%d) greater than " |
| 6124 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6125 | return -EINVAL; |
| 6126 | } |
| 6127 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6128 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6129 | if (rc) { |
| 6130 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6131 | "2806 Failed to enable sriov on this device " |
| 6132 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6133 | nr_vfn, rc); |
| 6134 | } else |
| 6135 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6136 | "2807 Successful enable sriov on this device " |
| 6137 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6138 | return rc; |
| 6139 | } |
| 6140 | |
| 6141 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6142 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6143 | * @phba: pointer to lpfc hba data structure. |
| 6144 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6145 | * This routine is invoked to set up the driver internal resources before the |
| 6146 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6147 | * |
| 6148 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6149 | * 0 - successful |
| 6150 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6151 | **/ |
| 6152 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6153 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6154 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6155 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6156 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6157 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6158 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6159 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6160 | atomic_set(&phba->fast_event_count, 0); |
| 6161 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6162 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6163 | /* Initialize ndlp management spinlock */ |
| 6164 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6165 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6166 | /* Initialize port_list spinlock */ |
| 6167 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6168 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6169 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6170 | INIT_LIST_HEAD(&phba->work_list); |
| 6171 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6172 | |
| 6173 | /* Initialize the wait queue head for the kernel thread */ |
| 6174 | init_waitqueue_head(&phba->work_waitq); |
| 6175 | |
| 6176 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6177 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6178 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6179 | "SCSI" : " "), |
| 6180 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6181 | "NVME" : " "), |
| 6182 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6183 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6184 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6185 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6186 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6187 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6188 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6189 | |
| 6190 | /* Initialize the fabric iocb list */ |
| 6191 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6192 | |
| 6193 | /* Initialize list to save ELS buffers */ |
| 6194 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6195 | |
| 6196 | /* Initialize FCF connection rec list */ |
| 6197 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6198 | |
| 6199 | /* Initialize OAS configuration list */ |
| 6200 | spin_lock_init(&phba->devicelock); |
| 6201 | INIT_LIST_HEAD(&phba->luns); |
| 6202 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6203 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6204 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6205 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6206 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6207 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6208 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6209 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6210 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6211 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6212 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6213 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6214 | return 0; |
| 6215 | } |
| 6216 | |
| 6217 | /** |
| 6218 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6219 | * @phba: pointer to lpfc hba data structure. |
| 6220 | * |
| 6221 | * This routine is invoked to set up the driver internal resources specific to |
| 6222 | * support the SLI-3 HBA device it attached to. |
| 6223 | * |
| 6224 | * Return codes |
| 6225 | * 0 - successful |
| 6226 | * other values - error |
| 6227 | **/ |
| 6228 | static int |
| 6229 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6230 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6231 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6232 | |
| 6233 | /* |
| 6234 | * Initialize timers used by driver |
| 6235 | */ |
| 6236 | |
| 6237 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6238 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6239 | |
| 6240 | /* Host attention work mask setup */ |
| 6241 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6242 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6243 | |
| 6244 | /* Get all the module params for configuring this host */ |
| 6245 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6246 | /* Set up phase-1 common device driver resources */ |
| 6247 | |
| 6248 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6249 | if (rc) |
| 6250 | return -ENODEV; |
| 6251 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6252 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6253 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6254 | /* check for menlo minimum sg count */ |
| 6255 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6256 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6257 | } |
| 6258 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6259 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6260 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6261 | sizeof(struct lpfc_sli_ring), |
| 6262 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6263 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6264 | return -ENOMEM; |
| 6265 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6266 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6267 | * 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] | 6268 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6269 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6270 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6271 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6272 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 6273 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 6274 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6275 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6276 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6277 | entry_sz = sizeof(struct sli4_sge); |
| 6278 | else |
| 6279 | entry_sz = sizeof(struct ulp_bde64); |
| 6280 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6281 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6282 | if (phba->cfg_enable_bg) { |
| 6283 | /* |
| 6284 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6285 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6286 | * over how many protection data segments the SCSI Layer |
| 6287 | * will hand us (ie: there could be one for every block |
| 6288 | * in the IO), we just allocate enough BDEs to accomidate |
| 6289 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6290 | * minimize the risk of running out. |
| 6291 | */ |
| 6292 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6293 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6294 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6295 | |
| 6296 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6297 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6298 | |
| 6299 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6300 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6301 | } else { |
| 6302 | /* |
| 6303 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6304 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6305 | * cfg_sg_seg_cnt data segments. |
| 6306 | */ |
| 6307 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6308 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6309 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6310 | |
| 6311 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6312 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6313 | } |
| 6314 | |
| 6315 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6316 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 6317 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6318 | phba->cfg_total_seg_cnt); |
| 6319 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6320 | phba->max_vpi = LPFC_MAX_VPI; |
| 6321 | /* This will be set to correct value after config_port mbox */ |
| 6322 | phba->max_vports = 0; |
| 6323 | |
| 6324 | /* |
| 6325 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6326 | */ |
| 6327 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6328 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6329 | |
| 6330 | /* Allocate device driver memory */ |
| 6331 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6332 | return -ENOMEM; |
| 6333 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6334 | /* |
| 6335 | * Enable sr-iov virtual functions if supported and configured |
| 6336 | * through the module parameter. |
| 6337 | */ |
| 6338 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6339 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6340 | phba->cfg_sriov_nr_virtfn); |
| 6341 | if (rc) { |
| 6342 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6343 | "2808 Requested number of SR-IOV " |
| 6344 | "virtual functions (%d) is not " |
| 6345 | "supported\n", |
| 6346 | phba->cfg_sriov_nr_virtfn); |
| 6347 | phba->cfg_sriov_nr_virtfn = 0; |
| 6348 | } |
| 6349 | } |
| 6350 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6351 | return 0; |
| 6352 | } |
| 6353 | |
| 6354 | /** |
| 6355 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6356 | * @phba: pointer to lpfc hba data structure. |
| 6357 | * |
| 6358 | * This routine is invoked to unset the driver internal resources set up |
| 6359 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6360 | **/ |
| 6361 | static void |
| 6362 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6363 | { |
| 6364 | /* Free device driver memory allocated */ |
| 6365 | lpfc_mem_free_all(phba); |
| 6366 | |
| 6367 | return; |
| 6368 | } |
| 6369 | |
| 6370 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6371 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6372 | * @phba: pointer to lpfc hba data structure. |
| 6373 | * |
| 6374 | * This routine is invoked to set up the driver internal resources specific to |
| 6375 | * support the SLI-4 HBA device it attached to. |
| 6376 | * |
| 6377 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6378 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6379 | * other values - error |
| 6380 | **/ |
| 6381 | static int |
| 6382 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6383 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6384 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6385 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6386 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6387 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 6388 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6389 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6390 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6391 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6392 | u32 if_type; |
| 6393 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6394 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6395 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6396 | phba->sli4_hba.num_possible_cpu = num_possible_cpus(); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6397 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6398 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6399 | /* Get all the module params for configuring this host */ |
| 6400 | lpfc_get_cfgparam(phba); |
| 6401 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6402 | /* Set up phase-1 common device driver resources */ |
| 6403 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6404 | if (rc) |
| 6405 | return -ENODEV; |
| 6406 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6407 | /* Before proceed, wait for POST done and device ready */ |
| 6408 | rc = lpfc_sli4_post_status_check(phba); |
| 6409 | if (rc) |
| 6410 | return -ENODEV; |
| 6411 | |
| 6412 | /* |
| 6413 | * Initialize timers used by driver |
| 6414 | */ |
| 6415 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6416 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6417 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6418 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6419 | 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] | 6420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6421 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6422 | * Control structure for handling external multi-buffer mailbox |
| 6423 | * command pass-through. |
| 6424 | */ |
| 6425 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6426 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6427 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6428 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6429 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6430 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6431 | /* This will be set to correct value after the read_config mbox */ |
| 6432 | phba->max_vports = 0; |
| 6433 | |
| 6434 | /* Program the default value of vlan_id and fc_map */ |
| 6435 | phba->valid_vlan = 0; |
| 6436 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6437 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6438 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6439 | |
| 6440 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6441 | * 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] | 6442 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6443 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6444 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6445 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6446 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6447 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6448 | * for boundary conditions in its max_sgl_segment template. |
| 6449 | */ |
| 6450 | extra = 2; |
| 6451 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6452 | extra++; |
| 6453 | |
| 6454 | /* |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6455 | * It doesn't matter what family our adapter is in, we are |
| 6456 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6457 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6458 | */ |
| 6459 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6460 | |
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 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6463 | * used to create the sg_dma_buf_pool must be calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6464 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 6465 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6466 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6467 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6468 | * the FCP rsp, and a SGE. Sice we have no control |
| 6469 | * over how many protection segments the SCSI Layer |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6470 | * will hand us (ie: there could be one for every block |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6471 | * in the IO), just allocate enough SGEs to accomidate |
| 6472 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6473 | * to minimize the risk of running out. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6474 | */ |
| 6475 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6476 | sizeof(struct fcp_rsp) + max_buf_size; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6477 | |
| 6478 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6479 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6480 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6481 | /* |
| 6482 | * If supporting DIF, reduce the seg count for scsi to |
| 6483 | * allow room for the DIF sges. |
| 6484 | */ |
| 6485 | if (phba->cfg_enable_bg && |
| 6486 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6487 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6488 | else |
| 6489 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6490 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6491 | } else { |
| 6492 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6493 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6494 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6495 | * cfg_sg_seg_cnt data segments. |
| 6496 | */ |
| 6497 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6498 | sizeof(struct fcp_rsp) + |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6499 | ((phba->cfg_sg_seg_cnt + extra) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6500 | sizeof(struct sli4_sge)); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6501 | |
| 6502 | /* Total SGEs for scsi_sg_list */ |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6503 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6504 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6505 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6506 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6507 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6508 | * need to post 1 page for the SGL. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6509 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6510 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 6511 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6512 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6513 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6514 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6515 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6516 | "6300 Reducing NVME sg segment " |
| 6517 | "cnt to %d\n", |
| 6518 | LPFC_MAX_NVME_SEG_CNT); |
| 6519 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6520 | } else |
| 6521 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6522 | } |
| 6523 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6524 | /* Initialize the host templates with the updated values. */ |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6525 | lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6526 | lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6527 | lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6528 | |
| 6529 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6530 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6531 | else |
| 6532 | phba->cfg_sg_dma_buf_size = |
| 6533 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6534 | |
| 6535 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6536 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6537 | "total:%d scsi:%d nvme:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6538 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6539 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6540 | phba->cfg_nvme_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6541 | |
| 6542 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6543 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6544 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6545 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6546 | |
| 6547 | /* |
| 6548 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6549 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6550 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 6551 | /* Initialize the Abort scsi buffer list used by driver */ |
| 6552 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 6553 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 6554 | } |
| 6555 | |
| 6556 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6557 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6558 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6559 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6560 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6561 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6562 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6565 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6566 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6567 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6568 | |
| 6569 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6570 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6571 | */ |
| 6572 | |
| 6573 | /* Driver internel slow-path CQ Event pool */ |
| 6574 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6575 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6576 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6577 | /* Asynchronous event CQ Event work queue list */ |
| 6578 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 6579 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 6580 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 6581 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6582 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6583 | /* Receive queue CQ Event work queue list */ |
| 6584 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6585 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6586 | /* Initialize extent block lists. */ |
| 6587 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6588 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6589 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6590 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6591 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6592 | /* Initialize mboxq lists. If the early init routines fail |
| 6593 | * these lists need to be correctly initialized. |
| 6594 | */ |
| 6595 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6596 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6597 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6598 | /* initialize optic_state to 0xFF */ |
| 6599 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6600 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6601 | /* Allocate device driver memory */ |
| 6602 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6603 | if (rc) |
| 6604 | return -ENOMEM; |
| 6605 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6606 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6607 | 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] | 6608 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6609 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6610 | if (unlikely(rc)) { |
| 6611 | rc = -ENODEV; |
| 6612 | goto out_free_mem; |
| 6613 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6614 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6615 | } |
| 6616 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6617 | /* Create the bootstrap mailbox command */ |
| 6618 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6619 | if (unlikely(rc)) |
| 6620 | goto out_free_mem; |
| 6621 | |
| 6622 | /* Set up the host's endian order with the device. */ |
| 6623 | rc = lpfc_setup_endian_order(phba); |
| 6624 | if (unlikely(rc)) |
| 6625 | goto out_free_bsmbx; |
| 6626 | |
| 6627 | /* Set up the hba's configuration parameters. */ |
| 6628 | rc = lpfc_sli4_read_config(phba); |
| 6629 | if (unlikely(rc)) |
| 6630 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6631 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6632 | if (unlikely(rc)) |
| 6633 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6634 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6635 | /* IF Type 0 ports get initialized now. */ |
| 6636 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6637 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6638 | rc = lpfc_pci_function_reset(phba); |
| 6639 | if (unlikely(rc)) |
| 6640 | goto out_free_bsmbx; |
| 6641 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6642 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6643 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6644 | GFP_KERNEL); |
| 6645 | if (!mboxq) { |
| 6646 | rc = -ENOMEM; |
| 6647 | goto out_free_bsmbx; |
| 6648 | } |
| 6649 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6650 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6651 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6652 | if (lpfc_enable_nvmet_cnt) { |
| 6653 | |
| 6654 | /* First get WWN of HBA instance */ |
| 6655 | lpfc_read_nv(phba, mboxq); |
| 6656 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6657 | if (rc != MBX_SUCCESS) { |
| 6658 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6659 | "6016 Mailbox failed , mbxCmd x%x " |
| 6660 | "READ_NV, mbxStatus x%x\n", |
| 6661 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6662 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6663 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6664 | rc = -EIO; |
| 6665 | goto out_free_bsmbx; |
| 6666 | } |
| 6667 | mb = &mboxq->u.mb; |
| 6668 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6669 | sizeof(uint64_t)); |
| 6670 | wwn = cpu_to_be64(wwn); |
| 6671 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6672 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6673 | sizeof(uint64_t)); |
| 6674 | /* wwn is WWPN of HBA instance */ |
| 6675 | wwn = cpu_to_be64(wwn); |
| 6676 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6677 | |
| 6678 | /* Check to see if it matches any module parameter */ |
| 6679 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6680 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6681 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6682 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6683 | break; |
| 6684 | |
| 6685 | phba->nvmet_support = 1; /* a match */ |
| 6686 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6688 | "6017 NVME Target %016llx\n", |
| 6689 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6690 | #else |
| 6691 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6692 | "6021 Can't enable NVME Target." |
| 6693 | " NVME_TARGET_FC infrastructure" |
| 6694 | " is not in kernel\n"); |
| 6695 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6696 | /* Not supported for NVMET */ |
| 6697 | phba->cfg_xri_rebalancing = 0; |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6698 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6699 | } |
| 6700 | } |
| 6701 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6702 | |
| 6703 | lpfc_nvme_mod_param_dep(phba); |
| 6704 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6705 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6706 | lpfc_supported_pages(mboxq); |
| 6707 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6708 | if (!rc) { |
| 6709 | mqe = &mboxq->u.mqe; |
| 6710 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6711 | LPFC_MAX_SUPPORTED_PAGES); |
| 6712 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6713 | switch (pn_page[i]) { |
| 6714 | case LPFC_SLI4_PARAMETERS: |
| 6715 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6716 | break; |
| 6717 | default: |
| 6718 | break; |
| 6719 | } |
| 6720 | } |
| 6721 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6722 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6723 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6724 | if (rc) { |
| 6725 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6726 | rc = -EIO; |
| 6727 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6728 | } |
| 6729 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6730 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6731 | /* |
| 6732 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6733 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6734 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6735 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6736 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6737 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6738 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6739 | &phba->sli4_hba.sli_intf); |
| 6740 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6741 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6742 | if (phba->sli4_hba.extents_in_use && |
| 6743 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6745 | "2999 Unsupported SLI4 Parameters " |
| 6746 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6747 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6748 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6749 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6750 | rc = -EIO; |
| 6751 | goto out_free_bsmbx; |
| 6752 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6753 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6754 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6755 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6756 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6757 | rc = -EIO; |
| 6758 | goto out_free_bsmbx; |
| 6759 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6760 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6761 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6762 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6763 | |
| 6764 | /* Verify OAS is supported */ |
| 6765 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6766 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6767 | /* Verify RAS support on adapter */ |
| 6768 | lpfc_sli4_ras_init(phba); |
| 6769 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6770 | /* Verify all the SLI4 queues */ |
| 6771 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6772 | if (rc) |
| 6773 | goto out_free_bsmbx; |
| 6774 | |
| 6775 | /* Create driver internal CQE event pool */ |
| 6776 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6777 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6778 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6779 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6780 | /* Initialize sgl lists per host */ |
| 6781 | lpfc_init_sgl_list(phba); |
| 6782 | |
| 6783 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6784 | rc = lpfc_init_active_sgl_array(phba); |
| 6785 | if (rc) { |
| 6786 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6787 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6788 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6789 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6790 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6791 | if (rc) { |
| 6792 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6793 | "1432 Failed to initialize rpi headers.\n"); |
| 6794 | goto out_free_active_sgl; |
| 6795 | } |
| 6796 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6797 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6798 | 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] | 6799 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6800 | GFP_KERNEL); |
| 6801 | if (!phba->fcf.fcf_rr_bmask) { |
| 6802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6803 | "2759 Failed allocate memory for FCF round " |
| 6804 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6805 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6806 | goto out_remove_rpi_hdrs; |
| 6807 | } |
| 6808 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 6809 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6810 | sizeof(struct lpfc_hba_eq_hdl), |
| 6811 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6812 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6813 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6814 | "2572 Failed allocate memory for " |
| 6815 | "fast-path per-EQ handle array\n"); |
| 6816 | rc = -ENOMEM; |
| 6817 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6820 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6821 | sizeof(struct lpfc_vector_map_info), |
| 6822 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6823 | if (!phba->sli4_hba.cpu_map) { |
| 6824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6825 | "3327 Failed allocate memory for msi-x " |
| 6826 | "interrupt vector mapping\n"); |
| 6827 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6828 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6829 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6830 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6831 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 6832 | if (!phba->sli4_hba.eq_info) { |
| 6833 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6834 | "3321 Failed allocation for per_cpu stats\n"); |
| 6835 | rc = -ENOMEM; |
| 6836 | goto out_free_hba_cpu_map; |
| 6837 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6838 | /* |
| 6839 | * Enable sr-iov virtual functions if supported and configured |
| 6840 | * through the module parameter. |
| 6841 | */ |
| 6842 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6843 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6844 | phba->cfg_sriov_nr_virtfn); |
| 6845 | if (rc) { |
| 6846 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6847 | "3020 Requested number of SR-IOV " |
| 6848 | "virtual functions (%d) is not " |
| 6849 | "supported\n", |
| 6850 | phba->cfg_sriov_nr_virtfn); |
| 6851 | phba->cfg_sriov_nr_virtfn = 0; |
| 6852 | } |
| 6853 | } |
| 6854 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6855 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6856 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6857 | out_free_hba_cpu_map: |
| 6858 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6859 | out_free_hba_eq_hdl: |
| 6860 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6861 | out_free_fcf_rr_bmask: |
| 6862 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6863 | out_remove_rpi_hdrs: |
| 6864 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6865 | out_free_active_sgl: |
| 6866 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6867 | out_destroy_cq_event_pool: |
| 6868 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6869 | out_free_bsmbx: |
| 6870 | lpfc_destroy_bootstrap_mbox(phba); |
| 6871 | out_free_mem: |
| 6872 | lpfc_mem_free(phba); |
| 6873 | return rc; |
| 6874 | } |
| 6875 | |
| 6876 | /** |
| 6877 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6878 | * @phba: pointer to lpfc hba data structure. |
| 6879 | * |
| 6880 | * This routine is invoked to unset the driver internal resources set up |
| 6881 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6882 | **/ |
| 6883 | static void |
| 6884 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6885 | { |
| 6886 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6887 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6888 | free_percpu(phba->sli4_hba.eq_info); |
| 6889 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6890 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6891 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6892 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6893 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6894 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6895 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6896 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6897 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6898 | |
| 6899 | /* Free the allocated rpi headers. */ |
| 6900 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 6901 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6902 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6903 | /* Free eligible FCF index bmask */ |
| 6904 | kfree(phba->fcf.fcf_rr_bmask); |
| 6905 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6906 | /* Free the ELS sgl list */ |
| 6907 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6908 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6909 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6910 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6911 | /* Free the completion queue EQ event pool */ |
| 6912 | lpfc_sli4_cq_event_release_all(phba); |
| 6913 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 6914 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6915 | /* Release resource identifiers. */ |
| 6916 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6917 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6918 | /* Free the bsmbx region. */ |
| 6919 | lpfc_destroy_bootstrap_mbox(phba); |
| 6920 | |
| 6921 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 6922 | lpfc_mem_free_all(phba); |
| 6923 | |
| 6924 | /* Free the current connect table */ |
| 6925 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6926 | &phba->fcf_conn_rec_list, list) { |
| 6927 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6928 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6929 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6930 | |
| 6931 | return; |
| 6932 | } |
| 6933 | |
| 6934 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6935 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6936 | * @phba: The hba struct for which this call is being executed. |
| 6937 | * @dev_grp: The HBA PCI-Device group number. |
| 6938 | * |
| 6939 | * This routine sets up the device INIT interface API function jump table |
| 6940 | * in @phba struct. |
| 6941 | * |
| 6942 | * Returns: 0 - success, -ENODEV - failure. |
| 6943 | **/ |
| 6944 | int |
| 6945 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 6946 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 6947 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 6948 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 6949 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6950 | switch (dev_grp) { |
| 6951 | case LPFC_PCI_DEV_LP: |
| 6952 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 6953 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 6954 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 6955 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6956 | case LPFC_PCI_DEV_OC: |
| 6957 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 6958 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 6959 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 6960 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6961 | default: |
| 6962 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6963 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 6964 | dev_grp); |
| 6965 | return -ENODEV; |
| 6966 | break; |
| 6967 | } |
| 6968 | return 0; |
| 6969 | } |
| 6970 | |
| 6971 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6972 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 6973 | * @phba: pointer to lpfc hba data structure. |
| 6974 | * |
| 6975 | * This routine is invoked to set up the driver internal resources after the |
| 6976 | * device specific resource setup to support the HBA device it attached to. |
| 6977 | * |
| 6978 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6979 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6980 | * other values - error |
| 6981 | **/ |
| 6982 | static int |
| 6983 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 6984 | { |
| 6985 | int error; |
| 6986 | |
| 6987 | /* Startup the kernel thread for this host adapter. */ |
| 6988 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 6989 | "lpfc_worker_%d", phba->brd_no); |
| 6990 | if (IS_ERR(phba->worker_thread)) { |
| 6991 | error = PTR_ERR(phba->worker_thread); |
| 6992 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6993 | } |
| 6994 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 6995 | /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */ |
| 6996 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6997 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6998 | else |
| 6999 | phba->wq = NULL; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7000 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7001 | return 0; |
| 7002 | } |
| 7003 | |
| 7004 | /** |
| 7005 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7006 | * @phba: pointer to lpfc hba data structure. |
| 7007 | * |
| 7008 | * This routine is invoked to unset the driver internal resources set up after |
| 7009 | * the device specific resource setup for supporting the HBA device it |
| 7010 | * attached to. |
| 7011 | **/ |
| 7012 | static void |
| 7013 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7014 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7015 | if (phba->wq) { |
| 7016 | flush_workqueue(phba->wq); |
| 7017 | destroy_workqueue(phba->wq); |
| 7018 | phba->wq = NULL; |
| 7019 | } |
| 7020 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7021 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7022 | if (phba->worker_thread) |
| 7023 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7024 | } |
| 7025 | |
| 7026 | /** |
| 7027 | * lpfc_free_iocb_list - Free iocb list. |
| 7028 | * @phba: pointer to lpfc hba data structure. |
| 7029 | * |
| 7030 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7031 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7032 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7033 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7034 | { |
| 7035 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7036 | |
| 7037 | spin_lock_irq(&phba->hbalock); |
| 7038 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7039 | &phba->lpfc_iocb_list, list) { |
| 7040 | list_del(&iocbq_entry->list); |
| 7041 | kfree(iocbq_entry); |
| 7042 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7043 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7044 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7045 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7046 | return; |
| 7047 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7048 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7049 | /** |
| 7050 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7051 | * @phba: pointer to lpfc hba data structure. |
| 7052 | * |
| 7053 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7054 | * list and set up the IOCB tag array accordingly. |
| 7055 | * |
| 7056 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7057 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7058 | * other values - error |
| 7059 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7060 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7061 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7062 | { |
| 7063 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7064 | uint16_t iotag; |
| 7065 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7066 | |
| 7067 | /* Initialize and populate the iocb list per host. */ |
| 7068 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7069 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7070 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7071 | if (iocbq_entry == NULL) { |
| 7072 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7073 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 7074 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7075 | goto out_free_iocbq; |
| 7076 | } |
| 7077 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7078 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7079 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7080 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7081 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7082 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7083 | goto out_free_iocbq; |
| 7084 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7085 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7086 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7087 | |
| 7088 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7089 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7090 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7091 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7092 | } |
| 7093 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7094 | return 0; |
| 7095 | |
| 7096 | out_free_iocbq: |
| 7097 | lpfc_free_iocb_list(phba); |
| 7098 | |
| 7099 | return -ENOMEM; |
| 7100 | } |
| 7101 | |
| 7102 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7103 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7104 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7105 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7106 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7107 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7108 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7109 | void |
| 7110 | 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] | 7111 | { |
| 7112 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7113 | |
| 7114 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7115 | list_del(&sglq_entry->list); |
| 7116 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7117 | kfree(sglq_entry); |
| 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | /** |
| 7122 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7123 | * @phba: pointer to lpfc hba data structure. |
| 7124 | * |
| 7125 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7126 | **/ |
| 7127 | static void |
| 7128 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7129 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7130 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7131 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7132 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7133 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7134 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7135 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 7136 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7137 | spin_unlock_irq(&phba->hbalock); |
| 7138 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7139 | /* Now free the sgl list */ |
| 7140 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7141 | } |
| 7142 | |
| 7143 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7144 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7145 | * @phba: pointer to lpfc hba data structure. |
| 7146 | * |
| 7147 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7148 | **/ |
| 7149 | static void |
| 7150 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7151 | { |
| 7152 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7153 | LIST_HEAD(sglq_list); |
| 7154 | |
| 7155 | /* Retrieve all nvmet sgls from driver list */ |
| 7156 | spin_lock_irq(&phba->hbalock); |
| 7157 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7158 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7159 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7160 | spin_unlock_irq(&phba->hbalock); |
| 7161 | |
| 7162 | /* Now free the sgl list */ |
| 7163 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7164 | list_del(&sglq_entry->list); |
| 7165 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7166 | kfree(sglq_entry); |
| 7167 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7168 | |
| 7169 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7170 | * The next initialization cycle sets the count and allocates |
| 7171 | * the sgls over again. |
| 7172 | */ |
| 7173 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7174 | } |
| 7175 | |
| 7176 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7177 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7178 | * @phba: pointer to lpfc hba data structure. |
| 7179 | * |
| 7180 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7181 | * This array will hold the sglq_entry's for active IOs. |
| 7182 | **/ |
| 7183 | static int |
| 7184 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7185 | { |
| 7186 | int size; |
| 7187 | size = sizeof(struct lpfc_sglq *); |
| 7188 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7189 | |
| 7190 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7191 | kzalloc(size, GFP_KERNEL); |
| 7192 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7193 | return -ENOMEM; |
| 7194 | return 0; |
| 7195 | } |
| 7196 | |
| 7197 | /** |
| 7198 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7199 | * @phba: pointer to lpfc hba data structure. |
| 7200 | * |
| 7201 | * This routine is invoked to walk through the array of active sglq entries |
| 7202 | * and free all of the resources. |
| 7203 | * This is just a place holder for now. |
| 7204 | **/ |
| 7205 | static void |
| 7206 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7207 | { |
| 7208 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7209 | } |
| 7210 | |
| 7211 | /** |
| 7212 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7213 | * @phba: pointer to lpfc hba data structure. |
| 7214 | * |
| 7215 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7216 | * list and set up the sgl xritag tag array accordingly. |
| 7217 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7218 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7219 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7220 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7221 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7222 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7223 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7224 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7225 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7226 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7227 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7228 | /* els xri-sgl book keeping */ |
| 7229 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7230 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7231 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7232 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | /** |
| 7236 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7237 | * @phba: pointer to lpfc hba data structure. |
| 7238 | * |
| 7239 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7240 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7241 | * 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] | 7242 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7243 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7244 | * |
| 7245 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7246 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7247 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7248 | **/ |
| 7249 | int |
| 7250 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7251 | { |
| 7252 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7253 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7254 | |
| 7255 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7256 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7257 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7258 | if (phba->sli4_hba.extents_in_use) |
| 7259 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7260 | |
| 7261 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7262 | if (!rpi_hdr) { |
| 7263 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7264 | "0391 Error during rpi post operation\n"); |
| 7265 | lpfc_sli4_remove_rpis(phba); |
| 7266 | rc = -ENODEV; |
| 7267 | } |
| 7268 | |
| 7269 | return rc; |
| 7270 | } |
| 7271 | |
| 7272 | /** |
| 7273 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7274 | * @phba: pointer to lpfc hba data structure. |
| 7275 | * |
| 7276 | * This routine is invoked to allocate a single 4KB memory region to |
| 7277 | * support rpis and stores them in the phba. This single region |
| 7278 | * provides support for up to 64 rpis. The region is used globally |
| 7279 | * by the device. |
| 7280 | * |
| 7281 | * Returns: |
| 7282 | * A valid rpi hdr on success. |
| 7283 | * A NULL pointer on any failure. |
| 7284 | **/ |
| 7285 | struct lpfc_rpi_hdr * |
| 7286 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7287 | { |
| 7288 | uint16_t rpi_limit, curr_rpi_range; |
| 7289 | struct lpfc_dmabuf *dmabuf; |
| 7290 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7291 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7292 | /* |
| 7293 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7294 | * required. Set the expected maximum count and let the actual value |
| 7295 | * get set when extents are fully allocated. |
| 7296 | */ |
| 7297 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7298 | return NULL; |
| 7299 | if (phba->sli4_hba.extents_in_use) |
| 7300 | return NULL; |
| 7301 | |
| 7302 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7303 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7304 | |
| 7305 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7306 | /* |
| 7307 | * Establish the starting RPI in this header block. The starting |
| 7308 | * rpi is normalized to a zero base because the physical rpi is |
| 7309 | * port based. |
| 7310 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7311 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7312 | spin_unlock_irq(&phba->hbalock); |
| 7313 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7314 | /* Reached full RPI range */ |
| 7315 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7316 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7317 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7318 | /* |
| 7319 | * First allocate the protocol header region for the port. The |
| 7320 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7321 | */ |
| 7322 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7323 | if (!dmabuf) |
| 7324 | return NULL; |
| 7325 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7326 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7327 | LPFC_HDR_TEMPLATE_SIZE, |
| 7328 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7329 | if (!dmabuf->virt) { |
| 7330 | rpi_hdr = NULL; |
| 7331 | goto err_free_dmabuf; |
| 7332 | } |
| 7333 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7334 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7335 | rpi_hdr = NULL; |
| 7336 | goto err_free_coherent; |
| 7337 | } |
| 7338 | |
| 7339 | /* Save the rpi header data for cleanup later. */ |
| 7340 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7341 | if (!rpi_hdr) |
| 7342 | goto err_free_coherent; |
| 7343 | |
| 7344 | rpi_hdr->dmabuf = dmabuf; |
| 7345 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7346 | rpi_hdr->page_count = 1; |
| 7347 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7348 | |
| 7349 | /* The rpi_hdr stores the logical index only. */ |
| 7350 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7351 | 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] | 7352 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7353 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7354 | spin_unlock_irq(&phba->hbalock); |
| 7355 | return rpi_hdr; |
| 7356 | |
| 7357 | err_free_coherent: |
| 7358 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7359 | dmabuf->virt, dmabuf->phys); |
| 7360 | err_free_dmabuf: |
| 7361 | kfree(dmabuf); |
| 7362 | return NULL; |
| 7363 | } |
| 7364 | |
| 7365 | /** |
| 7366 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7367 | * @phba: pointer to lpfc hba data structure. |
| 7368 | * |
| 7369 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7370 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7371 | * presumes the caller has released all rpis consumed by fabric or port |
| 7372 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7373 | **/ |
| 7374 | void |
| 7375 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7376 | { |
| 7377 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7378 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7379 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7380 | goto exit; |
| 7381 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7382 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7383 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7384 | list_del(&rpi_hdr->list); |
| 7385 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7386 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7387 | kfree(rpi_hdr->dmabuf); |
| 7388 | kfree(rpi_hdr); |
| 7389 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7390 | exit: |
| 7391 | /* There are no rpis available to the port now. */ |
| 7392 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7393 | } |
| 7394 | |
| 7395 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7396 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7397 | * @pdev: pointer to pci device data structure. |
| 7398 | * |
| 7399 | * This routine is invoked to allocate the driver hba data structure for an |
| 7400 | * HBA device. If the allocation is successful, the phba reference to the |
| 7401 | * PCI device data structure is set. |
| 7402 | * |
| 7403 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7404 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7405 | * NULL - error |
| 7406 | **/ |
| 7407 | static struct lpfc_hba * |
| 7408 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7409 | { |
| 7410 | struct lpfc_hba *phba; |
| 7411 | |
| 7412 | /* Allocate memory for HBA structure */ |
| 7413 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7414 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7415 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7416 | return NULL; |
| 7417 | } |
| 7418 | |
| 7419 | /* Set reference to PCI device in HBA structure */ |
| 7420 | phba->pcidev = pdev; |
| 7421 | |
| 7422 | /* Assign an unused board number */ |
| 7423 | phba->brd_no = lpfc_get_instance(); |
| 7424 | if (phba->brd_no < 0) { |
| 7425 | kfree(phba); |
| 7426 | return NULL; |
| 7427 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7428 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7429 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7430 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7431 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7432 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7433 | return phba; |
| 7434 | } |
| 7435 | |
| 7436 | /** |
| 7437 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7438 | * @phba: pointer to lpfc hba data structure. |
| 7439 | * |
| 7440 | * This routine is invoked to free the driver hba data structure with an |
| 7441 | * HBA device. |
| 7442 | **/ |
| 7443 | static void |
| 7444 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7445 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7446 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7447 | kfree(phba->sli4_hba.hdwq); |
| 7448 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7449 | /* Release the driver assigned board number */ |
| 7450 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7451 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7452 | /* Free memory allocated with sli3 rings */ |
| 7453 | kfree(phba->sli.sli3_ring); |
| 7454 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7455 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7456 | kfree(phba); |
| 7457 | return; |
| 7458 | } |
| 7459 | |
| 7460 | /** |
| 7461 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7462 | * @phba: pointer to lpfc hba data structure. |
| 7463 | * |
| 7464 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7465 | * host with it. |
| 7466 | * |
| 7467 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7468 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7469 | * other values - error |
| 7470 | **/ |
| 7471 | static int |
| 7472 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7473 | { |
| 7474 | struct lpfc_vport *vport; |
| 7475 | struct Scsi_Host *shost; |
| 7476 | |
| 7477 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7478 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7479 | phba->fc_ratov = FF_DEF_RATOV; |
| 7480 | phba->fc_altov = FF_DEF_ALTOV; |
| 7481 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7482 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7483 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7484 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7485 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7486 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7487 | |
| 7488 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7489 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7490 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7491 | if (phba->nvmet_support) { |
| 7492 | /* Only 1 vport (pport) will support NVME target */ |
| 7493 | if (phba->txrdy_payload_pool == NULL) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 7494 | phba->txrdy_payload_pool = dma_pool_create( |
| 7495 | "txrdy_pool", &phba->pcidev->dev, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7496 | TXRDY_PAYLOAD_LEN, 16, 0); |
| 7497 | if (phba->txrdy_payload_pool) { |
| 7498 | phba->targetport = NULL; |
| 7499 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7500 | lpfc_printf_log(phba, KERN_INFO, |
| 7501 | LOG_INIT | LOG_NVME_DISC, |
| 7502 | "6076 NVME Target Found\n"); |
| 7503 | } |
| 7504 | } |
| 7505 | } |
| 7506 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7507 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7508 | /* Put reference to SCSI host to driver's device private data */ |
| 7509 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7510 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7511 | /* |
| 7512 | * At this point we are fully registered with PSA. In addition, |
| 7513 | * any initial discovery should be completed. |
| 7514 | */ |
| 7515 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7516 | if (phba->cfg_enable_SmartSAN || |
| 7517 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7518 | |
| 7519 | /* Setup appropriate attribute masks */ |
| 7520 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7521 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7522 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7523 | else |
| 7524 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7525 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7526 | return 0; |
| 7527 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7528 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7529 | /** |
| 7530 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7531 | * @phba: pointer to lpfc hba data structure. |
| 7532 | * |
| 7533 | * This routine is invoked to destroy HBA physical port and the associated |
| 7534 | * SCSI host. |
| 7535 | **/ |
| 7536 | static void |
| 7537 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7538 | { |
| 7539 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7540 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7541 | /* Destroy physical port that associated with the SCSI host */ |
| 7542 | destroy_port(vport); |
| 7543 | |
| 7544 | return; |
| 7545 | } |
| 7546 | |
| 7547 | /** |
| 7548 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7549 | * @phba: pointer to lpfc hba data structure. |
| 7550 | * @shost: the shost to be used to detect Block guard settings. |
| 7551 | * |
| 7552 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7553 | * This routine also allocates memory for debugging bg buffers. |
| 7554 | **/ |
| 7555 | static void |
| 7556 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7557 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7558 | uint32_t old_mask; |
| 7559 | uint32_t old_guard; |
| 7560 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7561 | int pagecnt = 10; |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7562 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7564 | "1478 Registering BlockGuard with the " |
| 7565 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7566 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7567 | old_mask = phba->cfg_prot_mask; |
| 7568 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7569 | |
| 7570 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7571 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7572 | SHOST_DIX_TYPE0_PROTECTION | |
| 7573 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7574 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7575 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7576 | |
| 7577 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7578 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7579 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7580 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7581 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7582 | if ((old_mask != phba->cfg_prot_mask) || |
| 7583 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7585 | "1475 Registering BlockGuard with the " |
| 7586 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7587 | phba->cfg_prot_mask, |
| 7588 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7589 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7590 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7591 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7592 | } else |
| 7593 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7594 | "1479 Not Registering BlockGuard with the SCSI " |
| 7595 | "layer, Bad protection parameters: %d %d\n", |
| 7596 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7597 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7598 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7599 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7600 | while (pagecnt) { |
| 7601 | spin_lock_init(&_dump_buf_lock); |
| 7602 | _dump_buf_data = |
| 7603 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7604 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7605 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7606 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7607 | "_dump_buf_data at 0x%p\n", |
| 7608 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7609 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7610 | memset(_dump_buf_data, 0, |
| 7611 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7612 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7613 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7614 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7615 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7616 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7617 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7618 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7619 | "memory for hexdump\n"); |
| 7620 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7621 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7622 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7623 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7624 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7625 | while (pagecnt) { |
| 7626 | _dump_buf_dif = |
| 7627 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7628 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7629 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7630 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7631 | "_dump_buf_dif at 0x%p\n", |
| 7632 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7633 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7634 | memset(_dump_buf_dif, 0, |
| 7635 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7636 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7637 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7638 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7639 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7640 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7641 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7642 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7643 | "memory for hexdump\n"); |
| 7644 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7645 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7646 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7647 | _dump_buf_dif); |
| 7648 | } |
| 7649 | |
| 7650 | /** |
| 7651 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7652 | * @phba: pointer to lpfc hba data structure. |
| 7653 | * |
| 7654 | * This routine is invoked to perform all the necessary post initialization |
| 7655 | * setup for the device. |
| 7656 | **/ |
| 7657 | static void |
| 7658 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7659 | { |
| 7660 | struct Scsi_Host *shost; |
| 7661 | struct lpfc_adapter_event_header adapter_event; |
| 7662 | |
| 7663 | /* Get the default values for Model Name and Description */ |
| 7664 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7665 | |
| 7666 | /* |
| 7667 | * hba setup may have changed the hba_queue_depth so we need to |
| 7668 | * adjust the value of can_queue. |
| 7669 | */ |
| 7670 | shost = pci_get_drvdata(phba->pcidev); |
| 7671 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 7672 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 7673 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7674 | |
| 7675 | lpfc_host_attrib_init(shost); |
| 7676 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7677 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7678 | spin_lock_irq(shost->host_lock); |
| 7679 | lpfc_poll_start_timer(phba); |
| 7680 | spin_unlock_irq(shost->host_lock); |
| 7681 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7682 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7683 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7684 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7685 | /* Send board arrival event to upper layer */ |
| 7686 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7687 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7688 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7689 | sizeof(adapter_event), |
| 7690 | (char *) &adapter_event, |
| 7691 | LPFC_NL_VENDOR_ID); |
| 7692 | return; |
| 7693 | } |
| 7694 | |
| 7695 | /** |
| 7696 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7697 | * @phba: pointer to lpfc hba data structure. |
| 7698 | * |
| 7699 | * This routine is invoked to set up the PCI device memory space for device |
| 7700 | * with SLI-3 interface spec. |
| 7701 | * |
| 7702 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7703 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7704 | * other values - error |
| 7705 | **/ |
| 7706 | static int |
| 7707 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7708 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7709 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7710 | unsigned long bar0map_len, bar2map_len; |
| 7711 | int i, hbq_count; |
| 7712 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7713 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7714 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7715 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7716 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7717 | |
| 7718 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7719 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7720 | if (error) |
| 7721 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7722 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7723 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7724 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7725 | |
| 7726 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7727 | * required by each mapping. |
| 7728 | */ |
| 7729 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7730 | bar0map_len = pci_resource_len(pdev, 0); |
| 7731 | |
| 7732 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7733 | bar2map_len = pci_resource_len(pdev, 2); |
| 7734 | |
| 7735 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7736 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7737 | if (!phba->slim_memmap_p) { |
| 7738 | dev_printk(KERN_ERR, &pdev->dev, |
| 7739 | "ioremap failed for SLIM memory.\n"); |
| 7740 | goto out; |
| 7741 | } |
| 7742 | |
| 7743 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7744 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7745 | if (!phba->ctrl_regs_memmap_p) { |
| 7746 | dev_printk(KERN_ERR, &pdev->dev, |
| 7747 | "ioremap failed for HBA control registers.\n"); |
| 7748 | goto out_iounmap_slim; |
| 7749 | } |
| 7750 | |
| 7751 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7752 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7753 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7754 | if (!phba->slim2p.virt) |
| 7755 | goto out_iounmap; |
| 7756 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7757 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7758 | phba->mbox_ext = (phba->slim2p.virt + |
| 7759 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7760 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7761 | phba->IOCBs = (phba->slim2p.virt + |
| 7762 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7763 | |
| 7764 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7765 | lpfc_sli_hbq_size(), |
| 7766 | &phba->hbqslimp.phys, |
| 7767 | GFP_KERNEL); |
| 7768 | if (!phba->hbqslimp.virt) |
| 7769 | goto out_free_slim; |
| 7770 | |
| 7771 | hbq_count = lpfc_sli_hbq_count(); |
| 7772 | ptr = phba->hbqslimp.virt; |
| 7773 | for (i = 0; i < hbq_count; ++i) { |
| 7774 | phba->hbqs[i].hbq_virt = ptr; |
| 7775 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7776 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7777 | sizeof(struct lpfc_hbq_entry)); |
| 7778 | } |
| 7779 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7780 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7781 | |
| 7782 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7783 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7784 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7785 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7786 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7787 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7788 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7789 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7790 | return 0; |
| 7791 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7792 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7793 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7794 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7795 | out_iounmap: |
| 7796 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7797 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7798 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7799 | out: |
| 7800 | return error; |
| 7801 | } |
| 7802 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7803 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7804 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7805 | * @phba: pointer to lpfc hba data structure. |
| 7806 | * |
| 7807 | * This routine is invoked to unset the PCI device memory space for device |
| 7808 | * with SLI-3 interface spec. |
| 7809 | **/ |
| 7810 | static void |
| 7811 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7812 | { |
| 7813 | struct pci_dev *pdev; |
| 7814 | |
| 7815 | /* Obtain PCI device reference */ |
| 7816 | if (!phba->pcidev) |
| 7817 | return; |
| 7818 | else |
| 7819 | pdev = phba->pcidev; |
| 7820 | |
| 7821 | /* Free coherent DMA memory allocated */ |
| 7822 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7823 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7824 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7825 | phba->slim2p.virt, phba->slim2p.phys); |
| 7826 | |
| 7827 | /* I/O memory unmap */ |
| 7828 | iounmap(phba->ctrl_regs_memmap_p); |
| 7829 | iounmap(phba->slim_memmap_p); |
| 7830 | |
| 7831 | return; |
| 7832 | } |
| 7833 | |
| 7834 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7835 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7836 | * @phba: pointer to lpfc hba data structure. |
| 7837 | * |
| 7838 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7839 | * done and check status. |
| 7840 | * |
| 7841 | * Return 0 if successful, otherwise -ENODEV. |
| 7842 | **/ |
| 7843 | int |
| 7844 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7845 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7846 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7847 | struct lpfc_register reg_data; |
| 7848 | int i, port_error = 0; |
| 7849 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7850 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7851 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7852 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7853 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7854 | return -ENODEV; |
| 7855 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7856 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7857 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7858 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7859 | &portsmphr_reg.word0) || |
| 7860 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7861 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7862 | port_error = -ENODEV; |
| 7863 | break; |
| 7864 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7865 | if (LPFC_POST_STAGE_PORT_READY == |
| 7866 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7867 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7868 | msleep(10); |
| 7869 | } |
| 7870 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7871 | /* |
| 7872 | * If there was a port error during POST, then don't proceed with |
| 7873 | * other register reads as the data may not be valid. Just exit. |
| 7874 | */ |
| 7875 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7876 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7877 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7878 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7879 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7880 | portsmphr_reg.word0, |
| 7881 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7882 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7883 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7884 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7885 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7886 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7887 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7888 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7889 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7890 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7891 | "2534 Device Info: SLIFamily=0x%x, " |
| 7892 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7893 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7894 | bf_get(lpfc_sli_intf_sli_family, |
| 7895 | &phba->sli4_hba.sli_intf), |
| 7896 | bf_get(lpfc_sli_intf_slirev, |
| 7897 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7898 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7899 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7900 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7901 | &phba->sli4_hba.sli_intf), |
| 7902 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7903 | &phba->sli4_hba.sli_intf), |
| 7904 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7905 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7906 | /* |
| 7907 | * Check for other Port errors during the initialization |
| 7908 | * process. Fail the load if the port did not come up |
| 7909 | * correctly. |
| 7910 | */ |
| 7911 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7912 | &phba->sli4_hba.sli_intf); |
| 7913 | switch (if_type) { |
| 7914 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7915 | phba->sli4_hba.ue_mask_lo = |
| 7916 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7917 | phba->sli4_hba.ue_mask_hi = |
| 7918 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7919 | uerrlo_reg.word0 = |
| 7920 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7921 | uerrhi_reg.word0 = |
| 7922 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7923 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7924 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7926 | "1422 Unrecoverable Error " |
| 7927 | "Detected during POST " |
| 7928 | "uerr_lo_reg=0x%x, " |
| 7929 | "uerr_hi_reg=0x%x, " |
| 7930 | "ue_mask_lo_reg=0x%x, " |
| 7931 | "ue_mask_hi_reg=0x%x\n", |
| 7932 | uerrlo_reg.word0, |
| 7933 | uerrhi_reg.word0, |
| 7934 | phba->sli4_hba.ue_mask_lo, |
| 7935 | phba->sli4_hba.ue_mask_hi); |
| 7936 | port_error = -ENODEV; |
| 7937 | } |
| 7938 | break; |
| 7939 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7940 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7941 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7942 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7943 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7944 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7945 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7946 | phba->work_status[0] = |
| 7947 | readl(phba->sli4_hba.u.if_type2. |
| 7948 | ERR1regaddr); |
| 7949 | phba->work_status[1] = |
| 7950 | readl(phba->sli4_hba.u.if_type2. |
| 7951 | ERR2regaddr); |
| 7952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7953 | "2888 Unrecoverable port error " |
| 7954 | "following POST: port status reg " |
| 7955 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7956 | "error 1=0x%x, error 2=0x%x\n", |
| 7957 | reg_data.word0, |
| 7958 | portsmphr_reg.word0, |
| 7959 | phba->work_status[0], |
| 7960 | phba->work_status[1]); |
| 7961 | port_error = -ENODEV; |
| 7962 | } |
| 7963 | break; |
| 7964 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7965 | default: |
| 7966 | break; |
| 7967 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7968 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7969 | return port_error; |
| 7970 | } |
| 7971 | |
| 7972 | /** |
| 7973 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 7974 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7975 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7976 | * |
| 7977 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 7978 | * memory map. |
| 7979 | **/ |
| 7980 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7981 | 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] | 7982 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7983 | switch (if_type) { |
| 7984 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7985 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 7986 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 7987 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 7988 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 7989 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 7990 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 7991 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 7992 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 7993 | phba->sli4_hba.SLIINTFregaddr = |
| 7994 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7995 | break; |
| 7996 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 7997 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 7998 | phba->sli4_hba.conf_regs_memmap_p + |
| 7999 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8000 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8001 | phba->sli4_hba.conf_regs_memmap_p + |
| 8002 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8003 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8004 | phba->sli4_hba.conf_regs_memmap_p + |
| 8005 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8006 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8007 | phba->sli4_hba.conf_regs_memmap_p + |
| 8008 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8009 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8010 | phba->sli4_hba.conf_regs_memmap_p + |
| 8011 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8012 | phba->sli4_hba.SLIINTFregaddr = |
| 8013 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8014 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8015 | phba->sli4_hba.conf_regs_memmap_p + |
| 8016 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8017 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8018 | phba->sli4_hba.conf_regs_memmap_p + |
| 8019 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8020 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8021 | phba->sli4_hba.conf_regs_memmap_p + |
| 8022 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8023 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8024 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8025 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8026 | phba->sli4_hba.MQDBregaddr = |
| 8027 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8028 | phba->sli4_hba.BMBXregaddr = |
| 8029 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8030 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8031 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8032 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8033 | phba->sli4_hba.conf_regs_memmap_p + |
| 8034 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8035 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8036 | phba->sli4_hba.conf_regs_memmap_p + |
| 8037 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8038 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8039 | phba->sli4_hba.conf_regs_memmap_p + |
| 8040 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8041 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8042 | phba->sli4_hba.conf_regs_memmap_p + |
| 8043 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8044 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8045 | phba->sli4_hba.conf_regs_memmap_p + |
| 8046 | LPFC_CTL_PORT_STA_OFFSET; |
| 8047 | phba->sli4_hba.PSMPHRregaddr = |
| 8048 | phba->sli4_hba.conf_regs_memmap_p + |
| 8049 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8050 | phba->sli4_hba.BMBXregaddr = |
| 8051 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8052 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8053 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8054 | default: |
| 8055 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8056 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8057 | if_type); |
| 8058 | break; |
| 8059 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8064 | * @phba: pointer to lpfc hba data structure. |
| 8065 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8066 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8067 | **/ |
| 8068 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8069 | 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] | 8070 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8071 | switch (if_type) { |
| 8072 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8073 | phba->sli4_hba.PSMPHRregaddr = |
| 8074 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8075 | LPFC_SLIPORT_IF0_SMPHR; |
| 8076 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8077 | LPFC_HST_ISR0; |
| 8078 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8079 | LPFC_HST_IMR0; |
| 8080 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8081 | LPFC_HST_ISCR0; |
| 8082 | break; |
| 8083 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8084 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8085 | LPFC_IF6_RQ_DOORBELL; |
| 8086 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8087 | LPFC_IF6_WQ_DOORBELL; |
| 8088 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8089 | LPFC_IF6_CQ_DOORBELL; |
| 8090 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8091 | LPFC_IF6_EQ_DOORBELL; |
| 8092 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8093 | LPFC_IF6_MQ_DOORBELL; |
| 8094 | break; |
| 8095 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8096 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8097 | default: |
| 8098 | dev_err(&phba->pcidev->dev, |
| 8099 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8100 | if_type); |
| 8101 | break; |
| 8102 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8103 | } |
| 8104 | |
| 8105 | /** |
| 8106 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8107 | * @phba: pointer to lpfc hba data structure. |
| 8108 | * @vf: virtual function number |
| 8109 | * |
| 8110 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8111 | * based on the given viftual function number, @vf. |
| 8112 | * |
| 8113 | * Return 0 if successful, otherwise -ENODEV. |
| 8114 | **/ |
| 8115 | static int |
| 8116 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8117 | { |
| 8118 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8119 | return -ENODEV; |
| 8120 | |
| 8121 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8122 | vf * LPFC_VFR_PAGE_SIZE + |
| 8123 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8124 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8125 | vf * LPFC_VFR_PAGE_SIZE + |
| 8126 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8127 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8128 | vf * LPFC_VFR_PAGE_SIZE + |
| 8129 | LPFC_EQCQ_DOORBELL); |
| 8130 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8131 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8132 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8133 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8134 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8135 | return 0; |
| 8136 | } |
| 8137 | |
| 8138 | /** |
| 8139 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8140 | * @phba: pointer to lpfc hba data structure. |
| 8141 | * |
| 8142 | * This routine is invoked to create the bootstrap mailbox |
| 8143 | * region consistent with the SLI-4 interface spec. This |
| 8144 | * routine allocates all memory necessary to communicate |
| 8145 | * mailbox commands to the port and sets up all alignment |
| 8146 | * needs. No locks are expected to be held when calling |
| 8147 | * this routine. |
| 8148 | * |
| 8149 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8150 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8151 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8152 | **/ |
| 8153 | static int |
| 8154 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8155 | { |
| 8156 | uint32_t bmbx_size; |
| 8157 | struct lpfc_dmabuf *dmabuf; |
| 8158 | struct dma_address *dma_address; |
| 8159 | uint32_t pa_addr; |
| 8160 | uint64_t phys_addr; |
| 8161 | |
| 8162 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8163 | if (!dmabuf) |
| 8164 | return -ENOMEM; |
| 8165 | |
| 8166 | /* |
| 8167 | * The bootstrap mailbox region is comprised of 2 parts |
| 8168 | * plus an alignment restriction of 16 bytes. |
| 8169 | */ |
| 8170 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8171 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8172 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8173 | if (!dmabuf->virt) { |
| 8174 | kfree(dmabuf); |
| 8175 | return -ENOMEM; |
| 8176 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8177 | |
| 8178 | /* |
| 8179 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8180 | * operations are simple later. The mailbox dma address is required |
| 8181 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8182 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8183 | * command to the port. |
| 8184 | */ |
| 8185 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8186 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8187 | |
| 8188 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8189 | LPFC_ALIGN_16_BYTE); |
| 8190 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8191 | LPFC_ALIGN_16_BYTE); |
| 8192 | |
| 8193 | /* |
| 8194 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8195 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8196 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8197 | * the 30-bit address is the high or low address. |
| 8198 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8199 | * clean on 32 bit machines. |
| 8200 | */ |
| 8201 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8202 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8203 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8204 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8205 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8206 | |
| 8207 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8208 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8209 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8210 | return 0; |
| 8211 | } |
| 8212 | |
| 8213 | /** |
| 8214 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8215 | * @phba: pointer to lpfc hba data structure. |
| 8216 | * |
| 8217 | * This routine is invoked to teardown the bootstrap mailbox |
| 8218 | * region and release all host resources. This routine requires |
| 8219 | * the caller to ensure all mailbox commands recovered, no |
| 8220 | * additional mailbox comands are sent, and interrupts are disabled |
| 8221 | * before calling this routine. |
| 8222 | * |
| 8223 | **/ |
| 8224 | static void |
| 8225 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8226 | { |
| 8227 | dma_free_coherent(&phba->pcidev->dev, |
| 8228 | phba->sli4_hba.bmbx.bmbx_size, |
| 8229 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8230 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8231 | |
| 8232 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8233 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8234 | } |
| 8235 | |
| 8236 | /** |
| 8237 | * lpfc_sli4_read_config - Get the config parameters. |
| 8238 | * @phba: pointer to lpfc hba data structure. |
| 8239 | * |
| 8240 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8241 | * The configuration parameters are used to set the base and maximum values |
| 8242 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8243 | * allocation for the port. |
| 8244 | * |
| 8245 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8246 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8247 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8248 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8249 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8250 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8251 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8252 | { |
| 8253 | LPFC_MBOXQ_t *pmb; |
| 8254 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8255 | union lpfc_sli4_cfg_shdr *shdr; |
| 8256 | uint32_t shdr_status, shdr_add_status; |
| 8257 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8258 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8259 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8260 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8261 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8262 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8263 | |
| 8264 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8265 | if (!pmb) { |
| 8266 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8267 | "2011 Unable to allocate memory for issuing " |
| 8268 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8269 | return -ENOMEM; |
| 8270 | } |
| 8271 | |
| 8272 | lpfc_read_config(phba, pmb); |
| 8273 | |
| 8274 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8275 | if (rc != MBX_SUCCESS) { |
| 8276 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8277 | "2012 Mailbox failed , mbxCmd x%x " |
| 8278 | "READ_CONFIG, mbxStatus x%x\n", |
| 8279 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8280 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 8281 | rc = -EIO; |
| 8282 | } else { |
| 8283 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8284 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8285 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8286 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8287 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8288 | phba->sli4_hba.lnk_info.lnk_no = |
| 8289 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8290 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8291 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8292 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8293 | phba->sli4_hba.lnk_info.lnk_no); |
| 8294 | } else |
| 8295 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8296 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8297 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8298 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8299 | phba->bbcredit_support = 1; |
| 8300 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8301 | } |
| 8302 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8303 | phba->sli4_hba.conf_trunk = |
| 8304 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8305 | phba->sli4_hba.extents_in_use = |
| 8306 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8307 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8308 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 8309 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8310 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8311 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8312 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8313 | /* Limit the max we support */ |
| 8314 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8315 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8316 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8317 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8318 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8319 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8320 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8321 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8322 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8323 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8324 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8325 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8326 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8327 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8328 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8329 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8330 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8331 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8332 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8333 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8334 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8335 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8336 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8337 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8338 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8339 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8340 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8341 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8342 | phba->max_vports = phba->max_vpi; |
| 8343 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8344 | "2003 cfg params Extents? %d " |
| 8345 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8346 | "VPI(B:%d M:%d) " |
| 8347 | "VFI(B:%d M:%d) " |
| 8348 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8349 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8350 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8351 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8352 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8353 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8354 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8355 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8356 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8357 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8358 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8359 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8360 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8361 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8362 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8363 | phba->sli4_hba.max_cfg_param.max_rq); |
| 8364 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8365 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8366 | * Calculate queue resources based on how |
| 8367 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8368 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8369 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8370 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8371 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8372 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8373 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8374 | /* |
| 8375 | * Whats left after this can go toward NVME / FCP. |
| 8376 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8377 | * plus one extra. When configured for |
| 8378 | * NVMET, FCP io channel WQs are not created. |
| 8379 | */ |
| 8380 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8381 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8382 | /* If NVME is configured, double the number of CQ/WQs needed */ |
| 8383 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 8384 | !phba->nvmet_support) |
| 8385 | qmin /= 2; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8386 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8387 | /* Check to see if there is enough for NVME */ |
| 8388 | if ((phba->cfg_irq_chann > qmin) || |
| 8389 | (phba->cfg_hdw_queue > qmin)) { |
| 8390 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8391 | "2005 Reducing Queues: " |
| 8392 | "WQ %d CQ %d EQ %d: min %d: " |
| 8393 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8394 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8395 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8396 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8397 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8398 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8399 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8400 | if (phba->cfg_irq_chann > qmin) |
| 8401 | phba->cfg_irq_chann = qmin; |
| 8402 | if (phba->cfg_hdw_queue > qmin) |
| 8403 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8404 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8405 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8406 | |
| 8407 | if (rc) |
| 8408 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8409 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8410 | /* Update link speed if forced link speed is supported */ |
| 8411 | 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] | 8412 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8413 | forced_link_speed = |
| 8414 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8415 | if (forced_link_speed) { |
| 8416 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8417 | |
| 8418 | switch (forced_link_speed) { |
| 8419 | case LINK_SPEED_1G: |
| 8420 | phba->cfg_link_speed = |
| 8421 | LPFC_USER_LINK_SPEED_1G; |
| 8422 | break; |
| 8423 | case LINK_SPEED_2G: |
| 8424 | phba->cfg_link_speed = |
| 8425 | LPFC_USER_LINK_SPEED_2G; |
| 8426 | break; |
| 8427 | case LINK_SPEED_4G: |
| 8428 | phba->cfg_link_speed = |
| 8429 | LPFC_USER_LINK_SPEED_4G; |
| 8430 | break; |
| 8431 | case LINK_SPEED_8G: |
| 8432 | phba->cfg_link_speed = |
| 8433 | LPFC_USER_LINK_SPEED_8G; |
| 8434 | break; |
| 8435 | case LINK_SPEED_10G: |
| 8436 | phba->cfg_link_speed = |
| 8437 | LPFC_USER_LINK_SPEED_10G; |
| 8438 | break; |
| 8439 | case LINK_SPEED_16G: |
| 8440 | phba->cfg_link_speed = |
| 8441 | LPFC_USER_LINK_SPEED_16G; |
| 8442 | break; |
| 8443 | case LINK_SPEED_32G: |
| 8444 | phba->cfg_link_speed = |
| 8445 | LPFC_USER_LINK_SPEED_32G; |
| 8446 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8447 | case LINK_SPEED_64G: |
| 8448 | phba->cfg_link_speed = |
| 8449 | LPFC_USER_LINK_SPEED_64G; |
| 8450 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8451 | case 0xffff: |
| 8452 | phba->cfg_link_speed = |
| 8453 | LPFC_USER_LINK_SPEED_AUTO; |
| 8454 | break; |
| 8455 | default: |
| 8456 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8457 | "0047 Unrecognized link " |
| 8458 | "speed : %d\n", |
| 8459 | forced_link_speed); |
| 8460 | phba->cfg_link_speed = |
| 8461 | LPFC_USER_LINK_SPEED_AUTO; |
| 8462 | } |
| 8463 | } |
| 8464 | } |
| 8465 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8467 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8468 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8469 | if (phba->cfg_hba_queue_depth > length) { |
| 8470 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8471 | "3361 HBA queue depth changed from %d to %d\n", |
| 8472 | phba->cfg_hba_queue_depth, length); |
| 8473 | phba->cfg_hba_queue_depth = length; |
| 8474 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8475 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8476 | 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] | 8477 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8478 | goto read_cfg_out; |
| 8479 | |
| 8480 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8481 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8482 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8483 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8484 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8485 | length, LPFC_SLI4_MBX_EMBED); |
| 8486 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8487 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8488 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8489 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8490 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8491 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8492 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8493 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8494 | "3026 Mailbox failed , mbxCmd x%x " |
| 8495 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8496 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8497 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8498 | goto read_cfg_out; |
| 8499 | } |
| 8500 | |
| 8501 | /* search for fc_fcoe resrouce descriptor */ |
| 8502 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8503 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8504 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8505 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8506 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8507 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8508 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8509 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8510 | goto read_cfg_out; |
| 8511 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8512 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8513 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8514 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8515 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8516 | phba->sli4_hba.iov.pf_number = |
| 8517 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8518 | phba->sli4_hba.iov.vf_number = |
| 8519 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8520 | break; |
| 8521 | } |
| 8522 | } |
| 8523 | |
| 8524 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8525 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8526 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8527 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8528 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8529 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8530 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8531 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8532 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8533 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8534 | |
| 8535 | read_cfg_out: |
| 8536 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8537 | return rc; |
| 8538 | } |
| 8539 | |
| 8540 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8541 | * 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] | 8542 | * @phba: pointer to lpfc hba data structure. |
| 8543 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8544 | * This routine is invoked to setup the port-side endian order when |
| 8545 | * the port if_type is 0. This routine has no function for other |
| 8546 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8547 | * |
| 8548 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8549 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8550 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8551 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8552 | **/ |
| 8553 | static int |
| 8554 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8555 | { |
| 8556 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8557 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8558 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8559 | HOST_ENDIAN_HIGH_WORD1}; |
| 8560 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8561 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8562 | switch (if_type) { |
| 8563 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8564 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8565 | GFP_KERNEL); |
| 8566 | if (!mboxq) { |
| 8567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8568 | "0492 Unable to allocate memory for " |
| 8569 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8570 | "command\n"); |
| 8571 | return -ENOMEM; |
| 8572 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8573 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8574 | /* |
| 8575 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8576 | * two words to contain special data values and no other data. |
| 8577 | */ |
| 8578 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8579 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8580 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8581 | if (rc != MBX_SUCCESS) { |
| 8582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8583 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8584 | "failed with status x%x\n", |
| 8585 | rc); |
| 8586 | rc = -EIO; |
| 8587 | } |
| 8588 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8589 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8590 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8591 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8592 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8593 | default: |
| 8594 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8595 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8596 | return rc; |
| 8597 | } |
| 8598 | |
| 8599 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8600 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | * @phba: pointer to lpfc hba data structure. |
| 8602 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8603 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8604 | * 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] | 8605 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8606 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8607 | * |
| 8608 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8609 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8610 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8611 | **/ |
| 8612 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8613 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8614 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8615 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8616 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8617 | * device parameters |
| 8618 | */ |
| 8619 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8620 | if (phba->nvmet_support) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8621 | if (phba->cfg_irq_chann < phba->cfg_nvmet_mrq) |
| 8622 | phba->cfg_nvmet_mrq = phba->cfg_irq_chann; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8623 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8624 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8625 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8626 | |
| 8627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8628 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8629 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8630 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8631 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8632 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8633 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8634 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8635 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8636 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8637 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8638 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8639 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8640 | } |
| 8641 | |
| 8642 | static int |
| 8643 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8644 | { |
| 8645 | struct lpfc_queue *qdesc; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8646 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8647 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8648 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8649 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8650 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8651 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8652 | if (!qdesc) { |
| 8653 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8654 | "0508 Failed allocate fast-path NVME CQ (%d)\n", |
| 8655 | wqidx); |
| 8656 | return 1; |
| 8657 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8658 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8659 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8660 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8661 | phba->sli4_hba.hdwq[wqidx].nvme_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8662 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8663 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8664 | LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT, |
| 8665 | cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8666 | if (!qdesc) { |
| 8667 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8668 | "0509 Failed allocate fast-path NVME WQ (%d)\n", |
| 8669 | wqidx); |
| 8670 | return 1; |
| 8671 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8672 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8673 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8674 | phba->sli4_hba.hdwq[wqidx].nvme_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8675 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8676 | return 0; |
| 8677 | } |
| 8678 | |
| 8679 | static int |
| 8680 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8681 | { |
| 8682 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8683 | uint32_t wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8684 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8685 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8686 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8687 | /* Create Fast Path FCP CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8688 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8689 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8690 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8691 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8692 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8693 | |
| 8694 | else |
| 8695 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8696 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8697 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8698 | if (!qdesc) { |
| 8699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8700 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); |
| 8701 | return 1; |
| 8702 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8703 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8704 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8705 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8706 | phba->sli4_hba.hdwq[wqidx].fcp_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8707 | |
| 8708 | /* Create Fast Path FCP WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8709 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8710 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8711 | wqesize = (phba->fcp_embed_io) ? |
| 8712 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8713 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8714 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8715 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8716 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8717 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8718 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8719 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8720 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8721 | if (!qdesc) { |
| 8722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8723 | "0503 Failed allocate fast-path FCP WQ (%d)\n", |
| 8724 | wqidx); |
| 8725 | return 1; |
| 8726 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8727 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8728 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8729 | phba->sli4_hba.hdwq[wqidx].fcp_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8730 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8731 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8732 | } |
| 8733 | |
| 8734 | /** |
| 8735 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8736 | * @phba: pointer to lpfc hba data structure. |
| 8737 | * |
| 8738 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8739 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8740 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8741 | * we just use some constant number as place holder. |
| 8742 | * |
| 8743 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8744 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8745 | * -ENOMEM - No availble memory |
| 8746 | * -EIO - The mailbox failed to complete successfully. |
| 8747 | **/ |
| 8748 | int |
| 8749 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8750 | { |
| 8751 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8752 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8753 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8754 | struct lpfc_vector_map_info *cpup; |
| 8755 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8756 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8757 | |
| 8758 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8759 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8760 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8761 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8762 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8763 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8764 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8765 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8766 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8767 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8768 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8769 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8770 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8771 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8772 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8773 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8774 | phba->sli4_hba.hdwq = kcalloc( |
| 8775 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8776 | GFP_KERNEL); |
| 8777 | if (!phba->sli4_hba.hdwq) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8779 | "6427 Failed allocate memory for " |
| 8780 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8781 | goto out_error; |
| 8782 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8783 | /* Prepare hardware queues to take IO buffers */ |
| 8784 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8785 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8786 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8787 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8788 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 8789 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 8790 | qp->get_io_bufs = 0; |
| 8791 | qp->put_io_bufs = 0; |
| 8792 | qp->total_io_bufs = 0; |
| 8793 | spin_lock_init(&qp->abts_scsi_buf_list_lock); |
| 8794 | INIT_LIST_HEAD(&qp->lpfc_abts_scsi_buf_list); |
| 8795 | qp->abts_scsi_io_bufs = 0; |
| 8796 | spin_lock_init(&qp->abts_nvme_buf_list_lock); |
| 8797 | INIT_LIST_HEAD(&qp->lpfc_abts_nvme_buf_list); |
| 8798 | qp->abts_nvme_io_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8799 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8800 | } |
| 8801 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8802 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8803 | if (phba->nvmet_support) { |
| 8804 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8805 | phba->cfg_nvmet_mrq, |
| 8806 | sizeof(struct lpfc_queue *), |
| 8807 | GFP_KERNEL); |
| 8808 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8809 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8810 | "3121 Fail allocate memory for " |
| 8811 | "fast-path CQ set array\n"); |
| 8812 | goto out_error; |
| 8813 | } |
| 8814 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8815 | phba->cfg_nvmet_mrq, |
| 8816 | sizeof(struct lpfc_queue *), |
| 8817 | GFP_KERNEL); |
| 8818 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8820 | "3122 Fail allocate memory for " |
| 8821 | "fast-path RQ set hdr array\n"); |
| 8822 | goto out_error; |
| 8823 | } |
| 8824 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8825 | phba->cfg_nvmet_mrq, |
| 8826 | sizeof(struct lpfc_queue *), |
| 8827 | GFP_KERNEL); |
| 8828 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8829 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8830 | "3124 Fail allocate memory for " |
| 8831 | "fast-path RQ set data array\n"); |
| 8832 | goto out_error; |
| 8833 | } |
| 8834 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8835 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8836 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8837 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8838 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8839 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8840 | for_each_present_cpu(cpu) { |
| 8841 | /* We only want to create 1 EQ per vector, even though |
| 8842 | * multiple CPUs might be using that vector. so only |
| 8843 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8844 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8845 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8846 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8847 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8848 | |
| 8849 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 8850 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8851 | |
| 8852 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8853 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8854 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8855 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8856 | if (!qdesc) { |
| 8857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8858 | "0497 Failed allocate EQ (%d)\n", |
| 8859 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8860 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8861 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8862 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8863 | qdesc->hdwq = cpup->hdwq; |
| 8864 | qdesc->chann = cpu; /* First CPU this EQ is affinitised to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8865 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8866 | |
| 8867 | /* Save the allocated EQ in the Hardware Queue */ |
| 8868 | qp->hba_eq = qdesc; |
| 8869 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8870 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 8871 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8872 | } |
| 8873 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8874 | /* Now we need to populate the other Hardware Queues, that share |
| 8875 | * an IRQ vector, with the associated EQ ptr. |
| 8876 | */ |
| 8877 | for_each_present_cpu(cpu) { |
| 8878 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8879 | |
| 8880 | /* Check for EQ already allocated in previous loop */ |
| 8881 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 8882 | continue; |
| 8883 | |
| 8884 | /* Check for multiple CPUs per hdwq */ |
| 8885 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8886 | if (qp->hba_eq) |
| 8887 | continue; |
| 8888 | |
| 8889 | /* We need to share an EQ for this hdwq */ |
| 8890 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 8891 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 8892 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 8893 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8894 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8895 | /* Allocate SCSI SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8896 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8897 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) |
| 8898 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8899 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8900 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8901 | /* Allocate NVME SLI4 CQ/WQs */ |
| 8902 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8903 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8904 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) |
| 8905 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8906 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8907 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8908 | if (phba->nvmet_support) { |
| 8909 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8910 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 8911 | LPFC_FIND_BY_HDWQ); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8912 | qdesc = lpfc_sli4_queue_alloc( |
| 8913 | phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8914 | LPFC_DEFAULT_PAGE_SIZE, |
| 8915 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8916 | phba->sli4_hba.cq_ecount, |
| 8917 | cpu); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8918 | if (!qdesc) { |
| 8919 | lpfc_printf_log( |
| 8920 | phba, KERN_ERR, LOG_INIT, |
| 8921 | "3142 Failed allocate NVME " |
| 8922 | "CQ Set (%d)\n", idx); |
| 8923 | goto out_error; |
| 8924 | } |
| 8925 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8926 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8927 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8928 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8929 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8930 | } |
| 8931 | } |
| 8932 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8933 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8934 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8935 | */ |
| 8936 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8937 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8938 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8939 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8940 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8941 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8942 | if (!qdesc) { |
| 8943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8944 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8945 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8946 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8947 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8948 | phba->sli4_hba.mbx_cq = qdesc; |
| 8949 | |
| 8950 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8951 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8952 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8953 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8954 | if (!qdesc) { |
| 8955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8956 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8957 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8958 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8959 | qdesc->qe_valid = 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8960 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8961 | phba->sli4_hba.els_cq = qdesc; |
| 8962 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8964 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8965 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8966 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8967 | |
| 8968 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8969 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8970 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8971 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8972 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8973 | if (!qdesc) { |
| 8974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8975 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8976 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8977 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8978 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8979 | phba->sli4_hba.mbx_wq = qdesc; |
| 8980 | |
| 8981 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8982 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8983 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8984 | |
| 8985 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8986 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8987 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8988 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8989 | if (!qdesc) { |
| 8990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8991 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8992 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8993 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8994 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8995 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8996 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8997 | |
| 8998 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 8999 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9000 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9001 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9002 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9003 | if (!qdesc) { |
| 9004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9005 | "6079 Failed allocate NVME LS CQ\n"); |
| 9006 | goto out_error; |
| 9007 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9008 | qdesc->chann = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9009 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9010 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9011 | |
| 9012 | /* Create NVME LS Work 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.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9015 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9016 | if (!qdesc) { |
| 9017 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9018 | "6080 Failed allocate NVME LS WQ\n"); |
| 9019 | goto out_error; |
| 9020 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9021 | qdesc->chann = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9022 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9023 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9024 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9025 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9026 | /* |
| 9027 | * Create Receive Queue (RQ) |
| 9028 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9029 | |
| 9030 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9031 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9032 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9033 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9034 | if (!qdesc) { |
| 9035 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9036 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9037 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9038 | } |
| 9039 | phba->sli4_hba.hdr_rq = qdesc; |
| 9040 | |
| 9041 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9042 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9043 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9044 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9045 | if (!qdesc) { |
| 9046 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9047 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9048 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9049 | } |
| 9050 | phba->sli4_hba.dat_rq = qdesc; |
| 9051 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9052 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9053 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9054 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9055 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9056 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9057 | /* Create NVMET Receive Queue for header */ |
| 9058 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9059 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9060 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9061 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9062 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9063 | if (!qdesc) { |
| 9064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9065 | "3146 Failed allocate " |
| 9066 | "receive HRQ\n"); |
| 9067 | goto out_error; |
| 9068 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9069 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9070 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9071 | |
| 9072 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9073 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9074 | GFP_KERNEL, |
| 9075 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9076 | if (qdesc->rqbp == NULL) { |
| 9077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9078 | "6131 Failed allocate " |
| 9079 | "Header RQBP\n"); |
| 9080 | goto out_error; |
| 9081 | } |
| 9082 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9083 | /* Put list in known state in case driver load fails. */ |
| 9084 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9085 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9086 | /* Create NVMET Receive Queue for data */ |
| 9087 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9088 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9089 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9090 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9091 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9092 | if (!qdesc) { |
| 9093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9094 | "3156 Failed allocate " |
| 9095 | "receive DRQ\n"); |
| 9096 | goto out_error; |
| 9097 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9098 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9099 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9100 | } |
| 9101 | } |
| 9102 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9103 | #if defined(BUILD_NVME) |
| 9104 | /* Clear NVME stats */ |
| 9105 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9106 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9107 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9108 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9109 | } |
| 9110 | } |
| 9111 | #endif |
| 9112 | |
| 9113 | /* Clear SCSI stats */ |
| 9114 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9115 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9116 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9117 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9118 | } |
| 9119 | } |
| 9120 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9121 | return 0; |
| 9122 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9123 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9124 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9125 | return -ENOMEM; |
| 9126 | } |
| 9127 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9128 | static inline void |
| 9129 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9130 | { |
| 9131 | if (*qp != NULL) { |
| 9132 | lpfc_sli4_queue_free(*qp); |
| 9133 | *qp = NULL; |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | static inline void |
| 9138 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9139 | { |
| 9140 | int idx; |
| 9141 | |
| 9142 | if (*qs == NULL) |
| 9143 | return; |
| 9144 | |
| 9145 | for (idx = 0; idx < max; idx++) |
| 9146 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9147 | |
| 9148 | kfree(*qs); |
| 9149 | *qs = NULL; |
| 9150 | } |
| 9151 | |
| 9152 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9153 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9154 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9155 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9156 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9157 | uint32_t idx; |
| 9158 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9159 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9160 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9161 | /* Loop thru all Hardware Queues */ |
| 9162 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9163 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9164 | lpfc_sli4_queue_free(hdwq[idx].fcp_cq); |
| 9165 | lpfc_sli4_queue_free(hdwq[idx].nvme_cq); |
| 9166 | lpfc_sli4_queue_free(hdwq[idx].fcp_wq); |
| 9167 | lpfc_sli4_queue_free(hdwq[idx].nvme_wq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9168 | hdwq[idx].hba_eq = NULL; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9169 | hdwq[idx].fcp_cq = NULL; |
| 9170 | hdwq[idx].nvme_cq = NULL; |
| 9171 | hdwq[idx].fcp_wq = NULL; |
| 9172 | hdwq[idx].nvme_wq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9173 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9174 | /* Loop thru all IRQ vectors */ |
| 9175 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9176 | /* Free the EQ corresponding to the IRQ vector */ |
| 9177 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9178 | lpfc_sli4_queue_free(eq); |
| 9179 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9180 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9181 | } |
| 9182 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9183 | /** |
| 9184 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9185 | * @phba: pointer to lpfc hba data structure. |
| 9186 | * |
| 9187 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9188 | * operation. |
| 9189 | * |
| 9190 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9191 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9192 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9193 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9194 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9195 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9196 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9197 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9198 | /* |
| 9199 | * Set FREE_INIT before beginning to free the queues. |
| 9200 | * Wait until the users of queues to acknowledge to |
| 9201 | * release queues by clearing FREE_WAIT. |
| 9202 | */ |
| 9203 | spin_lock_irq(&phba->hbalock); |
| 9204 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9205 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9206 | spin_unlock_irq(&phba->hbalock); |
| 9207 | msleep(20); |
| 9208 | spin_lock_irq(&phba->hbalock); |
| 9209 | } |
| 9210 | spin_unlock_irq(&phba->hbalock); |
| 9211 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9212 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9213 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9214 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9215 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9216 | if (phba->nvmet_support) { |
| 9217 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9218 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9219 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9220 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9221 | phba->cfg_nvmet_mrq); |
| 9222 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9223 | phba->cfg_nvmet_mrq); |
| 9224 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9225 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9226 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9227 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9228 | |
| 9229 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9230 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9231 | |
| 9232 | /* Release ELS work queue */ |
| 9233 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9234 | |
| 9235 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9236 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9237 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9238 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9239 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9240 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9241 | |
| 9242 | /* Release NVME LS complete queue */ |
| 9243 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9244 | |
| 9245 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9246 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9247 | |
| 9248 | /* Everything on this list has been freed */ |
| 9249 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9250 | |
| 9251 | /* Done with freeing the queues */ |
| 9252 | spin_lock_irq(&phba->hbalock); |
| 9253 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9254 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9255 | } |
| 9256 | |
| 9257 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9258 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9259 | { |
| 9260 | struct lpfc_rqb *rqbp; |
| 9261 | struct lpfc_dmabuf *h_buf; |
| 9262 | struct rqb_dmabuf *rqb_buffer; |
| 9263 | |
| 9264 | rqbp = rq->rqbp; |
| 9265 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9266 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9267 | struct lpfc_dmabuf, list); |
| 9268 | |
| 9269 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9270 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9271 | rqbp->buffer_count--; |
| 9272 | } |
| 9273 | return 1; |
| 9274 | } |
| 9275 | |
| 9276 | static int |
| 9277 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9278 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9279 | int qidx, uint32_t qtype) |
| 9280 | { |
| 9281 | struct lpfc_sli_ring *pring; |
| 9282 | int rc; |
| 9283 | |
| 9284 | if (!eq || !cq || !wq) { |
| 9285 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9286 | "6085 Fast-path %s (%d) not allocated\n", |
| 9287 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9288 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9289 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9290 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9291 | /* create the Cq first */ |
| 9292 | rc = lpfc_cq_create(phba, cq, eq, |
| 9293 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9294 | if (rc) { |
| 9295 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9296 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9297 | qidx, (uint32_t)rc); |
| 9298 | return rc; |
| 9299 | } |
| 9300 | |
| 9301 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9302 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9303 | if (cq_map) |
| 9304 | *cq_map = cq->queue_id; |
| 9305 | |
| 9306 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9307 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9308 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9309 | |
| 9310 | /* create the wq */ |
| 9311 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9312 | if (rc) { |
| 9313 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9314 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9315 | qidx, (uint32_t)rc); |
| 9316 | /* no need to tear down cq - caller will do so */ |
| 9317 | return rc; |
| 9318 | } |
| 9319 | |
| 9320 | /* Bind this CQ/WQ to the NVME ring */ |
| 9321 | pring = wq->pring; |
| 9322 | pring->sli.sli4.wqp = (void *)wq; |
| 9323 | cq->pring = pring; |
| 9324 | |
| 9325 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9326 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9327 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9328 | } else { |
| 9329 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9330 | if (rc) { |
| 9331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9332 | "0539 Failed setup of slow-path MQ: " |
| 9333 | "rc = 0x%x\n", rc); |
| 9334 | /* no need to tear down cq - caller will do so */ |
| 9335 | return rc; |
| 9336 | } |
| 9337 | |
| 9338 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9339 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9340 | phba->sli4_hba.mbx_wq->queue_id, |
| 9341 | phba->sli4_hba.mbx_cq->queue_id); |
| 9342 | } |
| 9343 | |
| 9344 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9345 | } |
| 9346 | |
| 9347 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9348 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9349 | * @phba: pointer to lpfc hba data structure. |
| 9350 | * |
| 9351 | * This routine will populate the cq_lookup table by all |
| 9352 | * available CQ queue_id's. |
| 9353 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9354 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9355 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9356 | { |
| 9357 | struct lpfc_queue *eq, *childq; |
| 9358 | struct lpfc_sli4_hdw_queue *qp; |
| 9359 | int qidx; |
| 9360 | |
| 9361 | qp = phba->sli4_hba.hdwq; |
| 9362 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9363 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9364 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9365 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9366 | /* Get the EQ corresponding to the IRQ vector */ |
| 9367 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9368 | if (!eq) |
| 9369 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9370 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9371 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9372 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9373 | continue; |
| 9374 | if ((childq->subtype == LPFC_FCP) || |
| 9375 | (childq->subtype == LPFC_NVME)) |
| 9376 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9377 | childq; |
| 9378 | } |
| 9379 | } |
| 9380 | } |
| 9381 | |
| 9382 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9383 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9384 | * @phba: pointer to lpfc hba data structure. |
| 9385 | * |
| 9386 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9387 | * operation. |
| 9388 | * |
| 9389 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9390 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9391 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9392 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9393 | **/ |
| 9394 | int |
| 9395 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9396 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9397 | uint32_t shdr_status, shdr_add_status; |
| 9398 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9399 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9400 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9401 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9402 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9403 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9404 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9405 | |
| 9406 | /* Check for dual-ULP support */ |
| 9407 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9408 | if (!mboxq) { |
| 9409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9410 | "3249 Unable to allocate memory for " |
| 9411 | "QUERY_FW_CFG mailbox command\n"); |
| 9412 | return -ENOMEM; |
| 9413 | } |
| 9414 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9415 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9416 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9417 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9418 | length, LPFC_SLI4_MBX_EMBED); |
| 9419 | |
| 9420 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9421 | |
| 9422 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9423 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9424 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9425 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9426 | if (shdr_status || shdr_add_status || rc) { |
| 9427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9428 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9429 | "x%x add_status x%x, mbx status x%x\n", |
| 9430 | shdr_status, shdr_add_status, rc); |
| 9431 | if (rc != MBX_TIMEOUT) |
| 9432 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9433 | rc = -ENXIO; |
| 9434 | goto out_error; |
| 9435 | } |
| 9436 | |
| 9437 | phba->sli4_hba.fw_func_mode = |
| 9438 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9439 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9440 | 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] | 9441 | phba->sli4_hba.physical_port = |
| 9442 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9443 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9444 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9445 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9446 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9447 | |
| 9448 | if (rc != MBX_TIMEOUT) |
| 9449 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9450 | |
| 9451 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9452 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9453 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9454 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9455 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9456 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9457 | if (!qp) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9459 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9460 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9461 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9462 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9463 | |
| 9464 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9465 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9466 | /* Create HBA Event Queues (EQs) in order */ |
| 9467 | for_each_present_cpu(cpu) { |
| 9468 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9469 | |
| 9470 | /* Look for the CPU thats using that vector with |
| 9471 | * LPFC_CPU_FIRST_IRQ set. |
| 9472 | */ |
| 9473 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9474 | continue; |
| 9475 | if (qidx != cpup->eq) |
| 9476 | continue; |
| 9477 | |
| 9478 | /* Create an EQ for that vector */ |
| 9479 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9480 | phba->cfg_fcp_imax); |
| 9481 | if (rc) { |
| 9482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9483 | "0523 Failed setup of fast-path" |
| 9484 | " EQ (%d), rc = 0x%x\n", |
| 9485 | cpup->eq, (uint32_t)rc); |
| 9486 | goto out_destroy; |
| 9487 | } |
| 9488 | |
| 9489 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9490 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9491 | qp[cpup->hdwq].hba_eq; |
| 9492 | |
| 9493 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9494 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9495 | cpup->eq, |
| 9496 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9497 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9498 | } |
| 9499 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9500 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9501 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9502 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9503 | cpu = lpfc_find_cpu_handle(phba, qidx, |
| 9504 | LPFC_FIND_BY_HDWQ); |
| 9505 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9506 | |
| 9507 | /* Create the CQ/WQ corresponding to the |
| 9508 | * Hardware Queue |
| 9509 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9510 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9511 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9512 | qp[qidx].nvme_cq, |
| 9513 | qp[qidx].nvme_wq, |
| 9514 | &phba->sli4_hba.hdwq[qidx].nvme_cq_map, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9515 | qidx, LPFC_NVME); |
| 9516 | if (rc) { |
| 9517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9518 | "6123 Failed to setup fastpath " |
| 9519 | "NVME WQ/CQ (%d), rc = 0x%x\n", |
| 9520 | qidx, (uint32_t)rc); |
| 9521 | goto out_destroy; |
| 9522 | } |
| 9523 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9524 | } |
| 9525 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9526 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9527 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9528 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9529 | |
| 9530 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9531 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9532 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9533 | qp[qidx].fcp_cq, |
| 9534 | qp[qidx].fcp_wq, |
| 9535 | &phba->sli4_hba.hdwq[qidx].fcp_cq_map, |
| 9536 | qidx, LPFC_FCP); |
| 9537 | if (rc) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9539 | "0535 Failed to setup fastpath " |
| 9540 | "FCP WQ/CQ (%d), rc = 0x%x\n", |
| 9541 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9542 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9543 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9544 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9545 | |
| 9546 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9547 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9548 | */ |
| 9549 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9550 | /* Set up slow-path MBOX CQ/MQ */ |
| 9551 | |
| 9552 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9554 | "0528 %s not allocated\n", |
| 9555 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9556 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9557 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9558 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9559 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9560 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9561 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9562 | phba->sli4_hba.mbx_cq, |
| 9563 | phba->sli4_hba.mbx_wq, |
| 9564 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9565 | if (rc) { |
| 9566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9567 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9568 | (uint32_t)rc); |
| 9569 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9570 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9571 | if (phba->nvmet_support) { |
| 9572 | if (!phba->sli4_hba.nvmet_cqset) { |
| 9573 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9574 | "3165 Fast-path NVME CQ Set " |
| 9575 | "array not allocated\n"); |
| 9576 | rc = -ENOMEM; |
| 9577 | goto out_destroy; |
| 9578 | } |
| 9579 | if (phba->cfg_nvmet_mrq > 1) { |
| 9580 | rc = lpfc_cq_create_set(phba, |
| 9581 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9582 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9583 | LPFC_WCQ, LPFC_NVMET); |
| 9584 | if (rc) { |
| 9585 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9586 | "3164 Failed setup of NVME CQ " |
| 9587 | "Set, rc = 0x%x\n", |
| 9588 | (uint32_t)rc); |
| 9589 | goto out_destroy; |
| 9590 | } |
| 9591 | } else { |
| 9592 | /* Set up NVMET Receive Complete Queue */ |
| 9593 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9594 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9595 | LPFC_WCQ, LPFC_NVMET); |
| 9596 | if (rc) { |
| 9597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9598 | "6089 Failed setup NVMET CQ: " |
| 9599 | "rc = 0x%x\n", (uint32_t)rc); |
| 9600 | goto out_destroy; |
| 9601 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9602 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9603 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9604 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9605 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9606 | "parent eq-id=%d\n", |
| 9607 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9608 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9609 | } |
| 9610 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9611 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9612 | /* Set up slow-path ELS WQ/CQ */ |
| 9613 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9614 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9615 | "0530 ELS %s not allocated\n", |
| 9616 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9617 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9618 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9619 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9620 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9621 | phba->sli4_hba.els_cq, |
| 9622 | phba->sli4_hba.els_wq, |
| 9623 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9624 | if (rc) { |
| 9625 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9626 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9627 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9628 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9629 | } |
| 9630 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9631 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9632 | phba->sli4_hba.els_wq->queue_id, |
| 9633 | phba->sli4_hba.els_cq->queue_id); |
| 9634 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9635 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9636 | /* Set up NVME LS Complete Queue */ |
| 9637 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 9638 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9639 | "6091 LS %s not allocated\n", |
| 9640 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9641 | rc = -ENOMEM; |
| 9642 | goto out_destroy; |
| 9643 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9644 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9645 | phba->sli4_hba.nvmels_cq, |
| 9646 | phba->sli4_hba.nvmels_wq, |
| 9647 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9648 | if (rc) { |
| 9649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9650 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9651 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9652 | goto out_destroy; |
| 9653 | } |
| 9654 | |
| 9655 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9656 | "6096 ELS WQ setup: wq-id=%d, " |
| 9657 | "parent cq-id=%d\n", |
| 9658 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9659 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9660 | } |
| 9661 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9662 | /* |
| 9663 | * Create NVMET Receive Queue (RQ) |
| 9664 | */ |
| 9665 | if (phba->nvmet_support) { |
| 9666 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9667 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9668 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 9669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9670 | "6130 MRQ CQ Queues not " |
| 9671 | "allocated\n"); |
| 9672 | rc = -ENOMEM; |
| 9673 | goto out_destroy; |
| 9674 | } |
| 9675 | if (phba->cfg_nvmet_mrq > 1) { |
| 9676 | rc = lpfc_mrq_create(phba, |
| 9677 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9678 | phba->sli4_hba.nvmet_mrq_data, |
| 9679 | phba->sli4_hba.nvmet_cqset, |
| 9680 | LPFC_NVMET); |
| 9681 | if (rc) { |
| 9682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9683 | "6098 Failed setup of NVMET " |
| 9684 | "MRQ: rc = 0x%x\n", |
| 9685 | (uint32_t)rc); |
| 9686 | goto out_destroy; |
| 9687 | } |
| 9688 | |
| 9689 | } else { |
| 9690 | rc = lpfc_rq_create(phba, |
| 9691 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9692 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9693 | phba->sli4_hba.nvmet_cqset[0], |
| 9694 | LPFC_NVMET); |
| 9695 | if (rc) { |
| 9696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9697 | "6057 Failed setup of NVMET " |
| 9698 | "Receive Queue: rc = 0x%x\n", |
| 9699 | (uint32_t)rc); |
| 9700 | goto out_destroy; |
| 9701 | } |
| 9702 | |
| 9703 | lpfc_printf_log( |
| 9704 | phba, KERN_INFO, LOG_INIT, |
| 9705 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9706 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9707 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9708 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9709 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9710 | |
| 9711 | } |
| 9712 | } |
| 9713 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9714 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 9715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9716 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9717 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9718 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9719 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9720 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9721 | 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] | 9722 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9723 | if (rc) { |
| 9724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9725 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9726 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9727 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9728 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9729 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9730 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9731 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9732 | "parent cq-id=%d\n", |
| 9733 | phba->sli4_hba.hdr_rq->queue_id, |
| 9734 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9735 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9736 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9737 | if (phba->cfg_fcp_imax) |
| 9738 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9739 | else |
| 9740 | usdelay = 0; |
| 9741 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9742 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9743 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9744 | 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] | 9745 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9746 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9747 | if (phba->sli4_hba.cq_max) { |
| 9748 | kfree(phba->sli4_hba.cq_lookup); |
| 9749 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9750 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9751 | if (!phba->sli4_hba.cq_lookup) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9753 | "0549 Failed setup of CQ Lookup table: " |
| 9754 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9755 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9756 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9757 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9758 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9759 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9760 | return 0; |
| 9761 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9762 | out_destroy: |
| 9763 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9764 | out_error: |
| 9765 | return rc; |
| 9766 | } |
| 9767 | |
| 9768 | /** |
| 9769 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9770 | * @phba: pointer to lpfc hba data structure. |
| 9771 | * |
| 9772 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9773 | * operation. |
| 9774 | * |
| 9775 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9776 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9777 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9778 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9779 | **/ |
| 9780 | void |
| 9781 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9782 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9783 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9784 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9785 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9786 | |
| 9787 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9788 | if (phba->sli4_hba.mbx_wq) |
| 9789 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9790 | |
| 9791 | /* Unset NVME LS work queue */ |
| 9792 | if (phba->sli4_hba.nvmels_wq) |
| 9793 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9794 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9795 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9796 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9797 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9798 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9799 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9800 | if (phba->sli4_hba.hdr_rq) |
| 9801 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9802 | phba->sli4_hba.dat_rq); |
| 9803 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9804 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9805 | if (phba->sli4_hba.mbx_cq) |
| 9806 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9807 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9808 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9809 | if (phba->sli4_hba.els_cq) |
| 9810 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9811 | |
| 9812 | /* Unset NVME LS complete queue */ |
| 9813 | if (phba->sli4_hba.nvmels_cq) |
| 9814 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9815 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9816 | if (phba->nvmet_support) { |
| 9817 | /* Unset NVMET MRQ queue */ |
| 9818 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9819 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9820 | lpfc_rq_destroy( |
| 9821 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9822 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9823 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9824 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9825 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9826 | /* Unset NVMET CQ Set complete queue */ |
| 9827 | if (phba->sli4_hba.nvmet_cqset) { |
| 9828 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9829 | lpfc_cq_destroy( |
| 9830 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9831 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9832 | } |
| 9833 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9834 | /* Unset fast-path SLI4 queues */ |
| 9835 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9836 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9837 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9838 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9839 | qp = &phba->sli4_hba.hdwq[qidx]; |
| 9840 | lpfc_wq_destroy(phba, qp->fcp_wq); |
| 9841 | lpfc_wq_destroy(phba, qp->nvme_wq); |
| 9842 | lpfc_cq_destroy(phba, qp->fcp_cq); |
| 9843 | lpfc_cq_destroy(phba, qp->nvme_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9844 | } |
| 9845 | /* Loop thru all IRQ vectors */ |
| 9846 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 9847 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 9848 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 9849 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9850 | } |
| 9851 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9852 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9853 | kfree(phba->sli4_hba.cq_lookup); |
| 9854 | phba->sli4_hba.cq_lookup = NULL; |
| 9855 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9856 | } |
| 9857 | |
| 9858 | /** |
| 9859 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9860 | * @phba: pointer to lpfc hba data structure. |
| 9861 | * |
| 9862 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9863 | * events. The body of the completion queue event is a completion queue entry |
| 9864 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9865 | * the following HBA completion queue events for the worker thread to process: |
| 9866 | * - Mailbox asynchronous events |
| 9867 | * - Receive queue completion unsolicited events |
| 9868 | * Later, this can be used for all the slow-path events. |
| 9869 | * |
| 9870 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9871 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9872 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9873 | **/ |
| 9874 | static int |
| 9875 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9876 | { |
| 9877 | struct lpfc_cq_event *cq_event; |
| 9878 | int i; |
| 9879 | |
| 9880 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9881 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9882 | if (!cq_event) |
| 9883 | goto out_pool_create_fail; |
| 9884 | list_add_tail(&cq_event->list, |
| 9885 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9886 | } |
| 9887 | return 0; |
| 9888 | |
| 9889 | out_pool_create_fail: |
| 9890 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9891 | return -ENOMEM; |
| 9892 | } |
| 9893 | |
| 9894 | /** |
| 9895 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9896 | * @phba: pointer to lpfc hba data structure. |
| 9897 | * |
| 9898 | * This routine is invoked to free the pool of completion queue events at |
| 9899 | * driver unload time. Note that, it is the responsibility of the driver |
| 9900 | * cleanup routine to free all the outstanding completion-queue events |
| 9901 | * allocated from this pool back into the pool before invoking this routine |
| 9902 | * to destroy the pool. |
| 9903 | **/ |
| 9904 | static void |
| 9905 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9906 | { |
| 9907 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9908 | |
| 9909 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9910 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9911 | list_del(&cq_event->list); |
| 9912 | kfree(cq_event); |
| 9913 | } |
| 9914 | } |
| 9915 | |
| 9916 | /** |
| 9917 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9918 | * @phba: pointer to lpfc hba data structure. |
| 9919 | * |
| 9920 | * This routine is the lock free version of the API invoked to allocate a |
| 9921 | * completion-queue event from the free pool. |
| 9922 | * |
| 9923 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9924 | * NULL otherwise. |
| 9925 | **/ |
| 9926 | struct lpfc_cq_event * |
| 9927 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9928 | { |
| 9929 | struct lpfc_cq_event *cq_event = NULL; |
| 9930 | |
| 9931 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9932 | struct lpfc_cq_event, list); |
| 9933 | return cq_event; |
| 9934 | } |
| 9935 | |
| 9936 | /** |
| 9937 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9938 | * @phba: pointer to lpfc hba data structure. |
| 9939 | * |
| 9940 | * This routine is the lock version of the API invoked to allocate a |
| 9941 | * completion-queue event from the free pool. |
| 9942 | * |
| 9943 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9944 | * NULL otherwise. |
| 9945 | **/ |
| 9946 | struct lpfc_cq_event * |
| 9947 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9948 | { |
| 9949 | struct lpfc_cq_event *cq_event; |
| 9950 | unsigned long iflags; |
| 9951 | |
| 9952 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9953 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9954 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9955 | return cq_event; |
| 9956 | } |
| 9957 | |
| 9958 | /** |
| 9959 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9960 | * @phba: pointer to lpfc hba data structure. |
| 9961 | * @cq_event: pointer to the completion queue event to be freed. |
| 9962 | * |
| 9963 | * This routine is the lock free version of the API invoked to release a |
| 9964 | * completion-queue event back into the free pool. |
| 9965 | **/ |
| 9966 | void |
| 9967 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9968 | struct lpfc_cq_event *cq_event) |
| 9969 | { |
| 9970 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 9971 | } |
| 9972 | |
| 9973 | /** |
| 9974 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9975 | * @phba: pointer to lpfc hba data structure. |
| 9976 | * @cq_event: pointer to the completion queue event to be freed. |
| 9977 | * |
| 9978 | * This routine is the lock version of the API invoked to release a |
| 9979 | * completion-queue event back into the free pool. |
| 9980 | **/ |
| 9981 | void |
| 9982 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9983 | struct lpfc_cq_event *cq_event) |
| 9984 | { |
| 9985 | unsigned long iflags; |
| 9986 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9987 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 9988 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9989 | } |
| 9990 | |
| 9991 | /** |
| 9992 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 9993 | * @phba: pointer to lpfc hba data structure. |
| 9994 | * |
| 9995 | * This routine is to free all the pending completion-queue events to the |
| 9996 | * back into the free pool for device reset. |
| 9997 | **/ |
| 9998 | static void |
| 9999 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10000 | { |
| 10001 | LIST_HEAD(cqelist); |
| 10002 | struct lpfc_cq_event *cqe; |
| 10003 | unsigned long iflags; |
| 10004 | |
| 10005 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 10006 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10007 | /* Pending FCP XRI abort events */ |
| 10008 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10009 | &cqelist); |
| 10010 | /* Pending ELS XRI abort events */ |
| 10011 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10012 | &cqelist); |
| 10013 | /* Pending asynnc events */ |
| 10014 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10015 | &cqelist); |
| 10016 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10017 | |
| 10018 | while (!list_empty(&cqelist)) { |
| 10019 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 10020 | lpfc_sli4_cq_event_release(phba, cqe); |
| 10021 | } |
| 10022 | } |
| 10023 | |
| 10024 | /** |
| 10025 | * lpfc_pci_function_reset - Reset pci function. |
| 10026 | * @phba: pointer to lpfc hba data structure. |
| 10027 | * |
| 10028 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10029 | * all resources assigned to the PCI function which originates this request. |
| 10030 | * |
| 10031 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10032 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10033 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10034 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10035 | **/ |
| 10036 | int |
| 10037 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10038 | { |
| 10039 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10040 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10041 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10042 | uint32_t rdy_chk; |
| 10043 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10044 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10045 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10046 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10047 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10048 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10049 | switch (if_type) { |
| 10050 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10051 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10052 | GFP_KERNEL); |
| 10053 | if (!mboxq) { |
| 10054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10055 | "0494 Unable to allocate memory for " |
| 10056 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10057 | "command\n"); |
| 10058 | return -ENOMEM; |
| 10059 | } |
| 10060 | |
| 10061 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10062 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10063 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10064 | LPFC_SLI4_MBX_EMBED); |
| 10065 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10066 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10067 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10068 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10069 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10070 | &shdr->response); |
| 10071 | if (rc != MBX_TIMEOUT) |
| 10072 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10073 | if (shdr_status || shdr_add_status || rc) { |
| 10074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10075 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10076 | "failed with status x%x add_status x%x," |
| 10077 | " mbx status x%x\n", |
| 10078 | shdr_status, shdr_add_status, rc); |
| 10079 | rc = -ENXIO; |
| 10080 | } |
| 10081 | break; |
| 10082 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10083 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10084 | wait: |
| 10085 | /* |
| 10086 | * Poll the Port Status Register and wait for RDY for |
| 10087 | * up to 30 seconds. If the port doesn't respond, treat |
| 10088 | * it as an error. |
| 10089 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10090 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10091 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10092 | STATUSregaddr, ®_data.word0)) { |
| 10093 | rc = -ENODEV; |
| 10094 | goto out; |
| 10095 | } |
| 10096 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10097 | break; |
| 10098 | msleep(20); |
| 10099 | } |
| 10100 | |
| 10101 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10102 | phba->work_status[0] = readl( |
| 10103 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10104 | phba->work_status[1] = readl( |
| 10105 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10106 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10107 | "2890 Port not ready, port status reg " |
| 10108 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10109 | reg_data.word0, |
| 10110 | phba->work_status[0], |
| 10111 | phba->work_status[1]); |
| 10112 | rc = -ENODEV; |
| 10113 | goto out; |
| 10114 | } |
| 10115 | |
| 10116 | if (!port_reset) { |
| 10117 | /* |
| 10118 | * Reset the port now |
| 10119 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10120 | reg_data.word0 = 0; |
| 10121 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10122 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10123 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10124 | LPFC_SLIPORT_INIT_PORT); |
| 10125 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10126 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10127 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10128 | pci_read_config_word(phba->pcidev, |
| 10129 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10130 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10131 | port_reset = 1; |
| 10132 | msleep(20); |
| 10133 | goto wait; |
| 10134 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10135 | rc = -ENODEV; |
| 10136 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10137 | } |
| 10138 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10139 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10140 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10141 | default: |
| 10142 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10143 | } |
| 10144 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10145 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10146 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10147 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10149 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10150 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10151 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10152 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10153 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10154 | return rc; |
| 10155 | } |
| 10156 | |
| 10157 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10158 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10159 | * @phba: pointer to lpfc hba data structure. |
| 10160 | * |
| 10161 | * This routine is invoked to set up the PCI device memory space for device |
| 10162 | * with SLI-4 interface spec. |
| 10163 | * |
| 10164 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10165 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10166 | * other values - error |
| 10167 | **/ |
| 10168 | static int |
| 10169 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10170 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10171 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10172 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10173 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10174 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10175 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10176 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10177 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10178 | |
| 10179 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10180 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10181 | if (error) |
| 10182 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10183 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10184 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10185 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10186 | /* |
| 10187 | * The BARs and register set definitions and offset locations are |
| 10188 | * dependent on the if_type. |
| 10189 | */ |
| 10190 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10191 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10192 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10193 | } |
| 10194 | |
| 10195 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10196 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10197 | LPFC_SLI_INTF_VALID) { |
| 10198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10199 | "2894 SLI_INTF reg contents invalid " |
| 10200 | "sli_intf reg 0x%x\n", |
| 10201 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10202 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10203 | } |
| 10204 | |
| 10205 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10206 | /* |
| 10207 | * Get the bus address of SLI4 device Bar regions and the |
| 10208 | * number of bytes required by each mapping. The mapping of the |
| 10209 | * particular PCI BARs regions is dependent on the type of |
| 10210 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10211 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10212 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10213 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10214 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10215 | |
| 10216 | /* |
| 10217 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10218 | * addr |
| 10219 | */ |
| 10220 | phba->sli4_hba.conf_regs_memmap_p = |
| 10221 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10222 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10223 | dev_printk(KERN_ERR, &pdev->dev, |
| 10224 | "ioremap failed for SLI4 PCI config " |
| 10225 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10226 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10227 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10228 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10229 | /* Set up BAR0 PCI config space register memory map */ |
| 10230 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10231 | } else { |
| 10232 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10233 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10234 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10235 | dev_printk(KERN_ERR, &pdev->dev, |
| 10236 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10237 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10238 | } |
| 10239 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10240 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10241 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10242 | dev_printk(KERN_ERR, &pdev->dev, |
| 10243 | "ioremap failed for SLI4 PCI config " |
| 10244 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10245 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10246 | } |
| 10247 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10248 | } |
| 10249 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10250 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10251 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10252 | /* |
| 10253 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10254 | * kernel virtual address and setup the registers. |
| 10255 | */ |
| 10256 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10257 | PCI_64BIT_BAR2); |
| 10258 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10259 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10260 | ioremap(phba->pci_bar1_map, |
| 10261 | bar1map_len); |
| 10262 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10263 | dev_err(&pdev->dev, |
| 10264 | "ioremap failed for SLI4 HBA " |
| 10265 | "control registers.\n"); |
| 10266 | error = -ENOMEM; |
| 10267 | goto out_iounmap_conf; |
| 10268 | } |
| 10269 | phba->pci_bar2_memmap_p = |
| 10270 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10271 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10272 | } else { |
| 10273 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10274 | goto out_iounmap_conf; |
| 10275 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10276 | } |
| 10277 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10278 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10279 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10280 | /* |
| 10281 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10282 | * virtual address and setup the registers. |
| 10283 | */ |
| 10284 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10285 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10286 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10287 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10288 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10289 | dev_err(&pdev->dev, |
| 10290 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10291 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10292 | goto out_iounmap_conf; |
| 10293 | } |
| 10294 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10295 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10296 | } |
| 10297 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10298 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10299 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10300 | /* |
| 10301 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10302 | * a kernel virtual address and setup the registers. |
| 10303 | */ |
| 10304 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10305 | PCI_64BIT_BAR4); |
| 10306 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10307 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10308 | ioremap(phba->pci_bar2_map, |
| 10309 | bar2map_len); |
| 10310 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10311 | dev_err(&pdev->dev, |
| 10312 | "ioremap failed for SLI4 HBA" |
| 10313 | " doorbell registers.\n"); |
| 10314 | error = -ENOMEM; |
| 10315 | goto out_iounmap_ctrl; |
| 10316 | } |
| 10317 | phba->pci_bar4_memmap_p = |
| 10318 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10319 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10320 | if (error) |
| 10321 | goto out_iounmap_all; |
| 10322 | } else { |
| 10323 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10324 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10325 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10326 | } |
| 10327 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10328 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10329 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10330 | /* |
| 10331 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10332 | * virtual address and setup the registers. |
| 10333 | */ |
| 10334 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10335 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10336 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10337 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10338 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10339 | dev_err(&pdev->dev, |
| 10340 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10341 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10342 | goto out_iounmap_ctrl; |
| 10343 | } |
| 10344 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10345 | } |
| 10346 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10347 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10348 | switch (if_type) { |
| 10349 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10350 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10351 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10352 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10353 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10354 | break; |
| 10355 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10356 | 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] | 10357 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10358 | 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] | 10359 | break; |
| 10360 | default: |
| 10361 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10362 | } |
| 10363 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10364 | return 0; |
| 10365 | |
| 10366 | out_iounmap_all: |
| 10367 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10368 | out_iounmap_ctrl: |
| 10369 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10370 | out_iounmap_conf: |
| 10371 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10372 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10373 | return error; |
| 10374 | } |
| 10375 | |
| 10376 | /** |
| 10377 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10378 | * @phba: pointer to lpfc hba data structure. |
| 10379 | * |
| 10380 | * This routine is invoked to unset the PCI device memory space for device |
| 10381 | * with SLI-4 interface spec. |
| 10382 | **/ |
| 10383 | static void |
| 10384 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10385 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10386 | uint32_t if_type; |
| 10387 | 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] | 10388 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10389 | switch (if_type) { |
| 10390 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10391 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10392 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10393 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10394 | break; |
| 10395 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10396 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10397 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10398 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10399 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10400 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10401 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10402 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10403 | default: |
| 10404 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10405 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10406 | if_type); |
| 10407 | break; |
| 10408 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10409 | } |
| 10410 | |
| 10411 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10412 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10413 | * @phba: pointer to lpfc hba data structure. |
| 10414 | * |
| 10415 | * 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] | 10416 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10417 | * |
| 10418 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10419 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10420 | * other values - error |
| 10421 | **/ |
| 10422 | static int |
| 10423 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10424 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10425 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10426 | LPFC_MBOXQ_t *pmb; |
| 10427 | |
| 10428 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10429 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10430 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10431 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10432 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10433 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10434 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10435 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10436 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10437 | /* |
| 10438 | * Assign MSI-X vectors to interrupt handlers |
| 10439 | */ |
| 10440 | |
| 10441 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10442 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10443 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10444 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10445 | if (rc) { |
| 10446 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10447 | "0421 MSI-X slow-path request_irq failed " |
| 10448 | "(%d)\n", rc); |
| 10449 | goto msi_fail_out; |
| 10450 | } |
| 10451 | |
| 10452 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10453 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10454 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10455 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10456 | |
| 10457 | if (rc) { |
| 10458 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10459 | "0429 MSI-X fast-path request_irq failed " |
| 10460 | "(%d)\n", rc); |
| 10461 | goto irq_fail_out; |
| 10462 | } |
| 10463 | |
| 10464 | /* |
| 10465 | * Configure HBA MSI-X attention conditions to messages |
| 10466 | */ |
| 10467 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10468 | |
| 10469 | if (!pmb) { |
| 10470 | rc = -ENOMEM; |
| 10471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10472 | "0474 Unable to allocate memory for issuing " |
| 10473 | "MBOX_CONFIG_MSI command\n"); |
| 10474 | goto mem_fail_out; |
| 10475 | } |
| 10476 | rc = lpfc_config_msi(phba, pmb); |
| 10477 | if (rc) |
| 10478 | goto mbx_fail_out; |
| 10479 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10480 | if (rc != MBX_SUCCESS) { |
| 10481 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10482 | "0351 Config MSI mailbox command failed, " |
| 10483 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10484 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10485 | goto mbx_fail_out; |
| 10486 | } |
| 10487 | |
| 10488 | /* Free memory allocated for mailbox command */ |
| 10489 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10490 | return rc; |
| 10491 | |
| 10492 | mbx_fail_out: |
| 10493 | /* Free memory allocated for mailbox command */ |
| 10494 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10495 | |
| 10496 | mem_fail_out: |
| 10497 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10498 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10499 | |
| 10500 | irq_fail_out: |
| 10501 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10502 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10503 | |
| 10504 | msi_fail_out: |
| 10505 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10506 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10507 | |
| 10508 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10509 | return rc; |
| 10510 | } |
| 10511 | |
| 10512 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10513 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10514 | * @phba: pointer to lpfc hba data structure. |
| 10515 | * |
| 10516 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10517 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10518 | * enable the MSI vector. The device driver is responsible for calling the |
| 10519 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10520 | * is done in this function. |
| 10521 | * |
| 10522 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10523 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10524 | * other values - error |
| 10525 | */ |
| 10526 | static int |
| 10527 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10528 | { |
| 10529 | int rc; |
| 10530 | |
| 10531 | rc = pci_enable_msi(phba->pcidev); |
| 10532 | if (!rc) |
| 10533 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10534 | "0462 PCI enable MSI mode success.\n"); |
| 10535 | else { |
| 10536 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10537 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10538 | return rc; |
| 10539 | } |
| 10540 | |
| 10541 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10542 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10543 | if (rc) { |
| 10544 | pci_disable_msi(phba->pcidev); |
| 10545 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10546 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10547 | } |
| 10548 | return rc; |
| 10549 | } |
| 10550 | |
| 10551 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10552 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10553 | * @phba: pointer to lpfc hba data structure. |
| 10554 | * |
| 10555 | * This routine is invoked to enable device interrupt and associate driver's |
| 10556 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10557 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10558 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10559 | * mode which is supported by the platform, kernel, and device in the order |
| 10560 | * of: |
| 10561 | * MSI-X -> MSI -> IRQ. |
| 10562 | * |
| 10563 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10564 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10565 | * other values - error |
| 10566 | **/ |
| 10567 | static uint32_t |
| 10568 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10569 | { |
| 10570 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10571 | int retval; |
| 10572 | |
| 10573 | if (cfg_mode == 2) { |
| 10574 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10575 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10576 | if (!retval) { |
| 10577 | /* Now, try to enable MSI-X interrupt mode */ |
| 10578 | retval = lpfc_sli_enable_msix(phba); |
| 10579 | if (!retval) { |
| 10580 | /* Indicate initialization to MSI-X mode */ |
| 10581 | phba->intr_type = MSIX; |
| 10582 | intr_mode = 2; |
| 10583 | } |
| 10584 | } |
| 10585 | } |
| 10586 | |
| 10587 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10588 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10589 | retval = lpfc_sli_enable_msi(phba); |
| 10590 | if (!retval) { |
| 10591 | /* Indicate initialization to MSI mode */ |
| 10592 | phba->intr_type = MSI; |
| 10593 | intr_mode = 1; |
| 10594 | } |
| 10595 | } |
| 10596 | |
| 10597 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10598 | if (phba->intr_type == NONE) { |
| 10599 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10600 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10601 | if (!retval) { |
| 10602 | /* Indicate initialization to INTx mode */ |
| 10603 | phba->intr_type = INTx; |
| 10604 | intr_mode = 0; |
| 10605 | } |
| 10606 | } |
| 10607 | return intr_mode; |
| 10608 | } |
| 10609 | |
| 10610 | /** |
| 10611 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10612 | * @phba: pointer to lpfc hba data structure. |
| 10613 | * |
| 10614 | * This routine is invoked to disable device interrupt and disassociate the |
| 10615 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10616 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10617 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10618 | **/ |
| 10619 | static void |
| 10620 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10621 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10622 | int nr_irqs, i; |
| 10623 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10624 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10625 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10626 | else |
| 10627 | nr_irqs = 1; |
| 10628 | |
| 10629 | for (i = 0; i < nr_irqs; i++) |
| 10630 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10631 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10632 | |
| 10633 | /* Reset interrupt management states */ |
| 10634 | phba->intr_type = NONE; |
| 10635 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10636 | } |
| 10637 | |
| 10638 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10639 | * 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] | 10640 | * @phba: pointer to lpfc hba data structure. |
| 10641 | * @id: EQ vector index or Hardware Queue index |
| 10642 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10643 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10644 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10645 | */ |
| 10646 | static uint16_t |
| 10647 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10648 | { |
| 10649 | struct lpfc_vector_map_info *cpup; |
| 10650 | int cpu; |
| 10651 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10652 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10653 | for_each_present_cpu(cpu) { |
| 10654 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10655 | |
| 10656 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10657 | * using the same vector, so select the one with |
| 10658 | * LPFC_CPU_FIRST_IRQ set. |
| 10659 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10660 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10661 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10662 | (cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10663 | (cpup->eq == id)) |
| 10664 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10665 | |
| 10666 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10667 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10668 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10669 | } |
| 10670 | return 0; |
| 10671 | } |
| 10672 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10673 | #ifdef CONFIG_X86 |
| 10674 | /** |
| 10675 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10676 | * @phba: pointer to lpfc hba data structure. |
| 10677 | * @cpu: CPU map index |
| 10678 | * @phys_id: CPU package physical id |
| 10679 | * @core_id: CPU core id |
| 10680 | */ |
| 10681 | static int |
| 10682 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10683 | uint16_t phys_id, uint16_t core_id) |
| 10684 | { |
| 10685 | struct lpfc_vector_map_info *cpup; |
| 10686 | int idx; |
| 10687 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10688 | for_each_present_cpu(idx) { |
| 10689 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10690 | /* Does the cpup match the one we are looking for */ |
| 10691 | if ((cpup->phys_id == phys_id) && |
| 10692 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10693 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10694 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10695 | } |
| 10696 | return 0; |
| 10697 | } |
| 10698 | #endif |
| 10699 | |
| 10700 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10701 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10702 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10703 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10704 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10705 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10706 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10707 | * In addition, the CPU to IO channel mapping will be calculated |
| 10708 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10709 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10710 | static void |
| 10711 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10712 | { |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10713 | int i, cpu, idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10714 | int max_phys_id, min_phys_id; |
| 10715 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10716 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10717 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10718 | const struct cpumask *maskp; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10719 | #ifdef CONFIG_X86 |
| 10720 | struct cpuinfo_x86 *cpuinfo; |
| 10721 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10722 | |
| 10723 | /* Init cpu_map array */ |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10724 | for_each_possible_cpu(cpu) { |
| 10725 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10726 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10727 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10728 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10729 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10730 | cpup->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10731 | cpup->flag = 0; |
| 10732 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10733 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10734 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10735 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10736 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10737 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10738 | |
| 10739 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10740 | for_each_present_cpu(cpu) { |
| 10741 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10742 | #ifdef CONFIG_X86 |
| 10743 | cpuinfo = &cpu_data(cpu); |
| 10744 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10745 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10746 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10747 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10748 | #else |
| 10749 | /* No distinction between CPUs for other platforms */ |
| 10750 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10751 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10752 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10753 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10754 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10755 | "3328 CPU physid %d coreid %d\n", |
| 10756 | cpup->phys_id, cpup->core_id); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10757 | |
| 10758 | if (cpup->phys_id > max_phys_id) |
| 10759 | max_phys_id = cpup->phys_id; |
| 10760 | if (cpup->phys_id < min_phys_id) |
| 10761 | min_phys_id = cpup->phys_id; |
| 10762 | |
| 10763 | if (cpup->core_id > max_core_id) |
| 10764 | max_core_id = cpup->core_id; |
| 10765 | if (cpup->core_id < min_core_id) |
| 10766 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10767 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10768 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10769 | for_each_possible_cpu(i) { |
| 10770 | struct lpfc_eq_intr_info *eqi = |
| 10771 | per_cpu_ptr(phba->sli4_hba.eq_info, i); |
| 10772 | |
| 10773 | INIT_LIST_HEAD(&eqi->list); |
| 10774 | eqi->icnt = 0; |
| 10775 | } |
| 10776 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10777 | /* This loop sets up all CPUs that are affinitized with a |
| 10778 | * irq vector assigned to the driver. All affinitized CPUs |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10779 | * will get a link to that vectors IRQ and EQ. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10780 | */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10781 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10782 | /* Get a CPU mask for all CPUs affinitized to this vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10783 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 10784 | if (!maskp) |
| 10785 | continue; |
| 10786 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10787 | i = 0; |
| 10788 | /* Loop through all CPUs associated with vector idx */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10789 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10790 | /* Set the EQ index and IRQ for that vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10791 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10792 | cpup->eq = idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10793 | cpup->irq = pci_irq_vector(phba->pcidev, idx); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10794 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10795 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10796 | "3336 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10797 | "irq %d eq %d\n", |
| 10798 | cpu, cpup->irq, cpup->eq); |
| 10799 | |
| 10800 | /* If this is the first CPU thats assigned to this |
| 10801 | * vector, set LPFC_CPU_FIRST_IRQ. |
| 10802 | */ |
| 10803 | if (!i) |
| 10804 | cpup->flag |= LPFC_CPU_FIRST_IRQ; |
| 10805 | i++; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10806 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10807 | } |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10808 | |
| 10809 | /* After looking at each irq vector assigned to this pcidev, its |
| 10810 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10811 | * Next we will set any unassigned (unaffinitized) cpu map |
| 10812 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10813 | */ |
| 10814 | first_cpu = cpumask_first(cpu_present_mask); |
| 10815 | start_cpu = first_cpu; |
| 10816 | |
| 10817 | for_each_present_cpu(cpu) { |
| 10818 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10819 | |
| 10820 | /* Is this CPU entry unassigned */ |
| 10821 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10822 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 10823 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10824 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10825 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10826 | * phys_id as cpup. start_cpu will start where we |
| 10827 | * left off so all unassigned entries don't get assgined |
| 10828 | * the IRQ of the first entry. |
| 10829 | */ |
| 10830 | new_cpu = start_cpu; |
| 10831 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10832 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10833 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10834 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10835 | (new_cpup->phys_id == cpup->phys_id)) |
| 10836 | goto found_same; |
| 10837 | new_cpu = cpumask_next( |
| 10838 | new_cpu, cpu_present_mask); |
| 10839 | if (new_cpu == nr_cpumask_bits) |
| 10840 | new_cpu = first_cpu; |
| 10841 | } |
| 10842 | /* At this point, we leave the CPU as unassigned */ |
| 10843 | continue; |
| 10844 | found_same: |
| 10845 | /* We found a matching phys_id, so copy the IRQ info */ |
| 10846 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10847 | cpup->irq = new_cpup->irq; |
| 10848 | |
| 10849 | /* Bump start_cpu to the next slot to minmize the |
| 10850 | * chance of having multiple unassigned CPU entries |
| 10851 | * selecting the same IRQ. |
| 10852 | */ |
| 10853 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10854 | if (start_cpu == nr_cpumask_bits) |
| 10855 | start_cpu = first_cpu; |
| 10856 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10857 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10858 | "3337 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10859 | "irq %d from id %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10860 | "phys_id (%d)\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10861 | cpu, cpup->irq, new_cpu, cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10862 | } |
| 10863 | } |
| 10864 | |
| 10865 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 10866 | start_cpu = first_cpu; |
| 10867 | |
| 10868 | for_each_present_cpu(cpu) { |
| 10869 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10870 | |
| 10871 | /* Is this entry unassigned */ |
| 10872 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10873 | /* Mark it as IRQ not assigned by the kernel */ |
| 10874 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10875 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10876 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10877 | * as the cpup. start_cpu will start where we |
| 10878 | * left off so all unassigned entries don't get |
| 10879 | * assigned the IRQ of the first entry. |
| 10880 | */ |
| 10881 | new_cpu = start_cpu; |
| 10882 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10883 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10884 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10885 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY)) |
| 10886 | goto found_any; |
| 10887 | new_cpu = cpumask_next( |
| 10888 | new_cpu, cpu_present_mask); |
| 10889 | if (new_cpu == nr_cpumask_bits) |
| 10890 | new_cpu = first_cpu; |
| 10891 | } |
| 10892 | /* We should never leave an entry unassigned */ |
| 10893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10894 | "3339 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10895 | "irq %d UNASSIGNED\n", |
| 10896 | cpup->hdwq, cpup->irq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10897 | continue; |
| 10898 | found_any: |
| 10899 | /* We found an available entry, copy the IRQ info */ |
| 10900 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10901 | cpup->irq = new_cpup->irq; |
| 10902 | |
| 10903 | /* Bump start_cpu to the next slot to minmize the |
| 10904 | * chance of having multiple unassigned CPU entries |
| 10905 | * selecting the same IRQ. |
| 10906 | */ |
| 10907 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10908 | if (start_cpu == nr_cpumask_bits) |
| 10909 | start_cpu = first_cpu; |
| 10910 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10911 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10912 | "3338 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10913 | "irq %d from id %d (%d/%d)\n", |
| 10914 | cpu, cpup->irq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10915 | new_cpup->phys_id, new_cpup->core_id); |
| 10916 | } |
| 10917 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10918 | |
| 10919 | /* Finally we need to associate a hdwq with each cpu_map entry |
| 10920 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 10921 | * hardware queues then CPUs. For that case we will just round-robin |
| 10922 | * the available hardware queues as they get assigned to CPUs. |
| 10923 | */ |
| 10924 | idx = 0; |
| 10925 | start_cpu = 0; |
| 10926 | for_each_present_cpu(cpu) { |
| 10927 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10928 | if (idx >= phba->cfg_hdw_queue) { |
| 10929 | /* We need to reuse a Hardware Queue for another CPU, |
| 10930 | * so be smart about it and pick one that has its |
| 10931 | * IRQ/EQ mapped to the same phys_id (CPU package). |
| 10932 | * and core_id. |
| 10933 | */ |
| 10934 | new_cpu = start_cpu; |
| 10935 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10936 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10937 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10938 | (new_cpup->phys_id == cpup->phys_id) && |
| 10939 | (new_cpup->core_id == cpup->core_id)) |
| 10940 | goto found_hdwq; |
| 10941 | new_cpu = cpumask_next( |
| 10942 | new_cpu, cpu_present_mask); |
| 10943 | if (new_cpu == nr_cpumask_bits) |
| 10944 | new_cpu = first_cpu; |
| 10945 | } |
| 10946 | |
| 10947 | /* If we can't match both phys_id and core_id, |
| 10948 | * settle for just a phys_id match. |
| 10949 | */ |
| 10950 | new_cpu = start_cpu; |
| 10951 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10952 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10953 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10954 | (new_cpup->phys_id == cpup->phys_id)) |
| 10955 | goto found_hdwq; |
| 10956 | new_cpu = cpumask_next( |
| 10957 | new_cpu, cpu_present_mask); |
| 10958 | if (new_cpu == nr_cpumask_bits) |
| 10959 | new_cpu = first_cpu; |
| 10960 | } |
| 10961 | |
| 10962 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 10963 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 10964 | goto logit; |
| 10965 | found_hdwq: |
| 10966 | /* We found an available entry, copy the IRQ info */ |
| 10967 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10968 | if (start_cpu == nr_cpumask_bits) |
| 10969 | start_cpu = first_cpu; |
| 10970 | cpup->hdwq = new_cpup->hdwq; |
| 10971 | } else { |
| 10972 | /* 1 to 1, CPU to hdwq */ |
| 10973 | cpup->hdwq = idx; |
| 10974 | } |
| 10975 | logit: |
| 10976 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10977 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
| 10978 | "hdwq %d eq %d irq %d flg x%x\n", |
| 10979 | cpu, cpup->phys_id, cpup->core_id, |
| 10980 | cpup->hdwq, cpup->eq, cpup->irq, cpup->flag); |
| 10981 | idx++; |
| 10982 | } |
| 10983 | |
| 10984 | /* The cpu_map array will be used later during initialization |
| 10985 | * when EQ / CQ / WQs are allocated and configured. |
| 10986 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10987 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10988 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10989 | |
| 10990 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10991 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 10992 | * @phba: pointer to lpfc hba data structure. |
| 10993 | * |
| 10994 | * 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] | 10995 | * with SLI-4 interface spec. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10996 | * |
| 10997 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10998 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10999 | * other values - error |
| 11000 | **/ |
| 11001 | static int |
| 11002 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11003 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11004 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11005 | char *name; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11006 | |
| 11007 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11008 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11009 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11010 | rc = pci_alloc_irq_vectors(phba->pcidev, |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 11011 | 1, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11012 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11013 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11014 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11015 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11016 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11017 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11018 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11019 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11020 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11021 | for (index = 0; index < vectors; index++) { |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11022 | name = phba->sli4_hba.hba_eq_hdl[index].handler_name; |
| 11023 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11024 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11025 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11026 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11027 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11028 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11029 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11030 | &lpfc_sli4_hba_intr_handler, 0, |
| 11031 | name, |
| 11032 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11033 | if (rc) { |
| 11034 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11035 | "0486 MSI-X fast-path (%d) " |
| 11036 | "request_irq failed (%d)\n", index, rc); |
| 11037 | goto cfg_fail_out; |
| 11038 | } |
| 11039 | } |
| 11040 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11041 | if (vectors != phba->cfg_irq_chann) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11042 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11043 | "3238 Reducing IO channels to match number of " |
| 11044 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11045 | phba->cfg_irq_chann, vectors); |
| 11046 | if (phba->cfg_irq_chann > vectors) |
| 11047 | phba->cfg_irq_chann = vectors; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 11048 | if (phba->nvmet_support && (phba->cfg_nvmet_mrq > vectors)) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11049 | phba->cfg_nvmet_mrq = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11050 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11051 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11052 | return rc; |
| 11053 | |
| 11054 | cfg_fail_out: |
| 11055 | /* free the irq already requested */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11056 | for (--index; index >= 0; index--) |
| 11057 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11058 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11059 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11060 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11061 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11062 | |
| 11063 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11064 | return rc; |
| 11065 | } |
| 11066 | |
| 11067 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11068 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11069 | * @phba: pointer to lpfc hba data structure. |
| 11070 | * |
| 11071 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 11072 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 11073 | * to enable the MSI vector. The device driver is responsible for calling |
| 11074 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 11075 | * which is done in this function. |
| 11076 | * |
| 11077 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11078 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11079 | * other values - error |
| 11080 | **/ |
| 11081 | static int |
| 11082 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11083 | { |
| 11084 | int rc, index; |
| 11085 | |
| 11086 | rc = pci_enable_msi(phba->pcidev); |
| 11087 | if (!rc) |
| 11088 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11089 | "0487 PCI enable MSI mode success.\n"); |
| 11090 | else { |
| 11091 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11092 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 11093 | return rc; |
| 11094 | } |
| 11095 | |
| 11096 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11097 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11098 | if (rc) { |
| 11099 | pci_disable_msi(phba->pcidev); |
| 11100 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11101 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11102 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11103 | } |
| 11104 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11105 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11106 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11107 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11108 | } |
| 11109 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11110 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11111 | } |
| 11112 | |
| 11113 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11114 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11115 | * @phba: pointer to lpfc hba data structure. |
| 11116 | * |
| 11117 | * This routine is invoked to enable device interrupt and associate driver's |
| 11118 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11119 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11120 | * the driver will try to fallback from the configured interrupt mode to an |
| 11121 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11122 | * the order of: |
| 11123 | * MSI-X -> MSI -> IRQ. |
| 11124 | * |
| 11125 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11126 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11127 | * other values - error |
| 11128 | **/ |
| 11129 | static uint32_t |
| 11130 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11131 | { |
| 11132 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11133 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11134 | |
| 11135 | if (cfg_mode == 2) { |
| 11136 | /* Preparation before conf_msi mbox cmd */ |
| 11137 | retval = 0; |
| 11138 | if (!retval) { |
| 11139 | /* Now, try to enable MSI-X interrupt mode */ |
| 11140 | retval = lpfc_sli4_enable_msix(phba); |
| 11141 | if (!retval) { |
| 11142 | /* Indicate initialization to MSI-X mode */ |
| 11143 | phba->intr_type = MSIX; |
| 11144 | intr_mode = 2; |
| 11145 | } |
| 11146 | } |
| 11147 | } |
| 11148 | |
| 11149 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11150 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11151 | retval = lpfc_sli4_enable_msi(phba); |
| 11152 | if (!retval) { |
| 11153 | /* Indicate initialization to MSI mode */ |
| 11154 | phba->intr_type = MSI; |
| 11155 | intr_mode = 1; |
| 11156 | } |
| 11157 | } |
| 11158 | |
| 11159 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11160 | if (phba->intr_type == NONE) { |
| 11161 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11162 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11163 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11164 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11165 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11166 | /* Indicate initialization to INTx mode */ |
| 11167 | phba->intr_type = INTx; |
| 11168 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11169 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11170 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11171 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 11172 | eqhdl->idx = idx; |
| 11173 | eqhdl->phba = phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11174 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11175 | } |
| 11176 | } |
| 11177 | return intr_mode; |
| 11178 | } |
| 11179 | |
| 11180 | /** |
| 11181 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11182 | * @phba: pointer to lpfc hba data structure. |
| 11183 | * |
| 11184 | * This routine is invoked to disable device interrupt and disassociate |
| 11185 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11186 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11187 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11188 | **/ |
| 11189 | static void |
| 11190 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11191 | { |
| 11192 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11193 | if (phba->intr_type == MSIX) { |
| 11194 | int index; |
| 11195 | |
| 11196 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11197 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11198 | irq_set_affinity_hint( |
| 11199 | pci_irq_vector(phba->pcidev, index), |
| 11200 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11201 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11202 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11203 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11204 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11205 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11206 | } |
| 11207 | |
| 11208 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11209 | |
| 11210 | /* Reset interrupt management states */ |
| 11211 | phba->intr_type = NONE; |
| 11212 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11213 | } |
| 11214 | |
| 11215 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11216 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11217 | * @phba: pointer to lpfc hba data structure. |
| 11218 | * |
| 11219 | * This routine is invoked to unset the HBA device initialization steps to |
| 11220 | * a device with SLI-3 interface spec. |
| 11221 | **/ |
| 11222 | static void |
| 11223 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11224 | { |
| 11225 | struct lpfc_vport *vport = phba->pport; |
| 11226 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11227 | |
| 11228 | spin_lock_irq(shost->host_lock); |
| 11229 | vport->load_flag |= FC_UNLOADING; |
| 11230 | spin_unlock_irq(shost->host_lock); |
| 11231 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11232 | kfree(phba->vpi_bmask); |
| 11233 | kfree(phba->vpi_ids); |
| 11234 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11235 | lpfc_stop_hba_timers(phba); |
| 11236 | |
| 11237 | phba->pport->work_port_events = 0; |
| 11238 | |
| 11239 | lpfc_sli_hba_down(phba); |
| 11240 | |
| 11241 | lpfc_sli_brdrestart(phba); |
| 11242 | |
| 11243 | lpfc_sli_disable_intr(phba); |
| 11244 | |
| 11245 | return; |
| 11246 | } |
| 11247 | |
| 11248 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11249 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11250 | * @phba: Pointer to HBA context object. |
| 11251 | * |
| 11252 | * This function is called in the SLI4 code path to wait for completion |
| 11253 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11254 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11255 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11256 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11257 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11258 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11259 | * the rest of the driver unload resource release. |
| 11260 | **/ |
| 11261 | static void |
| 11262 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11263 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11264 | struct lpfc_sli4_hdw_queue *qp; |
| 11265 | int idx, ccnt, fcnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11266 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11267 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11268 | int nvmet_xri_cmpl = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11269 | int fcp_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11270 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11271 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11272 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11273 | * here to give the HBA time to complete the IO and get entries |
| 11274 | * into the abts lists. |
| 11275 | */ |
| 11276 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11277 | |
| 11278 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11279 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11280 | lpfc_nvme_wait_for_io_drain(phba); |
| 11281 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11282 | ccnt = 0; |
| 11283 | fcnt = 0; |
| 11284 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11285 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11286 | fcp_xri_cmpl = list_empty( |
| 11287 | &qp->lpfc_abts_scsi_buf_list); |
| 11288 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11289 | fcnt++; |
| 11290 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11291 | io_xri_cmpl = list_empty( |
| 11292 | &qp->lpfc_abts_nvme_buf_list); |
| 11293 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11294 | ccnt++; |
| 11295 | } |
| 11296 | } |
| 11297 | if (ccnt) |
| 11298 | io_xri_cmpl = 0; |
| 11299 | if (fcnt) |
| 11300 | fcp_xri_cmpl = 0; |
| 11301 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11302 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11303 | nvmet_xri_cmpl = |
| 11304 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11305 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11306 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11307 | while (!fcp_xri_cmpl || !els_xri_cmpl || !io_xri_cmpl || |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11308 | !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11309 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11310 | if (!nvmet_xri_cmpl) |
| 11311 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11312 | "6424 NVMET XRI exchange busy " |
| 11313 | "wait time: %d seconds.\n", |
| 11314 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11315 | if (!io_xri_cmpl) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11316 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11317 | "6100 NVME XRI exchange busy " |
| 11318 | "wait time: %d seconds.\n", |
| 11319 | wait_time/1000); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11320 | if (!fcp_xri_cmpl) |
| 11321 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11322 | "2877 FCP XRI exchange busy " |
| 11323 | "wait time: %d seconds.\n", |
| 11324 | wait_time/1000); |
| 11325 | if (!els_xri_cmpl) |
| 11326 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11327 | "2878 ELS XRI exchange busy " |
| 11328 | "wait time: %d seconds.\n", |
| 11329 | wait_time/1000); |
| 11330 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11331 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11332 | } else { |
| 11333 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11334 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11335 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11336 | |
| 11337 | ccnt = 0; |
| 11338 | fcnt = 0; |
| 11339 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11340 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11341 | fcp_xri_cmpl = list_empty( |
| 11342 | &qp->lpfc_abts_scsi_buf_list); |
| 11343 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11344 | fcnt++; |
| 11345 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11346 | io_xri_cmpl = list_empty( |
| 11347 | &qp->lpfc_abts_nvme_buf_list); |
| 11348 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11349 | ccnt++; |
| 11350 | } |
| 11351 | } |
| 11352 | if (ccnt) |
| 11353 | io_xri_cmpl = 0; |
| 11354 | if (fcnt) |
| 11355 | fcp_xri_cmpl = 0; |
| 11356 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11357 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11358 | nvmet_xri_cmpl = list_empty( |
| 11359 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11360 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11361 | els_xri_cmpl = |
| 11362 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11363 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11364 | } |
| 11365 | } |
| 11366 | |
| 11367 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11368 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11369 | * @phba: Pointer to HBA context object. |
| 11370 | * |
| 11371 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11372 | * function. The caller is not required to hold any lock. This routine |
| 11373 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11374 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11375 | * free any pending commands. |
| 11376 | **/ |
| 11377 | static void |
| 11378 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11379 | { |
| 11380 | int wait_cnt = 0; |
| 11381 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11382 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11383 | |
| 11384 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11385 | if (phba->pport) |
| 11386 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11387 | |
| 11388 | /* |
| 11389 | * Gracefully wait out the potential current outstanding asynchronous |
| 11390 | * mailbox command. |
| 11391 | */ |
| 11392 | |
| 11393 | /* First, block any pending async mailbox command from posted */ |
| 11394 | spin_lock_irq(&phba->hbalock); |
| 11395 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11396 | spin_unlock_irq(&phba->hbalock); |
| 11397 | /* Now, trying to wait it out if we can */ |
| 11398 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11399 | msleep(10); |
| 11400 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11401 | break; |
| 11402 | } |
| 11403 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11404 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11405 | spin_lock_irq(&phba->hbalock); |
| 11406 | mboxq = phba->sli.mbox_active; |
| 11407 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11408 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11409 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11410 | phba->sli.mbox_active = NULL; |
| 11411 | spin_unlock_irq(&phba->hbalock); |
| 11412 | } |
| 11413 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11414 | /* Abort all iocbs associated with the hba */ |
| 11415 | lpfc_sli_hba_iocb_abort(phba); |
| 11416 | |
| 11417 | /* Wait for completion of device XRI exchange busy */ |
| 11418 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 11419 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11420 | /* Disable PCI subsystem interrupt */ |
| 11421 | lpfc_sli4_disable_intr(phba); |
| 11422 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11423 | /* Disable SR-IOV if enabled */ |
| 11424 | if (phba->cfg_sriov_nr_virtfn) |
| 11425 | pci_disable_sriov(pdev); |
| 11426 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11427 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11428 | kthread_stop(phba->worker_thread); |
| 11429 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11430 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11431 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11432 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11433 | /* Unset the queues shared with the hardware then release all |
| 11434 | * allocated resources. |
| 11435 | */ |
| 11436 | lpfc_sli4_queue_unset(phba); |
| 11437 | lpfc_sli4_queue_destroy(phba); |
| 11438 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11439 | /* Reset SLI4 HBA FCoE function */ |
| 11440 | lpfc_pci_function_reset(phba); |
| 11441 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11442 | /* Free RAS DMA memory */ |
| 11443 | if (phba->ras_fwlog.ras_enabled) |
| 11444 | lpfc_sli4_ras_dma_free(phba); |
| 11445 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11446 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 11447 | if (phba->pport) |
| 11448 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11449 | } |
| 11450 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11451 | /** |
| 11452 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 11453 | * @phba: Pointer to HBA context object. |
| 11454 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11455 | * |
| 11456 | * This function is called in the SLI4 code path to read the port's |
| 11457 | * sli4 capabilities. |
| 11458 | * |
| 11459 | * This function may be be called from any context that can block-wait |
| 11460 | * for the completion. The expectation is that this routine is called |
| 11461 | * typically from probe_one or from the online routine. |
| 11462 | **/ |
| 11463 | int |
| 11464 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11465 | { |
| 11466 | int rc; |
| 11467 | struct lpfc_mqe *mqe; |
| 11468 | struct lpfc_pc_sli4_params *sli4_params; |
| 11469 | uint32_t mbox_tmo; |
| 11470 | |
| 11471 | rc = 0; |
| 11472 | mqe = &mboxq->u.mqe; |
| 11473 | |
| 11474 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11475 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11476 | if (!phba->sli4_hba.intr_enable) |
| 11477 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 11478 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11479 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11480 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11481 | } |
| 11482 | |
| 11483 | if (unlikely(rc)) |
| 11484 | return 1; |
| 11485 | |
| 11486 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11487 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 11488 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 11489 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 11490 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 11491 | &mqe->un.sli4_params); |
| 11492 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 11493 | &mqe->un.sli4_params); |
| 11494 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 11495 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 11496 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 11497 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 11498 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 11499 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 11500 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 11501 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 11502 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 11503 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 11504 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 11505 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 11506 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 11507 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 11508 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 11509 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 11510 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 11511 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 11512 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 11513 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 11514 | 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] | 11515 | |
| 11516 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11517 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11518 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11519 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11520 | return rc; |
| 11521 | } |
| 11522 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11523 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11524 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 11525 | * @phba: Pointer to HBA context object. |
| 11526 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11527 | * |
| 11528 | * This function is called in the SLI4 code path to read the port's |
| 11529 | * sli4 capabilities. |
| 11530 | * |
| 11531 | * This function may be be called from any context that can block-wait |
| 11532 | * for the completion. The expectation is that this routine is called |
| 11533 | * typically from probe_one or from the online routine. |
| 11534 | **/ |
| 11535 | int |
| 11536 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11537 | { |
| 11538 | int rc; |
| 11539 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 11540 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11541 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11542 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11543 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11544 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 11545 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11546 | /* |
| 11547 | * By default, the driver assumes the SLI4 port requires RPI |
| 11548 | * header postings. The SLI4_PARAM response will correct this |
| 11549 | * assumption. |
| 11550 | */ |
| 11551 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 11552 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11553 | /* Read the port's SLI4 Config Parameters */ |
| 11554 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 11555 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 11556 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11557 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 11558 | length, LPFC_SLI4_MBX_EMBED); |
| 11559 | if (!phba->sli4_hba.intr_enable) |
| 11560 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11561 | else { |
| 11562 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 11563 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11564 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11565 | if (unlikely(rc)) |
| 11566 | return rc; |
| 11567 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11568 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 11569 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 11570 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 11571 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 11572 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 11573 | mbx_sli4_parameters); |
| 11574 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 11575 | mbx_sli4_parameters); |
| 11576 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 11577 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 11578 | else |
| 11579 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 11580 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 11581 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11582 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11583 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 11584 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 11585 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 11586 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 11587 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 11588 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 11589 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 11590 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11591 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 11592 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11593 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11594 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 11595 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11596 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 11597 | 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] | 11598 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11599 | /* Check for firmware nvme support */ |
| 11600 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 11601 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11602 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11603 | if (rc) { |
| 11604 | /* Save this to indicate the Firmware supports NVME */ |
| 11605 | sli4_params->nvme = 1; |
| 11606 | |
| 11607 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 11608 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 11609 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 11610 | "6133 Disabling NVME support: " |
| 11611 | "FC4 type not supported: x%x\n", |
| 11612 | phba->cfg_enable_fc4_type); |
| 11613 | goto fcponly; |
| 11614 | } |
| 11615 | } else { |
| 11616 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 11617 | sli4_params->nvme = 0; |
| 11618 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 11620 | "6101 Disabling NVME support: Not " |
| 11621 | "supported by firmware (%d %d) x%x\n", |
| 11622 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 11623 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 11624 | phba->cfg_enable_fc4_type); |
| 11625 | fcponly: |
| 11626 | phba->nvme_support = 0; |
| 11627 | phba->nvmet_support = 0; |
| 11628 | phba->cfg_nvmet_mrq = 0; |
| 11629 | |
| 11630 | /* If no FC4 type support, move to just SCSI support */ |
| 11631 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 11632 | return -ENODEV; |
| 11633 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 11634 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11635 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11636 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11637 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 11638 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 11639 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 11640 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11641 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11642 | /* |
| 11643 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 11644 | * lpfc_suppress_rsp module parameter must be set (default). |
| 11645 | * In SLI4-Parameters Descriptor: |
| 11646 | * Extended Inline Buffers (XIB) must be supported. |
| 11647 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 11648 | * (double negative). |
| 11649 | */ |
| 11650 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 11651 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11652 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11653 | else |
| 11654 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11655 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 11656 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 11657 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 11658 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11659 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11660 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11661 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11662 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11663 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11664 | * Check whether the adapter supports an embedded copy of the |
| 11665 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 11666 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11667 | */ |
| 11668 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 11669 | phba->fcp_embed_io = 1; |
| 11670 | else |
| 11671 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11672 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11673 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11674 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11675 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11676 | phba->cfg_enable_pbde, |
| 11677 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 11678 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11679 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11680 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 11681 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 11682 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 11683 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11684 | exp_wqcq_pages = false; |
| 11685 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11686 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 11687 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11688 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11689 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 11690 | phba->enab_exp_wqcq_pages = 1; |
| 11691 | else |
| 11692 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11693 | /* |
| 11694 | * Check if the SLI port supports MDS Diagnostics |
| 11695 | */ |
| 11696 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 11697 | phba->mds_diags_support = 1; |
| 11698 | else |
| 11699 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11700 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11701 | return 0; |
| 11702 | } |
| 11703 | |
| 11704 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11705 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 11706 | * @pdev: pointer to PCI device |
| 11707 | * @pid: pointer to PCI device identifier |
| 11708 | * |
| 11709 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 11710 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11711 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 11712 | * information of the device and driver to see if the driver state that it can |
| 11713 | * support this kind of device. If the match is successful, the driver core |
| 11714 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 11715 | * does all the initialization that it needs to do to handle the HBA properly. |
| 11716 | * |
| 11717 | * Return code |
| 11718 | * 0 - driver can claim the device |
| 11719 | * negative value - driver can not claim the device |
| 11720 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11721 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11722 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11723 | { |
| 11724 | struct lpfc_hba *phba; |
| 11725 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11726 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11727 | int error; |
| 11728 | uint32_t cfg_mode, intr_mode; |
| 11729 | |
| 11730 | /* Allocate memory for HBA structure */ |
| 11731 | phba = lpfc_hba_alloc(pdev); |
| 11732 | if (!phba) |
| 11733 | return -ENOMEM; |
| 11734 | |
| 11735 | /* Perform generic PCI device enabling operation */ |
| 11736 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11737 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11738 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11739 | |
| 11740 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 11741 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 11742 | if (error) |
| 11743 | goto out_disable_pci_dev; |
| 11744 | |
| 11745 | /* Set up SLI-3 specific device PCI memory space */ |
| 11746 | error = lpfc_sli_pci_mem_setup(phba); |
| 11747 | if (error) { |
| 11748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11749 | "1402 Failed to set up pci memory space.\n"); |
| 11750 | goto out_disable_pci_dev; |
| 11751 | } |
| 11752 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11753 | /* Set up SLI-3 specific device driver resources */ |
| 11754 | error = lpfc_sli_driver_resource_setup(phba); |
| 11755 | if (error) { |
| 11756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11757 | "1404 Failed to set up driver resource.\n"); |
| 11758 | goto out_unset_pci_mem_s3; |
| 11759 | } |
| 11760 | |
| 11761 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11762 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11763 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 11764 | if (error) { |
| 11765 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11766 | "1405 Failed to initialize iocb list.\n"); |
| 11767 | goto out_unset_driver_resource_s3; |
| 11768 | } |
| 11769 | |
| 11770 | /* Set up common device driver resources */ |
| 11771 | error = lpfc_setup_driver_resource_phase2(phba); |
| 11772 | if (error) { |
| 11773 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11774 | "1406 Failed to set up driver resource.\n"); |
| 11775 | goto out_free_iocb_list; |
| 11776 | } |
| 11777 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11778 | /* Get the default values for Model Name and Description */ |
| 11779 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 11780 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11781 | /* Create SCSI host to the physical port */ |
| 11782 | error = lpfc_create_shost(phba); |
| 11783 | if (error) { |
| 11784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11785 | "1407 Failed to create scsi host.\n"); |
| 11786 | goto out_unset_driver_resource; |
| 11787 | } |
| 11788 | |
| 11789 | /* Configure sysfs attributes */ |
| 11790 | vport = phba->pport; |
| 11791 | error = lpfc_alloc_sysfs_attr(vport); |
| 11792 | if (error) { |
| 11793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11794 | "1476 Failed to allocate sysfs attr\n"); |
| 11795 | goto out_destroy_shost; |
| 11796 | } |
| 11797 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11798 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11799 | /* Now, trying to enable interrupt and bring up the device */ |
| 11800 | cfg_mode = phba->cfg_use_msi; |
| 11801 | while (true) { |
| 11802 | /* Put device to a known state before enabling interrupt */ |
| 11803 | lpfc_stop_port(phba); |
| 11804 | /* Configure and enable interrupt */ |
| 11805 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 11806 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11808 | "0431 Failed to enable interrupt.\n"); |
| 11809 | error = -ENODEV; |
| 11810 | goto out_free_sysfs_attr; |
| 11811 | } |
| 11812 | /* SLI-3 HBA setup */ |
| 11813 | if (lpfc_sli_hba_setup(phba)) { |
| 11814 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11815 | "1477 Failed to set up hba\n"); |
| 11816 | error = -ENODEV; |
| 11817 | goto out_remove_device; |
| 11818 | } |
| 11819 | |
| 11820 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 11821 | msleep(50); |
| 11822 | /* Check active interrupts on message signaled interrupts */ |
| 11823 | if (intr_mode == 0 || |
| 11824 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 11825 | /* Log the current active interrupt mode */ |
| 11826 | phba->intr_mode = intr_mode; |
| 11827 | lpfc_log_intr_mode(phba, intr_mode); |
| 11828 | break; |
| 11829 | } else { |
| 11830 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11831 | "0447 Configure interrupt mode (%d) " |
| 11832 | "failed active interrupt test.\n", |
| 11833 | intr_mode); |
| 11834 | /* Disable the current interrupt mode */ |
| 11835 | lpfc_sli_disable_intr(phba); |
| 11836 | /* Try next level of interrupt mode */ |
| 11837 | cfg_mode = --intr_mode; |
| 11838 | } |
| 11839 | } |
| 11840 | |
| 11841 | /* Perform post initialization setup */ |
| 11842 | lpfc_post_init_setup(phba); |
| 11843 | |
| 11844 | /* Check if there are static vports to be created. */ |
| 11845 | lpfc_create_static_vport(phba); |
| 11846 | |
| 11847 | return 0; |
| 11848 | |
| 11849 | out_remove_device: |
| 11850 | lpfc_unset_hba(phba); |
| 11851 | out_free_sysfs_attr: |
| 11852 | lpfc_free_sysfs_attr(vport); |
| 11853 | out_destroy_shost: |
| 11854 | lpfc_destroy_shost(phba); |
| 11855 | out_unset_driver_resource: |
| 11856 | lpfc_unset_driver_resource_phase2(phba); |
| 11857 | out_free_iocb_list: |
| 11858 | lpfc_free_iocb_list(phba); |
| 11859 | out_unset_driver_resource_s3: |
| 11860 | lpfc_sli_driver_resource_unset(phba); |
| 11861 | out_unset_pci_mem_s3: |
| 11862 | lpfc_sli_pci_mem_unset(phba); |
| 11863 | out_disable_pci_dev: |
| 11864 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11865 | if (shost) |
| 11866 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11867 | out_free_phba: |
| 11868 | lpfc_hba_free(phba); |
| 11869 | return error; |
| 11870 | } |
| 11871 | |
| 11872 | /** |
| 11873 | * 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] | 11874 | * @pdev: pointer to PCI device |
| 11875 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11876 | * This routine is to be called to disattach a device with SLI-3 interface |
| 11877 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11878 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 11879 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11880 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11881 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11882 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11883 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11884 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11885 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11886 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11887 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11888 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 11889 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11890 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11891 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11892 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11893 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11894 | lpfc_free_sysfs_attr(vport); |
| 11895 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11896 | /* Release all the vports against this physical port */ |
| 11897 | vports = lpfc_create_vport_work_array(phba); |
| 11898 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11899 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 11900 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 11901 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11902 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11903 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11904 | lpfc_destroy_vport_work_array(phba, vports); |
| 11905 | |
| 11906 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11907 | fc_remove_host(shost); |
| 11908 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 11909 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 11910 | lpfc_cleanup(vport); |
| 11911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11912 | /* |
| 11913 | * Bring down the SLI Layer. This step disable all interrupts, |
| 11914 | * clears the rings, discards all mailbox commands, and resets |
| 11915 | * the HBA. |
| 11916 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11917 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 11918 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11919 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11920 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11921 | kthread_stop(phba->worker_thread); |
| 11922 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11923 | lpfc_sli_brdrestart(phba); |
| 11924 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11925 | kfree(phba->vpi_bmask); |
| 11926 | kfree(phba->vpi_ids); |
| 11927 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11928 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11929 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11930 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11931 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11932 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11933 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11934 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11935 | /* Disable SR-IOV if enabled */ |
| 11936 | if (phba->cfg_sriov_nr_virtfn) |
| 11937 | pci_disable_sriov(pdev); |
| 11938 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11939 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11940 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11941 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11942 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11943 | |
| 11944 | /* |
| 11945 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 11946 | * corresponding pools here. |
| 11947 | */ |
| 11948 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 11949 | lpfc_free_iocb_list(phba); |
| 11950 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11951 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11952 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11953 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 11954 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11955 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11956 | /* Free resources associated with SLI2 interface */ |
| 11957 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11958 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11959 | |
| 11960 | /* unmap adapter SLIM and Control Registers */ |
| 11961 | iounmap(phba->ctrl_regs_memmap_p); |
| 11962 | iounmap(phba->slim_memmap_p); |
| 11963 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11964 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11965 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 11966 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11967 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11968 | } |
| 11969 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11970 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11971 | * 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] | 11972 | * @pdev: pointer to PCI device |
| 11973 | * @msg: power management message |
| 11974 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11975 | * This routine is to be called from the kernel's PCI subsystem to support |
| 11976 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 11977 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 11978 | * worker thread for the device, turning off device's interrupt and DMA, |
| 11979 | * and bring the device offline. Note that as the driver implements the |
| 11980 | * minimum PM requirements to a power-aware driver's PM support for the |
| 11981 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11982 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 11983 | * fully reinitialize its device during resume() method call, the driver will |
| 11984 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 11985 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11986 | * |
| 11987 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11988 | * 0 - driver suspended the device |
| 11989 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11990 | **/ |
| 11991 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11992 | 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] | 11993 | { |
| 11994 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11995 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11996 | |
| 11997 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11998 | "0473 PCI device Power Management suspend.\n"); |
| 11999 | |
| 12000 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12001 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12002 | lpfc_offline(phba); |
| 12003 | kthread_stop(phba->worker_thread); |
| 12004 | |
| 12005 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12006 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12007 | |
| 12008 | /* Save device state to PCI config space */ |
| 12009 | pci_save_state(pdev); |
| 12010 | pci_set_power_state(pdev, PCI_D3hot); |
| 12011 | |
| 12012 | return 0; |
| 12013 | } |
| 12014 | |
| 12015 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12016 | * 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] | 12017 | * @pdev: pointer to PCI device |
| 12018 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12019 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12020 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12021 | * invokes this method, it restores the device's PCI config space state and |
| 12022 | * fully reinitializes the device and brings it online. Note that as the |
| 12023 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12024 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12025 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12026 | * driver will fully reinitialize its device during resume() method call, |
| 12027 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12028 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12029 | * |
| 12030 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12031 | * 0 - driver suspended the device |
| 12032 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12033 | **/ |
| 12034 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12035 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12036 | { |
| 12037 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12038 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12039 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12040 | int error; |
| 12041 | |
| 12042 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12043 | "0452 PCI device Power Management resume.\n"); |
| 12044 | |
| 12045 | /* Restore device state from PCI config space */ |
| 12046 | pci_set_power_state(pdev, PCI_D0); |
| 12047 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12048 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12049 | /* |
| 12050 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12051 | * device saved_state flag, need to save the restored state again. |
| 12052 | */ |
| 12053 | pci_save_state(pdev); |
| 12054 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12055 | if (pdev->is_busmaster) |
| 12056 | pci_set_master(pdev); |
| 12057 | |
| 12058 | /* Startup the kernel thread for this host adapter. */ |
| 12059 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12060 | "lpfc_worker_%d", phba->brd_no); |
| 12061 | if (IS_ERR(phba->worker_thread)) { |
| 12062 | error = PTR_ERR(phba->worker_thread); |
| 12063 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12064 | "0434 PM resume failed to start worker " |
| 12065 | "thread: error=x%x.\n", error); |
| 12066 | return error; |
| 12067 | } |
| 12068 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12069 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12070 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12071 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12073 | "0430 PM resume Failed to enable interrupt\n"); |
| 12074 | return -EIO; |
| 12075 | } else |
| 12076 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12077 | |
| 12078 | /* Restart HBA and bring it online */ |
| 12079 | lpfc_sli_brdrestart(phba); |
| 12080 | lpfc_online(phba); |
| 12081 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12082 | /* Log the current active interrupt mode */ |
| 12083 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12084 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12085 | return 0; |
| 12086 | } |
| 12087 | |
| 12088 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12089 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12090 | * @phba: pointer to lpfc hba data structure. |
| 12091 | * |
| 12092 | * 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] | 12093 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12094 | **/ |
| 12095 | static void |
| 12096 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12097 | { |
| 12098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12099 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12100 | |
| 12101 | /* |
| 12102 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12103 | * and let the SCSI mid-layer to retry them to recover. |
| 12104 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12105 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12106 | } |
| 12107 | |
| 12108 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12109 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12110 | * @phba: pointer to lpfc hba data structure. |
| 12111 | * |
| 12112 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12113 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12114 | * pending I/Os. |
| 12115 | **/ |
| 12116 | static void |
| 12117 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12118 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12119 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12120 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12121 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12122 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12123 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12124 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12125 | /* Block all SCSI devices' I/Os on the host */ |
| 12126 | lpfc_scsi_dev_block(phba); |
| 12127 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12128 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12129 | lpfc_sli_flush_fcp_rings(phba); |
| 12130 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12131 | /* stop all timers */ |
| 12132 | lpfc_stop_hba_timers(phba); |
| 12133 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12134 | /* Disable interrupt and pci device */ |
| 12135 | lpfc_sli_disable_intr(phba); |
| 12136 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12137 | } |
| 12138 | |
| 12139 | /** |
| 12140 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12141 | * @phba: pointer to lpfc hba data structure. |
| 12142 | * |
| 12143 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12144 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12145 | * pending I/Os. |
| 12146 | **/ |
| 12147 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12148 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12149 | { |
| 12150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12151 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12152 | /* Block all SCSI devices' I/Os on the host */ |
| 12153 | lpfc_scsi_dev_block(phba); |
| 12154 | |
| 12155 | /* stop all timers */ |
| 12156 | lpfc_stop_hba_timers(phba); |
| 12157 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12158 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12159 | lpfc_sli_flush_fcp_rings(phba); |
| 12160 | } |
| 12161 | |
| 12162 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12163 | * 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] | 12164 | * @pdev: pointer to PCI device. |
| 12165 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12166 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12167 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12168 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12169 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12170 | * When this function is invoked, it will need to stop all the I/Os and |
| 12171 | * interrupt(s) to the device. Once that is done, it will return |
| 12172 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12173 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12174 | * |
| 12175 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12176 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12177 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12178 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12179 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12180 | static pci_ers_result_t |
| 12181 | 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] | 12182 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12183 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12184 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12185 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12186 | switch (state) { |
| 12187 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12188 | /* Non-fatal error, prepare for recovery */ |
| 12189 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12190 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12191 | case pci_channel_io_frozen: |
| 12192 | /* Fatal error, prepare for slot reset */ |
| 12193 | lpfc_sli_prep_dev_for_reset(phba); |
| 12194 | return PCI_ERS_RESULT_NEED_RESET; |
| 12195 | case pci_channel_io_perm_failure: |
| 12196 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12197 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12198 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12199 | default: |
| 12200 | /* Unknown state, prepare and request slot reset */ |
| 12201 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12202 | "0472 Unknown PCI error state: x%x\n", state); |
| 12203 | lpfc_sli_prep_dev_for_reset(phba); |
| 12204 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12205 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12206 | } |
| 12207 | |
| 12208 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12209 | * 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] | 12210 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12211 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12212 | * This routine is called from the PCI subsystem for error handling to |
| 12213 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12214 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12215 | * During the PCI subsystem error recovery, after driver returns |
| 12216 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12217 | * recovery and then call this routine before calling the .resume method |
| 12218 | * to recover the device. This function will initialize the HBA device, |
| 12219 | * enable the interrupt, but it will just put the HBA to offline state |
| 12220 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12221 | * |
| 12222 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12223 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12224 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12225 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12226 | static pci_ers_result_t |
| 12227 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12228 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12229 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12230 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12231 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12232 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12233 | |
| 12234 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12235 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12236 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12237 | "PCI device after reset.\n"); |
| 12238 | return PCI_ERS_RESULT_DISCONNECT; |
| 12239 | } |
| 12240 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12241 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12242 | |
| 12243 | /* |
| 12244 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12245 | * device saved_state flag, need to save the restored state again. |
| 12246 | */ |
| 12247 | pci_save_state(pdev); |
| 12248 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12249 | if (pdev->is_busmaster) |
| 12250 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12251 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12252 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12253 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12254 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12255 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12256 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12257 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12258 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12259 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12260 | "0427 Cannot re-enable interrupt after " |
| 12261 | "slot reset.\n"); |
| 12262 | return PCI_ERS_RESULT_DISCONNECT; |
| 12263 | } else |
| 12264 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12265 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12266 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12267 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12268 | lpfc_offline(phba); |
| 12269 | lpfc_sli_brdrestart(phba); |
| 12270 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12271 | /* Log the current active interrupt mode */ |
| 12272 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12273 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12274 | return PCI_ERS_RESULT_RECOVERED; |
| 12275 | } |
| 12276 | |
| 12277 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12278 | * 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] | 12279 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12280 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12281 | * This routine is called from the PCI subsystem for error handling to device |
| 12282 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12283 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12284 | * error recovery. After this call, traffic can start to flow from this device |
| 12285 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12286 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12287 | static void |
| 12288 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12289 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12290 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12291 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12292 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12293 | /* 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] | 12294 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12295 | } |
| 12296 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12297 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12298 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12299 | * @phba: pointer to lpfc hba data structure. |
| 12300 | * |
| 12301 | * returns the number of ELS/CT IOCBs to reserve |
| 12302 | **/ |
| 12303 | int |
| 12304 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12305 | { |
| 12306 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12307 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12308 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12309 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12310 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12311 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12312 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12313 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12314 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12315 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12316 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12317 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12318 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12319 | else if (max_xri <= 2048) |
| 12320 | return 200; |
| 12321 | else |
| 12322 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12323 | } else |
| 12324 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12325 | } |
| 12326 | |
| 12327 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12328 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12329 | * @phba: pointer to lpfc hba data structure. |
| 12330 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12331 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12332 | **/ |
| 12333 | int |
| 12334 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12335 | { |
| 12336 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12337 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12338 | if (phba->nvmet_support) |
| 12339 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12340 | return max_xri; |
| 12341 | } |
| 12342 | |
| 12343 | |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12344 | static void |
| 12345 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12346 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12347 | const struct firmware *fw) |
| 12348 | { |
James Smart | a72d56b | 2018-05-04 20:37:52 -0700 | [diff] [blame] | 12349 | if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) || |
| 12350 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
| 12351 | magic_number != MAGIC_NUMER_G6) || |
| 12352 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
| 12353 | magic_number != MAGIC_NUMER_G7)) |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12355 | "3030 This firmware version is not supported on " |
| 12356 | "this HBA model. Device:%x Magic:%x Type:%x " |
| 12357 | "ID:%x Size %d %zd\n", |
| 12358 | phba->pcidev->device, magic_number, ftype, fid, |
| 12359 | fsize, fw->size); |
| 12360 | else |
| 12361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12362 | "3022 FW Download failed. Device:%x Magic:%x Type:%x " |
| 12363 | "ID:%x Size %d %zd\n", |
| 12364 | phba->pcidev->device, magic_number, ftype, fid, |
| 12365 | fsize, fw->size); |
| 12366 | } |
| 12367 | |
| 12368 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12369 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12370 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12371 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12372 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12373 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12374 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12375 | static void |
| 12376 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12377 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12378 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12379 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12380 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12381 | struct list_head dma_buffer_list; |
| 12382 | int i, rc = 0; |
| 12383 | struct lpfc_dmabuf *dmabuf, *next; |
| 12384 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12385 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12386 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12387 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12388 | if (!fw) { |
| 12389 | rc = -ENXIO; |
| 12390 | goto out; |
| 12391 | } |
| 12392 | image = (struct lpfc_grp_hdr *)fw->data; |
| 12393 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12394 | magic_number = be32_to_cpu(image->magic_number); |
| 12395 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12396 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12397 | fsize = be32_to_cpu(image->size); |
| 12398 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12399 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12400 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12401 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12403 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12404 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12405 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12406 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 12407 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 12408 | GFP_KERNEL); |
| 12409 | if (!dmabuf) { |
| 12410 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12411 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12412 | } |
| 12413 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 12414 | SLI4_PAGE_SIZE, |
| 12415 | &dmabuf->phys, |
| 12416 | GFP_KERNEL); |
| 12417 | if (!dmabuf->virt) { |
| 12418 | kfree(dmabuf); |
| 12419 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12420 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12421 | } |
| 12422 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 12423 | } |
| 12424 | while (offset < fw->size) { |
| 12425 | temp_offset = offset; |
| 12426 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12427 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12428 | memcpy(dmabuf->virt, |
| 12429 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12430 | fw->size - temp_offset); |
| 12431 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12432 | break; |
| 12433 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12434 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 12435 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12436 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12437 | } |
| 12438 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 12439 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12440 | if (rc) { |
| 12441 | lpfc_log_write_firmware_error(phba, offset, |
| 12442 | magic_number, ftype, fid, fsize, fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12443 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12444 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12445 | } |
| 12446 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12447 | } else |
| 12448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12449 | "3029 Skipped Firmware update, Current " |
| 12450 | "Version:%s New Version:%s\n", |
| 12451 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12452 | |
| 12453 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12454 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 12455 | list_del(&dmabuf->list); |
| 12456 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 12457 | dmabuf->virt, dmabuf->phys); |
| 12458 | kfree(dmabuf); |
| 12459 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12460 | release_firmware(fw); |
| 12461 | out: |
| 12462 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12463 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12464 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12465 | } |
| 12466 | |
| 12467 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12468 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 12469 | * @phba: pointer to lpfc hba data structure. |
| 12470 | * |
| 12471 | * This routine is called to perform Linux generic firmware upgrade on device |
| 12472 | * that supports such feature. |
| 12473 | **/ |
| 12474 | int |
| 12475 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 12476 | { |
| 12477 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 12478 | int ret; |
| 12479 | const struct firmware *fw; |
| 12480 | |
| 12481 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12482 | 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] | 12483 | LPFC_SLI_INTF_IF_TYPE_2) |
| 12484 | return -EPERM; |
| 12485 | |
| 12486 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 12487 | |
| 12488 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 12489 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 12490 | file_name, &phba->pcidev->dev, |
| 12491 | GFP_KERNEL, (void *)phba, |
| 12492 | lpfc_write_firmware); |
| 12493 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 12494 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 12495 | if (!ret) |
| 12496 | lpfc_write_firmware(fw, (void *)phba); |
| 12497 | } else { |
| 12498 | ret = -EINVAL; |
| 12499 | } |
| 12500 | |
| 12501 | return ret; |
| 12502 | } |
| 12503 | |
| 12504 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12505 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 12506 | * @pdev: pointer to PCI device |
| 12507 | * @pid: pointer to PCI device identifier |
| 12508 | * |
| 12509 | * This routine is called from the kernel's PCI subsystem to device with |
| 12510 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12511 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12512 | * information of the device and driver to see if the driver state that it |
| 12513 | * can support this kind of device. If the match is successful, the driver |
| 12514 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 12515 | * it does all the initialization that it needs to do to handle the HBA |
| 12516 | * properly. |
| 12517 | * |
| 12518 | * Return code |
| 12519 | * 0 - driver can claim the device |
| 12520 | * negative value - driver can not claim the device |
| 12521 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12522 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12523 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12524 | { |
| 12525 | struct lpfc_hba *phba; |
| 12526 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12527 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12528 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12529 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12530 | |
| 12531 | /* Allocate memory for HBA structure */ |
| 12532 | phba = lpfc_hba_alloc(pdev); |
| 12533 | if (!phba) |
| 12534 | return -ENOMEM; |
| 12535 | |
| 12536 | /* Perform generic PCI device enabling operation */ |
| 12537 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12538 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12539 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12540 | |
| 12541 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 12542 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 12543 | if (error) |
| 12544 | goto out_disable_pci_dev; |
| 12545 | |
| 12546 | /* Set up SLI-4 specific device PCI memory space */ |
| 12547 | error = lpfc_sli4_pci_mem_setup(phba); |
| 12548 | if (error) { |
| 12549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12550 | "1410 Failed to set up pci memory space.\n"); |
| 12551 | goto out_disable_pci_dev; |
| 12552 | } |
| 12553 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12554 | /* Set up SLI-4 Specific device driver resources */ |
| 12555 | error = lpfc_sli4_driver_resource_setup(phba); |
| 12556 | if (error) { |
| 12557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12558 | "1412 Failed to set up driver resource.\n"); |
| 12559 | goto out_unset_pci_mem_s4; |
| 12560 | } |
| 12561 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12562 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 12563 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12564 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12565 | /* Set up common device driver resources */ |
| 12566 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12567 | if (error) { |
| 12568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12569 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12570 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12571 | } |
| 12572 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12573 | /* Get the default values for Model Name and Description */ |
| 12574 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12575 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12576 | /* Now, trying to enable interrupt and bring up the device */ |
| 12577 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12578 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12579 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12580 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12581 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12582 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12583 | /* Configure and enable interrupt */ |
| 12584 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 12585 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12586 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12587 | "0426 Failed to enable interrupt.\n"); |
| 12588 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12589 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12590 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12591 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12592 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12593 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12594 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12595 | if (phba->nvmet_support) |
| 12596 | phba->cfg_nvmet_mrq = 1; |
| 12597 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12598 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12599 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12600 | |
| 12601 | /* Create SCSI host to the physical port */ |
| 12602 | error = lpfc_create_shost(phba); |
| 12603 | if (error) { |
| 12604 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12605 | "1415 Failed to create scsi host.\n"); |
| 12606 | goto out_disable_intr; |
| 12607 | } |
| 12608 | vport = phba->pport; |
| 12609 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 12610 | |
| 12611 | /* Configure sysfs attributes */ |
| 12612 | error = lpfc_alloc_sysfs_attr(vport); |
| 12613 | if (error) { |
| 12614 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12615 | "1416 Failed to allocate sysfs attr\n"); |
| 12616 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12617 | } |
| 12618 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12619 | /* Set up SLI-4 HBA */ |
| 12620 | if (lpfc_sli4_hba_setup(phba)) { |
| 12621 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12622 | "1421 Failed to set up hba\n"); |
| 12623 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12624 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12625 | } |
| 12626 | |
| 12627 | /* Log the current active interrupt mode */ |
| 12628 | phba->intr_mode = intr_mode; |
| 12629 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12630 | |
| 12631 | /* Perform post initialization setup */ |
| 12632 | lpfc_post_init_setup(phba); |
| 12633 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12634 | /* NVME support in FW earlier in the driver load corrects the |
| 12635 | * FC4 type making a check for nvme_support unnecessary. |
| 12636 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12637 | if (phba->nvmet_support == 0) { |
| 12638 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12639 | /* Create NVME binding with nvme_fc_transport. This |
| 12640 | * ensures the vport is initialized. If the localport |
| 12641 | * create fails, it should not unload the driver to |
| 12642 | * support field issues. |
| 12643 | */ |
| 12644 | error = lpfc_nvme_create_localport(vport); |
| 12645 | if (error) { |
| 12646 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12647 | "6004 NVME registration " |
| 12648 | "failed, error x%x\n", |
| 12649 | error); |
| 12650 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12651 | } |
| 12652 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12653 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12654 | /* check for firmware upgrade or downgrade */ |
| 12655 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 12656 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12657 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 12658 | /* Check if there are static vports to be created. */ |
| 12659 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12660 | |
| 12661 | /* Enable RAS FW log support */ |
| 12662 | lpfc_sli4_ras_setup(phba); |
| 12663 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12664 | return 0; |
| 12665 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12666 | out_free_sysfs_attr: |
| 12667 | lpfc_free_sysfs_attr(vport); |
| 12668 | out_destroy_shost: |
| 12669 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12670 | out_disable_intr: |
| 12671 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12672 | out_unset_driver_resource: |
| 12673 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12674 | out_unset_driver_resource_s4: |
| 12675 | lpfc_sli4_driver_resource_unset(phba); |
| 12676 | out_unset_pci_mem_s4: |
| 12677 | lpfc_sli4_pci_mem_unset(phba); |
| 12678 | out_disable_pci_dev: |
| 12679 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12680 | if (shost) |
| 12681 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12682 | out_free_phba: |
| 12683 | lpfc_hba_free(phba); |
| 12684 | return error; |
| 12685 | } |
| 12686 | |
| 12687 | /** |
| 12688 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 12689 | * @pdev: pointer to PCI device |
| 12690 | * |
| 12691 | * This routine is called from the kernel's PCI subsystem to device with |
| 12692 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12693 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12694 | * device to be removed from the PCI subsystem properly. |
| 12695 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12696 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12697 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 12698 | { |
| 12699 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12700 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 12701 | struct lpfc_vport **vports; |
| 12702 | struct lpfc_hba *phba = vport->phba; |
| 12703 | int i; |
| 12704 | |
| 12705 | /* Mark the device unloading flag */ |
| 12706 | spin_lock_irq(&phba->hbalock); |
| 12707 | vport->load_flag |= FC_UNLOADING; |
| 12708 | spin_unlock_irq(&phba->hbalock); |
| 12709 | |
| 12710 | /* Free the HBA sysfs attributes */ |
| 12711 | lpfc_free_sysfs_attr(vport); |
| 12712 | |
| 12713 | /* Release all the vports against this physical port */ |
| 12714 | vports = lpfc_create_vport_work_array(phba); |
| 12715 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12716 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12717 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12718 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12719 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12720 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12721 | lpfc_destroy_vport_work_array(phba, vports); |
| 12722 | |
| 12723 | /* Remove FC host and then SCSI host with the physical port */ |
| 12724 | fc_remove_host(shost); |
| 12725 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12726 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12727 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 12728 | * localports are destroyed after to cleanup all transport memory. |
| 12729 | */ |
| 12730 | lpfc_cleanup(vport); |
| 12731 | lpfc_nvmet_destroy_targetport(phba); |
| 12732 | lpfc_nvme_destroy_localport(vport); |
| 12733 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12734 | /* De-allocate multi-XRI pools */ |
| 12735 | if (phba->cfg_xri_rebalancing) |
| 12736 | lpfc_destroy_multixri_pools(phba); |
| 12737 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 12738 | /* |
| 12739 | * Bring down the SLI Layer. This step disables all interrupts, |
| 12740 | * clears the rings, discards all mailbox commands, and resets |
| 12741 | * the HBA FCoE function. |
| 12742 | */ |
| 12743 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12744 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 12745 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12746 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12747 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12748 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12749 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12750 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12751 | * buffers are released to their corresponding pools here. |
| 12752 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12753 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12754 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12755 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12756 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 12757 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12758 | lpfc_sli4_driver_resource_unset(phba); |
| 12759 | |
| 12760 | /* Unmap adapter Control and Doorbell registers */ |
| 12761 | lpfc_sli4_pci_mem_unset(phba); |
| 12762 | |
| 12763 | /* Release PCI resources and disable device's PCI function */ |
| 12764 | scsi_host_put(shost); |
| 12765 | lpfc_disable_pci_dev(phba); |
| 12766 | |
| 12767 | /* Finally, free the driver's device data structure */ |
| 12768 | lpfc_hba_free(phba); |
| 12769 | |
| 12770 | return; |
| 12771 | } |
| 12772 | |
| 12773 | /** |
| 12774 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 12775 | * @pdev: pointer to PCI device |
| 12776 | * @msg: power management message |
| 12777 | * |
| 12778 | * This routine is called from the kernel's PCI subsystem to support system |
| 12779 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 12780 | * this method, it quiesces the device by stopping the driver's worker |
| 12781 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 12782 | * the device offline. Note that as the driver implements the minimum PM |
| 12783 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 12784 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 12785 | * method call will be treated as SUSPEND and the driver will fully |
| 12786 | * reinitialize its device during resume() method call, the driver will set |
| 12787 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 12788 | * according to the @msg provided by the PM. |
| 12789 | * |
| 12790 | * Return code |
| 12791 | * 0 - driver suspended the device |
| 12792 | * Error otherwise |
| 12793 | **/ |
| 12794 | static int |
| 12795 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 12796 | { |
| 12797 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12798 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12799 | |
| 12800 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12801 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12802 | |
| 12803 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12804 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12805 | lpfc_offline(phba); |
| 12806 | kthread_stop(phba->worker_thread); |
| 12807 | |
| 12808 | /* Disable interrupt from device */ |
| 12809 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12810 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12811 | |
| 12812 | /* Save device state to PCI config space */ |
| 12813 | pci_save_state(pdev); |
| 12814 | pci_set_power_state(pdev, PCI_D3hot); |
| 12815 | |
| 12816 | return 0; |
| 12817 | } |
| 12818 | |
| 12819 | /** |
| 12820 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 12821 | * @pdev: pointer to PCI device |
| 12822 | * |
| 12823 | * This routine is called from the kernel's PCI subsystem to support system |
| 12824 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 12825 | * this method, it restores the device's PCI config space state and fully |
| 12826 | * reinitializes the device and brings it online. Note that as the driver |
| 12827 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 12828 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12829 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 12830 | * will fully reinitialize its device during resume() method call, the device |
| 12831 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 12832 | * state. |
| 12833 | * |
| 12834 | * Return code |
| 12835 | * 0 - driver suspended the device |
| 12836 | * Error otherwise |
| 12837 | **/ |
| 12838 | static int |
| 12839 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 12840 | { |
| 12841 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12842 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12843 | uint32_t intr_mode; |
| 12844 | int error; |
| 12845 | |
| 12846 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12847 | "0292 PCI device Power Management resume.\n"); |
| 12848 | |
| 12849 | /* Restore device state from PCI config space */ |
| 12850 | pci_set_power_state(pdev, PCI_D0); |
| 12851 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12852 | |
| 12853 | /* |
| 12854 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12855 | * device saved_state flag, need to save the restored state again. |
| 12856 | */ |
| 12857 | pci_save_state(pdev); |
| 12858 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12859 | if (pdev->is_busmaster) |
| 12860 | pci_set_master(pdev); |
| 12861 | |
| 12862 | /* Startup the kernel thread for this host adapter. */ |
| 12863 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12864 | "lpfc_worker_%d", phba->brd_no); |
| 12865 | if (IS_ERR(phba->worker_thread)) { |
| 12866 | error = PTR_ERR(phba->worker_thread); |
| 12867 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12868 | "0293 PM resume failed to start worker " |
| 12869 | "thread: error=x%x.\n", error); |
| 12870 | return error; |
| 12871 | } |
| 12872 | |
| 12873 | /* Configure and enable interrupt */ |
| 12874 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 12875 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12876 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12877 | "0294 PM resume Failed to enable interrupt\n"); |
| 12878 | return -EIO; |
| 12879 | } else |
| 12880 | phba->intr_mode = intr_mode; |
| 12881 | |
| 12882 | /* Restart HBA and bring it online */ |
| 12883 | lpfc_sli_brdrestart(phba); |
| 12884 | lpfc_online(phba); |
| 12885 | |
| 12886 | /* Log the current active interrupt mode */ |
| 12887 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12888 | |
| 12889 | return 0; |
| 12890 | } |
| 12891 | |
| 12892 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12893 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 12894 | * @phba: pointer to lpfc hba data structure. |
| 12895 | * |
| 12896 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 12897 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 12898 | **/ |
| 12899 | static void |
| 12900 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12901 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12903 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 12904 | /* |
| 12905 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12906 | * and let the SCSI mid-layer to retry them to recover. |
| 12907 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12908 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12909 | } |
| 12910 | |
| 12911 | /** |
| 12912 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 12913 | * @phba: pointer to lpfc hba data structure. |
| 12914 | * |
| 12915 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 12916 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12917 | * pending I/Os. |
| 12918 | **/ |
| 12919 | static void |
| 12920 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12921 | { |
| 12922 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12923 | "2826 PCI channel disable preparing for reset\n"); |
| 12924 | |
| 12925 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12926 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12927 | |
| 12928 | /* Block all SCSI devices' I/Os on the host */ |
| 12929 | lpfc_scsi_dev_block(phba); |
| 12930 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12931 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12932 | lpfc_sli_flush_fcp_rings(phba); |
| 12933 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12934 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12935 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12936 | lpfc_sli_flush_nvme_rings(phba); |
| 12937 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12938 | /* stop all timers */ |
| 12939 | lpfc_stop_hba_timers(phba); |
| 12940 | |
| 12941 | /* Disable interrupt and pci device */ |
| 12942 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12943 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12944 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12945 | } |
| 12946 | |
| 12947 | /** |
| 12948 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 12949 | * @phba: pointer to lpfc hba data structure. |
| 12950 | * |
| 12951 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 12952 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12953 | * pending I/Os. |
| 12954 | **/ |
| 12955 | static void |
| 12956 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 12957 | { |
| 12958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12959 | "2827 PCI channel permanent disable for failure\n"); |
| 12960 | |
| 12961 | /* Block all SCSI devices' I/Os on the host */ |
| 12962 | lpfc_scsi_dev_block(phba); |
| 12963 | |
| 12964 | /* stop all timers */ |
| 12965 | lpfc_stop_hba_timers(phba); |
| 12966 | |
| 12967 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12968 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12969 | |
| 12970 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12971 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12972 | lpfc_sli_flush_nvme_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12973 | } |
| 12974 | |
| 12975 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12976 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 12977 | * @pdev: pointer to PCI device. |
| 12978 | * @state: the current PCI connection state. |
| 12979 | * |
| 12980 | * This routine is called from the PCI subsystem for error handling to device |
| 12981 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 12982 | * after a PCI bus error affecting this device has been detected. When this |
| 12983 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 12984 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 12985 | * for the PCI subsystem to perform proper recovery as desired. |
| 12986 | * |
| 12987 | * Return codes |
| 12988 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12989 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12990 | **/ |
| 12991 | static pci_ers_result_t |
| 12992 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 12993 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12994 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12995 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12996 | |
| 12997 | switch (state) { |
| 12998 | case pci_channel_io_normal: |
| 12999 | /* Non-fatal error, prepare for recovery */ |
| 13000 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13001 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13002 | case pci_channel_io_frozen: |
| 13003 | /* Fatal error, prepare for slot reset */ |
| 13004 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13005 | return PCI_ERS_RESULT_NEED_RESET; |
| 13006 | case pci_channel_io_perm_failure: |
| 13007 | /* Permanent failure, prepare for device down */ |
| 13008 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13009 | return PCI_ERS_RESULT_DISCONNECT; |
| 13010 | default: |
| 13011 | /* Unknown state, prepare and request slot reset */ |
| 13012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13013 | "2825 Unknown PCI error state: x%x\n", state); |
| 13014 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13015 | return PCI_ERS_RESULT_NEED_RESET; |
| 13016 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13017 | } |
| 13018 | |
| 13019 | /** |
| 13020 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13021 | * @pdev: pointer to PCI device. |
| 13022 | * |
| 13023 | * This routine is called from the PCI subsystem for error handling to device |
| 13024 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13025 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13026 | * PCI subsystem error recovery, after the driver returns |
| 13027 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13028 | * recovery and then call this routine before calling the .resume method to |
| 13029 | * recover the device. This function will initialize the HBA device, enable |
| 13030 | * the interrupt, but it will just put the HBA to offline state without |
| 13031 | * passing any I/O traffic. |
| 13032 | * |
| 13033 | * Return codes |
| 13034 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13035 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13036 | */ |
| 13037 | static pci_ers_result_t |
| 13038 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13039 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13040 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13041 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13042 | struct lpfc_sli *psli = &phba->sli; |
| 13043 | uint32_t intr_mode; |
| 13044 | |
| 13045 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13046 | if (pci_enable_device_mem(pdev)) { |
| 13047 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13048 | "PCI device after reset.\n"); |
| 13049 | return PCI_ERS_RESULT_DISCONNECT; |
| 13050 | } |
| 13051 | |
| 13052 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13053 | |
| 13054 | /* |
| 13055 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13056 | * device saved_state flag, need to save the restored state again. |
| 13057 | */ |
| 13058 | pci_save_state(pdev); |
| 13059 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13060 | if (pdev->is_busmaster) |
| 13061 | pci_set_master(pdev); |
| 13062 | |
| 13063 | spin_lock_irq(&phba->hbalock); |
| 13064 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13065 | spin_unlock_irq(&phba->hbalock); |
| 13066 | |
| 13067 | /* Configure and enable interrupt */ |
| 13068 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13069 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13070 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13071 | "2824 Cannot re-enable interrupt after " |
| 13072 | "slot reset.\n"); |
| 13073 | return PCI_ERS_RESULT_DISCONNECT; |
| 13074 | } else |
| 13075 | phba->intr_mode = intr_mode; |
| 13076 | |
| 13077 | /* Log the current active interrupt mode */ |
| 13078 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13079 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13080 | return PCI_ERS_RESULT_RECOVERED; |
| 13081 | } |
| 13082 | |
| 13083 | /** |
| 13084 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13085 | * @pdev: pointer to PCI device |
| 13086 | * |
| 13087 | * This routine is called from the PCI subsystem for error handling to device |
| 13088 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13089 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13090 | * error recovery. After this call, traffic can start to flow from this device |
| 13091 | * again. |
| 13092 | **/ |
| 13093 | static void |
| 13094 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13095 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13096 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13097 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13098 | |
| 13099 | /* |
| 13100 | * In case of slot reset, as function reset is performed through |
| 13101 | * mailbox command which needs DMA to be enabled, this operation |
| 13102 | * has to be moved to the io resume phase. Taking device offline |
| 13103 | * will perform the necessary cleanup. |
| 13104 | */ |
| 13105 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13106 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13107 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13108 | lpfc_offline(phba); |
| 13109 | lpfc_sli_brdrestart(phba); |
| 13110 | /* Bring the device back online */ |
| 13111 | lpfc_online(phba); |
| 13112 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13113 | } |
| 13114 | |
| 13115 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13116 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13117 | * @pdev: pointer to PCI device |
| 13118 | * @pid: pointer to PCI device identifier |
| 13119 | * |
| 13120 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13121 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13122 | * at PCI device-specific information of the device and driver to see if the |
| 13123 | * driver state that it can support this kind of device. If the match is |
| 13124 | * successful, the driver core invokes this routine. This routine dispatches |
| 13125 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13126 | * do all the initialization that it needs to do to handle the HBA device |
| 13127 | * properly. |
| 13128 | * |
| 13129 | * Return code |
| 13130 | * 0 - driver can claim the device |
| 13131 | * negative value - driver can not claim the device |
| 13132 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13133 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13134 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13135 | { |
| 13136 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13137 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13138 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13139 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13140 | return -ENODEV; |
| 13141 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13142 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13143 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13144 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13145 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13146 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13147 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13148 | return rc; |
| 13149 | } |
| 13150 | |
| 13151 | /** |
| 13152 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13153 | * @pdev: pointer to PCI device |
| 13154 | * |
| 13155 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13156 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13157 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13158 | * remove routine, which will perform all the necessary cleanup for the |
| 13159 | * device to be removed from the PCI subsystem properly. |
| 13160 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13161 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13162 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13163 | { |
| 13164 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13165 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13166 | |
| 13167 | switch (phba->pci_dev_grp) { |
| 13168 | case LPFC_PCI_DEV_LP: |
| 13169 | lpfc_pci_remove_one_s3(pdev); |
| 13170 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13171 | case LPFC_PCI_DEV_OC: |
| 13172 | lpfc_pci_remove_one_s4(pdev); |
| 13173 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13174 | default: |
| 13175 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13176 | "1424 Invalid PCI device group: 0x%x\n", |
| 13177 | phba->pci_dev_grp); |
| 13178 | break; |
| 13179 | } |
| 13180 | return; |
| 13181 | } |
| 13182 | |
| 13183 | /** |
| 13184 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 13185 | * @pdev: pointer to PCI device |
| 13186 | * @msg: power management message |
| 13187 | * |
| 13188 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13189 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13190 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13191 | * suspend the device. |
| 13192 | * |
| 13193 | * Return code |
| 13194 | * 0 - driver suspended the device |
| 13195 | * Error otherwise |
| 13196 | **/ |
| 13197 | static int |
| 13198 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 13199 | { |
| 13200 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13201 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13202 | int rc = -ENODEV; |
| 13203 | |
| 13204 | switch (phba->pci_dev_grp) { |
| 13205 | case LPFC_PCI_DEV_LP: |
| 13206 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 13207 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13208 | case LPFC_PCI_DEV_OC: |
| 13209 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 13210 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13211 | default: |
| 13212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13213 | "1425 Invalid PCI device group: 0x%x\n", |
| 13214 | phba->pci_dev_grp); |
| 13215 | break; |
| 13216 | } |
| 13217 | return rc; |
| 13218 | } |
| 13219 | |
| 13220 | /** |
| 13221 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 13222 | * @pdev: pointer to PCI device |
| 13223 | * |
| 13224 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13225 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13226 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13227 | * resume the device. |
| 13228 | * |
| 13229 | * Return code |
| 13230 | * 0 - driver suspended the device |
| 13231 | * Error otherwise |
| 13232 | **/ |
| 13233 | static int |
| 13234 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 13235 | { |
| 13236 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13237 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13238 | int rc = -ENODEV; |
| 13239 | |
| 13240 | switch (phba->pci_dev_grp) { |
| 13241 | case LPFC_PCI_DEV_LP: |
| 13242 | rc = lpfc_pci_resume_one_s3(pdev); |
| 13243 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13244 | case LPFC_PCI_DEV_OC: |
| 13245 | rc = lpfc_pci_resume_one_s4(pdev); |
| 13246 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13247 | default: |
| 13248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13249 | "1426 Invalid PCI device group: 0x%x\n", |
| 13250 | phba->pci_dev_grp); |
| 13251 | break; |
| 13252 | } |
| 13253 | return rc; |
| 13254 | } |
| 13255 | |
| 13256 | /** |
| 13257 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13258 | * @pdev: pointer to PCI device. |
| 13259 | * @state: the current PCI connection state. |
| 13260 | * |
| 13261 | * This routine is registered to the PCI subsystem for error handling. This |
| 13262 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13263 | * this device has been detected. When this routine is invoked, it dispatches |
| 13264 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13265 | * routine, which will perform the proper error detected operation. |
| 13266 | * |
| 13267 | * Return codes |
| 13268 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13269 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13270 | **/ |
| 13271 | static pci_ers_result_t |
| 13272 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13273 | { |
| 13274 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13275 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13276 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13277 | |
| 13278 | switch (phba->pci_dev_grp) { |
| 13279 | case LPFC_PCI_DEV_LP: |
| 13280 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13281 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13282 | case LPFC_PCI_DEV_OC: |
| 13283 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13284 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13285 | default: |
| 13286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13287 | "1427 Invalid PCI device group: 0x%x\n", |
| 13288 | phba->pci_dev_grp); |
| 13289 | break; |
| 13290 | } |
| 13291 | return rc; |
| 13292 | } |
| 13293 | |
| 13294 | /** |
| 13295 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13296 | * @pdev: pointer to PCI device. |
| 13297 | * |
| 13298 | * This routine is registered to the PCI subsystem for error handling. This |
| 13299 | * function is called after PCI bus has been reset to restart the PCI card |
| 13300 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13301 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13302 | * routine, which will perform the proper device reset. |
| 13303 | * |
| 13304 | * Return codes |
| 13305 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13306 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13307 | **/ |
| 13308 | static pci_ers_result_t |
| 13309 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13310 | { |
| 13311 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13312 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13313 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13314 | |
| 13315 | switch (phba->pci_dev_grp) { |
| 13316 | case LPFC_PCI_DEV_LP: |
| 13317 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13318 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13319 | case LPFC_PCI_DEV_OC: |
| 13320 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13321 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13322 | default: |
| 13323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13324 | "1428 Invalid PCI device group: 0x%x\n", |
| 13325 | phba->pci_dev_grp); |
| 13326 | break; |
| 13327 | } |
| 13328 | return rc; |
| 13329 | } |
| 13330 | |
| 13331 | /** |
| 13332 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13333 | * @pdev: pointer to PCI device |
| 13334 | * |
| 13335 | * This routine is registered to the PCI subsystem for error handling. It |
| 13336 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13337 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13338 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13339 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13340 | **/ |
| 13341 | static void |
| 13342 | lpfc_io_resume(struct pci_dev *pdev) |
| 13343 | { |
| 13344 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13345 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13346 | |
| 13347 | switch (phba->pci_dev_grp) { |
| 13348 | case LPFC_PCI_DEV_LP: |
| 13349 | lpfc_io_resume_s3(pdev); |
| 13350 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13351 | case LPFC_PCI_DEV_OC: |
| 13352 | lpfc_io_resume_s4(pdev); |
| 13353 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13354 | default: |
| 13355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13356 | "1429 Invalid PCI device group: 0x%x\n", |
| 13357 | phba->pci_dev_grp); |
| 13358 | break; |
| 13359 | } |
| 13360 | return; |
| 13361 | } |
| 13362 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13363 | /** |
| 13364 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13365 | * @phba: pointer to lpfc hba data structure. |
| 13366 | * |
| 13367 | * This routine checks to see if OAS is supported for this adapter. If |
| 13368 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13369 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13370 | * is destroyed. |
| 13371 | * |
| 13372 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13373 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13374 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13375 | { |
| 13376 | |
| 13377 | if (!phba->cfg_EnableXLane) |
| 13378 | return; |
| 13379 | |
| 13380 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13381 | phba->cfg_fof = 1; |
| 13382 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13383 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13384 | if (phba->device_data_mem_pool) |
| 13385 | mempool_destroy(phba->device_data_mem_pool); |
| 13386 | phba->device_data_mem_pool = NULL; |
| 13387 | } |
| 13388 | |
| 13389 | return; |
| 13390 | } |
| 13391 | |
| 13392 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13393 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13394 | * @phba: pointer to lpfc hba data structure. |
| 13395 | * |
| 13396 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13397 | * function through which RAS support enablement is to be done. |
| 13398 | **/ |
| 13399 | void |
| 13400 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 13401 | { |
| 13402 | switch (phba->pcidev->device) { |
| 13403 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 13404 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 13405 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 13406 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 13407 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13408 | phba->ras_fwlog.ras_enabled = true; |
| 13409 | else |
| 13410 | phba->ras_fwlog.ras_enabled = false; |
| 13411 | break; |
| 13412 | default: |
| 13413 | phba->ras_fwlog.ras_hwsupport = false; |
| 13414 | } |
| 13415 | } |
| 13416 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13417 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13418 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 13419 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 13420 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 13421 | .error_detected = lpfc_io_error_detected, |
| 13422 | .slot_reset = lpfc_io_slot_reset, |
| 13423 | .resume = lpfc_io_resume, |
| 13424 | }; |
| 13425 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13426 | static struct pci_driver lpfc_driver = { |
| 13427 | .name = LPFC_DRIVER_NAME, |
| 13428 | .id_table = lpfc_id_table, |
| 13429 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13430 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 13431 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 13432 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13433 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13434 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13435 | }; |
| 13436 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13437 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 13438 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13439 | }; |
| 13440 | |
| 13441 | static struct miscdevice lpfc_mgmt_dev = { |
| 13442 | .minor = MISC_DYNAMIC_MINOR, |
| 13443 | .name = "lpfcmgmt", |
| 13444 | .fops = &lpfc_mgmt_fop, |
| 13445 | }; |
| 13446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13448 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13449 | * |
| 13450 | * This routine is to be invoked when the lpfc module is loaded into the |
| 13451 | * kernel. The special kernel macro module_init() is used to indicate the |
| 13452 | * role of this routine to the kernel as lpfc module entry point. |
| 13453 | * |
| 13454 | * Return codes |
| 13455 | * 0 - successful |
| 13456 | * -ENOMEM - FC attach transport failed |
| 13457 | * all others - failed |
| 13458 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13459 | static int __init |
| 13460 | lpfc_init(void) |
| 13461 | { |
| 13462 | int error = 0; |
| 13463 | |
| 13464 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 13465 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13466 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13467 | error = misc_register(&lpfc_mgmt_dev); |
| 13468 | if (error) |
| 13469 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 13470 | "misc_register returned with status %d", error); |
| 13471 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13472 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 13473 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13474 | lpfc_transport_template = |
| 13475 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13476 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13477 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13478 | lpfc_vport_transport_template = |
| 13479 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 13480 | if (lpfc_vport_transport_template == NULL) { |
| 13481 | fc_release_transport(lpfc_transport_template); |
| 13482 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13483 | } |
James Smart | 5fd1108 | 2018-03-05 12:04:04 -0800 | [diff] [blame] | 13484 | lpfc_nvme_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 13485 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13486 | |
| 13487 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 13488 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13489 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13490 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13491 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13492 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13493 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13494 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13495 | |
| 13496 | return error; |
| 13497 | } |
| 13498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13500 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13501 | * |
| 13502 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 13503 | * The special kernel macro module_exit() is used to indicate the role of |
| 13504 | * this routine to the kernel as lpfc module exit point. |
| 13505 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13506 | static void __exit |
| 13507 | lpfc_exit(void) |
| 13508 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13509 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13510 | pci_unregister_driver(&lpfc_driver); |
| 13511 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13512 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13513 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13514 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 13515 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13516 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 13517 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 13518 | } |
| 13519 | |
| 13520 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13521 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 13522 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13523 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 13524 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 13525 | } |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 13526 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13527 | } |
| 13528 | |
| 13529 | module_init(lpfc_init); |
| 13530 | module_exit(lpfc_exit); |
| 13531 | MODULE_LICENSE("GPL"); |
| 13532 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 13533 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13534 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |