| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/idr.h> |
| 28 | #include <linux/interrupt.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <linux/kthread.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 33 | #include <linux/ctype.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 34 | #include <linux/aer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 36 | #include <linux/firmware.h> |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 37 | #include <linux/miscdevice.h> |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 38 | #include <linux/percpu.h> |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 39 | #include <linux/msi.h> |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 40 | #include <linux/irq.h> |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 41 | #include <linux/bitops.h> |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 42 | #include <linux/crash_dump.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 44 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include <scsi/scsi_device.h> |
| 46 | #include <scsi/scsi_host.h> |
| 47 | #include <scsi/scsi_transport_fc.h> |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 48 | #include <scsi/scsi_tcq.h> |
| 49 | #include <scsi/fc/fc_fs.h> |
| 50 | |
| 51 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 53 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_hw.h" |
| 55 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 56 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 57 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 60 | #include "lpfc_scsi.h" |
| 61 | #include "lpfc_nvme.h" |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 62 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 63 | #include "lpfc_logmsg.h" |
| 64 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 65 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 66 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 67 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 69 | char *_dump_buf_data; |
| 70 | unsigned long _dump_buf_data_order; |
| 71 | char *_dump_buf_dif; |
| 72 | unsigned long _dump_buf_dif_order; |
| 73 | spinlock_t _dump_buf_lock; |
| 74 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 75 | /* Used when mapping IRQ vectors in a driver centric manner */ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 76 | static uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 77 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 79 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 80 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 81 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 82 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 83 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 84 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 85 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 86 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 87 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 88 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 89 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 90 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 91 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 92 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 93 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 94 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 95 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 96 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 97 | static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int); |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 98 | static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | |
| 100 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 101 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 103 | #define LPFC_NVMET_BUF_POST 254 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 106 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 107 | * @phba: pointer to lpfc hba data structure. |
| 108 | * |
| 109 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 110 | * mailbox command. It retrieves the revision information from the HBA and |
| 111 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 112 | * configuration of the HBA. |
| 113 | * |
| 114 | * Return codes: |
| 115 | * 0 - success. |
| 116 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 117 | * Any other value - indicates an error. |
| 118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 120 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 121 | { |
| 122 | lpfc_vpd_t *vp = &phba->vpd; |
| 123 | int i = 0, rc; |
| 124 | LPFC_MBOXQ_t *pmb; |
| 125 | MAILBOX_t *mb; |
| 126 | char *lpfc_vpd_data = NULL; |
| 127 | uint16_t offset = 0; |
| 128 | static char licensed[56] = |
| 129 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 130 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 131 | |
| 132 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 133 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 134 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | return -ENOMEM; |
| 136 | } |
| 137 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 138 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 139 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | |
| 141 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 142 | if (init_key) { |
| 143 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 145 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 146 | *ptext = cpu_to_be32(*ptext); |
| 147 | init_key = 0; |
| 148 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | |
| 150 | lpfc_read_nv(phba, pmb); |
| 151 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 152 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 153 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 154 | sizeof (licensed)); |
| 155 | |
| 156 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 157 | |
| 158 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 159 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 160 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | "error, mbxCmd x%x READ_NVPARM, " |
| 162 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | mb->mbxCommand, mb->mbxStatus); |
| 164 | mempool_free(pmb, phba->mbox_mem_pool); |
| 165 | return -ERESTART; |
| 166 | } |
| 167 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 168 | sizeof(phba->wwnn)); |
| 169 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 170 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 173 | /* |
| 174 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 175 | * which was already set in lpfc_get_cfgparam() |
| 176 | */ |
| 177 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 178 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | /* Setup and issue mailbox READ REV command */ |
| 180 | lpfc_read_rev(phba, pmb); |
| 181 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 182 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 184 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | mb->mbxCommand, mb->mbxStatus); |
| 187 | mempool_free( pmb, phba->mbox_mem_pool); |
| 188 | return -ERESTART; |
| 189 | } |
| 190 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 191 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 192 | /* |
| 193 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 194 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 196 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 199 | "0440 Adapter failed to init, READ_REV has " |
| 200 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | mempool_free(pmb, phba->mbox_mem_pool); |
| 202 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | } |
| 204 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 205 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 206 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 207 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 208 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 209 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 211 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 213 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 214 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 215 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 216 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 218 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 219 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 220 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 221 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 222 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 223 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 224 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 225 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 226 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 227 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 228 | /* If the sli feature level is less then 9, we must |
| 229 | * tear down all RPIs and VPIs on link down if NPIV |
| 230 | * is enabled. |
| 231 | */ |
| 232 | if (vp->rev.feaLevelHigh < 9) |
| 233 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 234 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 236 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 237 | sizeof (phba->RandomData)); |
| 238 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 241 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 242 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 244 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 246 | |
| 247 | if (rc != MBX_SUCCESS) { |
| 248 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 249 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 252 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 253 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 254 | /* dump mem may return a zero when finished or we got a |
| 255 | * mailbox error, either way we are done. |
| 256 | */ |
| 257 | if (mb->un.varDmp.word_cnt == 0) |
| 258 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 259 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 260 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 261 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 262 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 263 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 264 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 265 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 266 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | |
| 268 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | out_free_mbox: |
| 270 | mempool_free(pmb, phba->mbox_mem_pool); |
| 271 | return 0; |
| 272 | } |
| 273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 275 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 276 | * @phba: pointer to lpfc hba data structure. |
| 277 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 278 | * |
| 279 | * This is the completion handler for driver's configuring asynchronous event |
| 280 | * mailbox command to the device. If the mailbox command returns successfully, |
| 281 | * it will set internal async event support flag to 1; otherwise, it will |
| 282 | * set internal async event support flag to 0. |
| 283 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 284 | static void |
| 285 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 286 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 287 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 288 | phba->temp_sensor_support = 1; |
| 289 | else |
| 290 | phba->temp_sensor_support = 0; |
| 291 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 292 | return; |
| 293 | } |
| 294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 296 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 297 | * @phba: pointer to lpfc hba data structure. |
| 298 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 299 | * |
| 300 | * This is the completion handler for dump mailbox command for getting |
| 301 | * wake up parameters. When this command complete, the response contain |
| 302 | * Option rom version of the HBA. This function translate the version number |
| 303 | * into a human readable string and store it in OptionROMVersion. |
| 304 | **/ |
| 305 | static void |
| 306 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 307 | { |
| 308 | struct prog_id *prg; |
| 309 | uint32_t prog_id_word; |
| 310 | char dist = ' '; |
| 311 | /* character array used for decoding dist type. */ |
| 312 | char dist_char[] = "nabx"; |
| 313 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 314 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 315 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 316 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 317 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 318 | |
| 319 | prg = (struct prog_id *) &prog_id_word; |
| 320 | |
| 321 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 322 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 323 | |
| 324 | /* Decode the Option rom version word to a readable string */ |
| 325 | if (prg->dist < 4) |
| 326 | dist = dist_char[prg->dist]; |
| 327 | |
| 328 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 329 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 330 | prg->ver, prg->rev, prg->lev); |
| 331 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 332 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 333 | prg->ver, prg->rev, prg->lev, |
| 334 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 335 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
| 339 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 340 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 341 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 342 | * @vport: pointer to lpfc vport data structure. |
| 343 | * |
| 344 | * |
| 345 | * Return codes |
| 346 | * None. |
| 347 | **/ |
| 348 | void |
| 349 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 350 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 351 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 352 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 353 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 354 | /* If the soft name exists then update it using the service params */ |
| 355 | if (vport->phba->cfg_soft_wwnn) |
| 356 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 357 | vport->fc_sparam.nodeName.u.wwn); |
| 358 | if (vport->phba->cfg_soft_wwpn) |
| 359 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 360 | vport->fc_sparam.portName.u.wwn); |
| 361 | |
| 362 | /* |
| 363 | * If the name is empty or there exists a soft name |
| 364 | * then copy the service params name, otherwise use the fc name |
| 365 | */ |
| 366 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 367 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 368 | sizeof(struct lpfc_name)); |
| 369 | else |
| 370 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 371 | sizeof(struct lpfc_name)); |
| 372 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 373 | /* |
| 374 | * If the port name has changed, then set the Param changes flag |
| 375 | * to unreg the login |
| 376 | */ |
| 377 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 378 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 379 | sizeof(struct lpfc_name))) |
| 380 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 381 | |
| 382 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 383 | vport->phba->cfg_soft_wwpn || |
| 384 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 385 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 386 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 387 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 388 | vport->vport_flag &= ~FAWWPN_SET; |
| 389 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 390 | vport->vport_flag |= FAWWPN_SET; |
| 391 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 392 | else |
| 393 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 394 | sizeof(struct lpfc_name)); |
| 395 | } |
| 396 | |
| 397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 398 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 399 | * @phba: pointer to lpfc hba data structure. |
| 400 | * |
| 401 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 402 | * command call. It performs all internal resource and state setups on the |
| 403 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 404 | * ELS ring timers, etc. |
| 405 | * |
| 406 | * Return codes |
| 407 | * 0 - success. |
| 408 | * Any other value - error. |
| 409 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 414 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | LPFC_MBOXQ_t *pmb; |
| 416 | MAILBOX_t *mb; |
| 417 | struct lpfc_dmabuf *mp; |
| 418 | struct lpfc_sli *psli = &phba->sli; |
| 419 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 420 | int i, j; |
| 421 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 423 | spin_lock_irq(&phba->hbalock); |
| 424 | /* |
| 425 | * If the Config port completed correctly the HBA is not |
| 426 | * over heated any more. |
| 427 | */ |
| 428 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 429 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 430 | spin_unlock_irq(&phba->hbalock); |
| 431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 433 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | return -ENOMEM; |
| 436 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 437 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 440 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 441 | if (rc) { |
| 442 | mempool_free(pmb, phba->mbox_mem_pool); |
| 443 | return -ENOMEM; |
| 444 | } |
| 445 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 446 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 447 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 449 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 452 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 453 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 454 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 455 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 456 | kfree(mp); |
| 457 | return -EIO; |
| 458 | } |
| 459 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 460 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 462 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 463 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 464 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 465 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 466 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 467 | |
| 468 | /* Update the fc_host data structures with new wwn. */ |
| 469 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 470 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 471 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 474 | /* This should be consolidated into parse_vpd ? - mr */ |
| 475 | if (phba->SerialNumber[0] == 0) { |
| 476 | uint8_t *outptr; |
| 477 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | for (i = 0; i < 12; i++) { |
| 480 | status = *outptr++; |
| 481 | j = ((status & 0xf0) >> 4); |
| 482 | if (j <= 9) |
| 483 | phba->SerialNumber[i] = |
| 484 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 485 | else |
| 486 | phba->SerialNumber[i] = |
| 487 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 488 | i++; |
| 489 | j = (status & 0xf); |
| 490 | if (j <= 9) |
| 491 | phba->SerialNumber[i] = |
| 492 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 493 | else |
| 494 | phba->SerialNumber[i] = |
| 495 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 496 | } |
| 497 | } |
| 498 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 500 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 503 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | mempool_free( pmb, phba->mbox_mem_pool); |
| 508 | return -EIO; |
| 509 | } |
| 510 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 511 | /* Check if the port is disabled */ |
| 512 | lpfc_sli_read_link_ste(phba); |
| 513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 515 | i = (mb->un.varRdConfig.max_xri + 1); |
| 516 | if (phba->cfg_hba_queue_depth > i) { |
| 517 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 518 | "3359 HBA queue depth changed from %d to %d\n", |
| 519 | phba->cfg_hba_queue_depth, i); |
| 520 | phba->cfg_hba_queue_depth = i; |
| 521 | } |
| 522 | |
| 523 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 524 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 525 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 526 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 527 | "3360 LUN queue depth changed from %d to %d\n", |
| 528 | phba->pport->cfg_lun_queue_depth, i); |
| 529 | phba->pport->cfg_lun_queue_depth = i; |
| 530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | |
| 532 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 533 | |
| 534 | /* Get the default values for Model Name and Description */ |
| 535 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 536 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 537 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 539 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 540 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 541 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 542 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 543 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 544 | |
| 545 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 546 | if (phba->sli_rev != 3) |
| 547 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 549 | /* |
| 550 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 551 | */ |
| 552 | if (phba->intr_type == MSIX) { |
| 553 | rc = lpfc_config_msi(phba, pmb); |
| 554 | if (rc) { |
| 555 | mempool_free(pmb, phba->mbox_mem_pool); |
| 556 | return -EIO; |
| 557 | } |
| 558 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 559 | if (rc != MBX_SUCCESS) { |
| 560 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 561 | "0352 Config MSI mailbox command " |
| 562 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 563 | pmb->u.mb.mbxCommand, |
| 564 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 565 | mempool_free(pmb, phba->mbox_mem_pool); |
| 566 | return -EIO; |
| 567 | } |
| 568 | } |
| 569 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 570 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 571 | /* Initialize ERATT handling flag */ |
| 572 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 575 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 576 | spin_unlock_irq(&phba->hbalock); |
| 577 | return -EIO; |
| 578 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 579 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 580 | if (psli->num_rings > 0) |
| 581 | status |= HC_R0INT_ENA; |
| 582 | if (psli->num_rings > 1) |
| 583 | status |= HC_R1INT_ENA; |
| 584 | if (psli->num_rings > 2) |
| 585 | status |= HC_R2INT_ENA; |
| 586 | if (psli->num_rings > 3) |
| 587 | status |= HC_R3INT_ENA; |
| 588 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 589 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 590 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 591 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 592 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | writel(status, phba->HCregaddr); |
| 594 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 595 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 597 | /* Set up ring-0 (ELS) timer */ |
| 598 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 599 | mod_timer(&vport->els_tmofunc, |
| 600 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 601 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 602 | mod_timer(&phba->hb_tmofunc, |
| 603 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 604 | phba->hb_outstanding = 0; |
| 605 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 606 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 607 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 608 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 609 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 610 | if (phba->hba_flag & LINK_DISABLED) { |
| 611 | lpfc_printf_log(phba, |
| 612 | KERN_ERR, LOG_INIT, |
| 613 | "2598 Adapter Link is disabled.\n"); |
| 614 | lpfc_down_link(phba, pmb); |
| 615 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 616 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 617 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 618 | lpfc_printf_log(phba, |
| 619 | KERN_ERR, LOG_INIT, |
| 620 | "2599 Adapter failed to issue DOWN_LINK" |
| 621 | " mbox command rc 0x%x\n", rc); |
| 622 | |
| 623 | mempool_free(pmb, phba->mbox_mem_pool); |
| 624 | return -EIO; |
| 625 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 626 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 627 | mempool_free(pmb, phba->mbox_mem_pool); |
| 628 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 629 | if (rc) |
| 630 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | } |
| 632 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 633 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 634 | if (!pmb) { |
| 635 | phba->link_state = LPFC_HBA_ERROR; |
| 636 | return -ENOMEM; |
| 637 | } |
| 638 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 639 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 640 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 641 | pmb->vport = phba->pport; |
| 642 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 644 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 645 | lpfc_printf_log(phba, |
| 646 | KERN_ERR, |
| 647 | LOG_INIT, |
| 648 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 649 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 650 | rc); |
| 651 | mempool_free(pmb, phba->mbox_mem_pool); |
| 652 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 653 | |
| 654 | /* Get Option rom version */ |
| 655 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 656 | if (!pmb) { |
| 657 | phba->link_state = LPFC_HBA_ERROR; |
| 658 | return -ENOMEM; |
| 659 | } |
| 660 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 661 | lpfc_dump_wakeup_param(phba, pmb); |
| 662 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 663 | pmb->vport = phba->pport; |
| 664 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 665 | |
| 666 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 667 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 668 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 669 | mempool_free(pmb, phba->mbox_mem_pool); |
| 670 | } |
| 671 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 672 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 673 | } |
| 674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 675 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 676 | * lpfc_hba_init_link - Initialize the FC link |
| 677 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 678 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 679 | * |
| 680 | * This routine will issue the INIT_LINK mailbox command call. |
| 681 | * It is available to other drivers through the lpfc_hba data |
| 682 | * structure for use as a delayed link up mechanism with the |
| 683 | * module parameter lpfc_suppress_link_up. |
| 684 | * |
| 685 | * Return code |
| 686 | * 0 - success |
| 687 | * Any other value - error |
| 688 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 689 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 690 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 691 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 692 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 697 | * @phba: pointer to lpfc hba data structure. |
| 698 | * @fc_topology: desired fc topology. |
| 699 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 700 | * |
| 701 | * This routine will issue the INIT_LINK mailbox command call. |
| 702 | * It is available to other drivers through the lpfc_hba data |
| 703 | * structure for use as a delayed link up mechanism with the |
| 704 | * module parameter lpfc_suppress_link_up. |
| 705 | * |
| 706 | * Return code |
| 707 | * 0 - success |
| 708 | * Any other value - error |
| 709 | **/ |
| 710 | int |
| 711 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 712 | uint32_t flag) |
| 713 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 714 | struct lpfc_vport *vport = phba->pport; |
| 715 | LPFC_MBOXQ_t *pmb; |
| 716 | MAILBOX_t *mb; |
| 717 | int rc; |
| 718 | |
| 719 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 720 | if (!pmb) { |
| 721 | phba->link_state = LPFC_HBA_ERROR; |
| 722 | return -ENOMEM; |
| 723 | } |
| 724 | mb = &pmb->u.mb; |
| 725 | pmb->vport = vport; |
| 726 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 727 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 728 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 729 | !(phba->lmt & LMT_1Gb)) || |
| 730 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 731 | !(phba->lmt & LMT_2Gb)) || |
| 732 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 733 | !(phba->lmt & LMT_4Gb)) || |
| 734 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 735 | !(phba->lmt & LMT_8Gb)) || |
| 736 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 737 | !(phba->lmt & LMT_10Gb)) || |
| 738 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 739 | !(phba->lmt & LMT_16Gb)) || |
| 740 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 741 | !(phba->lmt & LMT_32Gb)) || |
| 742 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 743 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 744 | /* Reset link speed to auto */ |
| 745 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 746 | "1302 Invalid speed for this board:%d " |
| 747 | "Reset link speed to auto.\n", |
| 748 | phba->cfg_link_speed); |
| 749 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 750 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 751 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 752 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 753 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 754 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 755 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 756 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 757 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 758 | "0498 Adapter failed to init, mbxCmd x%x " |
| 759 | "INIT_LINK, mbxStatus x%x\n", |
| 760 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 761 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 762 | /* Clear all interrupt enable conditions */ |
| 763 | writel(0, phba->HCregaddr); |
| 764 | readl(phba->HCregaddr); /* flush */ |
| 765 | /* Clear all pending interrupts */ |
| 766 | writel(0xffffffff, phba->HAregaddr); |
| 767 | readl(phba->HAregaddr); /* flush */ |
| 768 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 769 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 770 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 771 | mempool_free(pmb, phba->mbox_mem_pool); |
| 772 | return -EIO; |
| 773 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 774 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 775 | if (flag == MBX_POLL) |
| 776 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 783 | * @phba: pointer to lpfc hba data structure. |
| 784 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 785 | * |
| 786 | * This routine will issue the DOWN_LINK mailbox command call. |
| 787 | * It is available to other drivers through the lpfc_hba data |
| 788 | * structure for use to stop the link. |
| 789 | * |
| 790 | * Return code |
| 791 | * 0 - success |
| 792 | * Any other value - error |
| 793 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 794 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 795 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 796 | { |
| 797 | LPFC_MBOXQ_t *pmb; |
| 798 | int rc; |
| 799 | |
| 800 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 801 | if (!pmb) { |
| 802 | phba->link_state = LPFC_HBA_ERROR; |
| 803 | return -ENOMEM; |
| 804 | } |
| 805 | |
| 806 | lpfc_printf_log(phba, |
| 807 | KERN_ERR, LOG_INIT, |
| 808 | "0491 Adapter Link is disabled.\n"); |
| 809 | lpfc_down_link(phba, pmb); |
| 810 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 811 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 812 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 813 | lpfc_printf_log(phba, |
| 814 | KERN_ERR, LOG_INIT, |
| 815 | "2522 Adapter failed to issue DOWN_LINK" |
| 816 | " mbox command rc 0x%x\n", rc); |
| 817 | |
| 818 | mempool_free(pmb, phba->mbox_mem_pool); |
| 819 | return -EIO; |
| 820 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 821 | if (flag == MBX_POLL) |
| 822 | mempool_free(pmb, phba->mbox_mem_pool); |
| 823 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 828 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 829 | * @phba: pointer to lpfc HBA data structure. |
| 830 | * |
| 831 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 832 | * bringing down the SLI Layer. |
| 833 | * |
| 834 | * Return codes |
| 835 | * 0 - success. |
| 836 | * Any other value - error. |
| 837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 838 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 839 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 841 | struct lpfc_vport **vports; |
| 842 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 843 | |
| 844 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 845 | /* Disable interrupts */ |
| 846 | writel(0, phba->HCregaddr); |
| 847 | readl(phba->HCregaddr); /* flush */ |
| 848 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 850 | if (phba->pport->load_flag & FC_UNLOADING) |
| 851 | lpfc_cleanup_discovery_resources(phba->pport); |
| 852 | else { |
| 853 | vports = lpfc_create_vport_work_array(phba); |
| 854 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 855 | for (i = 0; i <= phba->max_vports && |
| 856 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 857 | lpfc_cleanup_discovery_resources(vports[i]); |
| 858 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 859 | } |
| 860 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 861 | } |
| 862 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 863 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 864 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 865 | * rspiocb which got deferred |
| 866 | * |
| 867 | * @phba: pointer to lpfc HBA data structure. |
| 868 | * |
| 869 | * This routine will cleanup completed slow path events after HBA is reset |
| 870 | * when bringing down the SLI Layer. |
| 871 | * |
| 872 | * |
| 873 | * Return codes |
| 874 | * void. |
| 875 | **/ |
| 876 | static void |
| 877 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 878 | { |
| 879 | struct lpfc_iocbq *rspiocbq; |
| 880 | struct hbq_dmabuf *dmabuf; |
| 881 | struct lpfc_cq_event *cq_event; |
| 882 | |
| 883 | spin_lock_irq(&phba->hbalock); |
| 884 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 885 | spin_unlock_irq(&phba->hbalock); |
| 886 | |
| 887 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 888 | /* Get the response iocb from the head of work queue */ |
| 889 | spin_lock_irq(&phba->hbalock); |
| 890 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 891 | cq_event, struct lpfc_cq_event, list); |
| 892 | spin_unlock_irq(&phba->hbalock); |
| 893 | |
| 894 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 895 | case CQE_CODE_COMPL_WQE: |
| 896 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 897 | cq_event); |
| 898 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 899 | break; |
| 900 | case CQE_CODE_RECEIVE: |
| 901 | case CQE_CODE_RECEIVE_V1: |
| 902 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 903 | cq_event); |
| 904 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 910 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 911 | * @phba: pointer to lpfc HBA data structure. |
| 912 | * |
| 913 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 914 | * when bringing down the SLI Layer. |
| 915 | * |
| 916 | * |
| 917 | * Return codes |
| 918 | * void. |
| 919 | **/ |
| 920 | static void |
| 921 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 922 | { |
| 923 | struct lpfc_sli *psli = &phba->sli; |
| 924 | struct lpfc_sli_ring *pring; |
| 925 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 926 | LIST_HEAD(buflist); |
| 927 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 928 | |
| 929 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 930 | lpfc_sli_hbqbuf_free_all(phba); |
| 931 | else { |
| 932 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 933 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 934 | spin_lock_irq(&phba->hbalock); |
| 935 | list_splice_init(&pring->postbufq, &buflist); |
| 936 | spin_unlock_irq(&phba->hbalock); |
| 937 | |
| 938 | count = 0; |
| 939 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 940 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 941 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 942 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 943 | kfree(mp); |
| 944 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 945 | |
| 946 | spin_lock_irq(&phba->hbalock); |
| 947 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 948 | spin_unlock_irq(&phba->hbalock); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 954 | * @phba: pointer to lpfc HBA data structure. |
| 955 | * |
| 956 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 957 | * down the SLI Layer. |
| 958 | * |
| 959 | * Return codes |
| 960 | * void |
| 961 | **/ |
| 962 | static void |
| 963 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 964 | { |
| 965 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 966 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 967 | struct lpfc_sli_ring *pring; |
| 968 | LIST_HEAD(completions); |
| 969 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 970 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 971 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 972 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 973 | for (i = 0; i < psli->num_rings; i++) { |
| 974 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 975 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 976 | /* At this point in time the HBA is either reset or DOA |
| 977 | * Nothing should be on txcmplq as it will |
| 978 | * NEVER complete. |
| 979 | */ |
| 980 | list_splice_init(&pring->txcmplq, &completions); |
| 981 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 982 | spin_unlock_irq(&phba->hbalock); |
| 983 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 984 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 985 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 986 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 987 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 988 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 989 | return; |
| 990 | } |
| 991 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 992 | pring = qp->pring; |
| 993 | if (!pring) |
| 994 | continue; |
| 995 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 996 | list_for_each_entry_safe(piocb, next_iocb, |
| 997 | &pring->txcmplq, list) |
| 998 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 999 | list_splice_init(&pring->txcmplq, &completions); |
| 1000 | pring->txcmplq_cnt = 0; |
| 1001 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1002 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1003 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1004 | /* Cancel all the IOCBs from the completions list */ |
| 1005 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 1006 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1010 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1011 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1012 | * @phba: pointer to lpfc HBA data structure. |
| 1013 | * |
| 1014 | * This routine will do uninitialization after the HBA is reset when bring |
| 1015 | * down the SLI Layer. |
| 1016 | * |
| 1017 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1018 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1019 | * Any other value - error. |
| 1020 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1021 | static int |
| 1022 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1023 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1024 | lpfc_hba_free_post_buf(phba); |
| 1025 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1028 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1029 | /** |
| 1030 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1031 | * @phba: pointer to lpfc HBA data structure. |
| 1032 | * |
| 1033 | * This routine will do uninitialization after the HBA is reset when bring |
| 1034 | * down the SLI Layer. |
| 1035 | * |
| 1036 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1037 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1038 | * Any other value - error. |
| 1039 | **/ |
| 1040 | static int |
| 1041 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1042 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1043 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1044 | struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1045 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1046 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1047 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1048 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1049 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1050 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1051 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1052 | |
| 1053 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1054 | lpfc_hba_clean_txcmplq(phba); |
| 1055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | /* At this point in time the HBA is either reset or DOA. Either |
| 1057 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1058 | * on the lpfc_els_sgl_list so that it can either be freed if the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1059 | * driver is unloading or reposted if the driver is restarting |
| 1060 | * the port. |
| 1061 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1062 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1064 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1065 | * list. |
| 1066 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1067 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1068 | list_for_each_entry(sglq_entry, |
| 1069 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1070 | sglq_entry->state = SGL_FREED; |
| 1071 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1072 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1074 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1075 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1076 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1077 | |
| 1078 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1079 | * list. |
| 1080 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1081 | cnt = 0; |
| 1082 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1083 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1084 | |
| 1085 | spin_lock(&qp->abts_scsi_buf_list_lock); |
| 1086 | list_splice_init(&qp->lpfc_abts_scsi_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1087 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1088 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1089 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1090 | psb->pCmd = NULL; |
| 1091 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1092 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1093 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1094 | spin_lock(&qp->io_buf_list_put_lock); |
| 1095 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1096 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
| 1097 | qp->abts_scsi_io_bufs = 0; |
| 1098 | spin_unlock(&qp->io_buf_list_put_lock); |
| 1099 | spin_unlock(&qp->abts_scsi_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1100 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1101 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1102 | spin_lock(&qp->abts_nvme_buf_list_lock); |
| 1103 | list_splice_init(&qp->lpfc_abts_nvme_buf_list, |
| 1104 | &nvme_aborts); |
| 1105 | list_for_each_entry_safe(psb, psb_next, &nvme_aborts, |
| 1106 | list) { |
| 1107 | psb->pCmd = NULL; |
| 1108 | psb->status = IOSTAT_SUCCESS; |
| 1109 | cnt++; |
| 1110 | } |
| 1111 | spin_lock(&qp->io_buf_list_put_lock); |
| 1112 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
| 1113 | qp->abts_nvme_io_bufs = 0; |
| 1114 | list_splice_init(&nvme_aborts, |
| 1115 | &qp->lpfc_io_buf_list_put); |
| 1116 | spin_unlock(&qp->io_buf_list_put_lock); |
| 1117 | spin_unlock(&qp->abts_nvme_buf_list_lock); |
| 1118 | |
| 1119 | } |
| 1120 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1121 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1122 | |
| 1123 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1124 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1125 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1126 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1127 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1128 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
| 1129 | ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1130 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1131 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1132 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1133 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1134 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1135 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1140 | * @phba: pointer to lpfc HBA data structure. |
| 1141 | * |
| 1142 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1143 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1144 | * |
| 1145 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1146 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1147 | * Any other value - error. |
| 1148 | **/ |
| 1149 | int |
| 1150 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1151 | { |
| 1152 | return (*phba->lpfc_hba_down_post)(phba); |
| 1153 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1156 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1158 | * |
| 1159 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1160 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1161 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1162 | * event will be used by the worker thread to invoke the actual timeout |
| 1163 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1164 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1165 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1166 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1167 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1168 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1169 | { |
| 1170 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1171 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1172 | unsigned long iflag; |
| 1173 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1174 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1175 | |
| 1176 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1178 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1179 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1180 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1181 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1182 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1183 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1184 | if (!tmo_posted) |
| 1185 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1186 | return; |
| 1187 | } |
| 1188 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1189 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1190 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1191 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1192 | * |
| 1193 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1194 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1195 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1196 | * event will be used by the worker thread to invoke the actual timeout |
| 1197 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1198 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1199 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1200 | **/ |
| 1201 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1202 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1203 | { |
| 1204 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1205 | unsigned long iflag; |
| 1206 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1207 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1208 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1209 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1210 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1211 | else |
| 1212 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1213 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1214 | |
| 1215 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1216 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1220 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | * @phba: pointer to lpfc hba data structure. |
| 1222 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1223 | * |
| 1224 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1225 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1226 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1227 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1228 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1229 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1230 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1231 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1232 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1233 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1234 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1235 | static void |
| 1236 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1237 | { |
| 1238 | unsigned long drvr_flag; |
| 1239 | |
| 1240 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1241 | phba->hb_outstanding = 0; |
| 1242 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1243 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1244 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1245 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1246 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1247 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1248 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1249 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1250 | jiffies + |
| 1251 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1252 | return; |
| 1253 | } |
| 1254 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1255 | static void |
| 1256 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1257 | { |
| 1258 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1259 | struct lpfc_hba, eq_delay_work); |
| 1260 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1261 | struct lpfc_queue *eq, *eq_next; |
| 1262 | unsigned char *eqcnt = NULL; |
| 1263 | uint32_t usdelay; |
| 1264 | int i; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame^] | 1265 | bool update = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1266 | |
| 1267 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1268 | return; |
| 1269 | |
| 1270 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1271 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1272 | goto requeue; |
| 1273 | |
| 1274 | eqcnt = kcalloc(num_possible_cpus(), sizeof(unsigned char), |
| 1275 | GFP_KERNEL); |
| 1276 | if (!eqcnt) |
| 1277 | goto requeue; |
| 1278 | |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame^] | 1279 | if (phba->cfg_irq_chann > 1) { |
| 1280 | /* Loop thru all IRQ vectors */ |
| 1281 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1282 | /* Get the EQ corresponding to the IRQ vector */ |
| 1283 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1284 | if (!eq) |
| 1285 | continue; |
| 1286 | if (eq->q_mode) { |
| 1287 | update = true; |
| 1288 | break; |
| 1289 | } |
| 1290 | if (eqcnt[eq->last_cpu] < 2) |
| 1291 | eqcnt[eq->last_cpu]++; |
| 1292 | } |
| 1293 | } else |
| 1294 | update = true; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1295 | |
| 1296 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1297 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame^] | 1298 | if (!update && eqcnt[i] < 2) { |
| 1299 | eqi->icnt = 0; |
| 1300 | continue; |
| 1301 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1302 | |
| 1303 | usdelay = (eqi->icnt / LPFC_IMAX_THRESHOLD) * |
| 1304 | LPFC_EQ_DELAY_STEP; |
| 1305 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1306 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1307 | |
| 1308 | eqi->icnt = 0; |
| 1309 | |
| 1310 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
| 1311 | if (eq->last_cpu != i) { |
| 1312 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1313 | eq->last_cpu); |
| 1314 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1315 | continue; |
| 1316 | } |
| 1317 | if (usdelay != eq->q_mode) |
| 1318 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1319 | usdelay); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | kfree(eqcnt); |
| 1324 | |
| 1325 | requeue: |
| 1326 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1327 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1328 | } |
| 1329 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1330 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1331 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1332 | * @phba: pointer to lpfc hba data structure. |
| 1333 | * |
| 1334 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1335 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1336 | **/ |
| 1337 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1338 | { |
| 1339 | u32 i; |
| 1340 | u32 hwq_count; |
| 1341 | |
| 1342 | hwq_count = phba->cfg_hdw_queue; |
| 1343 | for (i = 0; i < hwq_count; i++) { |
| 1344 | /* Adjust XRIs in private pool */ |
| 1345 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1346 | |
| 1347 | /* Adjust high watermark */ |
| 1348 | lpfc_adjust_high_watermark(phba, i); |
| 1349 | |
| 1350 | #ifdef LPFC_MXP_STAT |
| 1351 | /* Snapshot pbl, pvt and busy count */ |
| 1352 | lpfc_snapshot_mxp(phba, i); |
| 1353 | #endif |
| 1354 | } |
| 1355 | } |
| 1356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1358 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1359 | * @phba: pointer to lpfc hba data structure. |
| 1360 | * |
| 1361 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1362 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1363 | * handler performs any periodic operations needed for the device. If such |
| 1364 | * periodic event has already been attended to either in the interrupt handler |
| 1365 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1366 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1367 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1368 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1369 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1370 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1371 | * to offline. |
| 1372 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1373 | void |
| 1374 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1375 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1376 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1377 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1378 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1379 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1380 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1381 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1382 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1383 | if (phba->cfg_xri_rebalancing) { |
| 1384 | /* Multi-XRI pools handler */ |
| 1385 | lpfc_hb_mxp_handler(phba); |
| 1386 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1387 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1388 | vports = lpfc_create_vport_work_array(phba); |
| 1389 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1390 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1391 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1392 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1393 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1394 | lpfc_destroy_vport_work_array(phba, vports); |
| 1395 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1396 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1397 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1398 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1399 | return; |
| 1400 | |
| 1401 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1402 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1403 | if (time_after(phba->last_completion_time + |
| 1404 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1405 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1406 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1407 | if (!phba->hb_outstanding) |
| 1408 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1409 | jiffies + |
| 1410 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1411 | else |
| 1412 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1413 | jiffies + |
| 1414 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1415 | return; |
| 1416 | } |
| 1417 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1418 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1419 | if (phba->elsbuf_cnt && |
| 1420 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1421 | spin_lock_irq(&phba->hbalock); |
| 1422 | list_splice_init(&phba->elsbuf, &completions); |
| 1423 | phba->elsbuf_cnt = 0; |
| 1424 | phba->elsbuf_prev_cnt = 0; |
| 1425 | spin_unlock_irq(&phba->hbalock); |
| 1426 | |
| 1427 | while (!list_empty(&completions)) { |
| 1428 | list_remove_head(&completions, buf_ptr, |
| 1429 | struct lpfc_dmabuf, list); |
| 1430 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1431 | kfree(buf_ptr); |
| 1432 | } |
| 1433 | } |
| 1434 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1435 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1436 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1437 | if (phba->cfg_enable_hba_heartbeat) { |
| 1438 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1439 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1440 | (list_empty(&psli->mboxq))) { |
| 1441 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1442 | GFP_KERNEL); |
| 1443 | if (!pmboxq) { |
| 1444 | mod_timer(&phba->hb_tmofunc, |
| 1445 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1446 | msecs_to_jiffies(1000 * |
| 1447 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1448 | return; |
| 1449 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1450 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1451 | lpfc_heart_beat(phba, pmboxq); |
| 1452 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1453 | pmboxq->vport = phba->pport; |
| 1454 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1455 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1456 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1457 | if (retval != MBX_BUSY && |
| 1458 | retval != MBX_SUCCESS) { |
| 1459 | mempool_free(pmboxq, |
| 1460 | phba->mbox_mem_pool); |
| 1461 | mod_timer(&phba->hb_tmofunc, |
| 1462 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1463 | msecs_to_jiffies(1000 * |
| 1464 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1465 | return; |
| 1466 | } |
| 1467 | phba->skipped_hb = 0; |
| 1468 | phba->hb_outstanding = 1; |
| 1469 | } else if (time_before_eq(phba->last_completion_time, |
| 1470 | phba->skipped_hb)) { |
| 1471 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1472 | "2857 Last completion time not " |
| 1473 | " updated in %d ms\n", |
| 1474 | jiffies_to_msecs(jiffies |
| 1475 | - phba->last_completion_time)); |
| 1476 | } else |
| 1477 | phba->skipped_hb = jiffies; |
| 1478 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1479 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1480 | jiffies + |
| 1481 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1482 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1483 | } else { |
| 1484 | /* |
| 1485 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1486 | * we need to give the hb mailbox cmd a chance to |
| 1487 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1488 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1489 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1490 | "0459 Adapter heartbeat still out" |
| 1491 | "standing:last compl time was %d ms.\n", |
| 1492 | jiffies_to_msecs(jiffies |
| 1493 | - phba->last_completion_time)); |
| 1494 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1495 | jiffies + |
| 1496 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1497 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1498 | } else { |
| 1499 | mod_timer(&phba->hb_tmofunc, |
| 1500 | jiffies + |
| 1501 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1505 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1506 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1507 | * @phba: pointer to lpfc hba data structure. |
| 1508 | * |
| 1509 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1510 | * other than Port Error 6 has been detected. |
| 1511 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1512 | static void |
| 1513 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1514 | { |
| 1515 | struct lpfc_sli *psli = &phba->sli; |
| 1516 | |
| 1517 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1518 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1519 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1520 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1521 | |
| 1522 | lpfc_offline(phba); |
| 1523 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1524 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1525 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1526 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1527 | lpfc_hba_down_post(phba); |
| 1528 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1529 | lpfc_unblock_mgmt_io(phba); |
| 1530 | phba->link_state = LPFC_HBA_ERROR; |
| 1531 | return; |
| 1532 | } |
| 1533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1535 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1536 | * @phba: pointer to lpfc hba data structure. |
| 1537 | * |
| 1538 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1539 | * other than Port Error 6 has been detected. |
| 1540 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1541 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1542 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1543 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1544 | spin_lock_irq(&phba->hbalock); |
| 1545 | phba->link_state = LPFC_HBA_ERROR; |
| 1546 | spin_unlock_irq(&phba->hbalock); |
| 1547 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1548 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1549 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1550 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1551 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1555 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1556 | * @phba: pointer to lpfc hba data structure. |
| 1557 | * |
| 1558 | * This routine is invoked to handle the deferred HBA hardware error |
| 1559 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1560 | * and another ER bit in the host status register. The driver will |
| 1561 | * wait until the ER1 bit clears before handling the error condition. |
| 1562 | **/ |
| 1563 | static void |
| 1564 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1565 | { |
| 1566 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1567 | struct lpfc_sli *psli = &phba->sli; |
| 1568 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1569 | /* If the pci channel is offline, ignore possible errors, |
| 1570 | * since we cannot communicate with the pci card anyway. |
| 1571 | */ |
| 1572 | if (pci_channel_offline(phba->pcidev)) { |
| 1573 | spin_lock_irq(&phba->hbalock); |
| 1574 | phba->hba_flag &= ~DEFER_ERATT; |
| 1575 | spin_unlock_irq(&phba->hbalock); |
| 1576 | return; |
| 1577 | } |
| 1578 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1580 | "0479 Deferred Adapter Hardware Error " |
| 1581 | "Data: x%x x%x x%x\n", |
| 1582 | phba->work_hs, |
| 1583 | phba->work_status[0], phba->work_status[1]); |
| 1584 | |
| 1585 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1586 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1587 | spin_unlock_irq(&phba->hbalock); |
| 1588 | |
| 1589 | |
| 1590 | /* |
| 1591 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1592 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1593 | * SCSI layer retry it after re-establishing link. |
| 1594 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1595 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1596 | |
| 1597 | /* |
| 1598 | * There was a firmware error. Take the hba offline and then |
| 1599 | * attempt to restart it. |
| 1600 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1601 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1602 | lpfc_offline(phba); |
| 1603 | |
| 1604 | /* Wait for the ER1 bit to clear.*/ |
| 1605 | while (phba->work_hs & HS_FFER1) { |
| 1606 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1607 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1608 | phba->work_hs = UNPLUG_ERR ; |
| 1609 | break; |
| 1610 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1611 | /* If driver is unloading let the worker thread continue */ |
| 1612 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1613 | phba->work_hs = 0; |
| 1614 | break; |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * This is to ptrotect against a race condition in which |
| 1620 | * first write to the host attention register clear the |
| 1621 | * host status register. |
| 1622 | */ |
| 1623 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1624 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1625 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1626 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1627 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1628 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1629 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1630 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1631 | } |
| 1632 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1633 | static void |
| 1634 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1635 | { |
| 1636 | struct lpfc_board_event_header board_event; |
| 1637 | struct Scsi_Host *shost; |
| 1638 | |
| 1639 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1640 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1641 | shost = lpfc_shost_from_vport(phba->pport); |
| 1642 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1643 | sizeof(board_event), |
| 1644 | (char *) &board_event, |
| 1645 | LPFC_NL_VENDOR_ID); |
| 1646 | } |
| 1647 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1648 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1649 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1650 | * @phba: pointer to lpfc hba data structure. |
| 1651 | * |
| 1652 | * This routine is invoked to handle the following HBA hardware error |
| 1653 | * conditions: |
| 1654 | * 1 - HBA error attention interrupt |
| 1655 | * 2 - DMA ring index out of range |
| 1656 | * 3 - Mailbox command came back as unknown |
| 1657 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1658 | static void |
| 1659 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1661 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1662 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1663 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1664 | unsigned long temperature; |
| 1665 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1666 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1667 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1668 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1669 | * since we cannot communicate with the pci card anyway. |
| 1670 | */ |
| 1671 | if (pci_channel_offline(phba->pcidev)) { |
| 1672 | spin_lock_irq(&phba->hbalock); |
| 1673 | phba->hba_flag &= ~DEFER_ERATT; |
| 1674 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1675 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1678 | /* If resets are disabled then leave the HBA alone and return */ |
| 1679 | if (!phba->cfg_enable_hba_reset) |
| 1680 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1682 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1683 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1684 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1685 | if (phba->hba_flag & DEFER_ERATT) |
| 1686 | lpfc_handle_deferred_eratt(phba); |
| 1687 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1688 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1689 | if (phba->work_hs & HS_FFER6) |
| 1690 | /* Re-establishing Link */ |
| 1691 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1692 | "1301 Re-establishing Link " |
| 1693 | "Data: x%x x%x x%x\n", |
| 1694 | phba->work_hs, phba->work_status[0], |
| 1695 | phba->work_status[1]); |
| 1696 | if (phba->work_hs & HS_FFER8) |
| 1697 | /* Device Zeroization */ |
| 1698 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1699 | "2861 Host Authentication device " |
| 1700 | "zeroization Data:x%x x%x x%x\n", |
| 1701 | phba->work_hs, phba->work_status[0], |
| 1702 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1703 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1705 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1706 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
| 1708 | /* |
| 1709 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1710 | * That could cause the I/Os dropped by the firmware. |
| 1711 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1712 | * retry it after re-establishing link. |
| 1713 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1714 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | /* |
| 1717 | * There was a firmware error. Take the hba offline and then |
| 1718 | * attempt to restart it. |
| 1719 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1720 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1722 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1724 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | return; |
| 1726 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1727 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1728 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1729 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1730 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1731 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1732 | temp_event_data.data = (uint32_t)temperature; |
| 1733 | |
| 1734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1735 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1736 | "(%ld), taking this port offline " |
| 1737 | "Data: x%x x%x x%x\n", |
| 1738 | temperature, phba->work_hs, |
| 1739 | phba->work_status[0], phba->work_status[1]); |
| 1740 | |
| 1741 | shost = lpfc_shost_from_vport(phba->pport); |
| 1742 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1743 | sizeof(temp_event_data), |
| 1744 | (char *) &temp_event_data, |
| 1745 | SCSI_NL_VID_TYPE_PCI |
| 1746 | | PCI_VENDOR_ID_EMULEX); |
| 1747 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1748 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1749 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1750 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1751 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1752 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1753 | } else { |
| 1754 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1755 | * failure is a value other than FFER6. Do not call the offline |
| 1756 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | */ |
| 1758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1759 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1760 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1761 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | phba->work_status[0], phba->work_status[1]); |
| 1763 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1764 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1765 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1766 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1767 | sizeof(event_data), (char *) &event_data, |
| 1768 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1769 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1770 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1772 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | } |
| 1774 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1775 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1776 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1777 | * @phba: pointer to lpfc hba data structure. |
| 1778 | * @mbx_action: flag for mailbox shutdown action. |
| 1779 | * |
| 1780 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1781 | * response to port status register polling attention. It waits for port |
| 1782 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1783 | * During this process, interrupt vectors are freed and later requested |
| 1784 | * for handling possible port resource change. |
| 1785 | **/ |
| 1786 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1787 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1788 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1789 | { |
| 1790 | int rc; |
| 1791 | uint32_t intr_mode; |
| 1792 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1793 | 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] | 1794 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1795 | /* |
| 1796 | * On error status condition, driver need to wait for port |
| 1797 | * ready before performing reset. |
| 1798 | */ |
| 1799 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1800 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1801 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1802 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1803 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1804 | /* need reset: attempt for port recovery */ |
| 1805 | if (en_rn_msg) |
| 1806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1807 | "2887 Reset Needed: Attempting Port " |
| 1808 | "Recovery...\n"); |
| 1809 | lpfc_offline_prep(phba, mbx_action); |
| 1810 | lpfc_offline(phba); |
| 1811 | /* release interrupt for possible resource change */ |
| 1812 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1813 | rc = lpfc_sli_brdrestart(phba); |
| 1814 | if (rc) { |
| 1815 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1816 | "6309 Failed to restart board\n"); |
| 1817 | return rc; |
| 1818 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1819 | /* request and enable interrupt */ |
| 1820 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1821 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1822 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1823 | "3175 Failed to enable interrupt\n"); |
| 1824 | return -EIO; |
| 1825 | } |
| 1826 | phba->intr_mode = intr_mode; |
| 1827 | rc = lpfc_online(phba); |
| 1828 | if (rc == 0) |
| 1829 | lpfc_unblock_mgmt_io(phba); |
| 1830 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1831 | return rc; |
| 1832 | } |
| 1833 | |
| 1834 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1835 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1836 | * @phba: pointer to lpfc hba data structure. |
| 1837 | * |
| 1838 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1839 | * conditions. |
| 1840 | **/ |
| 1841 | static void |
| 1842 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1843 | { |
| 1844 | struct lpfc_vport *vport = phba->pport; |
| 1845 | uint32_t event_data; |
| 1846 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1847 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1848 | struct lpfc_register portstat_reg = {0}; |
| 1849 | uint32_t reg_err1, reg_err2; |
| 1850 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1851 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1852 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1853 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1854 | struct lpfc_register portsmphr_reg; |
| 1855 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1856 | |
| 1857 | /* If the pci channel is offline, ignore possible errors, since |
| 1858 | * we cannot communicate with the pci card anyway. |
| 1859 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1860 | if (pci_channel_offline(phba->pcidev)) { |
| 1861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1862 | "3166 pci channel is offline\n"); |
| 1863 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1864 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1865 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1866 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1867 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1868 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1869 | switch (if_type) { |
| 1870 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1871 | pci_rd_rc1 = lpfc_readl( |
| 1872 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1873 | &uerrlo_reg); |
| 1874 | pci_rd_rc2 = lpfc_readl( |
| 1875 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1876 | &uemasklo_reg); |
| 1877 | /* consider PCI bus read error as pci_channel_offline */ |
| 1878 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1879 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1880 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1881 | lpfc_sli4_offline_eratt(phba); |
| 1882 | return; |
| 1883 | } |
| 1884 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1885 | "7623 Checking UE recoverable"); |
| 1886 | |
| 1887 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1888 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1889 | &portsmphr_reg.word0)) |
| 1890 | continue; |
| 1891 | |
| 1892 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1893 | &portsmphr_reg); |
| 1894 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1895 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1896 | break; |
| 1897 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1898 | msleep(1000); |
| 1899 | } |
| 1900 | |
| 1901 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1902 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1903 | smphr_port_status, i); |
| 1904 | |
| 1905 | /* Recoverable UE, reset the HBA device */ |
| 1906 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1907 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1908 | for (i = 0; i < 20; i++) { |
| 1909 | msleep(1000); |
| 1910 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1911 | &portsmphr_reg.word0) && |
| 1912 | (LPFC_POST_STAGE_PORT_READY == |
| 1913 | bf_get(lpfc_port_smphr_port_status, |
| 1914 | &portsmphr_reg))) { |
| 1915 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1916 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1917 | if (rc == 0) |
| 1918 | return; |
| 1919 | lpfc_printf_log(phba, |
| 1920 | KERN_ERR, LOG_INIT, |
| 1921 | "4215 Failed to recover UE"); |
| 1922 | break; |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1927 | "7624 Firmware not ready: Failing UE recovery," |
| 1928 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1929 | lpfc_sli4_offline_eratt(phba); |
| 1930 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1931 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1932 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1933 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1934 | pci_rd_rc1 = lpfc_readl( |
| 1935 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1936 | &portstat_reg.word0); |
| 1937 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1938 | if (pci_rd_rc1 == -EIO) { |
| 1939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1940 | "3151 PCI bus read access failure: x%x\n", |
| 1941 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1942 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1943 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1944 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1945 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1946 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1947 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1949 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1950 | "taking port offline Data: x%x x%x\n", |
| 1951 | reg_err1, reg_err2); |
| 1952 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1953 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1954 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1955 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1956 | temp_event_data.data = 0xFFFFFFFF; |
| 1957 | |
| 1958 | shost = lpfc_shost_from_vport(phba->pport); |
| 1959 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1960 | sizeof(temp_event_data), |
| 1961 | (char *)&temp_event_data, |
| 1962 | SCSI_NL_VID_TYPE_PCI |
| 1963 | | PCI_VENDOR_ID_EMULEX); |
| 1964 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1965 | spin_lock_irq(&phba->hbalock); |
| 1966 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1967 | spin_unlock_irq(&phba->hbalock); |
| 1968 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1969 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1970 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1971 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1972 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1974 | "3143 Port Down: Firmware Update " |
| 1975 | "Detected\n"); |
| 1976 | en_rn_msg = false; |
| 1977 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1978 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1980 | "3144 Port Down: Debug Dump\n"); |
| 1981 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1982 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1984 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1985 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1986 | /* If resets are disabled then leave the HBA alone and return */ |
| 1987 | if (!phba->cfg_enable_hba_reset) |
| 1988 | return; |
| 1989 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1990 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1991 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1992 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1993 | if (rc == 0) { |
| 1994 | /* don't report event on forced debug dump */ |
| 1995 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1996 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1997 | return; |
| 1998 | else |
| 1999 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2000 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2001 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2002 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2003 | "3152 Unrecoverable error, bring the port " |
| 2004 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2005 | lpfc_sli4_offline_eratt(phba); |
| 2006 | break; |
| 2007 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 2008 | default: |
| 2009 | break; |
| 2010 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2011 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2012 | "3123 Report dump event to upper layer\n"); |
| 2013 | /* Send an internal error event to mgmt application */ |
| 2014 | lpfc_board_errevt_to_mgmt(phba); |
| 2015 | |
| 2016 | event_data = FC_REG_DUMP_EVENT; |
| 2017 | shost = lpfc_shost_from_vport(vport); |
| 2018 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2019 | sizeof(event_data), (char *) &event_data, |
| 2020 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2025 | * @phba: pointer to lpfc HBA data structure. |
| 2026 | * |
| 2027 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2028 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2029 | * |
| 2030 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2031 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2032 | * Any other value - error. |
| 2033 | **/ |
| 2034 | void |
| 2035 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2036 | { |
| 2037 | (*phba->lpfc_handle_eratt)(phba); |
| 2038 | } |
| 2039 | |
| 2040 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2041 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2042 | * @phba: pointer to lpfc hba data structure. |
| 2043 | * |
| 2044 | * 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] | 2045 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2046 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2050 | struct lpfc_vport *vport = phba->pport; |
| 2051 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | LPFC_MBOXQ_t *pmb; |
| 2053 | volatile uint32_t control; |
| 2054 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2055 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | |
| 2057 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2058 | if (!pmb) { |
| 2059 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2061 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | |
| 2063 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2064 | if (!mp) { |
| 2065 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2067 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | |
| 2069 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2070 | if (!mp->virt) { |
| 2071 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2073 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2075 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2076 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | |
| 2078 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2079 | lpfc_read_topology(phba, pmb, mp); |
| 2080 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2082 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2083 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2084 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2085 | if (rc == MBX_NOT_FINISHED) { |
| 2086 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2087 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2088 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | |
| 2090 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2091 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | writel(HA_LATT, phba->HAregaddr); |
| 2093 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
| 2096 | return; |
| 2097 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2098 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2099 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2100 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | lpfc_handle_latt_free_mp: |
| 2102 | kfree(mp); |
| 2103 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2104 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | lpfc_handle_latt_err_exit: |
| 2106 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2109 | control = readl(phba->HCregaddr); |
| 2110 | control |= HC_LAINT_ENA; |
| 2111 | writel(control, phba->HCregaddr); |
| 2112 | readl(phba->HCregaddr); /* flush */ |
| 2113 | |
| 2114 | /* Clear Link Attention in HA REG */ |
| 2115 | writel(HA_LATT, phba->HAregaddr); |
| 2116 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2117 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2118 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2121 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2122 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | |
| 2124 | return; |
| 2125 | } |
| 2126 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2127 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2128 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2129 | * @phba: pointer to lpfc hba data structure. |
| 2130 | * @vpd: pointer to the vital product data. |
| 2131 | * @len: length of the vital product data in bytes. |
| 2132 | * |
| 2133 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2134 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2135 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2136 | * |
| 2137 | * Return codes |
| 2138 | * 0 - pointer to the VPD passed in is NULL |
| 2139 | * 1 - success |
| 2140 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2141 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2142 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | { |
| 2144 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2145 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | int i, j; |
| 2147 | int finished = 0; |
| 2148 | int index = 0; |
| 2149 | |
| 2150 | if (!vpd) |
| 2151 | return 0; |
| 2152 | |
| 2153 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2154 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2155 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2157 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2158 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | switch (vpd[index]) { |
| 2160 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2161 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | index += 1; |
| 2163 | lenlo = vpd[index]; |
| 2164 | index += 1; |
| 2165 | lenhi = vpd[index]; |
| 2166 | index += 1; |
| 2167 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2168 | index += i; |
| 2169 | break; |
| 2170 | case 0x90: |
| 2171 | index += 1; |
| 2172 | lenlo = vpd[index]; |
| 2173 | index += 1; |
| 2174 | lenhi = vpd[index]; |
| 2175 | index += 1; |
| 2176 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2177 | if (Length > len - index) |
| 2178 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2179 | while (Length > 0) { |
| 2180 | /* Look for Serial Number */ |
| 2181 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2182 | index += 2; |
| 2183 | i = vpd[index]; |
| 2184 | index += 1; |
| 2185 | j = 0; |
| 2186 | Length -= (3+i); |
| 2187 | while(i--) { |
| 2188 | phba->SerialNumber[j++] = vpd[index++]; |
| 2189 | if (j == 31) |
| 2190 | break; |
| 2191 | } |
| 2192 | phba->SerialNumber[j] = 0; |
| 2193 | continue; |
| 2194 | } |
| 2195 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2196 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2197 | index += 2; |
| 2198 | i = vpd[index]; |
| 2199 | index += 1; |
| 2200 | j = 0; |
| 2201 | Length -= (3+i); |
| 2202 | while(i--) { |
| 2203 | phba->ModelDesc[j++] = vpd[index++]; |
| 2204 | if (j == 255) |
| 2205 | break; |
| 2206 | } |
| 2207 | phba->ModelDesc[j] = 0; |
| 2208 | continue; |
| 2209 | } |
| 2210 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2211 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2212 | index += 2; |
| 2213 | i = vpd[index]; |
| 2214 | index += 1; |
| 2215 | j = 0; |
| 2216 | Length -= (3+i); |
| 2217 | while(i--) { |
| 2218 | phba->ModelName[j++] = vpd[index++]; |
| 2219 | if (j == 79) |
| 2220 | break; |
| 2221 | } |
| 2222 | phba->ModelName[j] = 0; |
| 2223 | continue; |
| 2224 | } |
| 2225 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2226 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2227 | index += 2; |
| 2228 | i = vpd[index]; |
| 2229 | index += 1; |
| 2230 | j = 0; |
| 2231 | Length -= (3+i); |
| 2232 | while(i--) { |
| 2233 | phba->ProgramType[j++] = vpd[index++]; |
| 2234 | if (j == 255) |
| 2235 | break; |
| 2236 | } |
| 2237 | phba->ProgramType[j] = 0; |
| 2238 | continue; |
| 2239 | } |
| 2240 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2241 | phba->vpd_flag |= VPD_PORT; |
| 2242 | index += 2; |
| 2243 | i = vpd[index]; |
| 2244 | index += 1; |
| 2245 | j = 0; |
| 2246 | Length -= (3+i); |
| 2247 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2248 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2249 | (phba->sli4_hba.pport_name_sta == |
| 2250 | LPFC_SLI4_PPNAME_GET)) { |
| 2251 | j++; |
| 2252 | index++; |
| 2253 | } else |
| 2254 | phba->Port[j++] = vpd[index++]; |
| 2255 | if (j == 19) |
| 2256 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2257 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2258 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2259 | (phba->sli4_hba.pport_name_sta == |
| 2260 | LPFC_SLI4_PPNAME_NON)) |
| 2261 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | continue; |
| 2263 | } |
| 2264 | else { |
| 2265 | index += 2; |
| 2266 | i = vpd[index]; |
| 2267 | index += 1; |
| 2268 | index += i; |
| 2269 | Length -= (3 + i); |
| 2270 | } |
| 2271 | } |
| 2272 | finished = 0; |
| 2273 | break; |
| 2274 | case 0x78: |
| 2275 | finished = 1; |
| 2276 | break; |
| 2277 | default: |
| 2278 | index ++; |
| 2279 | break; |
| 2280 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2281 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2282 | |
| 2283 | return(1); |
| 2284 | } |
| 2285 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2286 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2287 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2288 | * @phba: pointer to lpfc hba data structure. |
| 2289 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2290 | * @descp: pointer to the data structure to hold the derived description. |
| 2291 | * |
| 2292 | * This routine retrieves HBA's description based on its registered PCI device |
| 2293 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2294 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2295 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2296 | * function returns, the @mdp will be filled with the model name. |
| 2297 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2299 | 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] | 2300 | { |
| 2301 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2302 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2303 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2304 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2305 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2306 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2307 | char *name; |
| 2308 | char *bus; |
| 2309 | char *function; |
| 2310 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2311 | |
| 2312 | if (mdp && mdp[0] != '\0' |
| 2313 | && descp && descp[0] != '\0') |
| 2314 | return; |
| 2315 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2316 | if (phba->lmt & LMT_64Gb) |
| 2317 | max_speed = 64; |
| 2318 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2319 | max_speed = 32; |
| 2320 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2321 | max_speed = 16; |
| 2322 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2323 | max_speed = 10; |
| 2324 | else if (phba->lmt & LMT_8Gb) |
| 2325 | max_speed = 8; |
| 2326 | else if (phba->lmt & LMT_4Gb) |
| 2327 | max_speed = 4; |
| 2328 | else if (phba->lmt & LMT_2Gb) |
| 2329 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2330 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2331 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2332 | else |
| 2333 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | |
| 2335 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2337 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2338 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2339 | m = (typeof(m)){"LP6000", "PCI", |
| 2340 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2341 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | case PCI_DEVICE_ID_SUPERFLY: |
| 2343 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2344 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2346 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2347 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | break; |
| 2349 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2350 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2351 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | break; |
| 2353 | case PCI_DEVICE_ID_CENTAUR: |
| 2354 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2355 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2357 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2358 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | break; |
| 2360 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2361 | m = (typeof(m)){"LP952", "PCI", |
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_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2365 | m = (typeof(m)){"LP9802", "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_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2369 | m = (typeof(m)){"LP10000", "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_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2373 | m = (typeof(m)){"LPX1000", "PCI-X", |
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; |
| 2376 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2377 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2378 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2381 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2382 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | break; |
| 2384 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2385 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2386 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2388 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2389 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 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_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2393 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2394 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2395 | break; |
| 2396 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2397 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2398 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2399 | break; |
| 2400 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2401 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2402 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2403 | break; |
| 2404 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2405 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2406 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2407 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2409 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | break; |
| 2411 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2412 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2413 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | break; |
| 2415 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2416 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2418 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2419 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2420 | break; |
| 2421 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2422 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2423 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2424 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2426 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | break; |
| 2428 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2429 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | break; |
| 2431 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2432 | m = (typeof(m)){"LP101", "PCI-X", |
| 2433 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2434 | break; |
| 2435 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2436 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2437 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2438 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2439 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2440 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2441 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2442 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2443 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2444 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2445 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2446 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2447 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2448 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2449 | break; |
| 2450 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2451 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2452 | break; |
| 2453 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2454 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2455 | break; |
| 2456 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2457 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2458 | break; |
| 2459 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2460 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2461 | break; |
| 2462 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2463 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2464 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2465 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2466 | m = (typeof(m)){"LP21000", "PCIe", |
| 2467 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2468 | GE = 1; |
| 2469 | break; |
| 2470 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2471 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2472 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2473 | break; |
| 2474 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2475 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2476 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2477 | break; |
| 2478 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2479 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2480 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2481 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2482 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2483 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2484 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2485 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2486 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2487 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2488 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2489 | break; |
| 2490 | case PCI_DEVICE_ID_FALCON: |
| 2491 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2492 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2493 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2494 | case PCI_DEVICE_ID_BALIUS: |
| 2495 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2496 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2497 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2498 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2499 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2500 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2501 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2502 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2503 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2504 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2505 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2506 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2507 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2508 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2509 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2510 | oneConnect = 1; |
| 2511 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2512 | "Obsolete, Unsupported FCoE"}; |
| 2513 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2514 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2515 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2516 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2517 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2518 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2519 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2520 | case PCI_DEVICE_ID_SKYHAWK: |
| 2521 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2522 | oneConnect = 1; |
| 2523 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2524 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2525 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2526 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2527 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2528 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2529 | |
| 2530 | if (mdp && mdp[0] == '\0') |
| 2531 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2532 | /* |
| 2533 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2534 | * and we put the port number on the end |
| 2535 | */ |
| 2536 | if (descp && descp[0] == '\0') { |
| 2537 | if (oneConnect) |
| 2538 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2539 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2540 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2541 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2542 | else if (max_speed == 0) |
| 2543 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2544 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2545 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2546 | else |
| 2547 | snprintf(descp, 255, |
| 2548 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2549 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2550 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2551 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2552 | } |
| 2553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2555 | * 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] | 2556 | * @phba: pointer to lpfc hba data structure. |
| 2557 | * @pring: pointer to a IOCB ring. |
| 2558 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2559 | * |
| 2560 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2561 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2562 | * |
| 2563 | * Return codes |
| 2564 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2565 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2567 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2568 | { |
| 2569 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2570 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | struct lpfc_dmabuf *mp1, *mp2; |
| 2572 | |
| 2573 | cnt += pring->missbufcnt; |
| 2574 | |
| 2575 | /* While there are buffers to post */ |
| 2576 | while (cnt > 0) { |
| 2577 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2578 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | if (iocb == NULL) { |
| 2580 | pring->missbufcnt = cnt; |
| 2581 | return cnt; |
| 2582 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | icmd = &iocb->iocb; |
| 2584 | |
| 2585 | /* 2 buffers can be posted per command */ |
| 2586 | /* Allocate buffer to post */ |
| 2587 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2588 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2589 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2590 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2591 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2592 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | pring->missbufcnt = cnt; |
| 2594 | return cnt; |
| 2595 | } |
| 2596 | |
| 2597 | INIT_LIST_HEAD(&mp1->list); |
| 2598 | /* Allocate buffer to post */ |
| 2599 | if (cnt > 1) { |
| 2600 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2601 | if (mp2) |
| 2602 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2603 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2604 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2605 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2607 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2608 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | pring->missbufcnt = cnt; |
| 2610 | return cnt; |
| 2611 | } |
| 2612 | |
| 2613 | INIT_LIST_HEAD(&mp2->list); |
| 2614 | } else { |
| 2615 | mp2 = NULL; |
| 2616 | } |
| 2617 | |
| 2618 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2619 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2620 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2621 | icmd->ulpBdeCount = 1; |
| 2622 | cnt--; |
| 2623 | if (mp2) { |
| 2624 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2625 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2626 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2627 | cnt--; |
| 2628 | icmd->ulpBdeCount = 2; |
| 2629 | } |
| 2630 | |
| 2631 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2632 | icmd->ulpLe = 1; |
| 2633 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2634 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2635 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2637 | kfree(mp1); |
| 2638 | cnt++; |
| 2639 | if (mp2) { |
| 2640 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2641 | kfree(mp2); |
| 2642 | cnt++; |
| 2643 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2644 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2645 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | return cnt; |
| 2647 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2649 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | } |
| 2652 | pring->missbufcnt = 0; |
| 2653 | return 0; |
| 2654 | } |
| 2655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2656 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2657 | * 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] | 2658 | * @phba: pointer to lpfc hba data structure. |
| 2659 | * |
| 2660 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2661 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2662 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2663 | * |
| 2664 | * Return codes |
| 2665 | * 0 - success (currently always success) |
| 2666 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2668 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | { |
| 2670 | struct lpfc_sli *psli = &phba->sli; |
| 2671 | |
| 2672 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2673 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | /* Ring 2 - FCP no buffers needed */ |
| 2675 | |
| 2676 | return 0; |
| 2677 | } |
| 2678 | |
| 2679 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2682 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2683 | * @HashResultPointer: pointer to an array as hash table. |
| 2684 | * |
| 2685 | * This routine sets up the initial values to the array of hash table entries |
| 2686 | * for the LC HBAs. |
| 2687 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | static void |
| 2689 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2690 | { |
| 2691 | HashResultPointer[0] = 0x67452301; |
| 2692 | HashResultPointer[1] = 0xEFCDAB89; |
| 2693 | HashResultPointer[2] = 0x98BADCFE; |
| 2694 | HashResultPointer[3] = 0x10325476; |
| 2695 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2696 | } |
| 2697 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2698 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2699 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2700 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2701 | * @HashWorkingPointer: pointer to an working hash table. |
| 2702 | * |
| 2703 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2704 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2705 | * The results are putting back to the initial hash table, returned through |
| 2706 | * the @HashResultPointer as the result hash table. |
| 2707 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | static void |
| 2709 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2710 | { |
| 2711 | int t; |
| 2712 | uint32_t TEMP; |
| 2713 | uint32_t A, B, C, D, E; |
| 2714 | t = 16; |
| 2715 | do { |
| 2716 | HashWorkingPointer[t] = |
| 2717 | S(1, |
| 2718 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2719 | 8] ^ |
| 2720 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2721 | } while (++t <= 79); |
| 2722 | t = 0; |
| 2723 | A = HashResultPointer[0]; |
| 2724 | B = HashResultPointer[1]; |
| 2725 | C = HashResultPointer[2]; |
| 2726 | D = HashResultPointer[3]; |
| 2727 | E = HashResultPointer[4]; |
| 2728 | |
| 2729 | do { |
| 2730 | if (t < 20) { |
| 2731 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2732 | } else if (t < 40) { |
| 2733 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2734 | } else if (t < 60) { |
| 2735 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2736 | } else { |
| 2737 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2738 | } |
| 2739 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2740 | E = D; |
| 2741 | D = C; |
| 2742 | C = S(30, B); |
| 2743 | B = A; |
| 2744 | A = TEMP; |
| 2745 | } while (++t <= 79); |
| 2746 | |
| 2747 | HashResultPointer[0] += A; |
| 2748 | HashResultPointer[1] += B; |
| 2749 | HashResultPointer[2] += C; |
| 2750 | HashResultPointer[3] += D; |
| 2751 | HashResultPointer[4] += E; |
| 2752 | |
| 2753 | } |
| 2754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2756 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2757 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2758 | * @HashWorking: pointer to the entry of the working hash array. |
| 2759 | * |
| 2760 | * This routine calculates the working hash array referred by @HashWorking |
| 2761 | * from the challenge random numbers associated with the host, referred by |
| 2762 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2763 | * array and returned by reference through @HashWorking. |
| 2764 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | static void |
| 2766 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2767 | { |
| 2768 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2769 | } |
| 2770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2772 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2773 | * @phba: pointer to lpfc hba data structure. |
| 2774 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2775 | * |
| 2776 | * This routine performs the special handling for LC HBA initialization. |
| 2777 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2778 | void |
| 2779 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2780 | { |
| 2781 | int t; |
| 2782 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2783 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2784 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2785 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | if (!HashWorking) |
| 2787 | return; |
| 2788 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2790 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2791 | |
| 2792 | for (t = 0; t < 7; t++) |
| 2793 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2794 | |
| 2795 | lpfc_sha_init(hbainit); |
| 2796 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2797 | kfree(HashWorking); |
| 2798 | } |
| 2799 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2800 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2801 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2802 | * @vport: pointer to a virtual N_Port data structure. |
| 2803 | * |
| 2804 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2805 | * It invokes the discovery state machine to perform necessary state |
| 2806 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2807 | * the physical port is treated as @vport 0. |
| 2808 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2809 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2812 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2814 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2816 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2817 | lpfc_port_link_failure(vport); |
| 2818 | |
| 2819 | 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] | 2820 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2821 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2822 | NLP_STE_UNUSED_NODE); |
| 2823 | if (!ndlp) |
| 2824 | continue; |
| 2825 | spin_lock_irq(&phba->ndlp_lock); |
| 2826 | NLP_SET_FREE_REQ(ndlp); |
| 2827 | spin_unlock_irq(&phba->ndlp_lock); |
| 2828 | /* Trigger the release of the ndlp memory */ |
| 2829 | lpfc_nlp_put(ndlp); |
| 2830 | continue; |
| 2831 | } |
| 2832 | spin_lock_irq(&phba->ndlp_lock); |
| 2833 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2834 | /* The ndlp should not be in memory free mode already */ |
| 2835 | spin_unlock_irq(&phba->ndlp_lock); |
| 2836 | continue; |
| 2837 | } else |
| 2838 | /* Indicate request for freeing ndlp memory */ |
| 2839 | NLP_SET_FREE_REQ(ndlp); |
| 2840 | spin_unlock_irq(&phba->ndlp_lock); |
| 2841 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2842 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2843 | ndlp->nlp_DID == Fabric_DID) { |
| 2844 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2845 | lpfc_nlp_put(ndlp); |
| 2846 | continue; |
| 2847 | } |
| 2848 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2849 | /* take care of nodes in unused state before the state |
| 2850 | * machine taking action. |
| 2851 | */ |
| 2852 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2853 | lpfc_nlp_put(ndlp); |
| 2854 | continue; |
| 2855 | } |
| 2856 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2857 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2858 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2859 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2860 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2861 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2862 | NLP_EVT_DEVICE_RM); |
| 2863 | } |
| 2864 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2865 | /* At this point, ALL ndlp's should be gone |
| 2866 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2867 | * Lets wait for this to happen, if needed. |
| 2868 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2869 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2870 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2871 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2872 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2873 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2874 | &vport->fc_nodes, nlp_listp) { |
| 2875 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2876 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2877 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2878 | "usgmap:x%x refcnt:%d\n", |
| 2879 | ndlp->nlp_DID, (void *)ndlp, |
| 2880 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2881 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2882 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2883 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2884 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2885 | |
| 2886 | /* Wait for any activity on ndlps to settle */ |
| 2887 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2888 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2889 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2890 | } |
| 2891 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2892 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2893 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2894 | * @vport: pointer to a virtual N_Port data structure. |
| 2895 | * |
| 2896 | * This routine stops all the timers associated with a @vport. This function |
| 2897 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2898 | * port is treated as @vport 0. |
| 2899 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2900 | void |
| 2901 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2903 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2904 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2905 | lpfc_can_disctmo(vport); |
| 2906 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2907 | } |
| 2908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2909 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2910 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2911 | * @phba: pointer to lpfc hba data structure. |
| 2912 | * |
| 2913 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2914 | * caller of this routine should already hold the host lock. |
| 2915 | **/ |
| 2916 | void |
| 2917 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2918 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2919 | /* Clear pending FCF rediscovery wait flag */ |
| 2920 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2921 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2922 | /* Now, try to stop the timer */ |
| 2923 | del_timer(&phba->fcf.redisc_wait); |
| 2924 | } |
| 2925 | |
| 2926 | /** |
| 2927 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2928 | * @phba: pointer to lpfc hba data structure. |
| 2929 | * |
| 2930 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2931 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2932 | * lock held before proceeding with disabling the timer and clearing the |
| 2933 | * wait timer pendig flag. |
| 2934 | **/ |
| 2935 | void |
| 2936 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2937 | { |
| 2938 | spin_lock_irq(&phba->hbalock); |
| 2939 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2940 | /* FCF rediscovery timer already fired or stopped */ |
| 2941 | spin_unlock_irq(&phba->hbalock); |
| 2942 | return; |
| 2943 | } |
| 2944 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2945 | /* Clear failover in progress flags */ |
| 2946 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2947 | spin_unlock_irq(&phba->hbalock); |
| 2948 | } |
| 2949 | |
| 2950 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2951 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2952 | * @phba: pointer to lpfc hba data structure. |
| 2953 | * |
| 2954 | * This routine stops all the timers associated with a HBA. This function is |
| 2955 | * invoked before either putting a HBA offline or unloading the driver. |
| 2956 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2957 | void |
| 2958 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2959 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 2960 | if (phba->pport) |
| 2961 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 2962 | cancel_delayed_work_sync(&phba->eq_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2963 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2964 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2965 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2966 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2967 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2968 | del_timer_sync(&phba->rrq_tmr); |
| 2969 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2970 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2971 | phba->hb_outstanding = 0; |
| 2972 | |
| 2973 | switch (phba->pci_dev_grp) { |
| 2974 | case LPFC_PCI_DEV_LP: |
| 2975 | /* Stop any LightPulse device specific driver timers */ |
| 2976 | del_timer_sync(&phba->fcp_poll_timer); |
| 2977 | break; |
| 2978 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 2979 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2980 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2981 | break; |
| 2982 | default: |
| 2983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2984 | "0297 Invalid device group (x%x)\n", |
| 2985 | phba->pci_dev_grp); |
| 2986 | break; |
| 2987 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2988 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | } |
| 2990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2991 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2992 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2993 | * @phba: pointer to lpfc hba data structure. |
| 2994 | * |
| 2995 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2996 | * management interface is marked as blocked, all the user space access to |
| 2997 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2998 | * all be blocked. The HBA is set to block the management interface when the |
| 2999 | * driver prepares the HBA interface for online or offline. |
| 3000 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3001 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3002 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3003 | { |
| 3004 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3005 | uint8_t actcmd = MBX_HEARTBEAT; |
| 3006 | unsigned long timeout; |
| 3007 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3008 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3009 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3010 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3011 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3012 | return; |
| 3013 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3014 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3015 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3016 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3017 | /* Determine how long we might wait for the active mailbox |
| 3018 | * command to be gracefully completed by firmware. |
| 3019 | */ |
| 3020 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3021 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3022 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3023 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3024 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3025 | /* Wait for the outstnading mailbox command to complete */ |
| 3026 | while (phba->sli.mbox_active) { |
| 3027 | /* Check active mailbox complete status every 2ms */ |
| 3028 | msleep(2); |
| 3029 | if (time_after(jiffies, timeout)) { |
| 3030 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3031 | "2813 Mgmt IO is Blocked %x " |
| 3032 | "- mbox cmd %x still active\n", |
| 3033 | phba->sli.sli_flag, actcmd); |
| 3034 | break; |
| 3035 | } |
| 3036 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3039 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3040 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3041 | * @phba: pointer to lpfc hba data structure. |
| 3042 | * |
| 3043 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3044 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3045 | * is to fixup the temporary rpi assignments. |
| 3046 | **/ |
| 3047 | void |
| 3048 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3049 | { |
| 3050 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3051 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3052 | int i, rpi; |
| 3053 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3054 | |
| 3055 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3056 | return; |
| 3057 | |
| 3058 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3059 | if (vports == NULL) |
| 3060 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3061 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3062 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3063 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3064 | continue; |
| 3065 | |
| 3066 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3067 | &vports[i]->fc_nodes, |
| 3068 | nlp_listp) { |
| 3069 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3070 | continue; |
| 3071 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3072 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3073 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3074 | NLP_CLR_NODE_ACT(ndlp); |
| 3075 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3076 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3077 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3078 | ndlp->nlp_rpi = rpi; |
| 3079 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3080 | "0009 rpi:%x DID:%x " |
| 3081 | "flg:%x map:%x %p\n", ndlp->nlp_rpi, |
| 3082 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3083 | ndlp->nlp_usg_map, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | lpfc_destroy_vport_work_array(phba, vports); |
| 3087 | } |
| 3088 | |
| 3089 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3090 | * lpfc_create_expedite_pool - create expedite pool |
| 3091 | * @phba: pointer to lpfc hba data structure. |
| 3092 | * |
| 3093 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3094 | * to expedite pool. Mark them as expedite. |
| 3095 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3096 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3097 | { |
| 3098 | struct lpfc_sli4_hdw_queue *qp; |
| 3099 | struct lpfc_io_buf *lpfc_ncmd; |
| 3100 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3101 | struct lpfc_epd_pool *epd_pool; |
| 3102 | unsigned long iflag; |
| 3103 | |
| 3104 | epd_pool = &phba->epd_pool; |
| 3105 | qp = &phba->sli4_hba.hdwq[0]; |
| 3106 | |
| 3107 | spin_lock_init(&epd_pool->lock); |
| 3108 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3109 | spin_lock(&epd_pool->lock); |
| 3110 | INIT_LIST_HEAD(&epd_pool->list); |
| 3111 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3112 | &qp->lpfc_io_buf_list_put, list) { |
| 3113 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3114 | lpfc_ncmd->expedite = true; |
| 3115 | qp->put_io_bufs--; |
| 3116 | epd_pool->count++; |
| 3117 | if (epd_pool->count >= XRI_BATCH) |
| 3118 | break; |
| 3119 | } |
| 3120 | spin_unlock(&epd_pool->lock); |
| 3121 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3126 | * @phba: pointer to lpfc hba data structure. |
| 3127 | * |
| 3128 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3129 | * of HWQ 0. Clear the mark. |
| 3130 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3131 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3132 | { |
| 3133 | struct lpfc_sli4_hdw_queue *qp; |
| 3134 | struct lpfc_io_buf *lpfc_ncmd; |
| 3135 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3136 | struct lpfc_epd_pool *epd_pool; |
| 3137 | unsigned long iflag; |
| 3138 | |
| 3139 | epd_pool = &phba->epd_pool; |
| 3140 | qp = &phba->sli4_hba.hdwq[0]; |
| 3141 | |
| 3142 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3143 | spin_lock(&epd_pool->lock); |
| 3144 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3145 | &epd_pool->list, list) { |
| 3146 | list_move_tail(&lpfc_ncmd->list, |
| 3147 | &qp->lpfc_io_buf_list_put); |
| 3148 | lpfc_ncmd->flags = false; |
| 3149 | qp->put_io_bufs++; |
| 3150 | epd_pool->count--; |
| 3151 | } |
| 3152 | spin_unlock(&epd_pool->lock); |
| 3153 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3154 | } |
| 3155 | |
| 3156 | /** |
| 3157 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3158 | * @phba: pointer to lpfc hba data structure. |
| 3159 | * |
| 3160 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3161 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3162 | * Initialized. |
| 3163 | **/ |
| 3164 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3165 | { |
| 3166 | u32 i, j; |
| 3167 | u32 hwq_count; |
| 3168 | u32 count_per_hwq; |
| 3169 | struct lpfc_io_buf *lpfc_ncmd; |
| 3170 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3171 | unsigned long iflag; |
| 3172 | struct lpfc_sli4_hdw_queue *qp; |
| 3173 | struct lpfc_multixri_pool *multixri_pool; |
| 3174 | struct lpfc_pbl_pool *pbl_pool; |
| 3175 | struct lpfc_pvt_pool *pvt_pool; |
| 3176 | |
| 3177 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3178 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3179 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3180 | phba->sli4_hba.io_xri_cnt); |
| 3181 | |
| 3182 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3183 | lpfc_create_expedite_pool(phba); |
| 3184 | |
| 3185 | hwq_count = phba->cfg_hdw_queue; |
| 3186 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3187 | |
| 3188 | for (i = 0; i < hwq_count; i++) { |
| 3189 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3190 | |
| 3191 | if (!multixri_pool) { |
| 3192 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3193 | "1238 Failed to allocate memory for " |
| 3194 | "multixri_pool\n"); |
| 3195 | |
| 3196 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3197 | lpfc_destroy_expedite_pool(phba); |
| 3198 | |
| 3199 | j = 0; |
| 3200 | while (j < i) { |
| 3201 | qp = &phba->sli4_hba.hdwq[j]; |
| 3202 | kfree(qp->p_multixri_pool); |
| 3203 | j++; |
| 3204 | } |
| 3205 | phba->cfg_xri_rebalancing = 0; |
| 3206 | return; |
| 3207 | } |
| 3208 | |
| 3209 | qp = &phba->sli4_hba.hdwq[i]; |
| 3210 | qp->p_multixri_pool = multixri_pool; |
| 3211 | |
| 3212 | multixri_pool->xri_limit = count_per_hwq; |
| 3213 | multixri_pool->rrb_next_hwqid = i; |
| 3214 | |
| 3215 | /* Deal with public free xri pool */ |
| 3216 | pbl_pool = &multixri_pool->pbl_pool; |
| 3217 | spin_lock_init(&pbl_pool->lock); |
| 3218 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3219 | spin_lock(&pbl_pool->lock); |
| 3220 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3221 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3222 | &qp->lpfc_io_buf_list_put, list) { |
| 3223 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3224 | qp->put_io_bufs--; |
| 3225 | pbl_pool->count++; |
| 3226 | } |
| 3227 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3228 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3229 | pbl_pool->count, i); |
| 3230 | spin_unlock(&pbl_pool->lock); |
| 3231 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3232 | |
| 3233 | /* Deal with private free xri pool */ |
| 3234 | pvt_pool = &multixri_pool->pvt_pool; |
| 3235 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3236 | pvt_pool->low_watermark = XRI_BATCH; |
| 3237 | spin_lock_init(&pvt_pool->lock); |
| 3238 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3239 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3240 | pvt_pool->count = 0; |
| 3241 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3247 | * @phba: pointer to lpfc hba data structure. |
| 3248 | * |
| 3249 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3250 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3251 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3252 | { |
| 3253 | u32 i; |
| 3254 | u32 hwq_count; |
| 3255 | struct lpfc_io_buf *lpfc_ncmd; |
| 3256 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3257 | unsigned long iflag; |
| 3258 | struct lpfc_sli4_hdw_queue *qp; |
| 3259 | struct lpfc_multixri_pool *multixri_pool; |
| 3260 | struct lpfc_pbl_pool *pbl_pool; |
| 3261 | struct lpfc_pvt_pool *pvt_pool; |
| 3262 | |
| 3263 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3264 | lpfc_destroy_expedite_pool(phba); |
| 3265 | |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3266 | if (!(phba->pport->load_flag & FC_UNLOADING)) { |
| 3267 | lpfc_sli_flush_fcp_rings(phba); |
| 3268 | |
| 3269 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3270 | lpfc_sli_flush_nvme_rings(phba); |
| 3271 | } |
| 3272 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3273 | hwq_count = phba->cfg_hdw_queue; |
| 3274 | |
| 3275 | for (i = 0; i < hwq_count; i++) { |
| 3276 | qp = &phba->sli4_hba.hdwq[i]; |
| 3277 | multixri_pool = qp->p_multixri_pool; |
| 3278 | if (!multixri_pool) |
| 3279 | continue; |
| 3280 | |
| 3281 | qp->p_multixri_pool = NULL; |
| 3282 | |
| 3283 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3284 | |
| 3285 | /* Deal with public free xri pool */ |
| 3286 | pbl_pool = &multixri_pool->pbl_pool; |
| 3287 | spin_lock(&pbl_pool->lock); |
| 3288 | |
| 3289 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3290 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3291 | pbl_pool->count, i); |
| 3292 | |
| 3293 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3294 | &pbl_pool->list, list) { |
| 3295 | list_move_tail(&lpfc_ncmd->list, |
| 3296 | &qp->lpfc_io_buf_list_put); |
| 3297 | qp->put_io_bufs++; |
| 3298 | pbl_pool->count--; |
| 3299 | } |
| 3300 | |
| 3301 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3302 | pbl_pool->count = 0; |
| 3303 | |
| 3304 | spin_unlock(&pbl_pool->lock); |
| 3305 | |
| 3306 | /* Deal with private free xri pool */ |
| 3307 | pvt_pool = &multixri_pool->pvt_pool; |
| 3308 | spin_lock(&pvt_pool->lock); |
| 3309 | |
| 3310 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3311 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3312 | pvt_pool->count, i); |
| 3313 | |
| 3314 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3315 | &pvt_pool->list, list) { |
| 3316 | list_move_tail(&lpfc_ncmd->list, |
| 3317 | &qp->lpfc_io_buf_list_put); |
| 3318 | qp->put_io_bufs++; |
| 3319 | pvt_pool->count--; |
| 3320 | } |
| 3321 | |
| 3322 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3323 | pvt_pool->count = 0; |
| 3324 | |
| 3325 | spin_unlock(&pvt_pool->lock); |
| 3326 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3327 | |
| 3328 | kfree(multixri_pool); |
| 3329 | } |
| 3330 | } |
| 3331 | |
| 3332 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3333 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3334 | * @phba: pointer to lpfc hba data structure. |
| 3335 | * |
| 3336 | * This routine initializes the HBA and brings a HBA online. During this |
| 3337 | * process, the management interface is blocked to prevent user space access |
| 3338 | * to the HBA interfering with the driver initialization. |
| 3339 | * |
| 3340 | * Return codes |
| 3341 | * 0 - successful |
| 3342 | * 1 - failed |
| 3343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3345 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3347 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3348 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3349 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3350 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3351 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | if (!phba) |
| 3353 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3354 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3356 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3357 | return 0; |
| 3358 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3359 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3360 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3362 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3364 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3365 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3366 | lpfc_unblock_mgmt_io(phba); |
| 3367 | return 1; |
| 3368 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3369 | spin_lock_irq(&phba->hbalock); |
| 3370 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3371 | vpis_cleared = true; |
| 3372 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3373 | |
| 3374 | /* Reestablish the local initiator port. |
| 3375 | * The offline process destroyed the previous lport. |
| 3376 | */ |
| 3377 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3378 | !phba->nvmet_support) { |
| 3379 | error = lpfc_nvme_create_localport(phba->pport); |
| 3380 | if (error) |
| 3381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3382 | "6132 NVME restore reg failed " |
| 3383 | "on nvmei error x%x\n", error); |
| 3384 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3385 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3386 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3387 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3388 | lpfc_unblock_mgmt_io(phba); |
| 3389 | return 1; |
| 3390 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3391 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3393 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3394 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3395 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3396 | struct Scsi_Host *shost; |
| 3397 | shost = lpfc_shost_from_vport(vports[i]); |
| 3398 | spin_lock_irq(shost->host_lock); |
| 3399 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3400 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3401 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3402 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3403 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3404 | if ((vpis_cleared) && |
| 3405 | (vports[i]->port_type != |
| 3406 | LPFC_PHYSICAL_PORT)) |
| 3407 | vports[i]->vpi = 0; |
| 3408 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3409 | spin_unlock_irq(shost->host_lock); |
| 3410 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3411 | } |
| 3412 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3413 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3414 | if (phba->cfg_xri_rebalancing) |
| 3415 | lpfc_create_multixri_pools(phba); |
| 3416 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3417 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3418 | return 0; |
| 3419 | } |
| 3420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3422 | * 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] | 3423 | * @phba: pointer to lpfc hba data structure. |
| 3424 | * |
| 3425 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3426 | * HBA's management interface is marked as not blocked, all the user space |
| 3427 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3428 | * interface will be allowed. The HBA is set to block the management interface |
| 3429 | * when the driver prepares the HBA interface for online or offline and then |
| 3430 | * set to unblock the management interface afterwards. |
| 3431 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3432 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3433 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3434 | { |
| 3435 | unsigned long iflag; |
| 3436 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3437 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3438 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3439 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3440 | } |
| 3441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3443 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3444 | * @phba: pointer to lpfc hba data structure. |
| 3445 | * |
| 3446 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3447 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3448 | * queue to make it ready to be brought offline. |
| 3449 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3450 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3451 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3452 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3453 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3454 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3455 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3456 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3457 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3459 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3460 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3462 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | |
| 3464 | lpfc_linkdown(phba); |
| 3465 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3466 | /* Issue an unreg_login to all nodes on all vports */ |
| 3467 | vports = lpfc_create_vport_work_array(phba); |
| 3468 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3469 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3470 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3471 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3472 | shost = lpfc_shost_from_vport(vports[i]); |
| 3473 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3474 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3475 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3476 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3477 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3478 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3479 | shost = lpfc_shost_from_vport(vports[i]); |
| 3480 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3481 | &vports[i]->fc_nodes, |
| 3482 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3483 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3484 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3485 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3486 | continue; |
| 3487 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3488 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3489 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3490 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3491 | NULL, NLP_EVT_DEVICE_RM); |
| 3492 | } |
| 3493 | spin_lock_irq(shost->host_lock); |
| 3494 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3495 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3496 | /* |
| 3497 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3498 | * RPI. Get a new RPI when the adapter port |
| 3499 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3500 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3501 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3502 | lpfc_printf_vlog(ndlp->vport, |
| 3503 | KERN_INFO, LOG_NODE, |
| 3504 | "0011 lpfc_offline: " |
| 3505 | "ndlp:x%p did %x " |
| 3506 | "usgmap:x%x rpi:%x\n", |
| 3507 | ndlp, ndlp->nlp_DID, |
| 3508 | ndlp->nlp_usg_map, |
| 3509 | ndlp->nlp_rpi); |
| 3510 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3511 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3512 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3513 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3514 | } |
| 3515 | } |
| 3516 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3517 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3519 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3520 | |
| 3521 | if (phba->wq) |
| 3522 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3523 | } |
| 3524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3525 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3526 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3527 | * @phba: pointer to lpfc hba data structure. |
| 3528 | * |
| 3529 | * This routine actually brings a HBA offline. It stops all the timers |
| 3530 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3531 | * marks the HBA as in offline state for the upper layer protocol. |
| 3532 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3533 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3535 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3536 | struct Scsi_Host *shost; |
| 3537 | struct lpfc_vport **vports; |
| 3538 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3539 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3540 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3541 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3542 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3543 | /* stop port and all timers associated with this hba */ |
| 3544 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3545 | |
| 3546 | /* Tear down the local and target port registrations. The |
| 3547 | * nvme transports need to cleanup. |
| 3548 | */ |
| 3549 | lpfc_nvmet_destroy_targetport(phba); |
| 3550 | lpfc_nvme_destroy_localport(phba->pport); |
| 3551 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3552 | vports = lpfc_create_vport_work_array(phba); |
| 3553 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3554 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3555 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3556 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3557 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3558 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3559 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3560 | now. */ |
| 3561 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3562 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3563 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3564 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3565 | vports = lpfc_create_vport_work_array(phba); |
| 3566 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3567 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3568 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3569 | spin_lock_irq(shost->host_lock); |
| 3570 | vports[i]->work_port_events = 0; |
| 3571 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3572 | spin_unlock_irq(shost->host_lock); |
| 3573 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3574 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3575 | |
| 3576 | if (phba->cfg_xri_rebalancing) |
| 3577 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3578 | } |
| 3579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3580 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3581 | * 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] | 3582 | * @phba: pointer to lpfc hba data structure. |
| 3583 | * |
| 3584 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3585 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3586 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3587 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3588 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3589 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3591 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3592 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3593 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3594 | return; |
| 3595 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3596 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3597 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3598 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3599 | |
| 3600 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3601 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3602 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3603 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3604 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3605 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3606 | kfree(sb); |
| 3607 | phba->total_scsi_bufs--; |
| 3608 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3609 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3610 | |
| 3611 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3612 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3613 | list) { |
| 3614 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3615 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3616 | sb->dma_handle); |
| 3617 | kfree(sb); |
| 3618 | phba->total_scsi_bufs--; |
| 3619 | } |
| 3620 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3621 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3622 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3623 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3624 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3625 | * 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] | 3626 | * @phba: pointer to lpfc hba data structure. |
| 3627 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3628 | * 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] | 3629 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3630 | * the internal resources before the device is removed from the system. |
| 3631 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3632 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3633 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3634 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3635 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3636 | struct lpfc_sli4_hdw_queue *qp; |
| 3637 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3638 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3639 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3640 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3641 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3642 | spin_lock(&qp->io_buf_list_put_lock); |
| 3643 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3644 | &qp->lpfc_io_buf_list_put, |
| 3645 | list) { |
| 3646 | list_del(&lpfc_ncmd->list); |
| 3647 | qp->put_io_bufs--; |
| 3648 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3649 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3650 | kfree(lpfc_ncmd); |
| 3651 | qp->total_io_bufs--; |
| 3652 | } |
| 3653 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3654 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3655 | spin_lock(&qp->io_buf_list_get_lock); |
| 3656 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3657 | &qp->lpfc_io_buf_list_get, |
| 3658 | list) { |
| 3659 | list_del(&lpfc_ncmd->list); |
| 3660 | qp->get_io_bufs--; |
| 3661 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3662 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3663 | kfree(lpfc_ncmd); |
| 3664 | qp->total_io_bufs--; |
| 3665 | } |
| 3666 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3667 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3668 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3669 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3670 | /** |
| 3671 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3672 | * @phba: pointer to lpfc hba data structure. |
| 3673 | * |
| 3674 | * This routine first calculates the sizes of the current els and allocated |
| 3675 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3676 | * XRIs assigned due to port function reset. During port initialization, the |
| 3677 | * current els and allocated scsi sgl lists are 0s. |
| 3678 | * |
| 3679 | * Return codes |
| 3680 | * 0 - successful (for now, it always returns 0) |
| 3681 | **/ |
| 3682 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3683 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3684 | { |
| 3685 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3686 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3687 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3688 | int rc; |
| 3689 | |
| 3690 | /* |
| 3691 | * update on pci function's els xri-sgl list |
| 3692 | */ |
| 3693 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3694 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3695 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3696 | /* els xri-sgl expanded */ |
| 3697 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3698 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3699 | "3157 ELS xri-sgl count increased from " |
| 3700 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3701 | els_xri_cnt); |
| 3702 | /* allocate the additional els sgls */ |
| 3703 | for (i = 0; i < xri_cnt; i++) { |
| 3704 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3705 | GFP_KERNEL); |
| 3706 | if (sglq_entry == NULL) { |
| 3707 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3708 | "2562 Failure to allocate an " |
| 3709 | "ELS sgl entry:%d\n", i); |
| 3710 | rc = -ENOMEM; |
| 3711 | goto out_free_mem; |
| 3712 | } |
| 3713 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3714 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3715 | &sglq_entry->phys); |
| 3716 | if (sglq_entry->virt == NULL) { |
| 3717 | kfree(sglq_entry); |
| 3718 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3719 | "2563 Failure to allocate an " |
| 3720 | "ELS mbuf:%d\n", i); |
| 3721 | rc = -ENOMEM; |
| 3722 | goto out_free_mem; |
| 3723 | } |
| 3724 | sglq_entry->sgl = sglq_entry->virt; |
| 3725 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3726 | sglq_entry->state = SGL_FREED; |
| 3727 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3728 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3729 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3730 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3731 | list_splice_init(&els_sgl_list, |
| 3732 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3733 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3734 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3735 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3736 | /* els xri-sgl shrinked */ |
| 3737 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3738 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3739 | "3158 ELS xri-sgl count decreased from " |
| 3740 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3741 | els_xri_cnt); |
| 3742 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3743 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3744 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3745 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3746 | /* release extra els sgls from list */ |
| 3747 | for (i = 0; i < xri_cnt; i++) { |
| 3748 | list_remove_head(&els_sgl_list, |
| 3749 | sglq_entry, struct lpfc_sglq, list); |
| 3750 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3751 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3752 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3753 | kfree(sglq_entry); |
| 3754 | } |
| 3755 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3756 | list_splice_init(&els_sgl_list, |
| 3757 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3758 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3759 | spin_unlock_irq(&phba->hbalock); |
| 3760 | } else |
| 3761 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3762 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3763 | els_xri_cnt); |
| 3764 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3765 | |
| 3766 | /* update xris to els sgls on the list */ |
| 3767 | sglq_entry = NULL; |
| 3768 | sglq_entry_next = NULL; |
| 3769 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3770 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3771 | lxri = lpfc_sli4_next_xritag(phba); |
| 3772 | if (lxri == NO_XRI) { |
| 3773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3774 | "2400 Failed to allocate xri for " |
| 3775 | "ELS sgl\n"); |
| 3776 | rc = -ENOMEM; |
| 3777 | goto out_free_mem; |
| 3778 | } |
| 3779 | sglq_entry->sli4_lxritag = lxri; |
| 3780 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3781 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3782 | return 0; |
| 3783 | |
| 3784 | out_free_mem: |
| 3785 | lpfc_free_els_sgl_list(phba); |
| 3786 | return rc; |
| 3787 | } |
| 3788 | |
| 3789 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3790 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3791 | * @phba: pointer to lpfc hba data structure. |
| 3792 | * |
| 3793 | * This routine first calculates the sizes of the current els and allocated |
| 3794 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3795 | * XRIs assigned due to port function reset. During port initialization, the |
| 3796 | * current els and allocated scsi sgl lists are 0s. |
| 3797 | * |
| 3798 | * Return codes |
| 3799 | * 0 - successful (for now, it always returns 0) |
| 3800 | **/ |
| 3801 | int |
| 3802 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3803 | { |
| 3804 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3805 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3806 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3807 | LIST_HEAD(nvmet_sgl_list); |
| 3808 | int rc; |
| 3809 | |
| 3810 | /* |
| 3811 | * update on pci function's nvmet xri-sgl list |
| 3812 | */ |
| 3813 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3814 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3815 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3816 | 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] | 3817 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3818 | /* els xri-sgl expanded */ |
| 3819 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3820 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3821 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3822 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3823 | /* allocate the additional nvmet sgls */ |
| 3824 | for (i = 0; i < xri_cnt; i++) { |
| 3825 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3826 | GFP_KERNEL); |
| 3827 | if (sglq_entry == NULL) { |
| 3828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3829 | "6303 Failure to allocate an " |
| 3830 | "NVMET sgl entry:%d\n", i); |
| 3831 | rc = -ENOMEM; |
| 3832 | goto out_free_mem; |
| 3833 | } |
| 3834 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3835 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3836 | &sglq_entry->phys); |
| 3837 | if (sglq_entry->virt == NULL) { |
| 3838 | kfree(sglq_entry); |
| 3839 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3840 | "6304 Failure to allocate an " |
| 3841 | "NVMET buf:%d\n", i); |
| 3842 | rc = -ENOMEM; |
| 3843 | goto out_free_mem; |
| 3844 | } |
| 3845 | sglq_entry->sgl = sglq_entry->virt; |
| 3846 | memset(sglq_entry->sgl, 0, |
| 3847 | phba->cfg_sg_dma_buf_size); |
| 3848 | sglq_entry->state = SGL_FREED; |
| 3849 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3850 | } |
| 3851 | spin_lock_irq(&phba->hbalock); |
| 3852 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3853 | list_splice_init(&nvmet_sgl_list, |
| 3854 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3855 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3856 | spin_unlock_irq(&phba->hbalock); |
| 3857 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3858 | /* nvmet xri-sgl shrunk */ |
| 3859 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3860 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3861 | "6305 NVMET xri-sgl count decreased from " |
| 3862 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3863 | nvmet_xri_cnt); |
| 3864 | spin_lock_irq(&phba->hbalock); |
| 3865 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3866 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3867 | &nvmet_sgl_list); |
| 3868 | /* release extra nvmet sgls from list */ |
| 3869 | for (i = 0; i < xri_cnt; i++) { |
| 3870 | list_remove_head(&nvmet_sgl_list, |
| 3871 | sglq_entry, struct lpfc_sglq, list); |
| 3872 | if (sglq_entry) { |
| 3873 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3874 | sglq_entry->phys); |
| 3875 | kfree(sglq_entry); |
| 3876 | } |
| 3877 | } |
| 3878 | list_splice_init(&nvmet_sgl_list, |
| 3879 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3880 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3881 | spin_unlock_irq(&phba->hbalock); |
| 3882 | } else |
| 3883 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3884 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3885 | nvmet_xri_cnt); |
| 3886 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3887 | |
| 3888 | /* update xris to nvmet sgls on the list */ |
| 3889 | sglq_entry = NULL; |
| 3890 | sglq_entry_next = NULL; |
| 3891 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3892 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3893 | lxri = lpfc_sli4_next_xritag(phba); |
| 3894 | if (lxri == NO_XRI) { |
| 3895 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3896 | "6307 Failed to allocate xri for " |
| 3897 | "NVMET sgl\n"); |
| 3898 | rc = -ENOMEM; |
| 3899 | goto out_free_mem; |
| 3900 | } |
| 3901 | sglq_entry->sli4_lxritag = lxri; |
| 3902 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3903 | } |
| 3904 | return 0; |
| 3905 | |
| 3906 | out_free_mem: |
| 3907 | lpfc_free_nvmet_sgl_list(phba); |
| 3908 | return rc; |
| 3909 | } |
| 3910 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3911 | int |
| 3912 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3913 | { |
| 3914 | LIST_HEAD(blist); |
| 3915 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3916 | struct lpfc_io_buf *lpfc_cmd; |
| 3917 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3918 | int idx, cnt, xri, inserted; |
| 3919 | |
| 3920 | cnt = 0; |
| 3921 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3922 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3923 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 3924 | spin_lock(&qp->io_buf_list_put_lock); |
| 3925 | |
| 3926 | /* Take everything off the get and put lists */ |
| 3927 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 3928 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 3929 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 3930 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 3931 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 3932 | qp->get_io_bufs = 0; |
| 3933 | qp->put_io_bufs = 0; |
| 3934 | qp->total_io_bufs = 0; |
| 3935 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3936 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 3937 | } |
| 3938 | |
| 3939 | /* |
| 3940 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 3941 | * This is because POST_SGL takes a sequential range of XRIs |
| 3942 | * to post to the firmware. |
| 3943 | */ |
| 3944 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3945 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3946 | if (!lpfc_cmd) |
| 3947 | return cnt; |
| 3948 | if (idx == 0) { |
| 3949 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3950 | continue; |
| 3951 | } |
| 3952 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 3953 | inserted = 0; |
| 3954 | prev_iobufp = NULL; |
| 3955 | list_for_each_entry(iobufp, cbuf, list) { |
| 3956 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 3957 | if (prev_iobufp) |
| 3958 | list_add(&lpfc_cmd->list, |
| 3959 | &prev_iobufp->list); |
| 3960 | else |
| 3961 | list_add(&lpfc_cmd->list, cbuf); |
| 3962 | inserted = 1; |
| 3963 | break; |
| 3964 | } |
| 3965 | prev_iobufp = iobufp; |
| 3966 | } |
| 3967 | if (!inserted) |
| 3968 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3969 | } |
| 3970 | return cnt; |
| 3971 | } |
| 3972 | |
| 3973 | int |
| 3974 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3975 | { |
| 3976 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3977 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3978 | int idx, cnt; |
| 3979 | |
| 3980 | qp = phba->sli4_hba.hdwq; |
| 3981 | cnt = 0; |
| 3982 | while (!list_empty(cbuf)) { |
| 3983 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3984 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3985 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3986 | if (!lpfc_cmd) |
| 3987 | return cnt; |
| 3988 | cnt++; |
| 3989 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 3990 | lpfc_cmd->hdwq_no = idx; |
| 3991 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3992 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 3993 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 3994 | spin_lock(&qp->io_buf_list_put_lock); |
| 3995 | list_add_tail(&lpfc_cmd->list, |
| 3996 | &qp->lpfc_io_buf_list_put); |
| 3997 | qp->put_io_bufs++; |
| 3998 | qp->total_io_bufs++; |
| 3999 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4000 | } |
| 4001 | } |
| 4002 | return cnt; |
| 4003 | } |
| 4004 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4005 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4006 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4007 | * @phba: pointer to lpfc hba data structure. |
| 4008 | * |
| 4009 | * This routine first calculates the sizes of the current els and allocated |
| 4010 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4011 | * XRIs assigned due to port function reset. During port initialization, the |
| 4012 | * current els and allocated scsi sgl lists are 0s. |
| 4013 | * |
| 4014 | * Return codes |
| 4015 | * 0 - successful (for now, it always returns 0) |
| 4016 | **/ |
| 4017 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4018 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4019 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4020 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4021 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4022 | uint16_t io_xri_cnt, io_xri_max; |
| 4023 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4024 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4025 | |
| 4026 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4027 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4028 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4029 | |
| 4030 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4031 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4032 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4033 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4034 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4035 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4036 | "6074 Current allocated XRI sgl count:%d, " |
| 4037 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4038 | phba->sli4_hba.io_xri_cnt, |
| 4039 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4040 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4041 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4042 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4043 | 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] | 4044 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4045 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4046 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4047 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4048 | for (i = 0; i < io_xri_cnt; i++) { |
| 4049 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4050 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4051 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4052 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4053 | lpfc_ncmd->data, |
| 4054 | lpfc_ncmd->dma_handle); |
| 4055 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4056 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4057 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4058 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4059 | } |
| 4060 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4061 | /* update xris associated to remaining allocated nvme buffers */ |
| 4062 | lpfc_ncmd = NULL; |
| 4063 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4064 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4065 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4066 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4067 | lxri = lpfc_sli4_next_xritag(phba); |
| 4068 | if (lxri == NO_XRI) { |
| 4069 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4070 | "6075 Failed to allocate xri for " |
| 4071 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4072 | rc = -ENOMEM; |
| 4073 | goto out_free_mem; |
| 4074 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4075 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4076 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4077 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4078 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4080 | |
| 4081 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4082 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4083 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | } |
| 4085 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4086 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4087 | * 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] | 4088 | * @vport: The virtual port for which this call being executed. |
| 4089 | * @num_to_allocate: The requested number of buffers to allocate. |
| 4090 | * |
| 4091 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4092 | * the nvme buffer contains all the necessary information needed to initiate |
| 4093 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4094 | * them on a list, it post them to the port by using SGL block post. |
| 4095 | * |
| 4096 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4097 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4098 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4099 | **/ |
| 4100 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4101 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4102 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4103 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4104 | struct lpfc_iocbq *pwqeq; |
| 4105 | uint16_t iotag, lxri = 0; |
| 4106 | int bcnt, num_posted; |
| 4107 | LIST_HEAD(prep_nblist); |
| 4108 | LIST_HEAD(post_nblist); |
| 4109 | LIST_HEAD(nvme_nblist); |
| 4110 | |
| 4111 | /* 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] | 4112 | if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4113 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Arnd Bergmann | f996861 | 2019-03-04 20:39:09 +0100 | [diff] [blame] | 4114 | "6426 Common buffer size %zd exceeds %d\n", |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4115 | sizeof(struct lpfc_io_buf), |
| 4116 | LPFC_COMMON_IO_BUF_SZ); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4117 | return 0; |
| 4118 | } |
| 4119 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4120 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4121 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 4122 | lpfc_ncmd = kzalloc(LPFC_COMMON_IO_BUF_SZ, GFP_KERNEL); |
| 4123 | if (!lpfc_ncmd) |
| 4124 | break; |
| 4125 | /* |
| 4126 | * Get memory from the pci pool to map the virt space to |
| 4127 | * pci bus space for an I/O. The DMA buffer includes the |
| 4128 | * number of SGE's necessary to support the sg_tablesize. |
| 4129 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4130 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4131 | GFP_KERNEL, |
| 4132 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4133 | if (!lpfc_ncmd->data) { |
| 4134 | kfree(lpfc_ncmd); |
| 4135 | break; |
| 4136 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4137 | |
| 4138 | /* |
| 4139 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 4140 | * to be sure. |
| 4141 | */ |
| 4142 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4143 | (((unsigned long)(lpfc_ncmd->data) & |
| 4144 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
| 4145 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 4146 | "3369 Memory alignment err: addr=%lx\n", |
| 4147 | (unsigned long)lpfc_ncmd->data); |
| 4148 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4149 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4150 | kfree(lpfc_ncmd); |
| 4151 | break; |
| 4152 | } |
| 4153 | |
| 4154 | lxri = lpfc_sli4_next_xritag(phba); |
| 4155 | if (lxri == NO_XRI) { |
| 4156 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4157 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4158 | kfree(lpfc_ncmd); |
| 4159 | break; |
| 4160 | } |
| 4161 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4162 | |
| 4163 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4164 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4165 | if (iotag == 0) { |
| 4166 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4167 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4168 | kfree(lpfc_ncmd); |
| 4169 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, |
| 4170 | "6121 Failed to allocate IOTAG for" |
| 4171 | " XRI:0x%x\n", lxri); |
| 4172 | lpfc_sli4_free_xri(phba, lxri); |
| 4173 | break; |
| 4174 | } |
| 4175 | pwqeq->sli4_lxritag = lxri; |
| 4176 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4177 | pwqeq->context1 = lpfc_ncmd; |
| 4178 | |
| 4179 | /* Initialize local short-hand pointers. */ |
| 4180 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4181 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4182 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4183 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4184 | |
| 4185 | /* add the nvme buffer to a post list */ |
| 4186 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4187 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4188 | } |
| 4189 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4190 | "6114 Allocate %d out of %d requested new NVME " |
| 4191 | "buffers\n", bcnt, num_to_alloc); |
| 4192 | |
| 4193 | /* post the list of nvme buffer sgls to port if available */ |
| 4194 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4195 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4196 | phba, &post_nblist, bcnt); |
| 4197 | else |
| 4198 | num_posted = 0; |
| 4199 | |
| 4200 | return num_posted; |
| 4201 | } |
| 4202 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4203 | static uint64_t |
| 4204 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4205 | { |
| 4206 | uint64_t wwn; |
| 4207 | int rc; |
| 4208 | LPFC_MBOXQ_t *mboxq; |
| 4209 | MAILBOX_t *mb; |
| 4210 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4211 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4212 | GFP_KERNEL); |
| 4213 | if (!mboxq) |
| 4214 | return (uint64_t)-1; |
| 4215 | |
| 4216 | /* First get WWN of HBA instance */ |
| 4217 | lpfc_read_nv(phba, mboxq); |
| 4218 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4219 | if (rc != MBX_SUCCESS) { |
| 4220 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4221 | "6019 Mailbox failed , mbxCmd x%x " |
| 4222 | "READ_NV, mbxStatus x%x\n", |
| 4223 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4224 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4225 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4226 | return (uint64_t) -1; |
| 4227 | } |
| 4228 | mb = &mboxq->u.mb; |
| 4229 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4230 | /* wwn is WWPN of HBA instance */ |
| 4231 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4232 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4233 | return be64_to_cpu(wwn); |
| 4234 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4235 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4236 | } |
| 4237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4239 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4240 | * @phba: pointer to lpfc hba data structure. |
| 4241 | * @instance: a unique integer ID to this FC port. |
| 4242 | * @dev: pointer to the device data structure. |
| 4243 | * |
| 4244 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4245 | * can be created on top of either a physical port or a virtual port provided |
| 4246 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4247 | * and associates the FC port created before adding the shost into the SCSI |
| 4248 | * layer. |
| 4249 | * |
| 4250 | * Return codes |
| 4251 | * @vport - pointer to the virtual N_Port data structure. |
| 4252 | * NULL - port create failed. |
| 4253 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4254 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4255 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4256 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4257 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4258 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4259 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4260 | int i; |
| 4261 | uint64_t wwn; |
| 4262 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4263 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4264 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4265 | if (lpfc_no_hba_reset_cnt) { |
| 4266 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4267 | dev == &phba->pcidev->dev) { |
| 4268 | /* Reset the port first */ |
| 4269 | lpfc_sli_brdrestart(phba); |
| 4270 | rc = lpfc_sli_chipset_init(phba); |
| 4271 | if (rc) |
| 4272 | return NULL; |
| 4273 | } |
| 4274 | wwn = lpfc_get_wwpn(phba); |
| 4275 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4276 | |
| 4277 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4278 | if (wwn == lpfc_no_hba_reset[i]) { |
| 4279 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4280 | "6020 Setting use_no_reset port=%llx\n", |
| 4281 | wwn); |
| 4282 | use_no_reset_hba = true; |
| 4283 | break; |
| 4284 | } |
| 4285 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4286 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4287 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4288 | if (dev != &phba->pcidev->dev) { |
| 4289 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 4290 | sizeof(struct lpfc_vport)); |
| 4291 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4292 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4293 | shost = scsi_host_alloc(&lpfc_template, |
| 4294 | sizeof(struct lpfc_vport)); |
| 4295 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4296 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4297 | sizeof(struct lpfc_vport)); |
| 4298 | } |
| 4299 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 4300 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4301 | sizeof(struct lpfc_vport)); |
| 4302 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4303 | if (!shost) |
| 4304 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4305 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4307 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4308 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4309 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4310 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4311 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4312 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4313 | /* Adjust value in vport */ |
| 4314 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4315 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | shost->unique_id = instance; |
| 4317 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4318 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4319 | shost->this_id = -1; |
| 4320 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4321 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4322 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4323 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) |
| 4324 | shost->nr_hw_queues = phba->cfg_hdw_queue; |
| 4325 | else |
| 4326 | shost->nr_hw_queues = phba->sli4_hba.num_present_cpu; |
| 4327 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4328 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4329 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 4330 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4331 | } else |
| 4332 | /* SLI-3 has a limited number of hardware queues (3), |
| 4333 | * thus there is only one for FCP processing. |
| 4334 | */ |
| 4335 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4336 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4337 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4338 | * Set initial can_queue value since 0 is no longer supported and |
| 4339 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4340 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4341 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4342 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4343 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4344 | shost->transportt = lpfc_vport_transport_template; |
| 4345 | vport->port_type = LPFC_NPIV_PORT; |
| 4346 | } else { |
| 4347 | shost->transportt = lpfc_transport_template; |
| 4348 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4349 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4350 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4351 | /* Initialize all internally managed lists. */ |
| 4352 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4353 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4354 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4355 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4356 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4357 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4358 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4359 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4360 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4361 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4362 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4363 | lpfc_setup_bg(phba, shost); |
| 4364 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4365 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4366 | if (error) |
| 4367 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4368 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4369 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4371 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4372 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4373 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4374 | out_put_shost: |
| 4375 | scsi_host_put(shost); |
| 4376 | out: |
| 4377 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4378 | } |
| 4379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4381 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4382 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4383 | * |
| 4384 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4385 | * resources associated with the port are released. |
| 4386 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | void |
| 4388 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4389 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4390 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4391 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4392 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4393 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4394 | fc_remove_host(shost); |
| 4395 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4396 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4397 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4398 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4399 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4400 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4401 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4402 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4403 | } |
| 4404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4406 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4407 | * |
| 4408 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4409 | * uses the kernel idr facility to perform the task. |
| 4410 | * |
| 4411 | * Return codes: |
| 4412 | * instance - a unique integer ID allocated as the new instance. |
| 4413 | * -1 - lpfc get instance failed. |
| 4414 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4415 | int |
| 4416 | lpfc_get_instance(void) |
| 4417 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4418 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4419 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4420 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4421 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4422 | } |
| 4423 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4424 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4425 | * 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] | 4426 | * @shost: pointer to SCSI host data structure. |
| 4427 | * @time: elapsed time of the scan in jiffies. |
| 4428 | * |
| 4429 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4430 | * whether the scan host is finished. |
| 4431 | * |
| 4432 | * Note: there is no scan_start function as adapter initialization will have |
| 4433 | * asynchronously kicked off the link initialization. |
| 4434 | * |
| 4435 | * Return codes |
| 4436 | * 0 - SCSI host scan is not over yet. |
| 4437 | * 1 - SCSI host scan is over. |
| 4438 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4439 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4440 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4441 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4442 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4443 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4444 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4445 | spin_lock_irq(shost->host_lock); |
| 4446 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4447 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4448 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4449 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4450 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4451 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4452 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4453 | "0461 Scanning longer than 30 " |
| 4454 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4455 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4456 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4458 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4459 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4461 | "0465 Link down longer than 15 " |
| 4462 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4463 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4464 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4465 | } |
| 4466 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4467 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4468 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4469 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4470 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4471 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4472 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4473 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4474 | goto finished; |
| 4475 | |
| 4476 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4477 | |
| 4478 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4479 | spin_unlock_irq(shost->host_lock); |
| 4480 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4481 | } |
| 4482 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4483 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4484 | { |
| 4485 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4486 | struct lpfc_hba *phba = vport->phba; |
| 4487 | |
| 4488 | fc_host_supported_speeds(shost) = 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4489 | if (phba->lmt & LMT_128Gb) |
| 4490 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4491 | if (phba->lmt & LMT_64Gb) |
| 4492 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4493 | if (phba->lmt & LMT_32Gb) |
| 4494 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4495 | if (phba->lmt & LMT_16Gb) |
| 4496 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4497 | if (phba->lmt & LMT_10Gb) |
| 4498 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4499 | if (phba->lmt & LMT_8Gb) |
| 4500 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4501 | if (phba->lmt & LMT_4Gb) |
| 4502 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4503 | if (phba->lmt & LMT_2Gb) |
| 4504 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4505 | if (phba->lmt & LMT_1Gb) |
| 4506 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4507 | } |
| 4508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4510 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4511 | * @shost: pointer to SCSI host data structure. |
| 4512 | * |
| 4513 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4514 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4515 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4516 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4517 | { |
| 4518 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4519 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4520 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4521 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4522 | */ |
| 4523 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4524 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4525 | 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] | 4526 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4527 | |
| 4528 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4530 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4531 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4532 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4534 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4535 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4536 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4537 | |
| 4538 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4539 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4540 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4541 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4542 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4543 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4544 | /* This value is also unchanging */ |
| 4545 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4547 | fc_host_active_fc4s(shost)[2] = 1; |
| 4548 | fc_host_active_fc4s(shost)[7] = 1; |
| 4549 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4550 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4551 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4552 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4553 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4554 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4556 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4557 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4558 | * @phba: pointer to lpfc hba data structure. |
| 4559 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4560 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4561 | * from generating interrupts and stops the device driver's timers for the |
| 4562 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4563 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4564 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4565 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4566 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4567 | /* Clear all interrupt enable conditions */ |
| 4568 | writel(0, phba->HCregaddr); |
| 4569 | readl(phba->HCregaddr); /* flush */ |
| 4570 | /* Clear all pending interrupts */ |
| 4571 | writel(0xffffffff, phba->HAregaddr); |
| 4572 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4573 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4574 | /* Reset some HBA SLI setup states */ |
| 4575 | lpfc_stop_hba_timers(phba); |
| 4576 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4577 | } |
| 4578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4580 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4581 | * @phba: pointer to lpfc hba data structure. |
| 4582 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4583 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4584 | * from generating interrupts and stops the device driver's timers for the |
| 4585 | * device. |
| 4586 | **/ |
| 4587 | static void |
| 4588 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4589 | { |
| 4590 | /* Reset some HBA SLI4 setup states */ |
| 4591 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4592 | if (phba->pport) |
| 4593 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4594 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | /** |
| 4598 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4599 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4600 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4601 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4602 | * the API jump table function pointer from the lpfc_hba struct. |
| 4603 | **/ |
| 4604 | void |
| 4605 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4606 | { |
| 4607 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4608 | |
| 4609 | if (phba->wq) |
| 4610 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4614 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4615 | * @phba: Pointer to hba for which this call is being executed. |
| 4616 | * |
| 4617 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4618 | **/ |
| 4619 | void |
| 4620 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4621 | { |
| 4622 | unsigned long fcf_redisc_wait_tmo = |
| 4623 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4624 | /* Start fcf rediscovery wait period timer */ |
| 4625 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4626 | spin_lock_irq(&phba->hbalock); |
| 4627 | /* Allow action to new fcf asynchronous event */ |
| 4628 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4629 | /* Mark the FCF rediscovery pending state */ |
| 4630 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4631 | spin_unlock_irq(&phba->hbalock); |
| 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4636 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4637 | * |
| 4638 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4639 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4640 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4641 | * list, and then worker thread shall be waked up for processing from the |
| 4642 | * worker thread context. |
| 4643 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4644 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4645 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4646 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4647 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4648 | |
| 4649 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4650 | spin_lock_irq(&phba->hbalock); |
| 4651 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4652 | spin_unlock_irq(&phba->hbalock); |
| 4653 | return; |
| 4654 | } |
| 4655 | /* Clear FCF rediscovery timer pending flag */ |
| 4656 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4657 | /* FCF rediscovery event to worker thread */ |
| 4658 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4659 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4660 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4661 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4662 | /* wake up worker thread */ |
| 4663 | lpfc_worker_wake_up(phba); |
| 4664 | } |
| 4665 | |
| 4666 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4667 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4668 | * @phba: pointer to lpfc hba data structure. |
| 4669 | * @acqe_link: pointer to the async link completion queue entry. |
| 4670 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4671 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4673 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4674 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4675 | struct lpfc_acqe_link *acqe_link) |
| 4676 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4677 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4678 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4679 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4680 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4681 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4682 | break; |
| 4683 | default: |
| 4684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4685 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4686 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4687 | break; |
| 4688 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | /** |
| 4692 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4693 | * @phba: pointer to lpfc hba data structure. |
| 4694 | * @acqe_link: pointer to the async link completion queue entry. |
| 4695 | * |
| 4696 | * This routine is to parse the SLI4 link attention type and translate it |
| 4697 | * into the base driver's link attention type coding. |
| 4698 | * |
| 4699 | * Return: Link attention type in terms of base driver's coding. |
| 4700 | **/ |
| 4701 | static uint8_t |
| 4702 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4703 | struct lpfc_acqe_link *acqe_link) |
| 4704 | { |
| 4705 | uint8_t att_type; |
| 4706 | |
| 4707 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4708 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4709 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4710 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4711 | break; |
| 4712 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4713 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4714 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4715 | break; |
| 4716 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4717 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4718 | break; |
| 4719 | default: |
| 4720 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4721 | "0399 Invalid link attention type: x%x\n", |
| 4722 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4723 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4724 | break; |
| 4725 | } |
| 4726 | return att_type; |
| 4727 | } |
| 4728 | |
| 4729 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4730 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4731 | * @phba: pointer to lpfc hba data structure. |
| 4732 | * |
| 4733 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4734 | * |
| 4735 | * Return: link speed in terms of Mbps. |
| 4736 | **/ |
| 4737 | uint32_t |
| 4738 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4739 | { |
| 4740 | uint32_t link_speed; |
| 4741 | |
| 4742 | if (!lpfc_is_link_up(phba)) |
| 4743 | return 0; |
| 4744 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4745 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4746 | switch (phba->fc_linkspeed) { |
| 4747 | case LPFC_LINK_SPEED_1GHZ: |
| 4748 | link_speed = 1000; |
| 4749 | break; |
| 4750 | case LPFC_LINK_SPEED_2GHZ: |
| 4751 | link_speed = 2000; |
| 4752 | break; |
| 4753 | case LPFC_LINK_SPEED_4GHZ: |
| 4754 | link_speed = 4000; |
| 4755 | break; |
| 4756 | case LPFC_LINK_SPEED_8GHZ: |
| 4757 | link_speed = 8000; |
| 4758 | break; |
| 4759 | case LPFC_LINK_SPEED_10GHZ: |
| 4760 | link_speed = 10000; |
| 4761 | break; |
| 4762 | case LPFC_LINK_SPEED_16GHZ: |
| 4763 | link_speed = 16000; |
| 4764 | break; |
| 4765 | default: |
| 4766 | link_speed = 0; |
| 4767 | } |
| 4768 | } else { |
| 4769 | if (phba->sli4_hba.link_state.logical_speed) |
| 4770 | link_speed = |
| 4771 | phba->sli4_hba.link_state.logical_speed; |
| 4772 | else |
| 4773 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4774 | } |
| 4775 | return link_speed; |
| 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4780 | * @phba: pointer to lpfc hba data structure. |
| 4781 | * @evt_code: asynchronous event code. |
| 4782 | * @speed_code: asynchronous event link speed code. |
| 4783 | * |
| 4784 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4785 | * value of Mbps for the link speed. |
| 4786 | * |
| 4787 | * Return: link speed in terms of Mbps. |
| 4788 | **/ |
| 4789 | static uint32_t |
| 4790 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4791 | uint8_t speed_code) |
| 4792 | { |
| 4793 | uint32_t port_speed; |
| 4794 | |
| 4795 | switch (evt_code) { |
| 4796 | case LPFC_TRAILER_CODE_LINK: |
| 4797 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4798 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4799 | port_speed = 0; |
| 4800 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4801 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4802 | port_speed = 10; |
| 4803 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4804 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4805 | port_speed = 100; |
| 4806 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4807 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4808 | port_speed = 1000; |
| 4809 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4810 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4811 | port_speed = 10000; |
| 4812 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4813 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4814 | port_speed = 20000; |
| 4815 | break; |
| 4816 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4817 | port_speed = 25000; |
| 4818 | break; |
| 4819 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4820 | port_speed = 40000; |
| 4821 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4822 | default: |
| 4823 | port_speed = 0; |
| 4824 | } |
| 4825 | break; |
| 4826 | case LPFC_TRAILER_CODE_FC: |
| 4827 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4828 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4829 | port_speed = 0; |
| 4830 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4831 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4832 | port_speed = 1000; |
| 4833 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4834 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4835 | port_speed = 2000; |
| 4836 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4837 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4838 | port_speed = 4000; |
| 4839 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4840 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4841 | port_speed = 8000; |
| 4842 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4843 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4844 | port_speed = 10000; |
| 4845 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4846 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4847 | port_speed = 16000; |
| 4848 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4849 | case LPFC_FC_LA_SPEED_32G: |
| 4850 | port_speed = 32000; |
| 4851 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4852 | case LPFC_FC_LA_SPEED_64G: |
| 4853 | port_speed = 64000; |
| 4854 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4855 | case LPFC_FC_LA_SPEED_128G: |
| 4856 | port_speed = 128000; |
| 4857 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4858 | default: |
| 4859 | port_speed = 0; |
| 4860 | } |
| 4861 | break; |
| 4862 | default: |
| 4863 | port_speed = 0; |
| 4864 | } |
| 4865 | return port_speed; |
| 4866 | } |
| 4867 | |
| 4868 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4869 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4870 | * @phba: pointer to lpfc hba data structure. |
| 4871 | * @acqe_link: pointer to the async link completion queue entry. |
| 4872 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4873 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4874 | **/ |
| 4875 | static void |
| 4876 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4877 | struct lpfc_acqe_link *acqe_link) |
| 4878 | { |
| 4879 | struct lpfc_dmabuf *mp; |
| 4880 | LPFC_MBOXQ_t *pmb; |
| 4881 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4882 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4883 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4884 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4885 | |
| 4886 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4887 | 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] | 4888 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4889 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4890 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4891 | if (!pmb) { |
| 4892 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4893 | "0395 The mboxq allocation failed\n"); |
| 4894 | return; |
| 4895 | } |
| 4896 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4897 | if (!mp) { |
| 4898 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4899 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4900 | goto out_free_pmb; |
| 4901 | } |
| 4902 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4903 | if (!mp->virt) { |
| 4904 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4905 | "0397 The mbuf allocation failed\n"); |
| 4906 | goto out_free_dmabuf; |
| 4907 | } |
| 4908 | |
| 4909 | /* Cleanup any outstanding ELS commands */ |
| 4910 | lpfc_els_flush_all_cmd(phba); |
| 4911 | |
| 4912 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4913 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4914 | |
| 4915 | /* Update link event statistics */ |
| 4916 | phba->sli.slistat.link_event++; |
| 4917 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4918 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4919 | lpfc_read_topology(phba, pmb, mp); |
| 4920 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4921 | pmb->vport = phba->pport; |
| 4922 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4923 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4924 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4925 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4926 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4927 | phba->sli4_hba.link_state.duplex = |
| 4928 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4929 | phba->sli4_hba.link_state.status = |
| 4930 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4931 | phba->sli4_hba.link_state.type = |
| 4932 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4933 | phba->sli4_hba.link_state.number = |
| 4934 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4935 | phba->sli4_hba.link_state.fault = |
| 4936 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4937 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4938 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4939 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4940 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4941 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4942 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4943 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4944 | phba->sli4_hba.link_state.speed, |
| 4945 | phba->sli4_hba.link_state.topology, |
| 4946 | phba->sli4_hba.link_state.status, |
| 4947 | phba->sli4_hba.link_state.type, |
| 4948 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4949 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4950 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4951 | /* |
| 4952 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4953 | * topology info. Note: Optional for non FC-AL ports. |
| 4954 | */ |
| 4955 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4956 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4957 | if (rc == MBX_NOT_FINISHED) |
| 4958 | goto out_free_dmabuf; |
| 4959 | return; |
| 4960 | } |
| 4961 | /* |
| 4962 | * For FCoE Mode: fill in all the topology information we need and call |
| 4963 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4964 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4965 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4966 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4967 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4968 | mb->mbxStatus = MBX_SUCCESS; |
| 4969 | |
| 4970 | /* Parse port fault information field */ |
| 4971 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4972 | |
| 4973 | /* Parse and translate link attention fields */ |
| 4974 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4975 | la->eventTag = acqe_link->event_tag; |
| 4976 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4977 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4978 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4979 | |
| 4980 | /* Fake the the following irrelvant fields */ |
| 4981 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4982 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4983 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4984 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4985 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4986 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4987 | |
| 4988 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4989 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4990 | |
| 4991 | return; |
| 4992 | |
| 4993 | out_free_dmabuf: |
| 4994 | kfree(mp); |
| 4995 | out_free_pmb: |
| 4996 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4997 | } |
| 4998 | |
| 4999 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5000 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 5001 | * topology. |
| 5002 | * @phba: pointer to lpfc hba data structure. |
| 5003 | * @evt_code: asynchronous event code. |
| 5004 | * @speed_code: asynchronous event link speed code. |
| 5005 | * |
| 5006 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5007 | * value of Read topology link speed. |
| 5008 | * |
| 5009 | * Return: link speed in terms of Read topology. |
| 5010 | **/ |
| 5011 | static uint8_t |
| 5012 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5013 | { |
| 5014 | uint8_t port_speed; |
| 5015 | |
| 5016 | switch (speed_code) { |
| 5017 | case LPFC_FC_LA_SPEED_1G: |
| 5018 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5019 | break; |
| 5020 | case LPFC_FC_LA_SPEED_2G: |
| 5021 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5022 | break; |
| 5023 | case LPFC_FC_LA_SPEED_4G: |
| 5024 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5025 | break; |
| 5026 | case LPFC_FC_LA_SPEED_8G: |
| 5027 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5028 | break; |
| 5029 | case LPFC_FC_LA_SPEED_16G: |
| 5030 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5031 | break; |
| 5032 | case LPFC_FC_LA_SPEED_32G: |
| 5033 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5034 | break; |
| 5035 | case LPFC_FC_LA_SPEED_64G: |
| 5036 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5037 | break; |
| 5038 | case LPFC_FC_LA_SPEED_128G: |
| 5039 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5040 | break; |
| 5041 | case LPFC_FC_LA_SPEED_256G: |
| 5042 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5043 | break; |
| 5044 | default: |
| 5045 | port_speed = 0; |
| 5046 | break; |
| 5047 | } |
| 5048 | |
| 5049 | return port_speed; |
| 5050 | } |
| 5051 | |
| 5052 | #define trunk_link_status(__idx)\ |
| 5053 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5054 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5055 | "Link up" : "Link down") : "NA" |
| 5056 | /* Did port __idx reported an error */ |
| 5057 | #define trunk_port_fault(__idx)\ |
| 5058 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5059 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5060 | |
| 5061 | static void |
| 5062 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5063 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5064 | { |
| 5065 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5066 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5067 | |
| 5068 | phba->sli4_hba.link_state.speed = |
| 5069 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5070 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5071 | |
| 5072 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5073 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5074 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5075 | phba->fc_linkspeed = |
| 5076 | lpfc_async_link_speed_to_read_top( |
| 5077 | phba, |
| 5078 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5079 | |
| 5080 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5081 | phba->trunk_link.link0.state = |
| 5082 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5083 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5084 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5085 | } |
| 5086 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5087 | phba->trunk_link.link1.state = |
| 5088 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5089 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5090 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5091 | } |
| 5092 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5093 | phba->trunk_link.link2.state = |
| 5094 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5095 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5096 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5097 | } |
| 5098 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5099 | phba->trunk_link.link3.state = |
| 5100 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5101 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5102 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5106 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5107 | "\tLogical speed:%d " |
| 5108 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5109 | phba->sli4_hba.link_state.speed, |
| 5110 | phba->sli4_hba.link_state.logical_speed, |
| 5111 | trunk_link_status(0), trunk_link_status(1), |
| 5112 | trunk_link_status(2), trunk_link_status(3)); |
| 5113 | |
| 5114 | if (port_fault) |
| 5115 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5116 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5117 | /* |
| 5118 | * SLI-4: We have only 0xA error codes |
| 5119 | * defined as of now. print an appropriate |
| 5120 | * message in case driver needs to be updated. |
| 5121 | */ |
| 5122 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5123 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5124 | trunk_port_fault(0), trunk_port_fault(1), |
| 5125 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5126 | } |
| 5127 | |
| 5128 | |
| 5129 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5130 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5131 | * @phba: pointer to lpfc hba data structure. |
| 5132 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5133 | * |
| 5134 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5135 | * that the event was received and then issue a read_topology mailbox command so |
| 5136 | * that the rest of the driver will treat it the same as SLI3. |
| 5137 | **/ |
| 5138 | static void |
| 5139 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5140 | { |
| 5141 | struct lpfc_dmabuf *mp; |
| 5142 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5143 | MAILBOX_t *mb; |
| 5144 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5145 | int rc; |
| 5146 | |
| 5147 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5148 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 5149 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5150 | "2895 Non FC link Event detected.(%d)\n", |
| 5151 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5152 | return; |
| 5153 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5154 | |
| 5155 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5156 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5157 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5158 | return; |
| 5159 | } |
| 5160 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5161 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5162 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5163 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5164 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5165 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5166 | phba->sli4_hba.link_state.topology = |
| 5167 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5168 | phba->sli4_hba.link_state.status = |
| 5169 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5170 | phba->sli4_hba.link_state.type = |
| 5171 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5172 | phba->sli4_hba.link_state.number = |
| 5173 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5174 | phba->sli4_hba.link_state.fault = |
| 5175 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5176 | |
| 5177 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5178 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5179 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5180 | else if (!phba->sli4_hba.conf_trunk) |
| 5181 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5182 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5183 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5184 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5185 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5186 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5187 | "%dMbps Fault:%d\n", |
| 5188 | phba->sli4_hba.link_state.speed, |
| 5189 | phba->sli4_hba.link_state.topology, |
| 5190 | phba->sli4_hba.link_state.status, |
| 5191 | phba->sli4_hba.link_state.type, |
| 5192 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5193 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5194 | phba->sli4_hba.link_state.fault); |
| 5195 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5196 | if (!pmb) { |
| 5197 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5198 | "2897 The mboxq allocation failed\n"); |
| 5199 | return; |
| 5200 | } |
| 5201 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5202 | if (!mp) { |
| 5203 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5204 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5205 | goto out_free_pmb; |
| 5206 | } |
| 5207 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5208 | if (!mp->virt) { |
| 5209 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5210 | "2899 The mbuf allocation failed\n"); |
| 5211 | goto out_free_dmabuf; |
| 5212 | } |
| 5213 | |
| 5214 | /* Cleanup any outstanding ELS commands */ |
| 5215 | lpfc_els_flush_all_cmd(phba); |
| 5216 | |
| 5217 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5218 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5219 | |
| 5220 | /* Update link event statistics */ |
| 5221 | phba->sli.slistat.link_event++; |
| 5222 | |
| 5223 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5224 | lpfc_read_topology(phba, pmb, mp); |
| 5225 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5226 | pmb->vport = phba->pport; |
| 5227 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5228 | 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] | 5229 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5230 | |
| 5231 | switch (phba->sli4_hba.link_state.status) { |
| 5232 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5233 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5234 | break; |
| 5235 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5236 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5237 | break; |
| 5238 | default: |
| 5239 | break; |
| 5240 | } |
| 5241 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5242 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5243 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5244 | mb->mbxStatus = MBX_SUCCESS; |
| 5245 | |
| 5246 | /* Parse port fault information field */ |
| 5247 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5248 | |
| 5249 | /* Parse and translate link attention fields */ |
| 5250 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5251 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5252 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5253 | if (phba->sli4_hba.link_state.status == |
| 5254 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5255 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5256 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5257 | } else { |
| 5258 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5259 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5260 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5261 | /* Invoke the mailbox command callback function */ |
| 5262 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5263 | |
| 5264 | return; |
| 5265 | } |
| 5266 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5267 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5268 | if (rc == MBX_NOT_FINISHED) |
| 5269 | goto out_free_dmabuf; |
| 5270 | return; |
| 5271 | |
| 5272 | out_free_dmabuf: |
| 5273 | kfree(mp); |
| 5274 | out_free_pmb: |
| 5275 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5276 | } |
| 5277 | |
| 5278 | /** |
| 5279 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5280 | * @phba: pointer to lpfc hba data structure. |
| 5281 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 5282 | * |
| 5283 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5284 | **/ |
| 5285 | static void |
| 5286 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5287 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5288 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5289 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5290 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5291 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5292 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5293 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5294 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5295 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5296 | struct lpfc_vport **vports; |
| 5297 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5298 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5299 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5300 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5301 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5302 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5303 | "x%08x SLI Event Type:%d\n", |
| 5304 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5305 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5306 | |
| 5307 | port_name = phba->Port[0]; |
| 5308 | if (port_name == 0x00) |
| 5309 | port_name = '?'; /* get port name is empty */ |
| 5310 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5311 | switch (evt_type) { |
| 5312 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5313 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5314 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5315 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5316 | |
| 5317 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5318 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5319 | acqe_sli->event_data1, port_name); |
| 5320 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5321 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5322 | shost = lpfc_shost_from_vport(phba->pport); |
| 5323 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5324 | sizeof(temp_event_data), |
| 5325 | (char *)&temp_event_data, |
| 5326 | SCSI_NL_VID_TYPE_PCI |
| 5327 | | PCI_VENDOR_ID_EMULEX); |
| 5328 | break; |
| 5329 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5330 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5331 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5332 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5333 | |
| 5334 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5335 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5336 | acqe_sli->event_data1, port_name); |
| 5337 | |
| 5338 | shost = lpfc_shost_from_vport(phba->pport); |
| 5339 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5340 | sizeof(temp_event_data), |
| 5341 | (char *)&temp_event_data, |
| 5342 | SCSI_NL_VID_TYPE_PCI |
| 5343 | | PCI_VENDOR_ID_EMULEX); |
| 5344 | break; |
| 5345 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5346 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5347 | &acqe_sli->event_data1; |
| 5348 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5349 | /* fetch the status for this port */ |
| 5350 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5351 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5352 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5353 | &misconfigured->theEvent); |
| 5354 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5355 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5356 | break; |
| 5357 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5358 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5359 | &misconfigured->theEvent); |
| 5360 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5361 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5362 | break; |
| 5363 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5364 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5365 | &misconfigured->theEvent); |
| 5366 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5367 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5368 | break; |
| 5369 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5370 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5371 | &misconfigured->theEvent); |
| 5372 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5373 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5374 | break; |
| 5375 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5377 | "3296 " |
| 5378 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5379 | "event: Invalid link %d", |
| 5380 | phba->sli4_hba.lnk_info.lnk_no); |
| 5381 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5382 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5383 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5384 | /* Skip if optic state unchanged */ |
| 5385 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5386 | return; |
| 5387 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5388 | switch (status) { |
| 5389 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5390 | sprintf(message, "Physical Link is functional"); |
| 5391 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5392 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5393 | sprintf(message, "Optics faulted/incorrectly " |
| 5394 | "installed/not installed - Reseat optics, " |
| 5395 | "if issue not resolved, replace."); |
| 5396 | break; |
| 5397 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5398 | sprintf(message, |
| 5399 | "Optics of two types installed - Remove one " |
| 5400 | "optic or install matching pair of optics."); |
| 5401 | break; |
| 5402 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5403 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5404 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5405 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5406 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5407 | sprintf(message, "Unqualified optics - Replace with " |
| 5408 | "Avago optics for Warranty and Technical " |
| 5409 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5410 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5411 | break; |
| 5412 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5413 | sprintf(message, "Uncertified optics - Replace with " |
| 5414 | "Avago-certified optics to enable link " |
| 5415 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5416 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5417 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5418 | default: |
| 5419 | /* firmware is reporting a status we don't know about */ |
| 5420 | sprintf(message, "Unknown event status x%02x", status); |
| 5421 | break; |
| 5422 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5423 | |
| 5424 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5425 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5426 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5427 | phba->lmt = 0; |
| 5428 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5429 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5430 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5431 | } |
| 5432 | vports = lpfc_create_vport_work_array(phba); |
| 5433 | if (vports != NULL) { |
| 5434 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5435 | i++) { |
| 5436 | shost = lpfc_shost_from_vport(vports[i]); |
| 5437 | lpfc_host_supported_speeds_set(shost); |
| 5438 | } |
| 5439 | } |
| 5440 | lpfc_destroy_vport_work_array(phba, vports); |
| 5441 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5442 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5443 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5444 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5445 | break; |
| 5446 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5447 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5448 | "3192 Remote DPort Test Initiated - " |
| 5449 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5450 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5451 | break; |
| 5452 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5453 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5454 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5455 | "x%08x SLI Event Type:%d\n", |
| 5456 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5457 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5458 | break; |
| 5459 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5463 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5464 | * @vport: pointer to vport data structure. |
| 5465 | * |
| 5466 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5467 | * response to a CVL event. |
| 5468 | * |
| 5469 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5470 | * return NULL. |
| 5471 | **/ |
| 5472 | static struct lpfc_nodelist * |
| 5473 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5474 | { |
| 5475 | struct lpfc_nodelist *ndlp; |
| 5476 | struct Scsi_Host *shost; |
| 5477 | struct lpfc_hba *phba; |
| 5478 | |
| 5479 | if (!vport) |
| 5480 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5481 | phba = vport->phba; |
| 5482 | if (!phba) |
| 5483 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5484 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5485 | if (!ndlp) { |
| 5486 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5487 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5488 | if (!ndlp) |
| 5489 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5490 | /* Set the node type */ |
| 5491 | ndlp->nlp_type |= NLP_FABRIC; |
| 5492 | /* Put ndlp onto node list */ |
| 5493 | lpfc_enqueue_node(vport, ndlp); |
| 5494 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5495 | /* re-setup ndlp without removing from node list */ |
| 5496 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5497 | if (!ndlp) |
| 5498 | return 0; |
| 5499 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5500 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5501 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5502 | return NULL; |
| 5503 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5504 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5505 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5506 | return NULL; |
| 5507 | shost = lpfc_shost_from_vport(vport); |
| 5508 | if (!shost) |
| 5509 | return NULL; |
| 5510 | lpfc_linkdown_port(vport); |
| 5511 | lpfc_cleanup_pending_mbox(vport); |
| 5512 | spin_lock_irq(shost->host_lock); |
| 5513 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5514 | spin_unlock_irq(shost->host_lock); |
| 5515 | |
| 5516 | return ndlp; |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 5521 | * @vport: pointer to lpfc hba data structure. |
| 5522 | * |
| 5523 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5524 | * response to a FCF dead event. |
| 5525 | **/ |
| 5526 | static void |
| 5527 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5528 | { |
| 5529 | struct lpfc_vport **vports; |
| 5530 | int i; |
| 5531 | |
| 5532 | vports = lpfc_create_vport_work_array(phba); |
| 5533 | if (vports) |
| 5534 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5535 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5536 | lpfc_destroy_vport_work_array(phba, vports); |
| 5537 | } |
| 5538 | |
| 5539 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5540 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5541 | * @phba: pointer to lpfc hba data structure. |
| 5542 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 5543 | * |
| 5544 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5545 | **/ |
| 5546 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5547 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5548 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5549 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5550 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5551 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5552 | struct lpfc_vport *vport; |
| 5553 | struct lpfc_nodelist *ndlp; |
| 5554 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5555 | int active_vlink_present; |
| 5556 | struct lpfc_vport **vports; |
| 5557 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5558 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5559 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5560 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5561 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5562 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5563 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5564 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5565 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5566 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5567 | "2546 New FCF event, evt_tag:x%x, " |
| 5568 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5569 | acqe_fip->event_tag, |
| 5570 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5571 | else |
| 5572 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5573 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5574 | "2788 FCF param modified event, " |
| 5575 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5576 | acqe_fip->event_tag, |
| 5577 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5578 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5579 | /* |
| 5580 | * During period of FCF discovery, read the FCF |
| 5581 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5582 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5583 | */ |
| 5584 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5585 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5586 | "2779 Read FCF (x%x) for updating " |
| 5587 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5588 | acqe_fip->index); |
| 5589 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5590 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5591 | |
| 5592 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5593 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5594 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5595 | spin_unlock_irq(&phba->hbalock); |
| 5596 | break; |
| 5597 | } |
| 5598 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5599 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5600 | spin_unlock_irq(&phba->hbalock); |
| 5601 | break; |
| 5602 | } |
| 5603 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5604 | /* If the FCF has been in discovered state, do nothing. */ |
| 5605 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5606 | spin_unlock_irq(&phba->hbalock); |
| 5607 | break; |
| 5608 | } |
| 5609 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5610 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5611 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5612 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5613 | "2770 Start FCF table scan per async FCF " |
| 5614 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5615 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5616 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5617 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5618 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5619 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5620 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5621 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5622 | break; |
| 5623 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5624 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5626 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5627 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5628 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5629 | break; |
| 5630 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5631 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5632 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5633 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5634 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5635 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5636 | /* |
| 5637 | * If we are in the middle of FCF failover process, clear |
| 5638 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5639 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5640 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5641 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5642 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5643 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5644 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5645 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5646 | break; |
| 5647 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5648 | spin_unlock_irq(&phba->hbalock); |
| 5649 | |
| 5650 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5651 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5652 | break; |
| 5653 | |
| 5654 | /* |
| 5655 | * Otherwise, request the port to rediscover the entire FCF |
| 5656 | * table for a fast recovery from case that the current FCF |
| 5657 | * is no longer valid as we are not in the middle of FCF |
| 5658 | * failover process already. |
| 5659 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5660 | spin_lock_irq(&phba->hbalock); |
| 5661 | /* Mark the fast failover process in progress */ |
| 5662 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5663 | spin_unlock_irq(&phba->hbalock); |
| 5664 | |
| 5665 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5666 | "2771 Start FCF fast failover process due to " |
| 5667 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5668 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5669 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5670 | if (rc) { |
| 5671 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5672 | LOG_DISCOVERY, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5673 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5674 | "command failed, fail through to FCF " |
| 5675 | "dead event\n"); |
| 5676 | spin_lock_irq(&phba->hbalock); |
| 5677 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5678 | spin_unlock_irq(&phba->hbalock); |
| 5679 | /* |
| 5680 | * Last resort will fail over by treating this |
| 5681 | * as a link down to FCF registration. |
| 5682 | */ |
| 5683 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5684 | } else { |
| 5685 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5686 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5687 | /* |
| 5688 | * Handling fast FCF failover to a DEAD FCF event is |
| 5689 | * considered equalivant to receiving CVL to all vports. |
| 5690 | */ |
| 5691 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5692 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5693 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5694 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5695 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5696 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5697 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5698 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5699 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5700 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5701 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5702 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5703 | if (!ndlp) |
| 5704 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5705 | active_vlink_present = 0; |
| 5706 | |
| 5707 | vports = lpfc_create_vport_work_array(phba); |
| 5708 | if (vports) { |
| 5709 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5710 | i++) { |
| 5711 | if ((!(vports[i]->fc_flag & |
| 5712 | FC_VPORT_CVL_RCVD)) && |
| 5713 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5714 | active_vlink_present = 1; |
| 5715 | break; |
| 5716 | } |
| 5717 | } |
| 5718 | lpfc_destroy_vport_work_array(phba, vports); |
| 5719 | } |
| 5720 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5721 | /* |
| 5722 | * Don't re-instantiate if vport is marked for deletion. |
| 5723 | * If we are here first then vport_delete is going to wait |
| 5724 | * for discovery to complete. |
| 5725 | */ |
| 5726 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5727 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5728 | /* |
| 5729 | * If there are other active VLinks present, |
| 5730 | * re-instantiate the Vlink using FDISC. |
| 5731 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5732 | mod_timer(&ndlp->nlp_delayfunc, |
| 5733 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5734 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5735 | spin_lock_irq(shost->host_lock); |
| 5736 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5737 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5738 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5739 | vport->port_state = LPFC_FDISC; |
| 5740 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5741 | /* |
| 5742 | * Otherwise, we request port to rediscover |
| 5743 | * the entire FCF table for a fast recovery |
| 5744 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5745 | * is no longer valid if we are not already |
| 5746 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5747 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5748 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5749 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5750 | spin_unlock_irq(&phba->hbalock); |
| 5751 | break; |
| 5752 | } |
| 5753 | /* Mark the fast failover process in progress */ |
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 | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5756 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5757 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5758 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5759 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5760 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5761 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5762 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5763 | LOG_DISCOVERY, |
| 5764 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5765 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5766 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5767 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5768 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5769 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5770 | /* |
| 5771 | * Last resort will be re-try on the |
| 5772 | * the current registered FCF entry. |
| 5773 | */ |
| 5774 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5775 | } else |
| 5776 | /* |
| 5777 | * Reset FCF roundrobin bmask for new |
| 5778 | * discovery. |
| 5779 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5780 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5781 | } |
| 5782 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5783 | default: |
| 5784 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5785 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5786 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5787 | break; |
| 5788 | } |
| 5789 | } |
| 5790 | |
| 5791 | /** |
| 5792 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5793 | * @phba: pointer to lpfc hba data structure. |
| 5794 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5795 | * |
| 5796 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5797 | **/ |
| 5798 | static void |
| 5799 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5800 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5801 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5802 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5803 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5804 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5805 | "handled yet\n"); |
| 5806 | } |
| 5807 | |
| 5808 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5809 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5810 | * @phba: pointer to lpfc hba data structure. |
| 5811 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5812 | * |
| 5813 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5814 | * is an asynchronous notified of a logical link speed change. The Port |
| 5815 | * reports the logical link speed in units of 10Mbps. |
| 5816 | **/ |
| 5817 | static void |
| 5818 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5819 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5820 | { |
| 5821 | uint16_t prev_ll_spd; |
| 5822 | |
| 5823 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5824 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5825 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5826 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5827 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5828 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5829 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5830 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5831 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5835 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5836 | * @phba: pointer to lpfc hba data structure. |
| 5837 | * |
| 5838 | * This routine is invoked by the worker thread to process all the pending |
| 5839 | * SLI4 asynchronous events. |
| 5840 | **/ |
| 5841 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5842 | { |
| 5843 | struct lpfc_cq_event *cq_event; |
| 5844 | |
| 5845 | /* First, declare the async event has been handled */ |
| 5846 | spin_lock_irq(&phba->hbalock); |
| 5847 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5848 | spin_unlock_irq(&phba->hbalock); |
| 5849 | /* Now, handle all the async events */ |
| 5850 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5851 | /* Get the first event from the head of the event queue */ |
| 5852 | spin_lock_irq(&phba->hbalock); |
| 5853 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5854 | cq_event, struct lpfc_cq_event, list); |
| 5855 | spin_unlock_irq(&phba->hbalock); |
| 5856 | /* Process the asynchronous event */ |
| 5857 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5858 | case LPFC_TRAILER_CODE_LINK: |
| 5859 | lpfc_sli4_async_link_evt(phba, |
| 5860 | &cq_event->cqe.acqe_link); |
| 5861 | break; |
| 5862 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5863 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5864 | break; |
| 5865 | case LPFC_TRAILER_CODE_DCBX: |
| 5866 | lpfc_sli4_async_dcbx_evt(phba, |
| 5867 | &cq_event->cqe.acqe_dcbx); |
| 5868 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5869 | case LPFC_TRAILER_CODE_GRP5: |
| 5870 | lpfc_sli4_async_grp5_evt(phba, |
| 5871 | &cq_event->cqe.acqe_grp5); |
| 5872 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5873 | case LPFC_TRAILER_CODE_FC: |
| 5874 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5875 | break; |
| 5876 | case LPFC_TRAILER_CODE_SLI: |
| 5877 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5878 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5879 | default: |
| 5880 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5881 | "1804 Invalid asynchrous event code: " |
| 5882 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5883 | &cq_event->cqe.mcqe_cmpl)); |
| 5884 | break; |
| 5885 | } |
| 5886 | /* Free the completion event processed to the free pool */ |
| 5887 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5892 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5893 | * @phba: pointer to lpfc hba data structure. |
| 5894 | * |
| 5895 | * This routine is invoked by the worker thread to process FCF table |
| 5896 | * rediscovery pending completion event. |
| 5897 | **/ |
| 5898 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5899 | { |
| 5900 | int rc; |
| 5901 | |
| 5902 | spin_lock_irq(&phba->hbalock); |
| 5903 | /* Clear FCF rediscovery timeout event */ |
| 5904 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5905 | /* Clear driver fast failover FCF record flag */ |
| 5906 | phba->fcf.failover_rec.flag = 0; |
| 5907 | /* Set state for FCF fast failover */ |
| 5908 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5909 | spin_unlock_irq(&phba->hbalock); |
| 5910 | |
| 5911 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5912 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5913 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5914 | 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] | 5915 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5916 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5917 | "2747 Issue FCF scan read FCF mailbox " |
| 5918 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5922 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5923 | * @phba: pointer to lpfc hba data structure. |
| 5924 | * @dev_grp: The HBA PCI-Device group number. |
| 5925 | * |
| 5926 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5927 | * API jump table entries. |
| 5928 | * |
| 5929 | * Return: 0 if success, otherwise -ENODEV |
| 5930 | **/ |
| 5931 | int |
| 5932 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5933 | { |
| 5934 | int rc; |
| 5935 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5936 | /* Set up lpfc PCI-device group */ |
| 5937 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5938 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5939 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5940 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5941 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5942 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5943 | /* Set up device INIT API function jump table */ |
| 5944 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5945 | if (rc) |
| 5946 | return -ENODEV; |
| 5947 | /* Set up SCSI API function jump table */ |
| 5948 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5949 | if (rc) |
| 5950 | return -ENODEV; |
| 5951 | /* Set up SLI API function jump table */ |
| 5952 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5953 | if (rc) |
| 5954 | return -ENODEV; |
| 5955 | /* Set up MBOX API function jump table */ |
| 5956 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5957 | if (rc) |
| 5958 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5959 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5960 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5964 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5965 | * @phba: pointer to lpfc hba data structure. |
| 5966 | * @intr_mode: active interrupt mode adopted. |
| 5967 | * |
| 5968 | * This routine it invoked to log the currently used active interrupt mode |
| 5969 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5970 | **/ |
| 5971 | 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] | 5972 | { |
| 5973 | switch (intr_mode) { |
| 5974 | case 0: |
| 5975 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5976 | "0470 Enable INTx interrupt mode.\n"); |
| 5977 | break; |
| 5978 | case 1: |
| 5979 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5980 | "0481 Enabled MSI interrupt mode.\n"); |
| 5981 | break; |
| 5982 | case 2: |
| 5983 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5984 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5985 | break; |
| 5986 | default: |
| 5987 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5988 | "0482 Illegal interrupt mode.\n"); |
| 5989 | break; |
| 5990 | } |
| 5991 | return; |
| 5992 | } |
| 5993 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5994 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5995 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5996 | * @phba: pointer to lpfc hba data structure. |
| 5997 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5998 | * This routine is invoked to enable the PCI device that is common to all |
| 5999 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6000 | * |
| 6001 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6002 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6003 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6004 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6005 | static int |
| 6006 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6007 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6008 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6009 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6010 | /* Obtain PCI device reference */ |
| 6011 | if (!phba->pcidev) |
| 6012 | goto out_error; |
| 6013 | else |
| 6014 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6015 | /* Enable PCI device */ |
| 6016 | if (pci_enable_device_mem(pdev)) |
| 6017 | goto out_error; |
| 6018 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6019 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6020 | goto out_disable_device; |
| 6021 | /* Set up device as PCI master and save state for EEH */ |
| 6022 | pci_set_master(pdev); |
| 6023 | pci_try_set_mwi(pdev); |
| 6024 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6025 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6026 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6027 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6028 | pdev->needs_freset = 1; |
| 6029 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6030 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6031 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6032 | out_disable_device: |
| 6033 | pci_disable_device(pdev); |
| 6034 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 6035 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6036 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6037 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6041 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6042 | * @phba: pointer to lpfc hba data structure. |
| 6043 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6044 | * This routine is invoked to disable the PCI device that is common to all |
| 6045 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6046 | **/ |
| 6047 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6048 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6049 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6050 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6051 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6052 | /* Obtain PCI device reference */ |
| 6053 | if (!phba->pcidev) |
| 6054 | return; |
| 6055 | else |
| 6056 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6057 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6058 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6059 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6060 | |
| 6061 | return; |
| 6062 | } |
| 6063 | |
| 6064 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6065 | * lpfc_reset_hba - Reset a hba |
| 6066 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6067 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6068 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6069 | * offline, performs a board restart, and then brings the board back |
| 6070 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6071 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6072 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6073 | void |
| 6074 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6075 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6076 | /* If resets are disabled then set error state and return. */ |
| 6077 | if (!phba->cfg_enable_hba_reset) { |
| 6078 | phba->link_state = LPFC_HBA_ERROR; |
| 6079 | return; |
| 6080 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6081 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 6082 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 6083 | else |
| 6084 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6085 | lpfc_offline(phba); |
| 6086 | lpfc_sli_brdrestart(phba); |
| 6087 | lpfc_online(phba); |
| 6088 | lpfc_unblock_mgmt_io(phba); |
| 6089 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6090 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6091 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6092 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6093 | * @phba: pointer to lpfc hba data structure. |
| 6094 | * |
| 6095 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6096 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6097 | * enable the number of virtual functions to the physical function. As |
| 6098 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6099 | * API call does not considered as an error condition for most of the device. |
| 6100 | **/ |
| 6101 | uint16_t |
| 6102 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6103 | { |
| 6104 | struct pci_dev *pdev = phba->pcidev; |
| 6105 | uint16_t nr_virtfn; |
| 6106 | int pos; |
| 6107 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6108 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6109 | if (pos == 0) |
| 6110 | return 0; |
| 6111 | |
| 6112 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6113 | return nr_virtfn; |
| 6114 | } |
| 6115 | |
| 6116 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6117 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6118 | * @phba: pointer to lpfc hba data structure. |
| 6119 | * @nr_vfn: number of virtual functions to be enabled. |
| 6120 | * |
| 6121 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6122 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6123 | * enable the number of virtual functions to the physical function. As |
| 6124 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6125 | * API call does not considered as an error condition for most of the device. |
| 6126 | **/ |
| 6127 | int |
| 6128 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6129 | { |
| 6130 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6131 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6132 | int rc; |
| 6133 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6134 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6135 | if (nr_vfn > max_nr_vfn) { |
| 6136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6137 | "3057 Requested vfs (%d) greater than " |
| 6138 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6139 | return -EINVAL; |
| 6140 | } |
| 6141 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6142 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6143 | if (rc) { |
| 6144 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6145 | "2806 Failed to enable sriov on this device " |
| 6146 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6147 | nr_vfn, rc); |
| 6148 | } else |
| 6149 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6150 | "2807 Successful enable sriov on this device " |
| 6151 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6152 | return rc; |
| 6153 | } |
| 6154 | |
| 6155 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6156 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6157 | * @phba: pointer to lpfc hba data structure. |
| 6158 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6159 | * This routine is invoked to set up the driver internal resources before the |
| 6160 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6161 | * |
| 6162 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6163 | * 0 - successful |
| 6164 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6165 | **/ |
| 6166 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6167 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6168 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6169 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6170 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6171 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6172 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6173 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6174 | atomic_set(&phba->fast_event_count, 0); |
| 6175 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6176 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6177 | /* Initialize ndlp management spinlock */ |
| 6178 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6179 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6180 | /* Initialize port_list spinlock */ |
| 6181 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6182 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6183 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6184 | INIT_LIST_HEAD(&phba->work_list); |
| 6185 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6186 | |
| 6187 | /* Initialize the wait queue head for the kernel thread */ |
| 6188 | init_waitqueue_head(&phba->work_waitq); |
| 6189 | |
| 6190 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6191 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6192 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6193 | "SCSI" : " "), |
| 6194 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6195 | "NVME" : " "), |
| 6196 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6197 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6198 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6199 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6200 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6201 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6202 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6203 | |
| 6204 | /* Initialize the fabric iocb list */ |
| 6205 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6206 | |
| 6207 | /* Initialize list to save ELS buffers */ |
| 6208 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6209 | |
| 6210 | /* Initialize FCF connection rec list */ |
| 6211 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6212 | |
| 6213 | /* Initialize OAS configuration list */ |
| 6214 | spin_lock_init(&phba->devicelock); |
| 6215 | INIT_LIST_HEAD(&phba->luns); |
| 6216 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6217 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6218 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6219 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6220 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6221 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6222 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6223 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6224 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6225 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6226 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6227 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6228 | return 0; |
| 6229 | } |
| 6230 | |
| 6231 | /** |
| 6232 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6233 | * @phba: pointer to lpfc hba data structure. |
| 6234 | * |
| 6235 | * This routine is invoked to set up the driver internal resources specific to |
| 6236 | * support the SLI-3 HBA device it attached to. |
| 6237 | * |
| 6238 | * Return codes |
| 6239 | * 0 - successful |
| 6240 | * other values - error |
| 6241 | **/ |
| 6242 | static int |
| 6243 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6244 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6245 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6246 | |
| 6247 | /* |
| 6248 | * Initialize timers used by driver |
| 6249 | */ |
| 6250 | |
| 6251 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6252 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6253 | |
| 6254 | /* Host attention work mask setup */ |
| 6255 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6256 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6257 | |
| 6258 | /* Get all the module params for configuring this host */ |
| 6259 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6260 | /* Set up phase-1 common device driver resources */ |
| 6261 | |
| 6262 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6263 | if (rc) |
| 6264 | return -ENODEV; |
| 6265 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6266 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6267 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6268 | /* check for menlo minimum sg count */ |
| 6269 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6270 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6271 | } |
| 6272 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6273 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6274 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6275 | sizeof(struct lpfc_sli_ring), |
| 6276 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6277 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6278 | return -ENOMEM; |
| 6279 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6280 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6281 | * 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] | 6282 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6283 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6284 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6285 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6286 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 6287 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 6288 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6289 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6290 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6291 | entry_sz = sizeof(struct sli4_sge); |
| 6292 | else |
| 6293 | entry_sz = sizeof(struct ulp_bde64); |
| 6294 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6295 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6296 | if (phba->cfg_enable_bg) { |
| 6297 | /* |
| 6298 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6299 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6300 | * over how many protection data segments the SCSI Layer |
| 6301 | * will hand us (ie: there could be one for every block |
| 6302 | * in the IO), we just allocate enough BDEs to accomidate |
| 6303 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6304 | * minimize the risk of running out. |
| 6305 | */ |
| 6306 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6307 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6308 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6309 | |
| 6310 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6311 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6312 | |
| 6313 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6314 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6315 | } else { |
| 6316 | /* |
| 6317 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6318 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6319 | * cfg_sg_seg_cnt data segments. |
| 6320 | */ |
| 6321 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6322 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6323 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6324 | |
| 6325 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6326 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6327 | } |
| 6328 | |
| 6329 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6330 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 6331 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6332 | phba->cfg_total_seg_cnt); |
| 6333 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6334 | phba->max_vpi = LPFC_MAX_VPI; |
| 6335 | /* This will be set to correct value after config_port mbox */ |
| 6336 | phba->max_vports = 0; |
| 6337 | |
| 6338 | /* |
| 6339 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6340 | */ |
| 6341 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6342 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6343 | |
| 6344 | /* Allocate device driver memory */ |
| 6345 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6346 | return -ENOMEM; |
| 6347 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6348 | /* |
| 6349 | * Enable sr-iov virtual functions if supported and configured |
| 6350 | * through the module parameter. |
| 6351 | */ |
| 6352 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6353 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6354 | phba->cfg_sriov_nr_virtfn); |
| 6355 | if (rc) { |
| 6356 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6357 | "2808 Requested number of SR-IOV " |
| 6358 | "virtual functions (%d) is not " |
| 6359 | "supported\n", |
| 6360 | phba->cfg_sriov_nr_virtfn); |
| 6361 | phba->cfg_sriov_nr_virtfn = 0; |
| 6362 | } |
| 6363 | } |
| 6364 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6365 | return 0; |
| 6366 | } |
| 6367 | |
| 6368 | /** |
| 6369 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6370 | * @phba: pointer to lpfc hba data structure. |
| 6371 | * |
| 6372 | * This routine is invoked to unset the driver internal resources set up |
| 6373 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6374 | **/ |
| 6375 | static void |
| 6376 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6377 | { |
| 6378 | /* Free device driver memory allocated */ |
| 6379 | lpfc_mem_free_all(phba); |
| 6380 | |
| 6381 | return; |
| 6382 | } |
| 6383 | |
| 6384 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6385 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6386 | * @phba: pointer to lpfc hba data structure. |
| 6387 | * |
| 6388 | * This routine is invoked to set up the driver internal resources specific to |
| 6389 | * support the SLI-4 HBA device it attached to. |
| 6390 | * |
| 6391 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6392 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6393 | * other values - error |
| 6394 | **/ |
| 6395 | static int |
| 6396 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6397 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6398 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6399 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6400 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6401 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 6402 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6403 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6404 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6405 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6406 | u32 if_type; |
| 6407 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6408 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6409 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6410 | phba->sli4_hba.num_possible_cpu = num_possible_cpus(); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6411 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6412 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6413 | /* Get all the module params for configuring this host */ |
| 6414 | lpfc_get_cfgparam(phba); |
| 6415 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6416 | /* Set up phase-1 common device driver resources */ |
| 6417 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6418 | if (rc) |
| 6419 | return -ENODEV; |
| 6420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6421 | /* Before proceed, wait for POST done and device ready */ |
| 6422 | rc = lpfc_sli4_post_status_check(phba); |
| 6423 | if (rc) |
| 6424 | return -ENODEV; |
| 6425 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 6426 | /* Allocate all driver workqueues here */ |
| 6427 | |
| 6428 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6429 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6430 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6431 | /* |
| 6432 | * Initialize timers used by driver |
| 6433 | */ |
| 6434 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6435 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6436 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6437 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6438 | 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] | 6439 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6440 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6441 | * Control structure for handling external multi-buffer mailbox |
| 6442 | * command pass-through. |
| 6443 | */ |
| 6444 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6445 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6446 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6447 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6448 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6449 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6450 | /* This will be set to correct value after the read_config mbox */ |
| 6451 | phba->max_vports = 0; |
| 6452 | |
| 6453 | /* Program the default value of vlan_id and fc_map */ |
| 6454 | phba->valid_vlan = 0; |
| 6455 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6456 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6457 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6458 | |
| 6459 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6460 | * 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] | 6461 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6462 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6463 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6464 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6465 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6466 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6467 | * for boundary conditions in its max_sgl_segment template. |
| 6468 | */ |
| 6469 | extra = 2; |
| 6470 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6471 | extra++; |
| 6472 | |
| 6473 | /* |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6474 | * It doesn't matter what family our adapter is in, we are |
| 6475 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6476 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6477 | */ |
| 6478 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6479 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6480 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6481 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6482 | * used to create the sg_dma_buf_pool must be calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6483 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 6484 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6485 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6486 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6487 | * the FCP rsp, and a SGE. Sice we have no control |
| 6488 | * over how many protection segments the SCSI Layer |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6489 | * will hand us (ie: there could be one for every block |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6490 | * in the IO), just allocate enough SGEs to accomidate |
| 6491 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6492 | * to minimize the risk of running out. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6493 | */ |
| 6494 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6495 | sizeof(struct fcp_rsp) + max_buf_size; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6496 | |
| 6497 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6498 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6499 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6500 | /* |
| 6501 | * If supporting DIF, reduce the seg count for scsi to |
| 6502 | * allow room for the DIF sges. |
| 6503 | */ |
| 6504 | if (phba->cfg_enable_bg && |
| 6505 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6506 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6507 | else |
| 6508 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6509 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6510 | } else { |
| 6511 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6512 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6513 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6514 | * cfg_sg_seg_cnt data segments. |
| 6515 | */ |
| 6516 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6517 | sizeof(struct fcp_rsp) + |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6518 | ((phba->cfg_sg_seg_cnt + extra) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6519 | sizeof(struct sli4_sge)); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6520 | |
| 6521 | /* Total SGEs for scsi_sg_list */ |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6522 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6523 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6524 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6525 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6526 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6527 | * need to post 1 page for the SGL. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6528 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6529 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 6530 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6531 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6532 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6533 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6534 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6535 | "6300 Reducing NVME sg segment " |
| 6536 | "cnt to %d\n", |
| 6537 | LPFC_MAX_NVME_SEG_CNT); |
| 6538 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6539 | } else |
| 6540 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6541 | } |
| 6542 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6543 | /* Initialize the host templates with the updated values. */ |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6544 | lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6545 | lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6546 | lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6547 | |
| 6548 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6549 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6550 | else |
| 6551 | phba->cfg_sg_dma_buf_size = |
| 6552 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6553 | |
| 6554 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6555 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6556 | "total:%d scsi:%d nvme:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6557 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6558 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6559 | phba->cfg_nvme_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6560 | |
| 6561 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6562 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6563 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6564 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6565 | |
| 6566 | /* |
| 6567 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6568 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6569 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 6570 | /* Initialize the Abort scsi buffer list used by driver */ |
| 6571 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 6572 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 6573 | } |
| 6574 | |
| 6575 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6576 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6577 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6578 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6579 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6580 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6581 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6582 | } |
| 6583 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6584 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6585 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6586 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6587 | |
| 6588 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6589 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6590 | */ |
| 6591 | |
| 6592 | /* Driver internel slow-path CQ Event pool */ |
| 6593 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6594 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6595 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6596 | /* Asynchronous event CQ Event work queue list */ |
| 6597 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 6598 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 6599 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 6600 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6601 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6602 | /* Receive queue CQ Event work queue list */ |
| 6603 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6604 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6605 | /* Initialize extent block lists. */ |
| 6606 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6607 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6608 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6609 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6610 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6611 | /* Initialize mboxq lists. If the early init routines fail |
| 6612 | * these lists need to be correctly initialized. |
| 6613 | */ |
| 6614 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6615 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6616 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6617 | /* initialize optic_state to 0xFF */ |
| 6618 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6619 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6620 | /* Allocate device driver memory */ |
| 6621 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6622 | if (rc) |
| 6623 | return -ENOMEM; |
| 6624 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6625 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6626 | 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] | 6627 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6628 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6629 | if (unlikely(rc)) { |
| 6630 | rc = -ENODEV; |
| 6631 | goto out_free_mem; |
| 6632 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6633 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6634 | } |
| 6635 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6636 | /* Create the bootstrap mailbox command */ |
| 6637 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6638 | if (unlikely(rc)) |
| 6639 | goto out_free_mem; |
| 6640 | |
| 6641 | /* Set up the host's endian order with the device. */ |
| 6642 | rc = lpfc_setup_endian_order(phba); |
| 6643 | if (unlikely(rc)) |
| 6644 | goto out_free_bsmbx; |
| 6645 | |
| 6646 | /* Set up the hba's configuration parameters. */ |
| 6647 | rc = lpfc_sli4_read_config(phba); |
| 6648 | if (unlikely(rc)) |
| 6649 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6650 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6651 | if (unlikely(rc)) |
| 6652 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6653 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6654 | /* IF Type 0 ports get initialized now. */ |
| 6655 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6656 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6657 | rc = lpfc_pci_function_reset(phba); |
| 6658 | if (unlikely(rc)) |
| 6659 | goto out_free_bsmbx; |
| 6660 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6661 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6662 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6663 | GFP_KERNEL); |
| 6664 | if (!mboxq) { |
| 6665 | rc = -ENOMEM; |
| 6666 | goto out_free_bsmbx; |
| 6667 | } |
| 6668 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6669 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6670 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6671 | if (lpfc_enable_nvmet_cnt) { |
| 6672 | |
| 6673 | /* First get WWN of HBA instance */ |
| 6674 | lpfc_read_nv(phba, mboxq); |
| 6675 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6676 | if (rc != MBX_SUCCESS) { |
| 6677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6678 | "6016 Mailbox failed , mbxCmd x%x " |
| 6679 | "READ_NV, mbxStatus x%x\n", |
| 6680 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6681 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6682 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6683 | rc = -EIO; |
| 6684 | goto out_free_bsmbx; |
| 6685 | } |
| 6686 | mb = &mboxq->u.mb; |
| 6687 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6688 | sizeof(uint64_t)); |
| 6689 | wwn = cpu_to_be64(wwn); |
| 6690 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6691 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6692 | sizeof(uint64_t)); |
| 6693 | /* wwn is WWPN of HBA instance */ |
| 6694 | wwn = cpu_to_be64(wwn); |
| 6695 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6696 | |
| 6697 | /* Check to see if it matches any module parameter */ |
| 6698 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6699 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6700 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6701 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6702 | break; |
| 6703 | |
| 6704 | phba->nvmet_support = 1; /* a match */ |
| 6705 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6706 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6707 | "6017 NVME Target %016llx\n", |
| 6708 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6709 | #else |
| 6710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6711 | "6021 Can't enable NVME Target." |
| 6712 | " NVME_TARGET_FC infrastructure" |
| 6713 | " is not in kernel\n"); |
| 6714 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6715 | /* Not supported for NVMET */ |
| 6716 | phba->cfg_xri_rebalancing = 0; |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6717 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6721 | |
| 6722 | lpfc_nvme_mod_param_dep(phba); |
| 6723 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6724 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6725 | lpfc_supported_pages(mboxq); |
| 6726 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6727 | if (!rc) { |
| 6728 | mqe = &mboxq->u.mqe; |
| 6729 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6730 | LPFC_MAX_SUPPORTED_PAGES); |
| 6731 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6732 | switch (pn_page[i]) { |
| 6733 | case LPFC_SLI4_PARAMETERS: |
| 6734 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6735 | break; |
| 6736 | default: |
| 6737 | break; |
| 6738 | } |
| 6739 | } |
| 6740 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6741 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6742 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6743 | if (rc) { |
| 6744 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6745 | rc = -EIO; |
| 6746 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6747 | } |
| 6748 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6749 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6750 | /* |
| 6751 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6752 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6753 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6754 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6755 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6756 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6757 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6758 | &phba->sli4_hba.sli_intf); |
| 6759 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6760 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6761 | if (phba->sli4_hba.extents_in_use && |
| 6762 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6763 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6764 | "2999 Unsupported SLI4 Parameters " |
| 6765 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6766 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6767 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6768 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6769 | rc = -EIO; |
| 6770 | goto out_free_bsmbx; |
| 6771 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6772 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6773 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6774 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6775 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6776 | rc = -EIO; |
| 6777 | goto out_free_bsmbx; |
| 6778 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6779 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6780 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6781 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6782 | |
| 6783 | /* Verify OAS is supported */ |
| 6784 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6785 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6786 | /* Verify RAS support on adapter */ |
| 6787 | lpfc_sli4_ras_init(phba); |
| 6788 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6789 | /* Verify all the SLI4 queues */ |
| 6790 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6791 | if (rc) |
| 6792 | goto out_free_bsmbx; |
| 6793 | |
| 6794 | /* Create driver internal CQE event pool */ |
| 6795 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6796 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6797 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6798 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6799 | /* Initialize sgl lists per host */ |
| 6800 | lpfc_init_sgl_list(phba); |
| 6801 | |
| 6802 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6803 | rc = lpfc_init_active_sgl_array(phba); |
| 6804 | if (rc) { |
| 6805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6806 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6807 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6808 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6809 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6810 | if (rc) { |
| 6811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6812 | "1432 Failed to initialize rpi headers.\n"); |
| 6813 | goto out_free_active_sgl; |
| 6814 | } |
| 6815 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6816 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6817 | 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] | 6818 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6819 | GFP_KERNEL); |
| 6820 | if (!phba->fcf.fcf_rr_bmask) { |
| 6821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6822 | "2759 Failed allocate memory for FCF round " |
| 6823 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6824 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6825 | goto out_remove_rpi_hdrs; |
| 6826 | } |
| 6827 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 6828 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6829 | sizeof(struct lpfc_hba_eq_hdl), |
| 6830 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6831 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6833 | "2572 Failed allocate memory for " |
| 6834 | "fast-path per-EQ handle array\n"); |
| 6835 | rc = -ENOMEM; |
| 6836 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6837 | } |
| 6838 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6839 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6840 | sizeof(struct lpfc_vector_map_info), |
| 6841 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6842 | if (!phba->sli4_hba.cpu_map) { |
| 6843 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6844 | "3327 Failed allocate memory for msi-x " |
| 6845 | "interrupt vector mapping\n"); |
| 6846 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6847 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6848 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6849 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6850 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 6851 | if (!phba->sli4_hba.eq_info) { |
| 6852 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6853 | "3321 Failed allocation for per_cpu stats\n"); |
| 6854 | rc = -ENOMEM; |
| 6855 | goto out_free_hba_cpu_map; |
| 6856 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6857 | /* |
| 6858 | * Enable sr-iov virtual functions if supported and configured |
| 6859 | * through the module parameter. |
| 6860 | */ |
| 6861 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6862 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6863 | phba->cfg_sriov_nr_virtfn); |
| 6864 | if (rc) { |
| 6865 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6866 | "3020 Requested number of SR-IOV " |
| 6867 | "virtual functions (%d) is not " |
| 6868 | "supported\n", |
| 6869 | phba->cfg_sriov_nr_virtfn); |
| 6870 | phba->cfg_sriov_nr_virtfn = 0; |
| 6871 | } |
| 6872 | } |
| 6873 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6874 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6875 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6876 | out_free_hba_cpu_map: |
| 6877 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6878 | out_free_hba_eq_hdl: |
| 6879 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6880 | out_free_fcf_rr_bmask: |
| 6881 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6882 | out_remove_rpi_hdrs: |
| 6883 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6884 | out_free_active_sgl: |
| 6885 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6886 | out_destroy_cq_event_pool: |
| 6887 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6888 | out_free_bsmbx: |
| 6889 | lpfc_destroy_bootstrap_mbox(phba); |
| 6890 | out_free_mem: |
| 6891 | lpfc_mem_free(phba); |
| 6892 | return rc; |
| 6893 | } |
| 6894 | |
| 6895 | /** |
| 6896 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6897 | * @phba: pointer to lpfc hba data structure. |
| 6898 | * |
| 6899 | * This routine is invoked to unset the driver internal resources set up |
| 6900 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6901 | **/ |
| 6902 | static void |
| 6903 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6904 | { |
| 6905 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6906 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6907 | free_percpu(phba->sli4_hba.eq_info); |
| 6908 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6909 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6910 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6911 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6912 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6913 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6914 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6915 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6916 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6917 | |
| 6918 | /* Free the allocated rpi headers. */ |
| 6919 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 6920 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6921 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6922 | /* Free eligible FCF index bmask */ |
| 6923 | kfree(phba->fcf.fcf_rr_bmask); |
| 6924 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6925 | /* Free the ELS sgl list */ |
| 6926 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6927 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6928 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6929 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6930 | /* Free the completion queue EQ event pool */ |
| 6931 | lpfc_sli4_cq_event_release_all(phba); |
| 6932 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 6933 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6934 | /* Release resource identifiers. */ |
| 6935 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6936 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6937 | /* Free the bsmbx region. */ |
| 6938 | lpfc_destroy_bootstrap_mbox(phba); |
| 6939 | |
| 6940 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 6941 | lpfc_mem_free_all(phba); |
| 6942 | |
| 6943 | /* Free the current connect table */ |
| 6944 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6945 | &phba->fcf_conn_rec_list, list) { |
| 6946 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6947 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6948 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6949 | |
| 6950 | return; |
| 6951 | } |
| 6952 | |
| 6953 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6954 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6955 | * @phba: The hba struct for which this call is being executed. |
| 6956 | * @dev_grp: The HBA PCI-Device group number. |
| 6957 | * |
| 6958 | * This routine sets up the device INIT interface API function jump table |
| 6959 | * in @phba struct. |
| 6960 | * |
| 6961 | * Returns: 0 - success, -ENODEV - failure. |
| 6962 | **/ |
| 6963 | int |
| 6964 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 6965 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 6966 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 6967 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 6968 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6969 | switch (dev_grp) { |
| 6970 | case LPFC_PCI_DEV_LP: |
| 6971 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 6972 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 6973 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 6974 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6975 | case LPFC_PCI_DEV_OC: |
| 6976 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 6977 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 6978 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 6979 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6980 | default: |
| 6981 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6982 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 6983 | dev_grp); |
| 6984 | return -ENODEV; |
| 6985 | break; |
| 6986 | } |
| 6987 | return 0; |
| 6988 | } |
| 6989 | |
| 6990 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6991 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 6992 | * @phba: pointer to lpfc hba data structure. |
| 6993 | * |
| 6994 | * This routine is invoked to set up the driver internal resources after the |
| 6995 | * device specific resource setup to support the HBA device it attached to. |
| 6996 | * |
| 6997 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6998 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6999 | * other values - error |
| 7000 | **/ |
| 7001 | static int |
| 7002 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 7003 | { |
| 7004 | int error; |
| 7005 | |
| 7006 | /* Startup the kernel thread for this host adapter. */ |
| 7007 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 7008 | "lpfc_worker_%d", phba->brd_no); |
| 7009 | if (IS_ERR(phba->worker_thread)) { |
| 7010 | error = PTR_ERR(phba->worker_thread); |
| 7011 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7012 | } |
| 7013 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7014 | return 0; |
| 7015 | } |
| 7016 | |
| 7017 | /** |
| 7018 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7019 | * @phba: pointer to lpfc hba data structure. |
| 7020 | * |
| 7021 | * This routine is invoked to unset the driver internal resources set up after |
| 7022 | * the device specific resource setup for supporting the HBA device it |
| 7023 | * attached to. |
| 7024 | **/ |
| 7025 | static void |
| 7026 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7027 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7028 | if (phba->wq) { |
| 7029 | flush_workqueue(phba->wq); |
| 7030 | destroy_workqueue(phba->wq); |
| 7031 | phba->wq = NULL; |
| 7032 | } |
| 7033 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7034 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7035 | if (phba->worker_thread) |
| 7036 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7037 | } |
| 7038 | |
| 7039 | /** |
| 7040 | * lpfc_free_iocb_list - Free iocb list. |
| 7041 | * @phba: pointer to lpfc hba data structure. |
| 7042 | * |
| 7043 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7044 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7045 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7046 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7047 | { |
| 7048 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7049 | |
| 7050 | spin_lock_irq(&phba->hbalock); |
| 7051 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7052 | &phba->lpfc_iocb_list, list) { |
| 7053 | list_del(&iocbq_entry->list); |
| 7054 | kfree(iocbq_entry); |
| 7055 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7056 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7057 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7058 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7059 | return; |
| 7060 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7061 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7062 | /** |
| 7063 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7064 | * @phba: pointer to lpfc hba data structure. |
| 7065 | * |
| 7066 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7067 | * list and set up the IOCB tag array accordingly. |
| 7068 | * |
| 7069 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7070 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7071 | * other values - error |
| 7072 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7073 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7074 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7075 | { |
| 7076 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7077 | uint16_t iotag; |
| 7078 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7079 | |
| 7080 | /* Initialize and populate the iocb list per host. */ |
| 7081 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7082 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7083 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7084 | if (iocbq_entry == NULL) { |
| 7085 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7086 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 7087 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7088 | goto out_free_iocbq; |
| 7089 | } |
| 7090 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7091 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7092 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7093 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7094 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7095 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7096 | goto out_free_iocbq; |
| 7097 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7098 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7099 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7100 | |
| 7101 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7102 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7103 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7104 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7105 | } |
| 7106 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7107 | return 0; |
| 7108 | |
| 7109 | out_free_iocbq: |
| 7110 | lpfc_free_iocb_list(phba); |
| 7111 | |
| 7112 | return -ENOMEM; |
| 7113 | } |
| 7114 | |
| 7115 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7116 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7117 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7118 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7119 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7120 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7121 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7122 | void |
| 7123 | 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] | 7124 | { |
| 7125 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7126 | |
| 7127 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7128 | list_del(&sglq_entry->list); |
| 7129 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7130 | kfree(sglq_entry); |
| 7131 | } |
| 7132 | } |
| 7133 | |
| 7134 | /** |
| 7135 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7136 | * @phba: pointer to lpfc hba data structure. |
| 7137 | * |
| 7138 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7139 | **/ |
| 7140 | static void |
| 7141 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7142 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7143 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7144 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7145 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7146 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7147 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7148 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 7149 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | spin_unlock_irq(&phba->hbalock); |
| 7151 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7152 | /* Now free the sgl list */ |
| 7153 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7157 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7158 | * @phba: pointer to lpfc hba data structure. |
| 7159 | * |
| 7160 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7161 | **/ |
| 7162 | static void |
| 7163 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7164 | { |
| 7165 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7166 | LIST_HEAD(sglq_list); |
| 7167 | |
| 7168 | /* Retrieve all nvmet sgls from driver list */ |
| 7169 | spin_lock_irq(&phba->hbalock); |
| 7170 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7171 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7172 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7173 | spin_unlock_irq(&phba->hbalock); |
| 7174 | |
| 7175 | /* Now free the sgl list */ |
| 7176 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7177 | list_del(&sglq_entry->list); |
| 7178 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7179 | kfree(sglq_entry); |
| 7180 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7181 | |
| 7182 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7183 | * The next initialization cycle sets the count and allocates |
| 7184 | * the sgls over again. |
| 7185 | */ |
| 7186 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7190 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7191 | * @phba: pointer to lpfc hba data structure. |
| 7192 | * |
| 7193 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7194 | * This array will hold the sglq_entry's for active IOs. |
| 7195 | **/ |
| 7196 | static int |
| 7197 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7198 | { |
| 7199 | int size; |
| 7200 | size = sizeof(struct lpfc_sglq *); |
| 7201 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7202 | |
| 7203 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7204 | kzalloc(size, GFP_KERNEL); |
| 7205 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7206 | return -ENOMEM; |
| 7207 | return 0; |
| 7208 | } |
| 7209 | |
| 7210 | /** |
| 7211 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7212 | * @phba: pointer to lpfc hba data structure. |
| 7213 | * |
| 7214 | * This routine is invoked to walk through the array of active sglq entries |
| 7215 | * and free all of the resources. |
| 7216 | * This is just a place holder for now. |
| 7217 | **/ |
| 7218 | static void |
| 7219 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7220 | { |
| 7221 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7222 | } |
| 7223 | |
| 7224 | /** |
| 7225 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7226 | * @phba: pointer to lpfc hba data structure. |
| 7227 | * |
| 7228 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7229 | * list and set up the sgl xritag tag array accordingly. |
| 7230 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7231 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7232 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7233 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7234 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7235 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7236 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7237 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7238 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7239 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7240 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7241 | /* els xri-sgl book keeping */ |
| 7242 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7243 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7244 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7245 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | /** |
| 7249 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7250 | * @phba: pointer to lpfc hba data structure. |
| 7251 | * |
| 7252 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7253 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7254 | * 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] | 7255 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7256 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7257 | * |
| 7258 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7259 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7260 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7261 | **/ |
| 7262 | int |
| 7263 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7264 | { |
| 7265 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7266 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7267 | |
| 7268 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7269 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7270 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7271 | if (phba->sli4_hba.extents_in_use) |
| 7272 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7273 | |
| 7274 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7275 | if (!rpi_hdr) { |
| 7276 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7277 | "0391 Error during rpi post operation\n"); |
| 7278 | lpfc_sli4_remove_rpis(phba); |
| 7279 | rc = -ENODEV; |
| 7280 | } |
| 7281 | |
| 7282 | return rc; |
| 7283 | } |
| 7284 | |
| 7285 | /** |
| 7286 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7287 | * @phba: pointer to lpfc hba data structure. |
| 7288 | * |
| 7289 | * This routine is invoked to allocate a single 4KB memory region to |
| 7290 | * support rpis and stores them in the phba. This single region |
| 7291 | * provides support for up to 64 rpis. The region is used globally |
| 7292 | * by the device. |
| 7293 | * |
| 7294 | * Returns: |
| 7295 | * A valid rpi hdr on success. |
| 7296 | * A NULL pointer on any failure. |
| 7297 | **/ |
| 7298 | struct lpfc_rpi_hdr * |
| 7299 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7300 | { |
| 7301 | uint16_t rpi_limit, curr_rpi_range; |
| 7302 | struct lpfc_dmabuf *dmabuf; |
| 7303 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7304 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7305 | /* |
| 7306 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7307 | * required. Set the expected maximum count and let the actual value |
| 7308 | * get set when extents are fully allocated. |
| 7309 | */ |
| 7310 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7311 | return NULL; |
| 7312 | if (phba->sli4_hba.extents_in_use) |
| 7313 | return NULL; |
| 7314 | |
| 7315 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7316 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7317 | |
| 7318 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7319 | /* |
| 7320 | * Establish the starting RPI in this header block. The starting |
| 7321 | * rpi is normalized to a zero base because the physical rpi is |
| 7322 | * port based. |
| 7323 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7324 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7325 | spin_unlock_irq(&phba->hbalock); |
| 7326 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7327 | /* Reached full RPI range */ |
| 7328 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7329 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7330 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7331 | /* |
| 7332 | * First allocate the protocol header region for the port. The |
| 7333 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7334 | */ |
| 7335 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7336 | if (!dmabuf) |
| 7337 | return NULL; |
| 7338 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7339 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7340 | LPFC_HDR_TEMPLATE_SIZE, |
| 7341 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7342 | if (!dmabuf->virt) { |
| 7343 | rpi_hdr = NULL; |
| 7344 | goto err_free_dmabuf; |
| 7345 | } |
| 7346 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7347 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7348 | rpi_hdr = NULL; |
| 7349 | goto err_free_coherent; |
| 7350 | } |
| 7351 | |
| 7352 | /* Save the rpi header data for cleanup later. */ |
| 7353 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7354 | if (!rpi_hdr) |
| 7355 | goto err_free_coherent; |
| 7356 | |
| 7357 | rpi_hdr->dmabuf = dmabuf; |
| 7358 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7359 | rpi_hdr->page_count = 1; |
| 7360 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7361 | |
| 7362 | /* The rpi_hdr stores the logical index only. */ |
| 7363 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7364 | 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] | 7365 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7366 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7367 | spin_unlock_irq(&phba->hbalock); |
| 7368 | return rpi_hdr; |
| 7369 | |
| 7370 | err_free_coherent: |
| 7371 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7372 | dmabuf->virt, dmabuf->phys); |
| 7373 | err_free_dmabuf: |
| 7374 | kfree(dmabuf); |
| 7375 | return NULL; |
| 7376 | } |
| 7377 | |
| 7378 | /** |
| 7379 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7380 | * @phba: pointer to lpfc hba data structure. |
| 7381 | * |
| 7382 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7383 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7384 | * presumes the caller has released all rpis consumed by fabric or port |
| 7385 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7386 | **/ |
| 7387 | void |
| 7388 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7389 | { |
| 7390 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7391 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7392 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7393 | goto exit; |
| 7394 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7395 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7396 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7397 | list_del(&rpi_hdr->list); |
| 7398 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7399 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7400 | kfree(rpi_hdr->dmabuf); |
| 7401 | kfree(rpi_hdr); |
| 7402 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7403 | exit: |
| 7404 | /* There are no rpis available to the port now. */ |
| 7405 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7409 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7410 | * @pdev: pointer to pci device data structure. |
| 7411 | * |
| 7412 | * This routine is invoked to allocate the driver hba data structure for an |
| 7413 | * HBA device. If the allocation is successful, the phba reference to the |
| 7414 | * PCI device data structure is set. |
| 7415 | * |
| 7416 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7417 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7418 | * NULL - error |
| 7419 | **/ |
| 7420 | static struct lpfc_hba * |
| 7421 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7422 | { |
| 7423 | struct lpfc_hba *phba; |
| 7424 | |
| 7425 | /* Allocate memory for HBA structure */ |
| 7426 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7427 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7428 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7429 | return NULL; |
| 7430 | } |
| 7431 | |
| 7432 | /* Set reference to PCI device in HBA structure */ |
| 7433 | phba->pcidev = pdev; |
| 7434 | |
| 7435 | /* Assign an unused board number */ |
| 7436 | phba->brd_no = lpfc_get_instance(); |
| 7437 | if (phba->brd_no < 0) { |
| 7438 | kfree(phba); |
| 7439 | return NULL; |
| 7440 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7441 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7442 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7443 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7444 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7445 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7446 | return phba; |
| 7447 | } |
| 7448 | |
| 7449 | /** |
| 7450 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7451 | * @phba: pointer to lpfc hba data structure. |
| 7452 | * |
| 7453 | * This routine is invoked to free the driver hba data structure with an |
| 7454 | * HBA device. |
| 7455 | **/ |
| 7456 | static void |
| 7457 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7458 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7459 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7460 | kfree(phba->sli4_hba.hdwq); |
| 7461 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7462 | /* Release the driver assigned board number */ |
| 7463 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7464 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7465 | /* Free memory allocated with sli3 rings */ |
| 7466 | kfree(phba->sli.sli3_ring); |
| 7467 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7468 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7469 | kfree(phba); |
| 7470 | return; |
| 7471 | } |
| 7472 | |
| 7473 | /** |
| 7474 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7475 | * @phba: pointer to lpfc hba data structure. |
| 7476 | * |
| 7477 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7478 | * host with it. |
| 7479 | * |
| 7480 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7481 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7482 | * other values - error |
| 7483 | **/ |
| 7484 | static int |
| 7485 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7486 | { |
| 7487 | struct lpfc_vport *vport; |
| 7488 | struct Scsi_Host *shost; |
| 7489 | |
| 7490 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7491 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7492 | phba->fc_ratov = FF_DEF_RATOV; |
| 7493 | phba->fc_altov = FF_DEF_ALTOV; |
| 7494 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7495 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7496 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7497 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7498 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7499 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7500 | |
| 7501 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7502 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7503 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7504 | if (phba->nvmet_support) { |
| 7505 | /* Only 1 vport (pport) will support NVME target */ |
| 7506 | if (phba->txrdy_payload_pool == NULL) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 7507 | phba->txrdy_payload_pool = dma_pool_create( |
| 7508 | "txrdy_pool", &phba->pcidev->dev, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7509 | TXRDY_PAYLOAD_LEN, 16, 0); |
| 7510 | if (phba->txrdy_payload_pool) { |
| 7511 | phba->targetport = NULL; |
| 7512 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7513 | lpfc_printf_log(phba, KERN_INFO, |
| 7514 | LOG_INIT | LOG_NVME_DISC, |
| 7515 | "6076 NVME Target Found\n"); |
| 7516 | } |
| 7517 | } |
| 7518 | } |
| 7519 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7520 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7521 | /* Put reference to SCSI host to driver's device private data */ |
| 7522 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7523 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7524 | /* |
| 7525 | * At this point we are fully registered with PSA. In addition, |
| 7526 | * any initial discovery should be completed. |
| 7527 | */ |
| 7528 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7529 | if (phba->cfg_enable_SmartSAN || |
| 7530 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7531 | |
| 7532 | /* Setup appropriate attribute masks */ |
| 7533 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7534 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7535 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7536 | else |
| 7537 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7538 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7539 | return 0; |
| 7540 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7541 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7542 | /** |
| 7543 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7544 | * @phba: pointer to lpfc hba data structure. |
| 7545 | * |
| 7546 | * This routine is invoked to destroy HBA physical port and the associated |
| 7547 | * SCSI host. |
| 7548 | **/ |
| 7549 | static void |
| 7550 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7551 | { |
| 7552 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7553 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7554 | /* Destroy physical port that associated with the SCSI host */ |
| 7555 | destroy_port(vport); |
| 7556 | |
| 7557 | return; |
| 7558 | } |
| 7559 | |
| 7560 | /** |
| 7561 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7562 | * @phba: pointer to lpfc hba data structure. |
| 7563 | * @shost: the shost to be used to detect Block guard settings. |
| 7564 | * |
| 7565 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7566 | * This routine also allocates memory for debugging bg buffers. |
| 7567 | **/ |
| 7568 | static void |
| 7569 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7570 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7571 | uint32_t old_mask; |
| 7572 | uint32_t old_guard; |
| 7573 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7574 | int pagecnt = 10; |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7575 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7576 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7577 | "1478 Registering BlockGuard with the " |
| 7578 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7579 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7580 | old_mask = phba->cfg_prot_mask; |
| 7581 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7582 | |
| 7583 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7584 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7585 | SHOST_DIX_TYPE0_PROTECTION | |
| 7586 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7587 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7588 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7589 | |
| 7590 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7591 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7592 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7593 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7594 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7595 | if ((old_mask != phba->cfg_prot_mask) || |
| 7596 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7598 | "1475 Registering BlockGuard with the " |
| 7599 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7600 | phba->cfg_prot_mask, |
| 7601 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7602 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7603 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7604 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7605 | } else |
| 7606 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7607 | "1479 Not Registering BlockGuard with the SCSI " |
| 7608 | "layer, Bad protection parameters: %d %d\n", |
| 7609 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7610 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7611 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7612 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7613 | while (pagecnt) { |
| 7614 | spin_lock_init(&_dump_buf_lock); |
| 7615 | _dump_buf_data = |
| 7616 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7617 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7618 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7619 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7620 | "_dump_buf_data at 0x%p\n", |
| 7621 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7622 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7623 | memset(_dump_buf_data, 0, |
| 7624 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7625 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7626 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7627 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7628 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7629 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7630 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7631 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7632 | "memory for hexdump\n"); |
| 7633 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7634 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7635 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7636 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7637 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7638 | while (pagecnt) { |
| 7639 | _dump_buf_dif = |
| 7640 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7641 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7642 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7643 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7644 | "_dump_buf_dif at 0x%p\n", |
| 7645 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7646 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7647 | memset(_dump_buf_dif, 0, |
| 7648 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7649 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7650 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7651 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7652 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7653 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7654 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7655 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7656 | "memory for hexdump\n"); |
| 7657 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7658 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7659 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7660 | _dump_buf_dif); |
| 7661 | } |
| 7662 | |
| 7663 | /** |
| 7664 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7665 | * @phba: pointer to lpfc hba data structure. |
| 7666 | * |
| 7667 | * This routine is invoked to perform all the necessary post initialization |
| 7668 | * setup for the device. |
| 7669 | **/ |
| 7670 | static void |
| 7671 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7672 | { |
| 7673 | struct Scsi_Host *shost; |
| 7674 | struct lpfc_adapter_event_header adapter_event; |
| 7675 | |
| 7676 | /* Get the default values for Model Name and Description */ |
| 7677 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7678 | |
| 7679 | /* |
| 7680 | * hba setup may have changed the hba_queue_depth so we need to |
| 7681 | * adjust the value of can_queue. |
| 7682 | */ |
| 7683 | shost = pci_get_drvdata(phba->pcidev); |
| 7684 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7685 | |
| 7686 | lpfc_host_attrib_init(shost); |
| 7687 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7688 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7689 | spin_lock_irq(shost->host_lock); |
| 7690 | lpfc_poll_start_timer(phba); |
| 7691 | spin_unlock_irq(shost->host_lock); |
| 7692 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7693 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7694 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7695 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7696 | /* Send board arrival event to upper layer */ |
| 7697 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7698 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7699 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7700 | sizeof(adapter_event), |
| 7701 | (char *) &adapter_event, |
| 7702 | LPFC_NL_VENDOR_ID); |
| 7703 | return; |
| 7704 | } |
| 7705 | |
| 7706 | /** |
| 7707 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7708 | * @phba: pointer to lpfc hba data structure. |
| 7709 | * |
| 7710 | * This routine is invoked to set up the PCI device memory space for device |
| 7711 | * with SLI-3 interface spec. |
| 7712 | * |
| 7713 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7714 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7715 | * other values - error |
| 7716 | **/ |
| 7717 | static int |
| 7718 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7719 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7720 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7721 | unsigned long bar0map_len, bar2map_len; |
| 7722 | int i, hbq_count; |
| 7723 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7724 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7725 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7726 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7727 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7728 | |
| 7729 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7730 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7731 | if (error) |
| 7732 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7733 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7734 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7735 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7736 | |
| 7737 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7738 | * required by each mapping. |
| 7739 | */ |
| 7740 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7741 | bar0map_len = pci_resource_len(pdev, 0); |
| 7742 | |
| 7743 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7744 | bar2map_len = pci_resource_len(pdev, 2); |
| 7745 | |
| 7746 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7747 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7748 | if (!phba->slim_memmap_p) { |
| 7749 | dev_printk(KERN_ERR, &pdev->dev, |
| 7750 | "ioremap failed for SLIM memory.\n"); |
| 7751 | goto out; |
| 7752 | } |
| 7753 | |
| 7754 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7755 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7756 | if (!phba->ctrl_regs_memmap_p) { |
| 7757 | dev_printk(KERN_ERR, &pdev->dev, |
| 7758 | "ioremap failed for HBA control registers.\n"); |
| 7759 | goto out_iounmap_slim; |
| 7760 | } |
| 7761 | |
| 7762 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7763 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7764 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7765 | if (!phba->slim2p.virt) |
| 7766 | goto out_iounmap; |
| 7767 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7768 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7769 | phba->mbox_ext = (phba->slim2p.virt + |
| 7770 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7771 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7772 | phba->IOCBs = (phba->slim2p.virt + |
| 7773 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7774 | |
| 7775 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7776 | lpfc_sli_hbq_size(), |
| 7777 | &phba->hbqslimp.phys, |
| 7778 | GFP_KERNEL); |
| 7779 | if (!phba->hbqslimp.virt) |
| 7780 | goto out_free_slim; |
| 7781 | |
| 7782 | hbq_count = lpfc_sli_hbq_count(); |
| 7783 | ptr = phba->hbqslimp.virt; |
| 7784 | for (i = 0; i < hbq_count; ++i) { |
| 7785 | phba->hbqs[i].hbq_virt = ptr; |
| 7786 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7787 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7788 | sizeof(struct lpfc_hbq_entry)); |
| 7789 | } |
| 7790 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7791 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7792 | |
| 7793 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7794 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7795 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7796 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7797 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7798 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7799 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7801 | return 0; |
| 7802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7803 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7804 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7805 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7806 | out_iounmap: |
| 7807 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7808 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7809 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7810 | out: |
| 7811 | return error; |
| 7812 | } |
| 7813 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7814 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7815 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7816 | * @phba: pointer to lpfc hba data structure. |
| 7817 | * |
| 7818 | * This routine is invoked to unset the PCI device memory space for device |
| 7819 | * with SLI-3 interface spec. |
| 7820 | **/ |
| 7821 | static void |
| 7822 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7823 | { |
| 7824 | struct pci_dev *pdev; |
| 7825 | |
| 7826 | /* Obtain PCI device reference */ |
| 7827 | if (!phba->pcidev) |
| 7828 | return; |
| 7829 | else |
| 7830 | pdev = phba->pcidev; |
| 7831 | |
| 7832 | /* Free coherent DMA memory allocated */ |
| 7833 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7834 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7835 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7836 | phba->slim2p.virt, phba->slim2p.phys); |
| 7837 | |
| 7838 | /* I/O memory unmap */ |
| 7839 | iounmap(phba->ctrl_regs_memmap_p); |
| 7840 | iounmap(phba->slim_memmap_p); |
| 7841 | |
| 7842 | return; |
| 7843 | } |
| 7844 | |
| 7845 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7846 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7847 | * @phba: pointer to lpfc hba data structure. |
| 7848 | * |
| 7849 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7850 | * done and check status. |
| 7851 | * |
| 7852 | * Return 0 if successful, otherwise -ENODEV. |
| 7853 | **/ |
| 7854 | int |
| 7855 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7856 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7857 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7858 | struct lpfc_register reg_data; |
| 7859 | int i, port_error = 0; |
| 7860 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7861 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7862 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7863 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7864 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7865 | return -ENODEV; |
| 7866 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7867 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7868 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7869 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7870 | &portsmphr_reg.word0) || |
| 7871 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7872 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7873 | port_error = -ENODEV; |
| 7874 | break; |
| 7875 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7876 | if (LPFC_POST_STAGE_PORT_READY == |
| 7877 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7878 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7879 | msleep(10); |
| 7880 | } |
| 7881 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7882 | /* |
| 7883 | * If there was a port error during POST, then don't proceed with |
| 7884 | * other register reads as the data may not be valid. Just exit. |
| 7885 | */ |
| 7886 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7887 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7888 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7889 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7890 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7891 | portsmphr_reg.word0, |
| 7892 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7893 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7894 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7895 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7896 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7897 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7898 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7899 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7900 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7901 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7902 | "2534 Device Info: SLIFamily=0x%x, " |
| 7903 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7904 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7905 | bf_get(lpfc_sli_intf_sli_family, |
| 7906 | &phba->sli4_hba.sli_intf), |
| 7907 | bf_get(lpfc_sli_intf_slirev, |
| 7908 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7909 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7910 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7911 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7912 | &phba->sli4_hba.sli_intf), |
| 7913 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7914 | &phba->sli4_hba.sli_intf), |
| 7915 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7916 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7917 | /* |
| 7918 | * Check for other Port errors during the initialization |
| 7919 | * process. Fail the load if the port did not come up |
| 7920 | * correctly. |
| 7921 | */ |
| 7922 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7923 | &phba->sli4_hba.sli_intf); |
| 7924 | switch (if_type) { |
| 7925 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7926 | phba->sli4_hba.ue_mask_lo = |
| 7927 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7928 | phba->sli4_hba.ue_mask_hi = |
| 7929 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7930 | uerrlo_reg.word0 = |
| 7931 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7932 | uerrhi_reg.word0 = |
| 7933 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7934 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7935 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7937 | "1422 Unrecoverable Error " |
| 7938 | "Detected during POST " |
| 7939 | "uerr_lo_reg=0x%x, " |
| 7940 | "uerr_hi_reg=0x%x, " |
| 7941 | "ue_mask_lo_reg=0x%x, " |
| 7942 | "ue_mask_hi_reg=0x%x\n", |
| 7943 | uerrlo_reg.word0, |
| 7944 | uerrhi_reg.word0, |
| 7945 | phba->sli4_hba.ue_mask_lo, |
| 7946 | phba->sli4_hba.ue_mask_hi); |
| 7947 | port_error = -ENODEV; |
| 7948 | } |
| 7949 | break; |
| 7950 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7951 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7952 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7953 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7954 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7955 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7956 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7957 | phba->work_status[0] = |
| 7958 | readl(phba->sli4_hba.u.if_type2. |
| 7959 | ERR1regaddr); |
| 7960 | phba->work_status[1] = |
| 7961 | readl(phba->sli4_hba.u.if_type2. |
| 7962 | ERR2regaddr); |
| 7963 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7964 | "2888 Unrecoverable port error " |
| 7965 | "following POST: port status reg " |
| 7966 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7967 | "error 1=0x%x, error 2=0x%x\n", |
| 7968 | reg_data.word0, |
| 7969 | portsmphr_reg.word0, |
| 7970 | phba->work_status[0], |
| 7971 | phba->work_status[1]); |
| 7972 | port_error = -ENODEV; |
| 7973 | } |
| 7974 | break; |
| 7975 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7976 | default: |
| 7977 | break; |
| 7978 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7979 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7980 | return port_error; |
| 7981 | } |
| 7982 | |
| 7983 | /** |
| 7984 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 7985 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7986 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7987 | * |
| 7988 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 7989 | * memory map. |
| 7990 | **/ |
| 7991 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7992 | 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] | 7993 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7994 | switch (if_type) { |
| 7995 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7996 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 7997 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 7998 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 7999 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 8000 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 8001 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 8002 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 8003 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 8004 | phba->sli4_hba.SLIINTFregaddr = |
| 8005 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8006 | break; |
| 8007 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8008 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8009 | phba->sli4_hba.conf_regs_memmap_p + |
| 8010 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8011 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8012 | phba->sli4_hba.conf_regs_memmap_p + |
| 8013 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8014 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8015 | phba->sli4_hba.conf_regs_memmap_p + |
| 8016 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8017 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8018 | phba->sli4_hba.conf_regs_memmap_p + |
| 8019 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8020 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8021 | phba->sli4_hba.conf_regs_memmap_p + |
| 8022 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8023 | phba->sli4_hba.SLIINTFregaddr = |
| 8024 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8025 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8026 | phba->sli4_hba.conf_regs_memmap_p + |
| 8027 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8028 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8029 | phba->sli4_hba.conf_regs_memmap_p + |
| 8030 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8031 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8032 | phba->sli4_hba.conf_regs_memmap_p + |
| 8033 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8034 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8035 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8036 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8037 | phba->sli4_hba.MQDBregaddr = |
| 8038 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8039 | phba->sli4_hba.BMBXregaddr = |
| 8040 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8041 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8042 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8043 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8044 | phba->sli4_hba.conf_regs_memmap_p + |
| 8045 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8046 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8047 | phba->sli4_hba.conf_regs_memmap_p + |
| 8048 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8049 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8050 | phba->sli4_hba.conf_regs_memmap_p + |
| 8051 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8052 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8053 | phba->sli4_hba.conf_regs_memmap_p + |
| 8054 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8055 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8056 | phba->sli4_hba.conf_regs_memmap_p + |
| 8057 | LPFC_CTL_PORT_STA_OFFSET; |
| 8058 | phba->sli4_hba.PSMPHRregaddr = |
| 8059 | phba->sli4_hba.conf_regs_memmap_p + |
| 8060 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8061 | phba->sli4_hba.BMBXregaddr = |
| 8062 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8063 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8064 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8065 | default: |
| 8066 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8067 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8068 | if_type); |
| 8069 | break; |
| 8070 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8071 | } |
| 8072 | |
| 8073 | /** |
| 8074 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8075 | * @phba: pointer to lpfc hba data structure. |
| 8076 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8077 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8078 | **/ |
| 8079 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8080 | 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] | 8081 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8082 | switch (if_type) { |
| 8083 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8084 | phba->sli4_hba.PSMPHRregaddr = |
| 8085 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8086 | LPFC_SLIPORT_IF0_SMPHR; |
| 8087 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8088 | LPFC_HST_ISR0; |
| 8089 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8090 | LPFC_HST_IMR0; |
| 8091 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8092 | LPFC_HST_ISCR0; |
| 8093 | break; |
| 8094 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8095 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8096 | LPFC_IF6_RQ_DOORBELL; |
| 8097 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8098 | LPFC_IF6_WQ_DOORBELL; |
| 8099 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8100 | LPFC_IF6_CQ_DOORBELL; |
| 8101 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8102 | LPFC_IF6_EQ_DOORBELL; |
| 8103 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8104 | LPFC_IF6_MQ_DOORBELL; |
| 8105 | break; |
| 8106 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8107 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8108 | default: |
| 8109 | dev_err(&phba->pcidev->dev, |
| 8110 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8111 | if_type); |
| 8112 | break; |
| 8113 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | /** |
| 8117 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8118 | * @phba: pointer to lpfc hba data structure. |
| 8119 | * @vf: virtual function number |
| 8120 | * |
| 8121 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8122 | * based on the given viftual function number, @vf. |
| 8123 | * |
| 8124 | * Return 0 if successful, otherwise -ENODEV. |
| 8125 | **/ |
| 8126 | static int |
| 8127 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8128 | { |
| 8129 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8130 | return -ENODEV; |
| 8131 | |
| 8132 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8133 | vf * LPFC_VFR_PAGE_SIZE + |
| 8134 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8135 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8136 | vf * LPFC_VFR_PAGE_SIZE + |
| 8137 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8138 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8139 | vf * LPFC_VFR_PAGE_SIZE + |
| 8140 | LPFC_EQCQ_DOORBELL); |
| 8141 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8142 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8143 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8144 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8145 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8146 | return 0; |
| 8147 | } |
| 8148 | |
| 8149 | /** |
| 8150 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8151 | * @phba: pointer to lpfc hba data structure. |
| 8152 | * |
| 8153 | * This routine is invoked to create the bootstrap mailbox |
| 8154 | * region consistent with the SLI-4 interface spec. This |
| 8155 | * routine allocates all memory necessary to communicate |
| 8156 | * mailbox commands to the port and sets up all alignment |
| 8157 | * needs. No locks are expected to be held when calling |
| 8158 | * this routine. |
| 8159 | * |
| 8160 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8161 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8162 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8163 | **/ |
| 8164 | static int |
| 8165 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8166 | { |
| 8167 | uint32_t bmbx_size; |
| 8168 | struct lpfc_dmabuf *dmabuf; |
| 8169 | struct dma_address *dma_address; |
| 8170 | uint32_t pa_addr; |
| 8171 | uint64_t phys_addr; |
| 8172 | |
| 8173 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8174 | if (!dmabuf) |
| 8175 | return -ENOMEM; |
| 8176 | |
| 8177 | /* |
| 8178 | * The bootstrap mailbox region is comprised of 2 parts |
| 8179 | * plus an alignment restriction of 16 bytes. |
| 8180 | */ |
| 8181 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8182 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8183 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8184 | if (!dmabuf->virt) { |
| 8185 | kfree(dmabuf); |
| 8186 | return -ENOMEM; |
| 8187 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8188 | |
| 8189 | /* |
| 8190 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8191 | * operations are simple later. The mailbox dma address is required |
| 8192 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8193 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8194 | * command to the port. |
| 8195 | */ |
| 8196 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8197 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8198 | |
| 8199 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8200 | LPFC_ALIGN_16_BYTE); |
| 8201 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8202 | LPFC_ALIGN_16_BYTE); |
| 8203 | |
| 8204 | /* |
| 8205 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8206 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8207 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8208 | * the 30-bit address is the high or low address. |
| 8209 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8210 | * clean on 32 bit machines. |
| 8211 | */ |
| 8212 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8213 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8214 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8215 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8216 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8217 | |
| 8218 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8219 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8220 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8221 | return 0; |
| 8222 | } |
| 8223 | |
| 8224 | /** |
| 8225 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8226 | * @phba: pointer to lpfc hba data structure. |
| 8227 | * |
| 8228 | * This routine is invoked to teardown the bootstrap mailbox |
| 8229 | * region and release all host resources. This routine requires |
| 8230 | * the caller to ensure all mailbox commands recovered, no |
| 8231 | * additional mailbox comands are sent, and interrupts are disabled |
| 8232 | * before calling this routine. |
| 8233 | * |
| 8234 | **/ |
| 8235 | static void |
| 8236 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8237 | { |
| 8238 | dma_free_coherent(&phba->pcidev->dev, |
| 8239 | phba->sli4_hba.bmbx.bmbx_size, |
| 8240 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8241 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8242 | |
| 8243 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8244 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8245 | } |
| 8246 | |
| 8247 | /** |
| 8248 | * lpfc_sli4_read_config - Get the config parameters. |
| 8249 | * @phba: pointer to lpfc hba data structure. |
| 8250 | * |
| 8251 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8252 | * The configuration parameters are used to set the base and maximum values |
| 8253 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8254 | * allocation for the port. |
| 8255 | * |
| 8256 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8257 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8258 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8259 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8260 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8261 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8262 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8263 | { |
| 8264 | LPFC_MBOXQ_t *pmb; |
| 8265 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8266 | union lpfc_sli4_cfg_shdr *shdr; |
| 8267 | uint32_t shdr_status, shdr_add_status; |
| 8268 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8269 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8270 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8271 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8272 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8273 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8274 | |
| 8275 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8276 | if (!pmb) { |
| 8277 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8278 | "2011 Unable to allocate memory for issuing " |
| 8279 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8280 | return -ENOMEM; |
| 8281 | } |
| 8282 | |
| 8283 | lpfc_read_config(phba, pmb); |
| 8284 | |
| 8285 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8286 | if (rc != MBX_SUCCESS) { |
| 8287 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8288 | "2012 Mailbox failed , mbxCmd x%x " |
| 8289 | "READ_CONFIG, mbxStatus x%x\n", |
| 8290 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8291 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 8292 | rc = -EIO; |
| 8293 | } else { |
| 8294 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8295 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8296 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8297 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8298 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8299 | phba->sli4_hba.lnk_info.lnk_no = |
| 8300 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8301 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8302 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8303 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8304 | phba->sli4_hba.lnk_info.lnk_no); |
| 8305 | } else |
| 8306 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8307 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8308 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8309 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8310 | phba->bbcredit_support = 1; |
| 8311 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8312 | } |
| 8313 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8314 | phba->sli4_hba.conf_trunk = |
| 8315 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8316 | phba->sli4_hba.extents_in_use = |
| 8317 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8318 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8319 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8320 | /* Reduce resource usage in kdump environment */ |
| 8321 | if (is_kdump_kernel() && |
| 8322 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8323 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8324 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8325 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8326 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8327 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8328 | /* Limit the max we support */ |
| 8329 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8330 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8331 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8332 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8333 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8334 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8335 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8336 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8337 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8338 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8339 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8340 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8341 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8342 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8343 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8344 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8345 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8346 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8347 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8348 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8349 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8350 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8351 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8352 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8353 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8354 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8355 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8356 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8357 | phba->max_vports = phba->max_vpi; |
| 8358 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8359 | "2003 cfg params Extents? %d " |
| 8360 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8361 | "VPI(B:%d M:%d) " |
| 8362 | "VFI(B:%d M:%d) " |
| 8363 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8364 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8365 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8366 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8367 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8368 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8369 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8370 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8371 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8372 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8373 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8374 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8375 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8376 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8377 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8378 | phba->sli4_hba.max_cfg_param.max_rq); |
| 8379 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8380 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8381 | * Calculate queue resources based on how |
| 8382 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8383 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8384 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8385 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8386 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8387 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8388 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8389 | /* |
| 8390 | * Whats left after this can go toward NVME / FCP. |
| 8391 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8392 | * plus one extra. When configured for |
| 8393 | * NVMET, FCP io channel WQs are not created. |
| 8394 | */ |
| 8395 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8396 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8397 | /* If NVME is configured, double the number of CQ/WQs needed */ |
| 8398 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 8399 | !phba->nvmet_support) |
| 8400 | qmin /= 2; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8401 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8402 | /* Check to see if there is enough for NVME */ |
| 8403 | if ((phba->cfg_irq_chann > qmin) || |
| 8404 | (phba->cfg_hdw_queue > qmin)) { |
| 8405 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8406 | "2005 Reducing Queues: " |
| 8407 | "WQ %d CQ %d EQ %d: min %d: " |
| 8408 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8409 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8410 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8411 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8412 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8413 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8414 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8415 | if (phba->cfg_irq_chann > qmin) |
| 8416 | phba->cfg_irq_chann = qmin; |
| 8417 | if (phba->cfg_hdw_queue > qmin) |
| 8418 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8419 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8420 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8421 | |
| 8422 | if (rc) |
| 8423 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8424 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8425 | /* Update link speed if forced link speed is supported */ |
| 8426 | 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] | 8427 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8428 | forced_link_speed = |
| 8429 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8430 | if (forced_link_speed) { |
| 8431 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8432 | |
| 8433 | switch (forced_link_speed) { |
| 8434 | case LINK_SPEED_1G: |
| 8435 | phba->cfg_link_speed = |
| 8436 | LPFC_USER_LINK_SPEED_1G; |
| 8437 | break; |
| 8438 | case LINK_SPEED_2G: |
| 8439 | phba->cfg_link_speed = |
| 8440 | LPFC_USER_LINK_SPEED_2G; |
| 8441 | break; |
| 8442 | case LINK_SPEED_4G: |
| 8443 | phba->cfg_link_speed = |
| 8444 | LPFC_USER_LINK_SPEED_4G; |
| 8445 | break; |
| 8446 | case LINK_SPEED_8G: |
| 8447 | phba->cfg_link_speed = |
| 8448 | LPFC_USER_LINK_SPEED_8G; |
| 8449 | break; |
| 8450 | case LINK_SPEED_10G: |
| 8451 | phba->cfg_link_speed = |
| 8452 | LPFC_USER_LINK_SPEED_10G; |
| 8453 | break; |
| 8454 | case LINK_SPEED_16G: |
| 8455 | phba->cfg_link_speed = |
| 8456 | LPFC_USER_LINK_SPEED_16G; |
| 8457 | break; |
| 8458 | case LINK_SPEED_32G: |
| 8459 | phba->cfg_link_speed = |
| 8460 | LPFC_USER_LINK_SPEED_32G; |
| 8461 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8462 | case LINK_SPEED_64G: |
| 8463 | phba->cfg_link_speed = |
| 8464 | LPFC_USER_LINK_SPEED_64G; |
| 8465 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8466 | case 0xffff: |
| 8467 | phba->cfg_link_speed = |
| 8468 | LPFC_USER_LINK_SPEED_AUTO; |
| 8469 | break; |
| 8470 | default: |
| 8471 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8472 | "0047 Unrecognized link " |
| 8473 | "speed : %d\n", |
| 8474 | forced_link_speed); |
| 8475 | phba->cfg_link_speed = |
| 8476 | LPFC_USER_LINK_SPEED_AUTO; |
| 8477 | } |
| 8478 | } |
| 8479 | } |
| 8480 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8481 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8482 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8483 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8484 | if (phba->cfg_hba_queue_depth > length) { |
| 8485 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8486 | "3361 HBA queue depth changed from %d to %d\n", |
| 8487 | phba->cfg_hba_queue_depth, length); |
| 8488 | phba->cfg_hba_queue_depth = length; |
| 8489 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8490 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8491 | 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] | 8492 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8493 | goto read_cfg_out; |
| 8494 | |
| 8495 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8496 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8497 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8498 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8499 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8500 | length, LPFC_SLI4_MBX_EMBED); |
| 8501 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8502 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8503 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8504 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8505 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8506 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8507 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8508 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8509 | "3026 Mailbox failed , mbxCmd x%x " |
| 8510 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8511 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8512 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8513 | goto read_cfg_out; |
| 8514 | } |
| 8515 | |
| 8516 | /* search for fc_fcoe resrouce descriptor */ |
| 8517 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8518 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8519 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8520 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8521 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8522 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8523 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8524 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8525 | goto read_cfg_out; |
| 8526 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8527 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8528 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8529 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8530 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8531 | phba->sli4_hba.iov.pf_number = |
| 8532 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8533 | phba->sli4_hba.iov.vf_number = |
| 8534 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8535 | break; |
| 8536 | } |
| 8537 | } |
| 8538 | |
| 8539 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8540 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8541 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8542 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8543 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8544 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8545 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8546 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8547 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8548 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8549 | |
| 8550 | read_cfg_out: |
| 8551 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8552 | return rc; |
| 8553 | } |
| 8554 | |
| 8555 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8556 | * 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] | 8557 | * @phba: pointer to lpfc hba data structure. |
| 8558 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8559 | * This routine is invoked to setup the port-side endian order when |
| 8560 | * the port if_type is 0. This routine has no function for other |
| 8561 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8562 | * |
| 8563 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8564 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8565 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8566 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8567 | **/ |
| 8568 | static int |
| 8569 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8570 | { |
| 8571 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8572 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8573 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8574 | HOST_ENDIAN_HIGH_WORD1}; |
| 8575 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8576 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8577 | switch (if_type) { |
| 8578 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8579 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8580 | GFP_KERNEL); |
| 8581 | if (!mboxq) { |
| 8582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8583 | "0492 Unable to allocate memory for " |
| 8584 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8585 | "command\n"); |
| 8586 | return -ENOMEM; |
| 8587 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8588 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8589 | /* |
| 8590 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8591 | * two words to contain special data values and no other data. |
| 8592 | */ |
| 8593 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8594 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8595 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8596 | if (rc != MBX_SUCCESS) { |
| 8597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8598 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8599 | "failed with status x%x\n", |
| 8600 | rc); |
| 8601 | rc = -EIO; |
| 8602 | } |
| 8603 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8604 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8605 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8606 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8607 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8608 | default: |
| 8609 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8610 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8611 | return rc; |
| 8612 | } |
| 8613 | |
| 8614 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8615 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8616 | * @phba: pointer to lpfc hba data structure. |
| 8617 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8618 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8619 | * 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] | 8620 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8621 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8622 | * |
| 8623 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8624 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8625 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8626 | **/ |
| 8627 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8628 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8629 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8630 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8631 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8632 | * device parameters |
| 8633 | */ |
| 8634 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8635 | if (phba->nvmet_support) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8636 | if (phba->cfg_irq_chann < phba->cfg_nvmet_mrq) |
| 8637 | phba->cfg_nvmet_mrq = phba->cfg_irq_chann; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8638 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8639 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8640 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8641 | |
| 8642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8643 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8644 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8645 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8646 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8647 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8648 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8649 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8650 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8651 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8652 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8653 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8654 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8655 | } |
| 8656 | |
| 8657 | static int |
| 8658 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8659 | { |
| 8660 | struct lpfc_queue *qdesc; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8661 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8662 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8663 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8664 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8665 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8666 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8667 | if (!qdesc) { |
| 8668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8669 | "0508 Failed allocate fast-path NVME CQ (%d)\n", |
| 8670 | wqidx); |
| 8671 | return 1; |
| 8672 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8673 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8674 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8675 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8676 | phba->sli4_hba.hdwq[wqidx].nvme_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8677 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8678 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8679 | LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT, |
| 8680 | cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8681 | if (!qdesc) { |
| 8682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8683 | "0509 Failed allocate fast-path NVME WQ (%d)\n", |
| 8684 | wqidx); |
| 8685 | return 1; |
| 8686 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8687 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8688 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8689 | phba->sli4_hba.hdwq[wqidx].nvme_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8690 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8691 | return 0; |
| 8692 | } |
| 8693 | |
| 8694 | static int |
| 8695 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8696 | { |
| 8697 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8698 | uint32_t wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8699 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8700 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8701 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8702 | /* Create Fast Path FCP CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8703 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8704 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8705 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8706 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8707 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8708 | |
| 8709 | else |
| 8710 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8711 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8712 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8713 | if (!qdesc) { |
| 8714 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8715 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); |
| 8716 | return 1; |
| 8717 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8718 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8719 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8720 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8721 | phba->sli4_hba.hdwq[wqidx].fcp_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8722 | |
| 8723 | /* Create Fast Path FCP WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8724 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8725 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8726 | wqesize = (phba->fcp_embed_io) ? |
| 8727 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8728 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8729 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8730 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8731 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8732 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8733 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8734 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8735 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8736 | if (!qdesc) { |
| 8737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8738 | "0503 Failed allocate fast-path FCP WQ (%d)\n", |
| 8739 | wqidx); |
| 8740 | return 1; |
| 8741 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8742 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8743 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8744 | phba->sli4_hba.hdwq[wqidx].fcp_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8745 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8746 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8747 | } |
| 8748 | |
| 8749 | /** |
| 8750 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8751 | * @phba: pointer to lpfc hba data structure. |
| 8752 | * |
| 8753 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8754 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8755 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8756 | * we just use some constant number as place holder. |
| 8757 | * |
| 8758 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8759 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8760 | * -ENOMEM - No availble memory |
| 8761 | * -EIO - The mailbox failed to complete successfully. |
| 8762 | **/ |
| 8763 | int |
| 8764 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8765 | { |
| 8766 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8767 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8768 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8769 | struct lpfc_vector_map_info *cpup; |
| 8770 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8771 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8772 | |
| 8773 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8774 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8775 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8776 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8777 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8778 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8779 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8780 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8781 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8782 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8783 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8784 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8785 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8786 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8787 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8788 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8789 | phba->sli4_hba.hdwq = kcalloc( |
| 8790 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8791 | GFP_KERNEL); |
| 8792 | if (!phba->sli4_hba.hdwq) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8794 | "6427 Failed allocate memory for " |
| 8795 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8796 | goto out_error; |
| 8797 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8798 | /* Prepare hardware queues to take IO buffers */ |
| 8799 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8800 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8801 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8802 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8803 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 8804 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 8805 | qp->get_io_bufs = 0; |
| 8806 | qp->put_io_bufs = 0; |
| 8807 | qp->total_io_bufs = 0; |
| 8808 | spin_lock_init(&qp->abts_scsi_buf_list_lock); |
| 8809 | INIT_LIST_HEAD(&qp->lpfc_abts_scsi_buf_list); |
| 8810 | qp->abts_scsi_io_bufs = 0; |
| 8811 | spin_lock_init(&qp->abts_nvme_buf_list_lock); |
| 8812 | INIT_LIST_HEAD(&qp->lpfc_abts_nvme_buf_list); |
| 8813 | qp->abts_nvme_io_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8814 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8815 | } |
| 8816 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8817 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8818 | if (phba->nvmet_support) { |
| 8819 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8820 | phba->cfg_nvmet_mrq, |
| 8821 | sizeof(struct lpfc_queue *), |
| 8822 | GFP_KERNEL); |
| 8823 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8825 | "3121 Fail allocate memory for " |
| 8826 | "fast-path CQ set array\n"); |
| 8827 | goto out_error; |
| 8828 | } |
| 8829 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8830 | phba->cfg_nvmet_mrq, |
| 8831 | sizeof(struct lpfc_queue *), |
| 8832 | GFP_KERNEL); |
| 8833 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8835 | "3122 Fail allocate memory for " |
| 8836 | "fast-path RQ set hdr array\n"); |
| 8837 | goto out_error; |
| 8838 | } |
| 8839 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8840 | phba->cfg_nvmet_mrq, |
| 8841 | sizeof(struct lpfc_queue *), |
| 8842 | GFP_KERNEL); |
| 8843 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8844 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8845 | "3124 Fail allocate memory for " |
| 8846 | "fast-path RQ set data array\n"); |
| 8847 | goto out_error; |
| 8848 | } |
| 8849 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8850 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8851 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8852 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8853 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8854 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8855 | for_each_present_cpu(cpu) { |
| 8856 | /* We only want to create 1 EQ per vector, even though |
| 8857 | * multiple CPUs might be using that vector. so only |
| 8858 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8859 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8860 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8861 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8862 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8863 | |
| 8864 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 8865 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8866 | |
| 8867 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8868 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8869 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8870 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8871 | if (!qdesc) { |
| 8872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8873 | "0497 Failed allocate EQ (%d)\n", |
| 8874 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8875 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8876 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8877 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8878 | qdesc->hdwq = cpup->hdwq; |
| 8879 | qdesc->chann = cpu; /* First CPU this EQ is affinitised to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8880 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8881 | |
| 8882 | /* Save the allocated EQ in the Hardware Queue */ |
| 8883 | qp->hba_eq = qdesc; |
| 8884 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8885 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 8886 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8887 | } |
| 8888 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8889 | /* Now we need to populate the other Hardware Queues, that share |
| 8890 | * an IRQ vector, with the associated EQ ptr. |
| 8891 | */ |
| 8892 | for_each_present_cpu(cpu) { |
| 8893 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8894 | |
| 8895 | /* Check for EQ already allocated in previous loop */ |
| 8896 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 8897 | continue; |
| 8898 | |
| 8899 | /* Check for multiple CPUs per hdwq */ |
| 8900 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8901 | if (qp->hba_eq) |
| 8902 | continue; |
| 8903 | |
| 8904 | /* We need to share an EQ for this hdwq */ |
| 8905 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 8906 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 8907 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 8908 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8909 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8910 | /* Allocate SCSI SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8911 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8912 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) |
| 8913 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8914 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8915 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8916 | /* Allocate NVME SLI4 CQ/WQs */ |
| 8917 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8918 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8919 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) |
| 8920 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8921 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8922 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8923 | if (phba->nvmet_support) { |
| 8924 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8925 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 8926 | LPFC_FIND_BY_HDWQ); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8927 | qdesc = lpfc_sli4_queue_alloc( |
| 8928 | phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8929 | LPFC_DEFAULT_PAGE_SIZE, |
| 8930 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8931 | phba->sli4_hba.cq_ecount, |
| 8932 | cpu); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8933 | if (!qdesc) { |
| 8934 | lpfc_printf_log( |
| 8935 | phba, KERN_ERR, LOG_INIT, |
| 8936 | "3142 Failed allocate NVME " |
| 8937 | "CQ Set (%d)\n", idx); |
| 8938 | goto out_error; |
| 8939 | } |
| 8940 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8941 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8942 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8943 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8944 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8945 | } |
| 8946 | } |
| 8947 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8948 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8949 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8950 | */ |
| 8951 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8952 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8953 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8954 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8955 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8956 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8957 | if (!qdesc) { |
| 8958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8959 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8960 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8961 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8962 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | phba->sli4_hba.mbx_cq = qdesc; |
| 8964 | |
| 8965 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8966 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8967 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8968 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8969 | if (!qdesc) { |
| 8970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8971 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8972 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8973 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8974 | qdesc->qe_valid = 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8975 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8976 | phba->sli4_hba.els_cq = qdesc; |
| 8977 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8978 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8979 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8980 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8981 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8982 | |
| 8983 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8984 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8985 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8986 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8987 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8988 | if (!qdesc) { |
| 8989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8990 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8991 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8992 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8993 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8994 | phba->sli4_hba.mbx_wq = qdesc; |
| 8995 | |
| 8996 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8997 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8998 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8999 | |
| 9000 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9001 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9002 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9003 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9004 | if (!qdesc) { |
| 9005 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9006 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9007 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9008 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9009 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9010 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9011 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9012 | |
| 9013 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9014 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9015 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9016 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9017 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9018 | if (!qdesc) { |
| 9019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9020 | "6079 Failed allocate NVME LS CQ\n"); |
| 9021 | goto out_error; |
| 9022 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9023 | qdesc->chann = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9024 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9025 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9026 | |
| 9027 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9028 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9029 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9030 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9031 | if (!qdesc) { |
| 9032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9033 | "6080 Failed allocate NVME LS WQ\n"); |
| 9034 | goto out_error; |
| 9035 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9036 | qdesc->chann = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9037 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9038 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9039 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9040 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9041 | /* |
| 9042 | * Create Receive Queue (RQ) |
| 9043 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9044 | |
| 9045 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9046 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9047 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9048 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9049 | if (!qdesc) { |
| 9050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9051 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9052 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9053 | } |
| 9054 | phba->sli4_hba.hdr_rq = qdesc; |
| 9055 | |
| 9056 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9057 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9058 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9059 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9060 | if (!qdesc) { |
| 9061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9062 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9063 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9064 | } |
| 9065 | phba->sli4_hba.dat_rq = qdesc; |
| 9066 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9067 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9068 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9069 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9070 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9071 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9072 | /* Create NVMET Receive Queue for header */ |
| 9073 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9074 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9075 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9076 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9077 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9078 | if (!qdesc) { |
| 9079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9080 | "3146 Failed allocate " |
| 9081 | "receive HRQ\n"); |
| 9082 | goto out_error; |
| 9083 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9084 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9085 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9086 | |
| 9087 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9088 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9089 | GFP_KERNEL, |
| 9090 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9091 | if (qdesc->rqbp == NULL) { |
| 9092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9093 | "6131 Failed allocate " |
| 9094 | "Header RQBP\n"); |
| 9095 | goto out_error; |
| 9096 | } |
| 9097 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9098 | /* Put list in known state in case driver load fails. */ |
| 9099 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9100 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9101 | /* Create NVMET Receive Queue for data */ |
| 9102 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9103 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9104 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9105 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9106 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9107 | if (!qdesc) { |
| 9108 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9109 | "3156 Failed allocate " |
| 9110 | "receive DRQ\n"); |
| 9111 | goto out_error; |
| 9112 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9113 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9114 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9115 | } |
| 9116 | } |
| 9117 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9118 | #if defined(BUILD_NVME) |
| 9119 | /* Clear NVME stats */ |
| 9120 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9121 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9122 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9123 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9124 | } |
| 9125 | } |
| 9126 | #endif |
| 9127 | |
| 9128 | /* Clear SCSI stats */ |
| 9129 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9130 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9131 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9132 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9133 | } |
| 9134 | } |
| 9135 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9136 | return 0; |
| 9137 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9138 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9139 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9140 | return -ENOMEM; |
| 9141 | } |
| 9142 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9143 | static inline void |
| 9144 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9145 | { |
| 9146 | if (*qp != NULL) { |
| 9147 | lpfc_sli4_queue_free(*qp); |
| 9148 | *qp = NULL; |
| 9149 | } |
| 9150 | } |
| 9151 | |
| 9152 | static inline void |
| 9153 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9154 | { |
| 9155 | int idx; |
| 9156 | |
| 9157 | if (*qs == NULL) |
| 9158 | return; |
| 9159 | |
| 9160 | for (idx = 0; idx < max; idx++) |
| 9161 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9162 | |
| 9163 | kfree(*qs); |
| 9164 | *qs = NULL; |
| 9165 | } |
| 9166 | |
| 9167 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9168 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9169 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9170 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9171 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9172 | uint32_t idx; |
| 9173 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9174 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9175 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9176 | /* Loop thru all Hardware Queues */ |
| 9177 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9178 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9179 | lpfc_sli4_queue_free(hdwq[idx].fcp_cq); |
| 9180 | lpfc_sli4_queue_free(hdwq[idx].nvme_cq); |
| 9181 | lpfc_sli4_queue_free(hdwq[idx].fcp_wq); |
| 9182 | lpfc_sli4_queue_free(hdwq[idx].nvme_wq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9183 | hdwq[idx].hba_eq = NULL; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9184 | hdwq[idx].fcp_cq = NULL; |
| 9185 | hdwq[idx].nvme_cq = NULL; |
| 9186 | hdwq[idx].fcp_wq = NULL; |
| 9187 | hdwq[idx].nvme_wq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9188 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9189 | /* Loop thru all IRQ vectors */ |
| 9190 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9191 | /* Free the EQ corresponding to the IRQ vector */ |
| 9192 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9193 | lpfc_sli4_queue_free(eq); |
| 9194 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9195 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9196 | } |
| 9197 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9198 | /** |
| 9199 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9200 | * @phba: pointer to lpfc hba data structure. |
| 9201 | * |
| 9202 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9203 | * operation. |
| 9204 | * |
| 9205 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9206 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9207 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9208 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9209 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9210 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9211 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9212 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9213 | /* |
| 9214 | * Set FREE_INIT before beginning to free the queues. |
| 9215 | * Wait until the users of queues to acknowledge to |
| 9216 | * release queues by clearing FREE_WAIT. |
| 9217 | */ |
| 9218 | spin_lock_irq(&phba->hbalock); |
| 9219 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9220 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9221 | spin_unlock_irq(&phba->hbalock); |
| 9222 | msleep(20); |
| 9223 | spin_lock_irq(&phba->hbalock); |
| 9224 | } |
| 9225 | spin_unlock_irq(&phba->hbalock); |
| 9226 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9227 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9228 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9229 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9230 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9231 | if (phba->nvmet_support) { |
| 9232 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9233 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9234 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9235 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9236 | phba->cfg_nvmet_mrq); |
| 9237 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9238 | phba->cfg_nvmet_mrq); |
| 9239 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9240 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9241 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9242 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9243 | |
| 9244 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9245 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9246 | |
| 9247 | /* Release ELS work queue */ |
| 9248 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9249 | |
| 9250 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9251 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9252 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9254 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9255 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9256 | |
| 9257 | /* Release NVME LS complete queue */ |
| 9258 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9259 | |
| 9260 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9261 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9262 | |
| 9263 | /* Everything on this list has been freed */ |
| 9264 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9265 | |
| 9266 | /* Done with freeing the queues */ |
| 9267 | spin_lock_irq(&phba->hbalock); |
| 9268 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9269 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9270 | } |
| 9271 | |
| 9272 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9273 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9274 | { |
| 9275 | struct lpfc_rqb *rqbp; |
| 9276 | struct lpfc_dmabuf *h_buf; |
| 9277 | struct rqb_dmabuf *rqb_buffer; |
| 9278 | |
| 9279 | rqbp = rq->rqbp; |
| 9280 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9281 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9282 | struct lpfc_dmabuf, list); |
| 9283 | |
| 9284 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9285 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9286 | rqbp->buffer_count--; |
| 9287 | } |
| 9288 | return 1; |
| 9289 | } |
| 9290 | |
| 9291 | static int |
| 9292 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9293 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9294 | int qidx, uint32_t qtype) |
| 9295 | { |
| 9296 | struct lpfc_sli_ring *pring; |
| 9297 | int rc; |
| 9298 | |
| 9299 | if (!eq || !cq || !wq) { |
| 9300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9301 | "6085 Fast-path %s (%d) not allocated\n", |
| 9302 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9303 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9304 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9305 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9306 | /* create the Cq first */ |
| 9307 | rc = lpfc_cq_create(phba, cq, eq, |
| 9308 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9309 | if (rc) { |
| 9310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9311 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9312 | qidx, (uint32_t)rc); |
| 9313 | return rc; |
| 9314 | } |
| 9315 | |
| 9316 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9317 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9318 | if (cq_map) |
| 9319 | *cq_map = cq->queue_id; |
| 9320 | |
| 9321 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9322 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9323 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9324 | |
| 9325 | /* create the wq */ |
| 9326 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9327 | if (rc) { |
| 9328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9329 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9330 | qidx, (uint32_t)rc); |
| 9331 | /* no need to tear down cq - caller will do so */ |
| 9332 | return rc; |
| 9333 | } |
| 9334 | |
| 9335 | /* Bind this CQ/WQ to the NVME ring */ |
| 9336 | pring = wq->pring; |
| 9337 | pring->sli.sli4.wqp = (void *)wq; |
| 9338 | cq->pring = pring; |
| 9339 | |
| 9340 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9341 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9342 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9343 | } else { |
| 9344 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9345 | if (rc) { |
| 9346 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9347 | "0539 Failed setup of slow-path MQ: " |
| 9348 | "rc = 0x%x\n", rc); |
| 9349 | /* no need to tear down cq - caller will do so */ |
| 9350 | return rc; |
| 9351 | } |
| 9352 | |
| 9353 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9354 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9355 | phba->sli4_hba.mbx_wq->queue_id, |
| 9356 | phba->sli4_hba.mbx_cq->queue_id); |
| 9357 | } |
| 9358 | |
| 9359 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9360 | } |
| 9361 | |
| 9362 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9363 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9364 | * @phba: pointer to lpfc hba data structure. |
| 9365 | * |
| 9366 | * This routine will populate the cq_lookup table by all |
| 9367 | * available CQ queue_id's. |
| 9368 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9369 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9370 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9371 | { |
| 9372 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9373 | int qidx; |
| 9374 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9375 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9376 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9377 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9378 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9379 | /* Get the EQ corresponding to the IRQ vector */ |
| 9380 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9381 | if (!eq) |
| 9382 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9383 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9384 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9385 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9386 | continue; |
| 9387 | if ((childq->subtype == LPFC_FCP) || |
| 9388 | (childq->subtype == LPFC_NVME)) |
| 9389 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9390 | childq; |
| 9391 | } |
| 9392 | } |
| 9393 | } |
| 9394 | |
| 9395 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9396 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9397 | * @phba: pointer to lpfc hba data structure. |
| 9398 | * |
| 9399 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9400 | * operation. |
| 9401 | * |
| 9402 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9403 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9404 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9405 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9406 | **/ |
| 9407 | int |
| 9408 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9409 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9410 | uint32_t shdr_status, shdr_add_status; |
| 9411 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9412 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9413 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9414 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9415 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9416 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9417 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9418 | |
| 9419 | /* Check for dual-ULP support */ |
| 9420 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9421 | if (!mboxq) { |
| 9422 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9423 | "3249 Unable to allocate memory for " |
| 9424 | "QUERY_FW_CFG mailbox command\n"); |
| 9425 | return -ENOMEM; |
| 9426 | } |
| 9427 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9428 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9429 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9430 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9431 | length, LPFC_SLI4_MBX_EMBED); |
| 9432 | |
| 9433 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9434 | |
| 9435 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9436 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9437 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9438 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9439 | if (shdr_status || shdr_add_status || rc) { |
| 9440 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9441 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9442 | "x%x add_status x%x, mbx status x%x\n", |
| 9443 | shdr_status, shdr_add_status, rc); |
| 9444 | if (rc != MBX_TIMEOUT) |
| 9445 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9446 | rc = -ENXIO; |
| 9447 | goto out_error; |
| 9448 | } |
| 9449 | |
| 9450 | phba->sli4_hba.fw_func_mode = |
| 9451 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9452 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9453 | 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] | 9454 | phba->sli4_hba.physical_port = |
| 9455 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9456 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9457 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9458 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9459 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9460 | |
| 9461 | if (rc != MBX_TIMEOUT) |
| 9462 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9463 | |
| 9464 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9465 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9466 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9467 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9468 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9469 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9470 | if (!qp) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9472 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9473 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9474 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9475 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9476 | |
| 9477 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9478 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9479 | /* Create HBA Event Queues (EQs) in order */ |
| 9480 | for_each_present_cpu(cpu) { |
| 9481 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9482 | |
| 9483 | /* Look for the CPU thats using that vector with |
| 9484 | * LPFC_CPU_FIRST_IRQ set. |
| 9485 | */ |
| 9486 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9487 | continue; |
| 9488 | if (qidx != cpup->eq) |
| 9489 | continue; |
| 9490 | |
| 9491 | /* Create an EQ for that vector */ |
| 9492 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9493 | phba->cfg_fcp_imax); |
| 9494 | if (rc) { |
| 9495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9496 | "0523 Failed setup of fast-path" |
| 9497 | " EQ (%d), rc = 0x%x\n", |
| 9498 | cpup->eq, (uint32_t)rc); |
| 9499 | goto out_destroy; |
| 9500 | } |
| 9501 | |
| 9502 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9503 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9504 | qp[cpup->hdwq].hba_eq; |
| 9505 | |
| 9506 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9507 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9508 | cpup->eq, |
| 9509 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9510 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9511 | } |
| 9512 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9513 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9514 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9515 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9516 | cpu = lpfc_find_cpu_handle(phba, qidx, |
| 9517 | LPFC_FIND_BY_HDWQ); |
| 9518 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9519 | |
| 9520 | /* Create the CQ/WQ corresponding to the |
| 9521 | * Hardware Queue |
| 9522 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9523 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9524 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9525 | qp[qidx].nvme_cq, |
| 9526 | qp[qidx].nvme_wq, |
| 9527 | &phba->sli4_hba.hdwq[qidx].nvme_cq_map, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9528 | qidx, LPFC_NVME); |
| 9529 | if (rc) { |
| 9530 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9531 | "6123 Failed to setup fastpath " |
| 9532 | "NVME WQ/CQ (%d), rc = 0x%x\n", |
| 9533 | qidx, (uint32_t)rc); |
| 9534 | goto out_destroy; |
| 9535 | } |
| 9536 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9537 | } |
| 9538 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9539 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9540 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9541 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9542 | |
| 9543 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9544 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9545 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9546 | qp[qidx].fcp_cq, |
| 9547 | qp[qidx].fcp_wq, |
| 9548 | &phba->sli4_hba.hdwq[qidx].fcp_cq_map, |
| 9549 | qidx, LPFC_FCP); |
| 9550 | if (rc) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9552 | "0535 Failed to setup fastpath " |
| 9553 | "FCP WQ/CQ (%d), rc = 0x%x\n", |
| 9554 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9555 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9556 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9557 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9558 | |
| 9559 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9560 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9561 | */ |
| 9562 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9563 | /* Set up slow-path MBOX CQ/MQ */ |
| 9564 | |
| 9565 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9567 | "0528 %s not allocated\n", |
| 9568 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9569 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9570 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9571 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9572 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9573 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9574 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9575 | phba->sli4_hba.mbx_cq, |
| 9576 | phba->sli4_hba.mbx_wq, |
| 9577 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9578 | if (rc) { |
| 9579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9580 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9581 | (uint32_t)rc); |
| 9582 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9583 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9584 | if (phba->nvmet_support) { |
| 9585 | if (!phba->sli4_hba.nvmet_cqset) { |
| 9586 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9587 | "3165 Fast-path NVME CQ Set " |
| 9588 | "array not allocated\n"); |
| 9589 | rc = -ENOMEM; |
| 9590 | goto out_destroy; |
| 9591 | } |
| 9592 | if (phba->cfg_nvmet_mrq > 1) { |
| 9593 | rc = lpfc_cq_create_set(phba, |
| 9594 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9595 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9596 | LPFC_WCQ, LPFC_NVMET); |
| 9597 | if (rc) { |
| 9598 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9599 | "3164 Failed setup of NVME CQ " |
| 9600 | "Set, rc = 0x%x\n", |
| 9601 | (uint32_t)rc); |
| 9602 | goto out_destroy; |
| 9603 | } |
| 9604 | } else { |
| 9605 | /* Set up NVMET Receive Complete Queue */ |
| 9606 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9607 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9608 | LPFC_WCQ, LPFC_NVMET); |
| 9609 | if (rc) { |
| 9610 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9611 | "6089 Failed setup NVMET CQ: " |
| 9612 | "rc = 0x%x\n", (uint32_t)rc); |
| 9613 | goto out_destroy; |
| 9614 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9615 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9616 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9617 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9618 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9619 | "parent eq-id=%d\n", |
| 9620 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9621 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9622 | } |
| 9623 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9624 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9625 | /* Set up slow-path ELS WQ/CQ */ |
| 9626 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9628 | "0530 ELS %s not allocated\n", |
| 9629 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9630 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9631 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9632 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9633 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9634 | phba->sli4_hba.els_cq, |
| 9635 | phba->sli4_hba.els_wq, |
| 9636 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9637 | if (rc) { |
| 9638 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9639 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9640 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9641 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9642 | } |
| 9643 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9644 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9645 | phba->sli4_hba.els_wq->queue_id, |
| 9646 | phba->sli4_hba.els_cq->queue_id); |
| 9647 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9648 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9649 | /* Set up NVME LS Complete Queue */ |
| 9650 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 9651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9652 | "6091 LS %s not allocated\n", |
| 9653 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9654 | rc = -ENOMEM; |
| 9655 | goto out_destroy; |
| 9656 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9657 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9658 | phba->sli4_hba.nvmels_cq, |
| 9659 | phba->sli4_hba.nvmels_wq, |
| 9660 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9661 | if (rc) { |
| 9662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9663 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9664 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9665 | goto out_destroy; |
| 9666 | } |
| 9667 | |
| 9668 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9669 | "6096 ELS WQ setup: wq-id=%d, " |
| 9670 | "parent cq-id=%d\n", |
| 9671 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9672 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9673 | } |
| 9674 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9675 | /* |
| 9676 | * Create NVMET Receive Queue (RQ) |
| 9677 | */ |
| 9678 | if (phba->nvmet_support) { |
| 9679 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9680 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9681 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 9682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9683 | "6130 MRQ CQ Queues not " |
| 9684 | "allocated\n"); |
| 9685 | rc = -ENOMEM; |
| 9686 | goto out_destroy; |
| 9687 | } |
| 9688 | if (phba->cfg_nvmet_mrq > 1) { |
| 9689 | rc = lpfc_mrq_create(phba, |
| 9690 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9691 | phba->sli4_hba.nvmet_mrq_data, |
| 9692 | phba->sli4_hba.nvmet_cqset, |
| 9693 | LPFC_NVMET); |
| 9694 | if (rc) { |
| 9695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9696 | "6098 Failed setup of NVMET " |
| 9697 | "MRQ: rc = 0x%x\n", |
| 9698 | (uint32_t)rc); |
| 9699 | goto out_destroy; |
| 9700 | } |
| 9701 | |
| 9702 | } else { |
| 9703 | rc = lpfc_rq_create(phba, |
| 9704 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9705 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9706 | phba->sli4_hba.nvmet_cqset[0], |
| 9707 | LPFC_NVMET); |
| 9708 | if (rc) { |
| 9709 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9710 | "6057 Failed setup of NVMET " |
| 9711 | "Receive Queue: rc = 0x%x\n", |
| 9712 | (uint32_t)rc); |
| 9713 | goto out_destroy; |
| 9714 | } |
| 9715 | |
| 9716 | lpfc_printf_log( |
| 9717 | phba, KERN_INFO, LOG_INIT, |
| 9718 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9719 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9720 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9721 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9722 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9723 | |
| 9724 | } |
| 9725 | } |
| 9726 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9727 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 9728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9729 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9730 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9731 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9732 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9733 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9734 | 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] | 9735 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9736 | if (rc) { |
| 9737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9738 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9739 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9740 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9741 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9742 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9743 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9744 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9745 | "parent cq-id=%d\n", |
| 9746 | phba->sli4_hba.hdr_rq->queue_id, |
| 9747 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9748 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9749 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9750 | if (phba->cfg_fcp_imax) |
| 9751 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9752 | else |
| 9753 | usdelay = 0; |
| 9754 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9755 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9756 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9757 | 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] | 9758 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9759 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9760 | if (phba->sli4_hba.cq_max) { |
| 9761 | kfree(phba->sli4_hba.cq_lookup); |
| 9762 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9763 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9764 | if (!phba->sli4_hba.cq_lookup) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9765 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9766 | "0549 Failed setup of CQ Lookup table: " |
| 9767 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9768 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9769 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9770 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9771 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9772 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9773 | return 0; |
| 9774 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9775 | out_destroy: |
| 9776 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9777 | out_error: |
| 9778 | return rc; |
| 9779 | } |
| 9780 | |
| 9781 | /** |
| 9782 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9783 | * @phba: pointer to lpfc hba data structure. |
| 9784 | * |
| 9785 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9786 | * operation. |
| 9787 | * |
| 9788 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9789 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9790 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9791 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9792 | **/ |
| 9793 | void |
| 9794 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9795 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9796 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9797 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9798 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9799 | |
| 9800 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9801 | if (phba->sli4_hba.mbx_wq) |
| 9802 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9803 | |
| 9804 | /* Unset NVME LS work queue */ |
| 9805 | if (phba->sli4_hba.nvmels_wq) |
| 9806 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9807 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9808 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9809 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9810 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9811 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9812 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9813 | if (phba->sli4_hba.hdr_rq) |
| 9814 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9815 | phba->sli4_hba.dat_rq); |
| 9816 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9817 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9818 | if (phba->sli4_hba.mbx_cq) |
| 9819 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9820 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9821 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9822 | if (phba->sli4_hba.els_cq) |
| 9823 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9824 | |
| 9825 | /* Unset NVME LS complete queue */ |
| 9826 | if (phba->sli4_hba.nvmels_cq) |
| 9827 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9828 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9829 | if (phba->nvmet_support) { |
| 9830 | /* Unset NVMET MRQ queue */ |
| 9831 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9832 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9833 | lpfc_rq_destroy( |
| 9834 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9835 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9836 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9837 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9838 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9839 | /* Unset NVMET CQ Set complete queue */ |
| 9840 | if (phba->sli4_hba.nvmet_cqset) { |
| 9841 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9842 | lpfc_cq_destroy( |
| 9843 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9844 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9845 | } |
| 9846 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9847 | /* Unset fast-path SLI4 queues */ |
| 9848 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9849 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9850 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9851 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9852 | qp = &phba->sli4_hba.hdwq[qidx]; |
| 9853 | lpfc_wq_destroy(phba, qp->fcp_wq); |
| 9854 | lpfc_wq_destroy(phba, qp->nvme_wq); |
| 9855 | lpfc_cq_destroy(phba, qp->fcp_cq); |
| 9856 | lpfc_cq_destroy(phba, qp->nvme_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9857 | } |
| 9858 | /* Loop thru all IRQ vectors */ |
| 9859 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 9860 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 9861 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 9862 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9863 | } |
| 9864 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9865 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9866 | kfree(phba->sli4_hba.cq_lookup); |
| 9867 | phba->sli4_hba.cq_lookup = NULL; |
| 9868 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9873 | * @phba: pointer to lpfc hba data structure. |
| 9874 | * |
| 9875 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9876 | * events. The body of the completion queue event is a completion queue entry |
| 9877 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9878 | * the following HBA completion queue events for the worker thread to process: |
| 9879 | * - Mailbox asynchronous events |
| 9880 | * - Receive queue completion unsolicited events |
| 9881 | * Later, this can be used for all the slow-path events. |
| 9882 | * |
| 9883 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9884 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9885 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9886 | **/ |
| 9887 | static int |
| 9888 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9889 | { |
| 9890 | struct lpfc_cq_event *cq_event; |
| 9891 | int i; |
| 9892 | |
| 9893 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9894 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9895 | if (!cq_event) |
| 9896 | goto out_pool_create_fail; |
| 9897 | list_add_tail(&cq_event->list, |
| 9898 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9899 | } |
| 9900 | return 0; |
| 9901 | |
| 9902 | out_pool_create_fail: |
| 9903 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9904 | return -ENOMEM; |
| 9905 | } |
| 9906 | |
| 9907 | /** |
| 9908 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9909 | * @phba: pointer to lpfc hba data structure. |
| 9910 | * |
| 9911 | * This routine is invoked to free the pool of completion queue events at |
| 9912 | * driver unload time. Note that, it is the responsibility of the driver |
| 9913 | * cleanup routine to free all the outstanding completion-queue events |
| 9914 | * allocated from this pool back into the pool before invoking this routine |
| 9915 | * to destroy the pool. |
| 9916 | **/ |
| 9917 | static void |
| 9918 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9919 | { |
| 9920 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9921 | |
| 9922 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9923 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9924 | list_del(&cq_event->list); |
| 9925 | kfree(cq_event); |
| 9926 | } |
| 9927 | } |
| 9928 | |
| 9929 | /** |
| 9930 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9931 | * @phba: pointer to lpfc hba data structure. |
| 9932 | * |
| 9933 | * This routine is the lock free version of the API invoked to allocate a |
| 9934 | * completion-queue event from the free pool. |
| 9935 | * |
| 9936 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9937 | * NULL otherwise. |
| 9938 | **/ |
| 9939 | struct lpfc_cq_event * |
| 9940 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9941 | { |
| 9942 | struct lpfc_cq_event *cq_event = NULL; |
| 9943 | |
| 9944 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9945 | struct lpfc_cq_event, list); |
| 9946 | return cq_event; |
| 9947 | } |
| 9948 | |
| 9949 | /** |
| 9950 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9951 | * @phba: pointer to lpfc hba data structure. |
| 9952 | * |
| 9953 | * This routine is the lock version of the API invoked to allocate a |
| 9954 | * completion-queue event from the free pool. |
| 9955 | * |
| 9956 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9957 | * NULL otherwise. |
| 9958 | **/ |
| 9959 | struct lpfc_cq_event * |
| 9960 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9961 | { |
| 9962 | struct lpfc_cq_event *cq_event; |
| 9963 | unsigned long iflags; |
| 9964 | |
| 9965 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9966 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9967 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9968 | return cq_event; |
| 9969 | } |
| 9970 | |
| 9971 | /** |
| 9972 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9973 | * @phba: pointer to lpfc hba data structure. |
| 9974 | * @cq_event: pointer to the completion queue event to be freed. |
| 9975 | * |
| 9976 | * This routine is the lock free version of the API invoked to release a |
| 9977 | * completion-queue event back into the free pool. |
| 9978 | **/ |
| 9979 | void |
| 9980 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9981 | struct lpfc_cq_event *cq_event) |
| 9982 | { |
| 9983 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 9984 | } |
| 9985 | |
| 9986 | /** |
| 9987 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9988 | * @phba: pointer to lpfc hba data structure. |
| 9989 | * @cq_event: pointer to the completion queue event to be freed. |
| 9990 | * |
| 9991 | * This routine is the lock version of the API invoked to release a |
| 9992 | * completion-queue event back into the free pool. |
| 9993 | **/ |
| 9994 | void |
| 9995 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9996 | struct lpfc_cq_event *cq_event) |
| 9997 | { |
| 9998 | unsigned long iflags; |
| 9999 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10000 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 10001 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10002 | } |
| 10003 | |
| 10004 | /** |
| 10005 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 10006 | * @phba: pointer to lpfc hba data structure. |
| 10007 | * |
| 10008 | * This routine is to free all the pending completion-queue events to the |
| 10009 | * back into the free pool for device reset. |
| 10010 | **/ |
| 10011 | static void |
| 10012 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10013 | { |
| 10014 | LIST_HEAD(cqelist); |
| 10015 | struct lpfc_cq_event *cqe; |
| 10016 | unsigned long iflags; |
| 10017 | |
| 10018 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 10019 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10020 | /* Pending FCP XRI abort events */ |
| 10021 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10022 | &cqelist); |
| 10023 | /* Pending ELS XRI abort events */ |
| 10024 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10025 | &cqelist); |
| 10026 | /* Pending asynnc events */ |
| 10027 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10028 | &cqelist); |
| 10029 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10030 | |
| 10031 | while (!list_empty(&cqelist)) { |
| 10032 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 10033 | lpfc_sli4_cq_event_release(phba, cqe); |
| 10034 | } |
| 10035 | } |
| 10036 | |
| 10037 | /** |
| 10038 | * lpfc_pci_function_reset - Reset pci function. |
| 10039 | * @phba: pointer to lpfc hba data structure. |
| 10040 | * |
| 10041 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10042 | * all resources assigned to the PCI function which originates this request. |
| 10043 | * |
| 10044 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10045 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10046 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10047 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10048 | **/ |
| 10049 | int |
| 10050 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10051 | { |
| 10052 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10053 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10054 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10055 | uint32_t rdy_chk; |
| 10056 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10057 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10058 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10059 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10060 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10061 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10062 | switch (if_type) { |
| 10063 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10064 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10065 | GFP_KERNEL); |
| 10066 | if (!mboxq) { |
| 10067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10068 | "0494 Unable to allocate memory for " |
| 10069 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10070 | "command\n"); |
| 10071 | return -ENOMEM; |
| 10072 | } |
| 10073 | |
| 10074 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10075 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10076 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10077 | LPFC_SLI4_MBX_EMBED); |
| 10078 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10079 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10080 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10081 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10082 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10083 | &shdr->response); |
| 10084 | if (rc != MBX_TIMEOUT) |
| 10085 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10086 | if (shdr_status || shdr_add_status || rc) { |
| 10087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10088 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10089 | "failed with status x%x add_status x%x," |
| 10090 | " mbx status x%x\n", |
| 10091 | shdr_status, shdr_add_status, rc); |
| 10092 | rc = -ENXIO; |
| 10093 | } |
| 10094 | break; |
| 10095 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10096 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10097 | wait: |
| 10098 | /* |
| 10099 | * Poll the Port Status Register and wait for RDY for |
| 10100 | * up to 30 seconds. If the port doesn't respond, treat |
| 10101 | * it as an error. |
| 10102 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10103 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10104 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10105 | STATUSregaddr, ®_data.word0)) { |
| 10106 | rc = -ENODEV; |
| 10107 | goto out; |
| 10108 | } |
| 10109 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10110 | break; |
| 10111 | msleep(20); |
| 10112 | } |
| 10113 | |
| 10114 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10115 | phba->work_status[0] = readl( |
| 10116 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10117 | phba->work_status[1] = readl( |
| 10118 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10119 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10120 | "2890 Port not ready, port status reg " |
| 10121 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10122 | reg_data.word0, |
| 10123 | phba->work_status[0], |
| 10124 | phba->work_status[1]); |
| 10125 | rc = -ENODEV; |
| 10126 | goto out; |
| 10127 | } |
| 10128 | |
| 10129 | if (!port_reset) { |
| 10130 | /* |
| 10131 | * Reset the port now |
| 10132 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10133 | reg_data.word0 = 0; |
| 10134 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10135 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10136 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10137 | LPFC_SLIPORT_INIT_PORT); |
| 10138 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10139 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10140 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10141 | pci_read_config_word(phba->pcidev, |
| 10142 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10143 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10144 | port_reset = 1; |
| 10145 | msleep(20); |
| 10146 | goto wait; |
| 10147 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10148 | rc = -ENODEV; |
| 10149 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10150 | } |
| 10151 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10152 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10153 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10154 | default: |
| 10155 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10156 | } |
| 10157 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10158 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10159 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10160 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10162 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10163 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10164 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10165 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10166 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10167 | return rc; |
| 10168 | } |
| 10169 | |
| 10170 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10171 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10172 | * @phba: pointer to lpfc hba data structure. |
| 10173 | * |
| 10174 | * This routine is invoked to set up the PCI device memory space for device |
| 10175 | * with SLI-4 interface spec. |
| 10176 | * |
| 10177 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10178 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10179 | * other values - error |
| 10180 | **/ |
| 10181 | static int |
| 10182 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10183 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10184 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10185 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10186 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10187 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10188 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10189 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10190 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10191 | |
| 10192 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10193 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10194 | if (error) |
| 10195 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10196 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10197 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10198 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10199 | /* |
| 10200 | * The BARs and register set definitions and offset locations are |
| 10201 | * dependent on the if_type. |
| 10202 | */ |
| 10203 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10204 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10205 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10206 | } |
| 10207 | |
| 10208 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10209 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10210 | LPFC_SLI_INTF_VALID) { |
| 10211 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10212 | "2894 SLI_INTF reg contents invalid " |
| 10213 | "sli_intf reg 0x%x\n", |
| 10214 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10215 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10216 | } |
| 10217 | |
| 10218 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10219 | /* |
| 10220 | * Get the bus address of SLI4 device Bar regions and the |
| 10221 | * number of bytes required by each mapping. The mapping of the |
| 10222 | * particular PCI BARs regions is dependent on the type of |
| 10223 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10224 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10225 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10226 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10227 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10228 | |
| 10229 | /* |
| 10230 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10231 | * addr |
| 10232 | */ |
| 10233 | phba->sli4_hba.conf_regs_memmap_p = |
| 10234 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10235 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10236 | dev_printk(KERN_ERR, &pdev->dev, |
| 10237 | "ioremap failed for SLI4 PCI config " |
| 10238 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10239 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10240 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10241 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10242 | /* Set up BAR0 PCI config space register memory map */ |
| 10243 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10244 | } else { |
| 10245 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10246 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10247 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10248 | dev_printk(KERN_ERR, &pdev->dev, |
| 10249 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10250 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10251 | } |
| 10252 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10253 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10254 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10255 | dev_printk(KERN_ERR, &pdev->dev, |
| 10256 | "ioremap failed for SLI4 PCI config " |
| 10257 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10258 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10259 | } |
| 10260 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10261 | } |
| 10262 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10263 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10264 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10265 | /* |
| 10266 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10267 | * kernel virtual address and setup the registers. |
| 10268 | */ |
| 10269 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10270 | PCI_64BIT_BAR2); |
| 10271 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10272 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10273 | ioremap(phba->pci_bar1_map, |
| 10274 | bar1map_len); |
| 10275 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10276 | dev_err(&pdev->dev, |
| 10277 | "ioremap failed for SLI4 HBA " |
| 10278 | "control registers.\n"); |
| 10279 | error = -ENOMEM; |
| 10280 | goto out_iounmap_conf; |
| 10281 | } |
| 10282 | phba->pci_bar2_memmap_p = |
| 10283 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10284 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10285 | } else { |
| 10286 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10287 | goto out_iounmap_conf; |
| 10288 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10289 | } |
| 10290 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10291 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10292 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10293 | /* |
| 10294 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10295 | * virtual address and setup the registers. |
| 10296 | */ |
| 10297 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10298 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10299 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10300 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10301 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10302 | dev_err(&pdev->dev, |
| 10303 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10304 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10305 | goto out_iounmap_conf; |
| 10306 | } |
| 10307 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10308 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10309 | } |
| 10310 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10311 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10312 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10313 | /* |
| 10314 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10315 | * a kernel virtual address and setup the registers. |
| 10316 | */ |
| 10317 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10318 | PCI_64BIT_BAR4); |
| 10319 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10320 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10321 | ioremap(phba->pci_bar2_map, |
| 10322 | bar2map_len); |
| 10323 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10324 | dev_err(&pdev->dev, |
| 10325 | "ioremap failed for SLI4 HBA" |
| 10326 | " doorbell registers.\n"); |
| 10327 | error = -ENOMEM; |
| 10328 | goto out_iounmap_ctrl; |
| 10329 | } |
| 10330 | phba->pci_bar4_memmap_p = |
| 10331 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10332 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10333 | if (error) |
| 10334 | goto out_iounmap_all; |
| 10335 | } else { |
| 10336 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10337 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10338 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10339 | } |
| 10340 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10341 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10342 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10343 | /* |
| 10344 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10345 | * virtual address and setup the registers. |
| 10346 | */ |
| 10347 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10348 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10349 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10350 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10351 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10352 | dev_err(&pdev->dev, |
| 10353 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10354 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10355 | goto out_iounmap_ctrl; |
| 10356 | } |
| 10357 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10358 | } |
| 10359 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10360 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10361 | switch (if_type) { |
| 10362 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10363 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10364 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10365 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10366 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10367 | break; |
| 10368 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10369 | 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] | 10370 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10371 | 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] | 10372 | break; |
| 10373 | default: |
| 10374 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10375 | } |
| 10376 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10377 | return 0; |
| 10378 | |
| 10379 | out_iounmap_all: |
| 10380 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10381 | out_iounmap_ctrl: |
| 10382 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10383 | out_iounmap_conf: |
| 10384 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10385 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10386 | return error; |
| 10387 | } |
| 10388 | |
| 10389 | /** |
| 10390 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10391 | * @phba: pointer to lpfc hba data structure. |
| 10392 | * |
| 10393 | * This routine is invoked to unset the PCI device memory space for device |
| 10394 | * with SLI-4 interface spec. |
| 10395 | **/ |
| 10396 | static void |
| 10397 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10398 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10399 | uint32_t if_type; |
| 10400 | 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] | 10401 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10402 | switch (if_type) { |
| 10403 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10404 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10405 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10406 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10407 | break; |
| 10408 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10409 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10410 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10411 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10412 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10413 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10414 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10415 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10416 | default: |
| 10417 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10418 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10419 | if_type); |
| 10420 | break; |
| 10421 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10422 | } |
| 10423 | |
| 10424 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10425 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10426 | * @phba: pointer to lpfc hba data structure. |
| 10427 | * |
| 10428 | * 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] | 10429 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10430 | * |
| 10431 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10432 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10433 | * other values - error |
| 10434 | **/ |
| 10435 | static int |
| 10436 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10437 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10438 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10439 | LPFC_MBOXQ_t *pmb; |
| 10440 | |
| 10441 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10442 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10443 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10444 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10445 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10446 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10447 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10448 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10449 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10450 | /* |
| 10451 | * Assign MSI-X vectors to interrupt handlers |
| 10452 | */ |
| 10453 | |
| 10454 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10455 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10456 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10457 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10458 | if (rc) { |
| 10459 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10460 | "0421 MSI-X slow-path request_irq failed " |
| 10461 | "(%d)\n", rc); |
| 10462 | goto msi_fail_out; |
| 10463 | } |
| 10464 | |
| 10465 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10466 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10467 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10468 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10469 | |
| 10470 | if (rc) { |
| 10471 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10472 | "0429 MSI-X fast-path request_irq failed " |
| 10473 | "(%d)\n", rc); |
| 10474 | goto irq_fail_out; |
| 10475 | } |
| 10476 | |
| 10477 | /* |
| 10478 | * Configure HBA MSI-X attention conditions to messages |
| 10479 | */ |
| 10480 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10481 | |
| 10482 | if (!pmb) { |
| 10483 | rc = -ENOMEM; |
| 10484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10485 | "0474 Unable to allocate memory for issuing " |
| 10486 | "MBOX_CONFIG_MSI command\n"); |
| 10487 | goto mem_fail_out; |
| 10488 | } |
| 10489 | rc = lpfc_config_msi(phba, pmb); |
| 10490 | if (rc) |
| 10491 | goto mbx_fail_out; |
| 10492 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10493 | if (rc != MBX_SUCCESS) { |
| 10494 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10495 | "0351 Config MSI mailbox command failed, " |
| 10496 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10497 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10498 | goto mbx_fail_out; |
| 10499 | } |
| 10500 | |
| 10501 | /* Free memory allocated for mailbox command */ |
| 10502 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10503 | return rc; |
| 10504 | |
| 10505 | mbx_fail_out: |
| 10506 | /* Free memory allocated for mailbox command */ |
| 10507 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10508 | |
| 10509 | mem_fail_out: |
| 10510 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10511 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10512 | |
| 10513 | irq_fail_out: |
| 10514 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10515 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10516 | |
| 10517 | msi_fail_out: |
| 10518 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10519 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10520 | |
| 10521 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10522 | return rc; |
| 10523 | } |
| 10524 | |
| 10525 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10526 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10527 | * @phba: pointer to lpfc hba data structure. |
| 10528 | * |
| 10529 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10530 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10531 | * enable the MSI vector. The device driver is responsible for calling the |
| 10532 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10533 | * is done in this function. |
| 10534 | * |
| 10535 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10536 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10537 | * other values - error |
| 10538 | */ |
| 10539 | static int |
| 10540 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10541 | { |
| 10542 | int rc; |
| 10543 | |
| 10544 | rc = pci_enable_msi(phba->pcidev); |
| 10545 | if (!rc) |
| 10546 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10547 | "0462 PCI enable MSI mode success.\n"); |
| 10548 | else { |
| 10549 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10550 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10551 | return rc; |
| 10552 | } |
| 10553 | |
| 10554 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10555 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10556 | if (rc) { |
| 10557 | pci_disable_msi(phba->pcidev); |
| 10558 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10559 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10560 | } |
| 10561 | return rc; |
| 10562 | } |
| 10563 | |
| 10564 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10565 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10566 | * @phba: pointer to lpfc hba data structure. |
| 10567 | * |
| 10568 | * This routine is invoked to enable device interrupt and associate driver's |
| 10569 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10570 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10571 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10572 | * mode which is supported by the platform, kernel, and device in the order |
| 10573 | * of: |
| 10574 | * MSI-X -> MSI -> IRQ. |
| 10575 | * |
| 10576 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10577 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10578 | * other values - error |
| 10579 | **/ |
| 10580 | static uint32_t |
| 10581 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10582 | { |
| 10583 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10584 | int retval; |
| 10585 | |
| 10586 | if (cfg_mode == 2) { |
| 10587 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10588 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10589 | if (!retval) { |
| 10590 | /* Now, try to enable MSI-X interrupt mode */ |
| 10591 | retval = lpfc_sli_enable_msix(phba); |
| 10592 | if (!retval) { |
| 10593 | /* Indicate initialization to MSI-X mode */ |
| 10594 | phba->intr_type = MSIX; |
| 10595 | intr_mode = 2; |
| 10596 | } |
| 10597 | } |
| 10598 | } |
| 10599 | |
| 10600 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10601 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10602 | retval = lpfc_sli_enable_msi(phba); |
| 10603 | if (!retval) { |
| 10604 | /* Indicate initialization to MSI mode */ |
| 10605 | phba->intr_type = MSI; |
| 10606 | intr_mode = 1; |
| 10607 | } |
| 10608 | } |
| 10609 | |
| 10610 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10611 | if (phba->intr_type == NONE) { |
| 10612 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10613 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10614 | if (!retval) { |
| 10615 | /* Indicate initialization to INTx mode */ |
| 10616 | phba->intr_type = INTx; |
| 10617 | intr_mode = 0; |
| 10618 | } |
| 10619 | } |
| 10620 | return intr_mode; |
| 10621 | } |
| 10622 | |
| 10623 | /** |
| 10624 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10625 | * @phba: pointer to lpfc hba data structure. |
| 10626 | * |
| 10627 | * This routine is invoked to disable device interrupt and disassociate the |
| 10628 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10629 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10630 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10631 | **/ |
| 10632 | static void |
| 10633 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10634 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10635 | int nr_irqs, i; |
| 10636 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10637 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10638 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10639 | else |
| 10640 | nr_irqs = 1; |
| 10641 | |
| 10642 | for (i = 0; i < nr_irqs; i++) |
| 10643 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10644 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10645 | |
| 10646 | /* Reset interrupt management states */ |
| 10647 | phba->intr_type = NONE; |
| 10648 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10649 | } |
| 10650 | |
| 10651 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10652 | * 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] | 10653 | * @phba: pointer to lpfc hba data structure. |
| 10654 | * @id: EQ vector index or Hardware Queue index |
| 10655 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10656 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10657 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10658 | */ |
| 10659 | static uint16_t |
| 10660 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10661 | { |
| 10662 | struct lpfc_vector_map_info *cpup; |
| 10663 | int cpu; |
| 10664 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10665 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10666 | for_each_present_cpu(cpu) { |
| 10667 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10668 | |
| 10669 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10670 | * using the same vector, so select the one with |
| 10671 | * LPFC_CPU_FIRST_IRQ set. |
| 10672 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10673 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10674 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10675 | (cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10676 | (cpup->eq == id)) |
| 10677 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10678 | |
| 10679 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10680 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10681 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10682 | } |
| 10683 | return 0; |
| 10684 | } |
| 10685 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10686 | #ifdef CONFIG_X86 |
| 10687 | /** |
| 10688 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10689 | * @phba: pointer to lpfc hba data structure. |
| 10690 | * @cpu: CPU map index |
| 10691 | * @phys_id: CPU package physical id |
| 10692 | * @core_id: CPU core id |
| 10693 | */ |
| 10694 | static int |
| 10695 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10696 | uint16_t phys_id, uint16_t core_id) |
| 10697 | { |
| 10698 | struct lpfc_vector_map_info *cpup; |
| 10699 | int idx; |
| 10700 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10701 | for_each_present_cpu(idx) { |
| 10702 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10703 | /* Does the cpup match the one we are looking for */ |
| 10704 | if ((cpup->phys_id == phys_id) && |
| 10705 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10706 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10707 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10708 | } |
| 10709 | return 0; |
| 10710 | } |
| 10711 | #endif |
| 10712 | |
| 10713 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10714 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10715 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10716 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10717 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10718 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10719 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10720 | * In addition, the CPU to IO channel mapping will be calculated |
| 10721 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10722 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10723 | static void |
| 10724 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10725 | { |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10726 | int i, cpu, idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10727 | int max_phys_id, min_phys_id; |
| 10728 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10729 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10730 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10731 | const struct cpumask *maskp; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10732 | #ifdef CONFIG_X86 |
| 10733 | struct cpuinfo_x86 *cpuinfo; |
| 10734 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10735 | |
| 10736 | /* Init cpu_map array */ |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10737 | for_each_possible_cpu(cpu) { |
| 10738 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10739 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10740 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10741 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10742 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10743 | cpup->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10744 | cpup->flag = 0; |
| 10745 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10746 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10747 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10748 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10749 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10750 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10751 | |
| 10752 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10753 | for_each_present_cpu(cpu) { |
| 10754 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10755 | #ifdef CONFIG_X86 |
| 10756 | cpuinfo = &cpu_data(cpu); |
| 10757 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10758 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10759 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10760 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10761 | #else |
| 10762 | /* No distinction between CPUs for other platforms */ |
| 10763 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10764 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10765 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10766 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10767 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10768 | "3328 CPU physid %d coreid %d\n", |
| 10769 | cpup->phys_id, cpup->core_id); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10770 | |
| 10771 | if (cpup->phys_id > max_phys_id) |
| 10772 | max_phys_id = cpup->phys_id; |
| 10773 | if (cpup->phys_id < min_phys_id) |
| 10774 | min_phys_id = cpup->phys_id; |
| 10775 | |
| 10776 | if (cpup->core_id > max_core_id) |
| 10777 | max_core_id = cpup->core_id; |
| 10778 | if (cpup->core_id < min_core_id) |
| 10779 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10780 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10781 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10782 | for_each_possible_cpu(i) { |
| 10783 | struct lpfc_eq_intr_info *eqi = |
| 10784 | per_cpu_ptr(phba->sli4_hba.eq_info, i); |
| 10785 | |
| 10786 | INIT_LIST_HEAD(&eqi->list); |
| 10787 | eqi->icnt = 0; |
| 10788 | } |
| 10789 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10790 | /* This loop sets up all CPUs that are affinitized with a |
| 10791 | * irq vector assigned to the driver. All affinitized CPUs |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10792 | * will get a link to that vectors IRQ and EQ. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10793 | */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10794 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10795 | /* Get a CPU mask for all CPUs affinitized to this vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10796 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 10797 | if (!maskp) |
| 10798 | continue; |
| 10799 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10800 | i = 0; |
| 10801 | /* Loop through all CPUs associated with vector idx */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10802 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10803 | /* Set the EQ index and IRQ for that vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10804 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10805 | cpup->eq = idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10806 | cpup->irq = pci_irq_vector(phba->pcidev, idx); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10807 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10808 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10809 | "3336 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10810 | "irq %d eq %d\n", |
| 10811 | cpu, cpup->irq, cpup->eq); |
| 10812 | |
| 10813 | /* If this is the first CPU thats assigned to this |
| 10814 | * vector, set LPFC_CPU_FIRST_IRQ. |
| 10815 | */ |
| 10816 | if (!i) |
| 10817 | cpup->flag |= LPFC_CPU_FIRST_IRQ; |
| 10818 | i++; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10819 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10820 | } |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10821 | |
| 10822 | /* After looking at each irq vector assigned to this pcidev, its |
| 10823 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10824 | * Next we will set any unassigned (unaffinitized) cpu map |
| 10825 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10826 | */ |
| 10827 | first_cpu = cpumask_first(cpu_present_mask); |
| 10828 | start_cpu = first_cpu; |
| 10829 | |
| 10830 | for_each_present_cpu(cpu) { |
| 10831 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10832 | |
| 10833 | /* Is this CPU entry unassigned */ |
| 10834 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10835 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 10836 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10837 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10838 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10839 | * phys_id as cpup. start_cpu will start where we |
| 10840 | * left off so all unassigned entries don't get assgined |
| 10841 | * the IRQ of the first entry. |
| 10842 | */ |
| 10843 | new_cpu = start_cpu; |
| 10844 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10845 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10846 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10847 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10848 | (new_cpup->phys_id == cpup->phys_id)) |
| 10849 | goto found_same; |
| 10850 | new_cpu = cpumask_next( |
| 10851 | new_cpu, cpu_present_mask); |
| 10852 | if (new_cpu == nr_cpumask_bits) |
| 10853 | new_cpu = first_cpu; |
| 10854 | } |
| 10855 | /* At this point, we leave the CPU as unassigned */ |
| 10856 | continue; |
| 10857 | found_same: |
| 10858 | /* We found a matching phys_id, so copy the IRQ info */ |
| 10859 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10860 | cpup->irq = new_cpup->irq; |
| 10861 | |
| 10862 | /* Bump start_cpu to the next slot to minmize the |
| 10863 | * chance of having multiple unassigned CPU entries |
| 10864 | * selecting the same IRQ. |
| 10865 | */ |
| 10866 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10867 | if (start_cpu == nr_cpumask_bits) |
| 10868 | start_cpu = first_cpu; |
| 10869 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10870 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10871 | "3337 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10872 | "irq %d from id %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10873 | "phys_id (%d)\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10874 | cpu, cpup->irq, new_cpu, cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10875 | } |
| 10876 | } |
| 10877 | |
| 10878 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 10879 | start_cpu = first_cpu; |
| 10880 | |
| 10881 | for_each_present_cpu(cpu) { |
| 10882 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10883 | |
| 10884 | /* Is this entry unassigned */ |
| 10885 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10886 | /* Mark it as IRQ not assigned by the kernel */ |
| 10887 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10888 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10889 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10890 | * as the cpup. start_cpu will start where we |
| 10891 | * left off so all unassigned entries don't get |
| 10892 | * assigned the IRQ of the first entry. |
| 10893 | */ |
| 10894 | new_cpu = start_cpu; |
| 10895 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10896 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10897 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10898 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY)) |
| 10899 | goto found_any; |
| 10900 | new_cpu = cpumask_next( |
| 10901 | new_cpu, cpu_present_mask); |
| 10902 | if (new_cpu == nr_cpumask_bits) |
| 10903 | new_cpu = first_cpu; |
| 10904 | } |
| 10905 | /* We should never leave an entry unassigned */ |
| 10906 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10907 | "3339 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10908 | "irq %d UNASSIGNED\n", |
| 10909 | cpup->hdwq, cpup->irq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10910 | continue; |
| 10911 | found_any: |
| 10912 | /* We found an available entry, copy the IRQ info */ |
| 10913 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10914 | cpup->irq = new_cpup->irq; |
| 10915 | |
| 10916 | /* Bump start_cpu to the next slot to minmize the |
| 10917 | * chance of having multiple unassigned CPU entries |
| 10918 | * selecting the same IRQ. |
| 10919 | */ |
| 10920 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10921 | if (start_cpu == nr_cpumask_bits) |
| 10922 | start_cpu = first_cpu; |
| 10923 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10924 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10925 | "3338 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10926 | "irq %d from id %d (%d/%d)\n", |
| 10927 | cpu, cpup->irq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10928 | new_cpup->phys_id, new_cpup->core_id); |
| 10929 | } |
| 10930 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10931 | |
| 10932 | /* Finally we need to associate a hdwq with each cpu_map entry |
| 10933 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 10934 | * hardware queues then CPUs. For that case we will just round-robin |
| 10935 | * the available hardware queues as they get assigned to CPUs. |
| 10936 | */ |
| 10937 | idx = 0; |
| 10938 | start_cpu = 0; |
| 10939 | for_each_present_cpu(cpu) { |
| 10940 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10941 | if (idx >= phba->cfg_hdw_queue) { |
| 10942 | /* We need to reuse a Hardware Queue for another CPU, |
| 10943 | * so be smart about it and pick one that has its |
| 10944 | * IRQ/EQ mapped to the same phys_id (CPU package). |
| 10945 | * and core_id. |
| 10946 | */ |
| 10947 | new_cpu = start_cpu; |
| 10948 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10949 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10950 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10951 | (new_cpup->phys_id == cpup->phys_id) && |
| 10952 | (new_cpup->core_id == cpup->core_id)) |
| 10953 | goto found_hdwq; |
| 10954 | new_cpu = cpumask_next( |
| 10955 | new_cpu, cpu_present_mask); |
| 10956 | if (new_cpu == nr_cpumask_bits) |
| 10957 | new_cpu = first_cpu; |
| 10958 | } |
| 10959 | |
| 10960 | /* If we can't match both phys_id and core_id, |
| 10961 | * settle for just a phys_id match. |
| 10962 | */ |
| 10963 | new_cpu = start_cpu; |
| 10964 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10965 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10966 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10967 | (new_cpup->phys_id == cpup->phys_id)) |
| 10968 | goto found_hdwq; |
| 10969 | new_cpu = cpumask_next( |
| 10970 | new_cpu, cpu_present_mask); |
| 10971 | if (new_cpu == nr_cpumask_bits) |
| 10972 | new_cpu = first_cpu; |
| 10973 | } |
| 10974 | |
| 10975 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 10976 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 10977 | goto logit; |
| 10978 | found_hdwq: |
| 10979 | /* We found an available entry, copy the IRQ info */ |
| 10980 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10981 | if (start_cpu == nr_cpumask_bits) |
| 10982 | start_cpu = first_cpu; |
| 10983 | cpup->hdwq = new_cpup->hdwq; |
| 10984 | } else { |
| 10985 | /* 1 to 1, CPU to hdwq */ |
| 10986 | cpup->hdwq = idx; |
| 10987 | } |
| 10988 | logit: |
| 10989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10990 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
| 10991 | "hdwq %d eq %d irq %d flg x%x\n", |
| 10992 | cpu, cpup->phys_id, cpup->core_id, |
| 10993 | cpup->hdwq, cpup->eq, cpup->irq, cpup->flag); |
| 10994 | idx++; |
| 10995 | } |
| 10996 | |
| 10997 | /* The cpu_map array will be used later during initialization |
| 10998 | * when EQ / CQ / WQs are allocated and configured. |
| 10999 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11000 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11001 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11002 | |
| 11003 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11004 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 11005 | * @phba: pointer to lpfc hba data structure. |
| 11006 | * |
| 11007 | * 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] | 11008 | * with SLI-4 interface spec. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11009 | * |
| 11010 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11011 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11012 | * other values - error |
| 11013 | **/ |
| 11014 | static int |
| 11015 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11016 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11017 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11018 | char *name; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11019 | |
| 11020 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11021 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11022 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11023 | rc = pci_alloc_irq_vectors(phba->pcidev, |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 11024 | 1, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11025 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11026 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11027 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11028 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11029 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11030 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11031 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11032 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11033 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11034 | for (index = 0; index < vectors; index++) { |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11035 | name = phba->sli4_hba.hba_eq_hdl[index].handler_name; |
| 11036 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11037 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11038 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11039 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11040 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11041 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11042 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11043 | &lpfc_sli4_hba_intr_handler, 0, |
| 11044 | name, |
| 11045 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11046 | if (rc) { |
| 11047 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11048 | "0486 MSI-X fast-path (%d) " |
| 11049 | "request_irq failed (%d)\n", index, rc); |
| 11050 | goto cfg_fail_out; |
| 11051 | } |
| 11052 | } |
| 11053 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11054 | if (vectors != phba->cfg_irq_chann) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11055 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11056 | "3238 Reducing IO channels to match number of " |
| 11057 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11058 | phba->cfg_irq_chann, vectors); |
| 11059 | if (phba->cfg_irq_chann > vectors) |
| 11060 | phba->cfg_irq_chann = vectors; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 11061 | if (phba->nvmet_support && (phba->cfg_nvmet_mrq > vectors)) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11062 | phba->cfg_nvmet_mrq = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11063 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11064 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11065 | return rc; |
| 11066 | |
| 11067 | cfg_fail_out: |
| 11068 | /* free the irq already requested */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11069 | for (--index; index >= 0; index--) |
| 11070 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11071 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11072 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11073 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11074 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11075 | |
| 11076 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11077 | return rc; |
| 11078 | } |
| 11079 | |
| 11080 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11081 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11082 | * @phba: pointer to lpfc hba data structure. |
| 11083 | * |
| 11084 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 11085 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 11086 | * to enable the MSI vector. The device driver is responsible for calling |
| 11087 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 11088 | * which is done in this function. |
| 11089 | * |
| 11090 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11091 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11092 | * other values - error |
| 11093 | **/ |
| 11094 | static int |
| 11095 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11096 | { |
| 11097 | int rc, index; |
| 11098 | |
| 11099 | rc = pci_enable_msi(phba->pcidev); |
| 11100 | if (!rc) |
| 11101 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11102 | "0487 PCI enable MSI mode success.\n"); |
| 11103 | else { |
| 11104 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11105 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 11106 | return rc; |
| 11107 | } |
| 11108 | |
| 11109 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11110 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11111 | if (rc) { |
| 11112 | pci_disable_msi(phba->pcidev); |
| 11113 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11114 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11115 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11116 | } |
| 11117 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11118 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11119 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11120 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11121 | } |
| 11122 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11123 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11124 | } |
| 11125 | |
| 11126 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11127 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11128 | * @phba: pointer to lpfc hba data structure. |
| 11129 | * |
| 11130 | * This routine is invoked to enable device interrupt and associate driver's |
| 11131 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11132 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11133 | * the driver will try to fallback from the configured interrupt mode to an |
| 11134 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11135 | * the order of: |
| 11136 | * MSI-X -> MSI -> IRQ. |
| 11137 | * |
| 11138 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11139 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11140 | * other values - error |
| 11141 | **/ |
| 11142 | static uint32_t |
| 11143 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11144 | { |
| 11145 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11146 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11147 | |
| 11148 | if (cfg_mode == 2) { |
| 11149 | /* Preparation before conf_msi mbox cmd */ |
| 11150 | retval = 0; |
| 11151 | if (!retval) { |
| 11152 | /* Now, try to enable MSI-X interrupt mode */ |
| 11153 | retval = lpfc_sli4_enable_msix(phba); |
| 11154 | if (!retval) { |
| 11155 | /* Indicate initialization to MSI-X mode */ |
| 11156 | phba->intr_type = MSIX; |
| 11157 | intr_mode = 2; |
| 11158 | } |
| 11159 | } |
| 11160 | } |
| 11161 | |
| 11162 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11163 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11164 | retval = lpfc_sli4_enable_msi(phba); |
| 11165 | if (!retval) { |
| 11166 | /* Indicate initialization to MSI mode */ |
| 11167 | phba->intr_type = MSI; |
| 11168 | intr_mode = 1; |
| 11169 | } |
| 11170 | } |
| 11171 | |
| 11172 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11173 | if (phba->intr_type == NONE) { |
| 11174 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11175 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11176 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11177 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11178 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11179 | /* Indicate initialization to INTx mode */ |
| 11180 | phba->intr_type = INTx; |
| 11181 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11182 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11183 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11184 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 11185 | eqhdl->idx = idx; |
| 11186 | eqhdl->phba = phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11187 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11188 | } |
| 11189 | } |
| 11190 | return intr_mode; |
| 11191 | } |
| 11192 | |
| 11193 | /** |
| 11194 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11195 | * @phba: pointer to lpfc hba data structure. |
| 11196 | * |
| 11197 | * This routine is invoked to disable device interrupt and disassociate |
| 11198 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11199 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11200 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11201 | **/ |
| 11202 | static void |
| 11203 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11204 | { |
| 11205 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11206 | if (phba->intr_type == MSIX) { |
| 11207 | int index; |
| 11208 | |
| 11209 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11210 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11211 | irq_set_affinity_hint( |
| 11212 | pci_irq_vector(phba->pcidev, index), |
| 11213 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11214 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11215 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11216 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11217 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11218 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11219 | } |
| 11220 | |
| 11221 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11222 | |
| 11223 | /* Reset interrupt management states */ |
| 11224 | phba->intr_type = NONE; |
| 11225 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11226 | } |
| 11227 | |
| 11228 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11229 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11230 | * @phba: pointer to lpfc hba data structure. |
| 11231 | * |
| 11232 | * This routine is invoked to unset the HBA device initialization steps to |
| 11233 | * a device with SLI-3 interface spec. |
| 11234 | **/ |
| 11235 | static void |
| 11236 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11237 | { |
| 11238 | struct lpfc_vport *vport = phba->pport; |
| 11239 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11240 | |
| 11241 | spin_lock_irq(shost->host_lock); |
| 11242 | vport->load_flag |= FC_UNLOADING; |
| 11243 | spin_unlock_irq(shost->host_lock); |
| 11244 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11245 | kfree(phba->vpi_bmask); |
| 11246 | kfree(phba->vpi_ids); |
| 11247 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11248 | lpfc_stop_hba_timers(phba); |
| 11249 | |
| 11250 | phba->pport->work_port_events = 0; |
| 11251 | |
| 11252 | lpfc_sli_hba_down(phba); |
| 11253 | |
| 11254 | lpfc_sli_brdrestart(phba); |
| 11255 | |
| 11256 | lpfc_sli_disable_intr(phba); |
| 11257 | |
| 11258 | return; |
| 11259 | } |
| 11260 | |
| 11261 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11262 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11263 | * @phba: Pointer to HBA context object. |
| 11264 | * |
| 11265 | * This function is called in the SLI4 code path to wait for completion |
| 11266 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11267 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11268 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11269 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11270 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11271 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11272 | * the rest of the driver unload resource release. |
| 11273 | **/ |
| 11274 | static void |
| 11275 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11276 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11277 | struct lpfc_sli4_hdw_queue *qp; |
| 11278 | int idx, ccnt, fcnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11279 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11280 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11281 | int nvmet_xri_cmpl = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11282 | int fcp_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11283 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11284 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11285 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11286 | * here to give the HBA time to complete the IO and get entries |
| 11287 | * into the abts lists. |
| 11288 | */ |
| 11289 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11290 | |
| 11291 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11292 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11293 | lpfc_nvme_wait_for_io_drain(phba); |
| 11294 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11295 | ccnt = 0; |
| 11296 | fcnt = 0; |
| 11297 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11298 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11299 | fcp_xri_cmpl = list_empty( |
| 11300 | &qp->lpfc_abts_scsi_buf_list); |
| 11301 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11302 | fcnt++; |
| 11303 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11304 | io_xri_cmpl = list_empty( |
| 11305 | &qp->lpfc_abts_nvme_buf_list); |
| 11306 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11307 | ccnt++; |
| 11308 | } |
| 11309 | } |
| 11310 | if (ccnt) |
| 11311 | io_xri_cmpl = 0; |
| 11312 | if (fcnt) |
| 11313 | fcp_xri_cmpl = 0; |
| 11314 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11315 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11316 | nvmet_xri_cmpl = |
| 11317 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11318 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11319 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11320 | while (!fcp_xri_cmpl || !els_xri_cmpl || !io_xri_cmpl || |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11321 | !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11322 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11323 | if (!nvmet_xri_cmpl) |
| 11324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11325 | "6424 NVMET XRI exchange busy " |
| 11326 | "wait time: %d seconds.\n", |
| 11327 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11328 | if (!io_xri_cmpl) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11330 | "6100 NVME XRI exchange busy " |
| 11331 | "wait time: %d seconds.\n", |
| 11332 | wait_time/1000); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11333 | if (!fcp_xri_cmpl) |
| 11334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11335 | "2877 FCP XRI exchange busy " |
| 11336 | "wait time: %d seconds.\n", |
| 11337 | wait_time/1000); |
| 11338 | if (!els_xri_cmpl) |
| 11339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11340 | "2878 ELS XRI exchange busy " |
| 11341 | "wait time: %d seconds.\n", |
| 11342 | wait_time/1000); |
| 11343 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11344 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11345 | } else { |
| 11346 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11347 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11348 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11349 | |
| 11350 | ccnt = 0; |
| 11351 | fcnt = 0; |
| 11352 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11353 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11354 | fcp_xri_cmpl = list_empty( |
| 11355 | &qp->lpfc_abts_scsi_buf_list); |
| 11356 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11357 | fcnt++; |
| 11358 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11359 | io_xri_cmpl = list_empty( |
| 11360 | &qp->lpfc_abts_nvme_buf_list); |
| 11361 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11362 | ccnt++; |
| 11363 | } |
| 11364 | } |
| 11365 | if (ccnt) |
| 11366 | io_xri_cmpl = 0; |
| 11367 | if (fcnt) |
| 11368 | fcp_xri_cmpl = 0; |
| 11369 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11370 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11371 | nvmet_xri_cmpl = list_empty( |
| 11372 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11373 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11374 | els_xri_cmpl = |
| 11375 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11376 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11377 | } |
| 11378 | } |
| 11379 | |
| 11380 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11381 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11382 | * @phba: Pointer to HBA context object. |
| 11383 | * |
| 11384 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11385 | * function. The caller is not required to hold any lock. This routine |
| 11386 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11387 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11388 | * free any pending commands. |
| 11389 | **/ |
| 11390 | static void |
| 11391 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11392 | { |
| 11393 | int wait_cnt = 0; |
| 11394 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11395 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11396 | |
| 11397 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11398 | if (phba->pport) |
| 11399 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11400 | |
| 11401 | /* |
| 11402 | * Gracefully wait out the potential current outstanding asynchronous |
| 11403 | * mailbox command. |
| 11404 | */ |
| 11405 | |
| 11406 | /* First, block any pending async mailbox command from posted */ |
| 11407 | spin_lock_irq(&phba->hbalock); |
| 11408 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11409 | spin_unlock_irq(&phba->hbalock); |
| 11410 | /* Now, trying to wait it out if we can */ |
| 11411 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11412 | msleep(10); |
| 11413 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11414 | break; |
| 11415 | } |
| 11416 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11417 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11418 | spin_lock_irq(&phba->hbalock); |
| 11419 | mboxq = phba->sli.mbox_active; |
| 11420 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11421 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11422 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11423 | phba->sli.mbox_active = NULL; |
| 11424 | spin_unlock_irq(&phba->hbalock); |
| 11425 | } |
| 11426 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11427 | /* Abort all iocbs associated with the hba */ |
| 11428 | lpfc_sli_hba_iocb_abort(phba); |
| 11429 | |
| 11430 | /* Wait for completion of device XRI exchange busy */ |
| 11431 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 11432 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11433 | /* Disable PCI subsystem interrupt */ |
| 11434 | lpfc_sli4_disable_intr(phba); |
| 11435 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11436 | /* Disable SR-IOV if enabled */ |
| 11437 | if (phba->cfg_sriov_nr_virtfn) |
| 11438 | pci_disable_sriov(pdev); |
| 11439 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11440 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11441 | kthread_stop(phba->worker_thread); |
| 11442 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11443 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11444 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11445 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11446 | /* Unset the queues shared with the hardware then release all |
| 11447 | * allocated resources. |
| 11448 | */ |
| 11449 | lpfc_sli4_queue_unset(phba); |
| 11450 | lpfc_sli4_queue_destroy(phba); |
| 11451 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11452 | /* Reset SLI4 HBA FCoE function */ |
| 11453 | lpfc_pci_function_reset(phba); |
| 11454 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11455 | /* Free RAS DMA memory */ |
| 11456 | if (phba->ras_fwlog.ras_enabled) |
| 11457 | lpfc_sli4_ras_dma_free(phba); |
| 11458 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11459 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 11460 | if (phba->pport) |
| 11461 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11462 | } |
| 11463 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11464 | /** |
| 11465 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 11466 | * @phba: Pointer to HBA context object. |
| 11467 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11468 | * |
| 11469 | * This function is called in the SLI4 code path to read the port's |
| 11470 | * sli4 capabilities. |
| 11471 | * |
| 11472 | * This function may be be called from any context that can block-wait |
| 11473 | * for the completion. The expectation is that this routine is called |
| 11474 | * typically from probe_one or from the online routine. |
| 11475 | **/ |
| 11476 | int |
| 11477 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11478 | { |
| 11479 | int rc; |
| 11480 | struct lpfc_mqe *mqe; |
| 11481 | struct lpfc_pc_sli4_params *sli4_params; |
| 11482 | uint32_t mbox_tmo; |
| 11483 | |
| 11484 | rc = 0; |
| 11485 | mqe = &mboxq->u.mqe; |
| 11486 | |
| 11487 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11488 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11489 | if (!phba->sli4_hba.intr_enable) |
| 11490 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 11491 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11492 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11493 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11494 | } |
| 11495 | |
| 11496 | if (unlikely(rc)) |
| 11497 | return 1; |
| 11498 | |
| 11499 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11500 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 11501 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 11502 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 11503 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 11504 | &mqe->un.sli4_params); |
| 11505 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 11506 | &mqe->un.sli4_params); |
| 11507 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 11508 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 11509 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 11510 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 11511 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 11512 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 11513 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 11514 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 11515 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 11516 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 11517 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 11518 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 11519 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 11520 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 11521 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 11522 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 11523 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 11524 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 11525 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 11526 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 11527 | 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] | 11528 | |
| 11529 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11530 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11531 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11532 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11533 | return rc; |
| 11534 | } |
| 11535 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11536 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11537 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 11538 | * @phba: Pointer to HBA context object. |
| 11539 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11540 | * |
| 11541 | * This function is called in the SLI4 code path to read the port's |
| 11542 | * sli4 capabilities. |
| 11543 | * |
| 11544 | * This function may be be called from any context that can block-wait |
| 11545 | * for the completion. The expectation is that this routine is called |
| 11546 | * typically from probe_one or from the online routine. |
| 11547 | **/ |
| 11548 | int |
| 11549 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11550 | { |
| 11551 | int rc; |
| 11552 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 11553 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11554 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11555 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11556 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11557 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 11558 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11559 | /* |
| 11560 | * By default, the driver assumes the SLI4 port requires RPI |
| 11561 | * header postings. The SLI4_PARAM response will correct this |
| 11562 | * assumption. |
| 11563 | */ |
| 11564 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 11565 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11566 | /* Read the port's SLI4 Config Parameters */ |
| 11567 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 11568 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 11569 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11570 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 11571 | length, LPFC_SLI4_MBX_EMBED); |
| 11572 | if (!phba->sli4_hba.intr_enable) |
| 11573 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11574 | else { |
| 11575 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 11576 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11577 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11578 | if (unlikely(rc)) |
| 11579 | return rc; |
| 11580 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11581 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 11582 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 11583 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 11584 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 11585 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 11586 | mbx_sli4_parameters); |
| 11587 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 11588 | mbx_sli4_parameters); |
| 11589 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 11590 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 11591 | else |
| 11592 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 11593 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 11594 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11595 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11596 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 11597 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 11598 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 11599 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 11600 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 11601 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 11602 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 11603 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11604 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 11605 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11606 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11607 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 11608 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11609 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 11610 | 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] | 11611 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11612 | /* Check for firmware nvme support */ |
| 11613 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 11614 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11615 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11616 | if (rc) { |
| 11617 | /* Save this to indicate the Firmware supports NVME */ |
| 11618 | sli4_params->nvme = 1; |
| 11619 | |
| 11620 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 11621 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 11622 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 11623 | "6133 Disabling NVME support: " |
| 11624 | "FC4 type not supported: x%x\n", |
| 11625 | phba->cfg_enable_fc4_type); |
| 11626 | goto fcponly; |
| 11627 | } |
| 11628 | } else { |
| 11629 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 11630 | sli4_params->nvme = 0; |
| 11631 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11632 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 11633 | "6101 Disabling NVME support: Not " |
| 11634 | "supported by firmware (%d %d) x%x\n", |
| 11635 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 11636 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 11637 | phba->cfg_enable_fc4_type); |
| 11638 | fcponly: |
| 11639 | phba->nvme_support = 0; |
| 11640 | phba->nvmet_support = 0; |
| 11641 | phba->cfg_nvmet_mrq = 0; |
| 11642 | |
| 11643 | /* If no FC4 type support, move to just SCSI support */ |
| 11644 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 11645 | return -ENODEV; |
| 11646 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 11647 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11648 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11649 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11650 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 11651 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 11652 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 11653 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11654 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11655 | /* |
| 11656 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 11657 | * lpfc_suppress_rsp module parameter must be set (default). |
| 11658 | * In SLI4-Parameters Descriptor: |
| 11659 | * Extended Inline Buffers (XIB) must be supported. |
| 11660 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 11661 | * (double negative). |
| 11662 | */ |
| 11663 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 11664 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11665 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11666 | else |
| 11667 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11668 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 11669 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 11670 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 11671 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11672 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11673 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11674 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11675 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11676 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11677 | * Check whether the adapter supports an embedded copy of the |
| 11678 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 11679 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11680 | */ |
| 11681 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 11682 | phba->fcp_embed_io = 1; |
| 11683 | else |
| 11684 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11685 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11686 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11687 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11688 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11689 | phba->cfg_enable_pbde, |
| 11690 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 11691 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11692 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11693 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 11694 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 11695 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 11696 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11697 | exp_wqcq_pages = false; |
| 11698 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11699 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 11700 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11701 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11702 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 11703 | phba->enab_exp_wqcq_pages = 1; |
| 11704 | else |
| 11705 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11706 | /* |
| 11707 | * Check if the SLI port supports MDS Diagnostics |
| 11708 | */ |
| 11709 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 11710 | phba->mds_diags_support = 1; |
| 11711 | else |
| 11712 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11713 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11714 | return 0; |
| 11715 | } |
| 11716 | |
| 11717 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11718 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 11719 | * @pdev: pointer to PCI device |
| 11720 | * @pid: pointer to PCI device identifier |
| 11721 | * |
| 11722 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 11723 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11724 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 11725 | * information of the device and driver to see if the driver state that it can |
| 11726 | * support this kind of device. If the match is successful, the driver core |
| 11727 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 11728 | * does all the initialization that it needs to do to handle the HBA properly. |
| 11729 | * |
| 11730 | * Return code |
| 11731 | * 0 - driver can claim the device |
| 11732 | * negative value - driver can not claim the device |
| 11733 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11734 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11735 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11736 | { |
| 11737 | struct lpfc_hba *phba; |
| 11738 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11739 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11740 | int error; |
| 11741 | uint32_t cfg_mode, intr_mode; |
| 11742 | |
| 11743 | /* Allocate memory for HBA structure */ |
| 11744 | phba = lpfc_hba_alloc(pdev); |
| 11745 | if (!phba) |
| 11746 | return -ENOMEM; |
| 11747 | |
| 11748 | /* Perform generic PCI device enabling operation */ |
| 11749 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11750 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11751 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11752 | |
| 11753 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 11754 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 11755 | if (error) |
| 11756 | goto out_disable_pci_dev; |
| 11757 | |
| 11758 | /* Set up SLI-3 specific device PCI memory space */ |
| 11759 | error = lpfc_sli_pci_mem_setup(phba); |
| 11760 | if (error) { |
| 11761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11762 | "1402 Failed to set up pci memory space.\n"); |
| 11763 | goto out_disable_pci_dev; |
| 11764 | } |
| 11765 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11766 | /* Set up SLI-3 specific device driver resources */ |
| 11767 | error = lpfc_sli_driver_resource_setup(phba); |
| 11768 | if (error) { |
| 11769 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11770 | "1404 Failed to set up driver resource.\n"); |
| 11771 | goto out_unset_pci_mem_s3; |
| 11772 | } |
| 11773 | |
| 11774 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11775 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11776 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 11777 | if (error) { |
| 11778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11779 | "1405 Failed to initialize iocb list.\n"); |
| 11780 | goto out_unset_driver_resource_s3; |
| 11781 | } |
| 11782 | |
| 11783 | /* Set up common device driver resources */ |
| 11784 | error = lpfc_setup_driver_resource_phase2(phba); |
| 11785 | if (error) { |
| 11786 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11787 | "1406 Failed to set up driver resource.\n"); |
| 11788 | goto out_free_iocb_list; |
| 11789 | } |
| 11790 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11791 | /* Get the default values for Model Name and Description */ |
| 11792 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 11793 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11794 | /* Create SCSI host to the physical port */ |
| 11795 | error = lpfc_create_shost(phba); |
| 11796 | if (error) { |
| 11797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11798 | "1407 Failed to create scsi host.\n"); |
| 11799 | goto out_unset_driver_resource; |
| 11800 | } |
| 11801 | |
| 11802 | /* Configure sysfs attributes */ |
| 11803 | vport = phba->pport; |
| 11804 | error = lpfc_alloc_sysfs_attr(vport); |
| 11805 | if (error) { |
| 11806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11807 | "1476 Failed to allocate sysfs attr\n"); |
| 11808 | goto out_destroy_shost; |
| 11809 | } |
| 11810 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11811 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11812 | /* Now, trying to enable interrupt and bring up the device */ |
| 11813 | cfg_mode = phba->cfg_use_msi; |
| 11814 | while (true) { |
| 11815 | /* Put device to a known state before enabling interrupt */ |
| 11816 | lpfc_stop_port(phba); |
| 11817 | /* Configure and enable interrupt */ |
| 11818 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 11819 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11820 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11821 | "0431 Failed to enable interrupt.\n"); |
| 11822 | error = -ENODEV; |
| 11823 | goto out_free_sysfs_attr; |
| 11824 | } |
| 11825 | /* SLI-3 HBA setup */ |
| 11826 | if (lpfc_sli_hba_setup(phba)) { |
| 11827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11828 | "1477 Failed to set up hba\n"); |
| 11829 | error = -ENODEV; |
| 11830 | goto out_remove_device; |
| 11831 | } |
| 11832 | |
| 11833 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 11834 | msleep(50); |
| 11835 | /* Check active interrupts on message signaled interrupts */ |
| 11836 | if (intr_mode == 0 || |
| 11837 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 11838 | /* Log the current active interrupt mode */ |
| 11839 | phba->intr_mode = intr_mode; |
| 11840 | lpfc_log_intr_mode(phba, intr_mode); |
| 11841 | break; |
| 11842 | } else { |
| 11843 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11844 | "0447 Configure interrupt mode (%d) " |
| 11845 | "failed active interrupt test.\n", |
| 11846 | intr_mode); |
| 11847 | /* Disable the current interrupt mode */ |
| 11848 | lpfc_sli_disable_intr(phba); |
| 11849 | /* Try next level of interrupt mode */ |
| 11850 | cfg_mode = --intr_mode; |
| 11851 | } |
| 11852 | } |
| 11853 | |
| 11854 | /* Perform post initialization setup */ |
| 11855 | lpfc_post_init_setup(phba); |
| 11856 | |
| 11857 | /* Check if there are static vports to be created. */ |
| 11858 | lpfc_create_static_vport(phba); |
| 11859 | |
| 11860 | return 0; |
| 11861 | |
| 11862 | out_remove_device: |
| 11863 | lpfc_unset_hba(phba); |
| 11864 | out_free_sysfs_attr: |
| 11865 | lpfc_free_sysfs_attr(vport); |
| 11866 | out_destroy_shost: |
| 11867 | lpfc_destroy_shost(phba); |
| 11868 | out_unset_driver_resource: |
| 11869 | lpfc_unset_driver_resource_phase2(phba); |
| 11870 | out_free_iocb_list: |
| 11871 | lpfc_free_iocb_list(phba); |
| 11872 | out_unset_driver_resource_s3: |
| 11873 | lpfc_sli_driver_resource_unset(phba); |
| 11874 | out_unset_pci_mem_s3: |
| 11875 | lpfc_sli_pci_mem_unset(phba); |
| 11876 | out_disable_pci_dev: |
| 11877 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11878 | if (shost) |
| 11879 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11880 | out_free_phba: |
| 11881 | lpfc_hba_free(phba); |
| 11882 | return error; |
| 11883 | } |
| 11884 | |
| 11885 | /** |
| 11886 | * 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] | 11887 | * @pdev: pointer to PCI device |
| 11888 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11889 | * This routine is to be called to disattach a device with SLI-3 interface |
| 11890 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11891 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 11892 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11893 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11894 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11895 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11896 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11897 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11898 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11899 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11900 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11901 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 11902 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11903 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11904 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11905 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11906 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11907 | lpfc_free_sysfs_attr(vport); |
| 11908 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11909 | /* Release all the vports against this physical port */ |
| 11910 | vports = lpfc_create_vport_work_array(phba); |
| 11911 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11912 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 11913 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 11914 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11915 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11916 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11917 | lpfc_destroy_vport_work_array(phba, vports); |
| 11918 | |
| 11919 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11920 | fc_remove_host(shost); |
| 11921 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 11922 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 11923 | lpfc_cleanup(vport); |
| 11924 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11925 | /* |
| 11926 | * Bring down the SLI Layer. This step disable all interrupts, |
| 11927 | * clears the rings, discards all mailbox commands, and resets |
| 11928 | * the HBA. |
| 11929 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11930 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 11931 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11932 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11933 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11934 | kthread_stop(phba->worker_thread); |
| 11935 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11936 | lpfc_sli_brdrestart(phba); |
| 11937 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11938 | kfree(phba->vpi_bmask); |
| 11939 | kfree(phba->vpi_ids); |
| 11940 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11941 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11942 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11943 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11944 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11945 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11946 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11947 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11948 | /* Disable SR-IOV if enabled */ |
| 11949 | if (phba->cfg_sriov_nr_virtfn) |
| 11950 | pci_disable_sriov(pdev); |
| 11951 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11952 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11953 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11954 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11955 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11956 | |
| 11957 | /* |
| 11958 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 11959 | * corresponding pools here. |
| 11960 | */ |
| 11961 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 11962 | lpfc_free_iocb_list(phba); |
| 11963 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11964 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11965 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11966 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 11967 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11968 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11969 | /* Free resources associated with SLI2 interface */ |
| 11970 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11971 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11972 | |
| 11973 | /* unmap adapter SLIM and Control Registers */ |
| 11974 | iounmap(phba->ctrl_regs_memmap_p); |
| 11975 | iounmap(phba->slim_memmap_p); |
| 11976 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11977 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11978 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 11979 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11980 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11981 | } |
| 11982 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11983 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11984 | * 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] | 11985 | * @pdev: pointer to PCI device |
| 11986 | * @msg: power management message |
| 11987 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11988 | * This routine is to be called from the kernel's PCI subsystem to support |
| 11989 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 11990 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 11991 | * worker thread for the device, turning off device's interrupt and DMA, |
| 11992 | * and bring the device offline. Note that as the driver implements the |
| 11993 | * minimum PM requirements to a power-aware driver's PM support for the |
| 11994 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11995 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 11996 | * fully reinitialize its device during resume() method call, the driver will |
| 11997 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 11998 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11999 | * |
| 12000 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12001 | * 0 - driver suspended the device |
| 12002 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12003 | **/ |
| 12004 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12005 | 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] | 12006 | { |
| 12007 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12008 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12009 | |
| 12010 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12011 | "0473 PCI device Power Management suspend.\n"); |
| 12012 | |
| 12013 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12014 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12015 | lpfc_offline(phba); |
| 12016 | kthread_stop(phba->worker_thread); |
| 12017 | |
| 12018 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12019 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12020 | |
| 12021 | /* Save device state to PCI config space */ |
| 12022 | pci_save_state(pdev); |
| 12023 | pci_set_power_state(pdev, PCI_D3hot); |
| 12024 | |
| 12025 | return 0; |
| 12026 | } |
| 12027 | |
| 12028 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12029 | * 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] | 12030 | * @pdev: pointer to PCI device |
| 12031 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12032 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12033 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12034 | * invokes this method, it restores the device's PCI config space state and |
| 12035 | * fully reinitializes the device and brings it online. Note that as the |
| 12036 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12037 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12038 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12039 | * driver will fully reinitialize its device during resume() method call, |
| 12040 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12041 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12042 | * |
| 12043 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12044 | * 0 - driver suspended the device |
| 12045 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12046 | **/ |
| 12047 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12048 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12049 | { |
| 12050 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12051 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12052 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12053 | int error; |
| 12054 | |
| 12055 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12056 | "0452 PCI device Power Management resume.\n"); |
| 12057 | |
| 12058 | /* Restore device state from PCI config space */ |
| 12059 | pci_set_power_state(pdev, PCI_D0); |
| 12060 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12061 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12062 | /* |
| 12063 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12064 | * device saved_state flag, need to save the restored state again. |
| 12065 | */ |
| 12066 | pci_save_state(pdev); |
| 12067 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12068 | if (pdev->is_busmaster) |
| 12069 | pci_set_master(pdev); |
| 12070 | |
| 12071 | /* Startup the kernel thread for this host adapter. */ |
| 12072 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12073 | "lpfc_worker_%d", phba->brd_no); |
| 12074 | if (IS_ERR(phba->worker_thread)) { |
| 12075 | error = PTR_ERR(phba->worker_thread); |
| 12076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12077 | "0434 PM resume failed to start worker " |
| 12078 | "thread: error=x%x.\n", error); |
| 12079 | return error; |
| 12080 | } |
| 12081 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12082 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12083 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12084 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12086 | "0430 PM resume Failed to enable interrupt\n"); |
| 12087 | return -EIO; |
| 12088 | } else |
| 12089 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12090 | |
| 12091 | /* Restart HBA and bring it online */ |
| 12092 | lpfc_sli_brdrestart(phba); |
| 12093 | lpfc_online(phba); |
| 12094 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12095 | /* Log the current active interrupt mode */ |
| 12096 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12097 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12098 | return 0; |
| 12099 | } |
| 12100 | |
| 12101 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12102 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12103 | * @phba: pointer to lpfc hba data structure. |
| 12104 | * |
| 12105 | * 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] | 12106 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12107 | **/ |
| 12108 | static void |
| 12109 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12110 | { |
| 12111 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12112 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12113 | |
| 12114 | /* |
| 12115 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12116 | * and let the SCSI mid-layer to retry them to recover. |
| 12117 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12118 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12119 | } |
| 12120 | |
| 12121 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12122 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12123 | * @phba: pointer to lpfc hba data structure. |
| 12124 | * |
| 12125 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12126 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12127 | * pending I/Os. |
| 12128 | **/ |
| 12129 | static void |
| 12130 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12131 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12133 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12134 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12135 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12136 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12137 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12138 | /* Block all SCSI devices' I/Os on the host */ |
| 12139 | lpfc_scsi_dev_block(phba); |
| 12140 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12141 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12142 | lpfc_sli_flush_fcp_rings(phba); |
| 12143 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12144 | /* stop all timers */ |
| 12145 | lpfc_stop_hba_timers(phba); |
| 12146 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12147 | /* Disable interrupt and pci device */ |
| 12148 | lpfc_sli_disable_intr(phba); |
| 12149 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12150 | } |
| 12151 | |
| 12152 | /** |
| 12153 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12154 | * @phba: pointer to lpfc hba data structure. |
| 12155 | * |
| 12156 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12157 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12158 | * pending I/Os. |
| 12159 | **/ |
| 12160 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12161 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12162 | { |
| 12163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12164 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12165 | /* Block all SCSI devices' I/Os on the host */ |
| 12166 | lpfc_scsi_dev_block(phba); |
| 12167 | |
| 12168 | /* stop all timers */ |
| 12169 | lpfc_stop_hba_timers(phba); |
| 12170 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12171 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12172 | lpfc_sli_flush_fcp_rings(phba); |
| 12173 | } |
| 12174 | |
| 12175 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12176 | * 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] | 12177 | * @pdev: pointer to PCI device. |
| 12178 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12179 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12180 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12181 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12182 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12183 | * When this function is invoked, it will need to stop all the I/Os and |
| 12184 | * interrupt(s) to the device. Once that is done, it will return |
| 12185 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12186 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12187 | * |
| 12188 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12189 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12190 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12191 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12192 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12193 | static pci_ers_result_t |
| 12194 | 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] | 12195 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12196 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12197 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12198 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12199 | switch (state) { |
| 12200 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12201 | /* Non-fatal error, prepare for recovery */ |
| 12202 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12203 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12204 | case pci_channel_io_frozen: |
| 12205 | /* Fatal error, prepare for slot reset */ |
| 12206 | lpfc_sli_prep_dev_for_reset(phba); |
| 12207 | return PCI_ERS_RESULT_NEED_RESET; |
| 12208 | case pci_channel_io_perm_failure: |
| 12209 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12210 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12211 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12212 | default: |
| 12213 | /* Unknown state, prepare and request slot reset */ |
| 12214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12215 | "0472 Unknown PCI error state: x%x\n", state); |
| 12216 | lpfc_sli_prep_dev_for_reset(phba); |
| 12217 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12218 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12219 | } |
| 12220 | |
| 12221 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12222 | * 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] | 12223 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12224 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12225 | * This routine is called from the PCI subsystem for error handling to |
| 12226 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12227 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12228 | * During the PCI subsystem error recovery, after driver returns |
| 12229 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12230 | * recovery and then call this routine before calling the .resume method |
| 12231 | * to recover the device. This function will initialize the HBA device, |
| 12232 | * enable the interrupt, but it will just put the HBA to offline state |
| 12233 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12234 | * |
| 12235 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12236 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12237 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12238 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12239 | static pci_ers_result_t |
| 12240 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12241 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12242 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12243 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12244 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12245 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12246 | |
| 12247 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12248 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12249 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12250 | "PCI device after reset.\n"); |
| 12251 | return PCI_ERS_RESULT_DISCONNECT; |
| 12252 | } |
| 12253 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12254 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12255 | |
| 12256 | /* |
| 12257 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12258 | * device saved_state flag, need to save the restored state again. |
| 12259 | */ |
| 12260 | pci_save_state(pdev); |
| 12261 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12262 | if (pdev->is_busmaster) |
| 12263 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12264 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12265 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12266 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12267 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12268 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12269 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12270 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12271 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12273 | "0427 Cannot re-enable interrupt after " |
| 12274 | "slot reset.\n"); |
| 12275 | return PCI_ERS_RESULT_DISCONNECT; |
| 12276 | } else |
| 12277 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12278 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12279 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12280 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12281 | lpfc_offline(phba); |
| 12282 | lpfc_sli_brdrestart(phba); |
| 12283 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12284 | /* Log the current active interrupt mode */ |
| 12285 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12286 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12287 | return PCI_ERS_RESULT_RECOVERED; |
| 12288 | } |
| 12289 | |
| 12290 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12291 | * 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] | 12292 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12293 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12294 | * This routine is called from the PCI subsystem for error handling to device |
| 12295 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12296 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12297 | * error recovery. After this call, traffic can start to flow from this device |
| 12298 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12299 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12300 | static void |
| 12301 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12302 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12303 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12304 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12305 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12306 | /* 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] | 12307 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12308 | } |
| 12309 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12310 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12311 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12312 | * @phba: pointer to lpfc hba data structure. |
| 12313 | * |
| 12314 | * returns the number of ELS/CT IOCBs to reserve |
| 12315 | **/ |
| 12316 | int |
| 12317 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12318 | { |
| 12319 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12320 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12321 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12322 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12323 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12324 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12325 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12326 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12327 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12328 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12329 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12330 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12331 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12332 | else if (max_xri <= 2048) |
| 12333 | return 200; |
| 12334 | else |
| 12335 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12336 | } else |
| 12337 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12338 | } |
| 12339 | |
| 12340 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12341 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12342 | * @phba: pointer to lpfc hba data structure. |
| 12343 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12344 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12345 | **/ |
| 12346 | int |
| 12347 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12348 | { |
| 12349 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12350 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12351 | if (phba->nvmet_support) |
| 12352 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12353 | return max_xri; |
| 12354 | } |
| 12355 | |
| 12356 | |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12357 | static void |
| 12358 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12359 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12360 | const struct firmware *fw) |
| 12361 | { |
James Smart | a72d56b | 2018-05-04 20:37:52 -0700 | [diff] [blame] | 12362 | if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) || |
| 12363 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
| 12364 | magic_number != MAGIC_NUMER_G6) || |
| 12365 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
| 12366 | magic_number != MAGIC_NUMER_G7)) |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12368 | "3030 This firmware version is not supported on " |
| 12369 | "this HBA model. Device:%x Magic:%x Type:%x " |
| 12370 | "ID:%x Size %d %zd\n", |
| 12371 | phba->pcidev->device, magic_number, ftype, fid, |
| 12372 | fsize, fw->size); |
| 12373 | else |
| 12374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12375 | "3022 FW Download failed. Device:%x Magic:%x Type:%x " |
| 12376 | "ID:%x Size %d %zd\n", |
| 12377 | phba->pcidev->device, magic_number, ftype, fid, |
| 12378 | fsize, fw->size); |
| 12379 | } |
| 12380 | |
| 12381 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12382 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12383 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12384 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12385 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12386 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12387 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12388 | static void |
| 12389 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12390 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12391 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12392 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12393 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12394 | struct list_head dma_buffer_list; |
| 12395 | int i, rc = 0; |
| 12396 | struct lpfc_dmabuf *dmabuf, *next; |
| 12397 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12398 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12399 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12400 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12401 | if (!fw) { |
| 12402 | rc = -ENXIO; |
| 12403 | goto out; |
| 12404 | } |
| 12405 | image = (struct lpfc_grp_hdr *)fw->data; |
| 12406 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12407 | magic_number = be32_to_cpu(image->magic_number); |
| 12408 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12409 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12410 | fsize = be32_to_cpu(image->size); |
| 12411 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12412 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12413 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12414 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12416 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12417 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12418 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12419 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 12420 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 12421 | GFP_KERNEL); |
| 12422 | if (!dmabuf) { |
| 12423 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12424 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12425 | } |
| 12426 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 12427 | SLI4_PAGE_SIZE, |
| 12428 | &dmabuf->phys, |
| 12429 | GFP_KERNEL); |
| 12430 | if (!dmabuf->virt) { |
| 12431 | kfree(dmabuf); |
| 12432 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12433 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12434 | } |
| 12435 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 12436 | } |
| 12437 | while (offset < fw->size) { |
| 12438 | temp_offset = offset; |
| 12439 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12440 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12441 | memcpy(dmabuf->virt, |
| 12442 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12443 | fw->size - temp_offset); |
| 12444 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12445 | break; |
| 12446 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12447 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 12448 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12449 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12450 | } |
| 12451 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 12452 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12453 | if (rc) { |
| 12454 | lpfc_log_write_firmware_error(phba, offset, |
| 12455 | magic_number, ftype, fid, fsize, fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12456 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12457 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12458 | } |
| 12459 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12460 | } else |
| 12461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12462 | "3029 Skipped Firmware update, Current " |
| 12463 | "Version:%s New Version:%s\n", |
| 12464 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12465 | |
| 12466 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12467 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 12468 | list_del(&dmabuf->list); |
| 12469 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 12470 | dmabuf->virt, dmabuf->phys); |
| 12471 | kfree(dmabuf); |
| 12472 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12473 | release_firmware(fw); |
| 12474 | out: |
| 12475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12476 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12477 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12478 | } |
| 12479 | |
| 12480 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12481 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 12482 | * @phba: pointer to lpfc hba data structure. |
| 12483 | * |
| 12484 | * This routine is called to perform Linux generic firmware upgrade on device |
| 12485 | * that supports such feature. |
| 12486 | **/ |
| 12487 | int |
| 12488 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 12489 | { |
| 12490 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 12491 | int ret; |
| 12492 | const struct firmware *fw; |
| 12493 | |
| 12494 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12495 | 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] | 12496 | LPFC_SLI_INTF_IF_TYPE_2) |
| 12497 | return -EPERM; |
| 12498 | |
| 12499 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 12500 | |
| 12501 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 12502 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 12503 | file_name, &phba->pcidev->dev, |
| 12504 | GFP_KERNEL, (void *)phba, |
| 12505 | lpfc_write_firmware); |
| 12506 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 12507 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 12508 | if (!ret) |
| 12509 | lpfc_write_firmware(fw, (void *)phba); |
| 12510 | } else { |
| 12511 | ret = -EINVAL; |
| 12512 | } |
| 12513 | |
| 12514 | return ret; |
| 12515 | } |
| 12516 | |
| 12517 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12518 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 12519 | * @pdev: pointer to PCI device |
| 12520 | * @pid: pointer to PCI device identifier |
| 12521 | * |
| 12522 | * This routine is called from the kernel's PCI subsystem to device with |
| 12523 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12524 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12525 | * information of the device and driver to see if the driver state that it |
| 12526 | * can support this kind of device. If the match is successful, the driver |
| 12527 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 12528 | * it does all the initialization that it needs to do to handle the HBA |
| 12529 | * properly. |
| 12530 | * |
| 12531 | * Return code |
| 12532 | * 0 - driver can claim the device |
| 12533 | * negative value - driver can not claim the device |
| 12534 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12535 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12536 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12537 | { |
| 12538 | struct lpfc_hba *phba; |
| 12539 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12540 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12541 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12542 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12543 | |
| 12544 | /* Allocate memory for HBA structure */ |
| 12545 | phba = lpfc_hba_alloc(pdev); |
| 12546 | if (!phba) |
| 12547 | return -ENOMEM; |
| 12548 | |
| 12549 | /* Perform generic PCI device enabling operation */ |
| 12550 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12551 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12552 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12553 | |
| 12554 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 12555 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 12556 | if (error) |
| 12557 | goto out_disable_pci_dev; |
| 12558 | |
| 12559 | /* Set up SLI-4 specific device PCI memory space */ |
| 12560 | error = lpfc_sli4_pci_mem_setup(phba); |
| 12561 | if (error) { |
| 12562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12563 | "1410 Failed to set up pci memory space.\n"); |
| 12564 | goto out_disable_pci_dev; |
| 12565 | } |
| 12566 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12567 | /* Set up SLI-4 Specific device driver resources */ |
| 12568 | error = lpfc_sli4_driver_resource_setup(phba); |
| 12569 | if (error) { |
| 12570 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12571 | "1412 Failed to set up driver resource.\n"); |
| 12572 | goto out_unset_pci_mem_s4; |
| 12573 | } |
| 12574 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12575 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 12576 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12577 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12578 | /* Set up common device driver resources */ |
| 12579 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12580 | if (error) { |
| 12581 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12582 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12583 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12584 | } |
| 12585 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12586 | /* Get the default values for Model Name and Description */ |
| 12587 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12588 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12589 | /* Now, trying to enable interrupt and bring up the device */ |
| 12590 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12591 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12592 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12593 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12594 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12595 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12596 | /* Configure and enable interrupt */ |
| 12597 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 12598 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12599 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12600 | "0426 Failed to enable interrupt.\n"); |
| 12601 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12602 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12603 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12604 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12605 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12606 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12607 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12608 | if (phba->nvmet_support) |
| 12609 | phba->cfg_nvmet_mrq = 1; |
| 12610 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12611 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12612 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12613 | |
| 12614 | /* Create SCSI host to the physical port */ |
| 12615 | error = lpfc_create_shost(phba); |
| 12616 | if (error) { |
| 12617 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12618 | "1415 Failed to create scsi host.\n"); |
| 12619 | goto out_disable_intr; |
| 12620 | } |
| 12621 | vport = phba->pport; |
| 12622 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 12623 | |
| 12624 | /* Configure sysfs attributes */ |
| 12625 | error = lpfc_alloc_sysfs_attr(vport); |
| 12626 | if (error) { |
| 12627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12628 | "1416 Failed to allocate sysfs attr\n"); |
| 12629 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12630 | } |
| 12631 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12632 | /* Set up SLI-4 HBA */ |
| 12633 | if (lpfc_sli4_hba_setup(phba)) { |
| 12634 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12635 | "1421 Failed to set up hba\n"); |
| 12636 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12637 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12638 | } |
| 12639 | |
| 12640 | /* Log the current active interrupt mode */ |
| 12641 | phba->intr_mode = intr_mode; |
| 12642 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12643 | |
| 12644 | /* Perform post initialization setup */ |
| 12645 | lpfc_post_init_setup(phba); |
| 12646 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12647 | /* NVME support in FW earlier in the driver load corrects the |
| 12648 | * FC4 type making a check for nvme_support unnecessary. |
| 12649 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12650 | if (phba->nvmet_support == 0) { |
| 12651 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12652 | /* Create NVME binding with nvme_fc_transport. This |
| 12653 | * ensures the vport is initialized. If the localport |
| 12654 | * create fails, it should not unload the driver to |
| 12655 | * support field issues. |
| 12656 | */ |
| 12657 | error = lpfc_nvme_create_localport(vport); |
| 12658 | if (error) { |
| 12659 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12660 | "6004 NVME registration " |
| 12661 | "failed, error x%x\n", |
| 12662 | error); |
| 12663 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12664 | } |
| 12665 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12666 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12667 | /* check for firmware upgrade or downgrade */ |
| 12668 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 12669 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12670 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 12671 | /* Check if there are static vports to be created. */ |
| 12672 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12673 | |
| 12674 | /* Enable RAS FW log support */ |
| 12675 | lpfc_sli4_ras_setup(phba); |
| 12676 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12677 | return 0; |
| 12678 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12679 | out_free_sysfs_attr: |
| 12680 | lpfc_free_sysfs_attr(vport); |
| 12681 | out_destroy_shost: |
| 12682 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12683 | out_disable_intr: |
| 12684 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12685 | out_unset_driver_resource: |
| 12686 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12687 | out_unset_driver_resource_s4: |
| 12688 | lpfc_sli4_driver_resource_unset(phba); |
| 12689 | out_unset_pci_mem_s4: |
| 12690 | lpfc_sli4_pci_mem_unset(phba); |
| 12691 | out_disable_pci_dev: |
| 12692 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12693 | if (shost) |
| 12694 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12695 | out_free_phba: |
| 12696 | lpfc_hba_free(phba); |
| 12697 | return error; |
| 12698 | } |
| 12699 | |
| 12700 | /** |
| 12701 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 12702 | * @pdev: pointer to PCI device |
| 12703 | * |
| 12704 | * This routine is called from the kernel's PCI subsystem to device with |
| 12705 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12706 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12707 | * device to be removed from the PCI subsystem properly. |
| 12708 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12709 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12710 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 12711 | { |
| 12712 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12713 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 12714 | struct lpfc_vport **vports; |
| 12715 | struct lpfc_hba *phba = vport->phba; |
| 12716 | int i; |
| 12717 | |
| 12718 | /* Mark the device unloading flag */ |
| 12719 | spin_lock_irq(&phba->hbalock); |
| 12720 | vport->load_flag |= FC_UNLOADING; |
| 12721 | spin_unlock_irq(&phba->hbalock); |
| 12722 | |
| 12723 | /* Free the HBA sysfs attributes */ |
| 12724 | lpfc_free_sysfs_attr(vport); |
| 12725 | |
| 12726 | /* Release all the vports against this physical port */ |
| 12727 | vports = lpfc_create_vport_work_array(phba); |
| 12728 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12729 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12730 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12731 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12732 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12733 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12734 | lpfc_destroy_vport_work_array(phba, vports); |
| 12735 | |
| 12736 | /* Remove FC host and then SCSI host with the physical port */ |
| 12737 | fc_remove_host(shost); |
| 12738 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12739 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12740 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 12741 | * localports are destroyed after to cleanup all transport memory. |
| 12742 | */ |
| 12743 | lpfc_cleanup(vport); |
| 12744 | lpfc_nvmet_destroy_targetport(phba); |
| 12745 | lpfc_nvme_destroy_localport(vport); |
| 12746 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12747 | /* De-allocate multi-XRI pools */ |
| 12748 | if (phba->cfg_xri_rebalancing) |
| 12749 | lpfc_destroy_multixri_pools(phba); |
| 12750 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 12751 | /* |
| 12752 | * Bring down the SLI Layer. This step disables all interrupts, |
| 12753 | * clears the rings, discards all mailbox commands, and resets |
| 12754 | * the HBA FCoE function. |
| 12755 | */ |
| 12756 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12757 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 12758 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12759 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12760 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12761 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12762 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12763 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12764 | * buffers are released to their corresponding pools here. |
| 12765 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12766 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12767 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12768 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12769 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 12770 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12771 | lpfc_sli4_driver_resource_unset(phba); |
| 12772 | |
| 12773 | /* Unmap adapter Control and Doorbell registers */ |
| 12774 | lpfc_sli4_pci_mem_unset(phba); |
| 12775 | |
| 12776 | /* Release PCI resources and disable device's PCI function */ |
| 12777 | scsi_host_put(shost); |
| 12778 | lpfc_disable_pci_dev(phba); |
| 12779 | |
| 12780 | /* Finally, free the driver's device data structure */ |
| 12781 | lpfc_hba_free(phba); |
| 12782 | |
| 12783 | return; |
| 12784 | } |
| 12785 | |
| 12786 | /** |
| 12787 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 12788 | * @pdev: pointer to PCI device |
| 12789 | * @msg: power management message |
| 12790 | * |
| 12791 | * This routine is called from the kernel's PCI subsystem to support system |
| 12792 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 12793 | * this method, it quiesces the device by stopping the driver's worker |
| 12794 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 12795 | * the device offline. Note that as the driver implements the minimum PM |
| 12796 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 12797 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 12798 | * method call will be treated as SUSPEND and the driver will fully |
| 12799 | * reinitialize its device during resume() method call, the driver will set |
| 12800 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 12801 | * according to the @msg provided by the PM. |
| 12802 | * |
| 12803 | * Return code |
| 12804 | * 0 - driver suspended the device |
| 12805 | * Error otherwise |
| 12806 | **/ |
| 12807 | static int |
| 12808 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 12809 | { |
| 12810 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12811 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12812 | |
| 12813 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12814 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12815 | |
| 12816 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12817 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12818 | lpfc_offline(phba); |
| 12819 | kthread_stop(phba->worker_thread); |
| 12820 | |
| 12821 | /* Disable interrupt from device */ |
| 12822 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12823 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12824 | |
| 12825 | /* Save device state to PCI config space */ |
| 12826 | pci_save_state(pdev); |
| 12827 | pci_set_power_state(pdev, PCI_D3hot); |
| 12828 | |
| 12829 | return 0; |
| 12830 | } |
| 12831 | |
| 12832 | /** |
| 12833 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 12834 | * @pdev: pointer to PCI device |
| 12835 | * |
| 12836 | * This routine is called from the kernel's PCI subsystem to support system |
| 12837 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 12838 | * this method, it restores the device's PCI config space state and fully |
| 12839 | * reinitializes the device and brings it online. Note that as the driver |
| 12840 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 12841 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12842 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 12843 | * will fully reinitialize its device during resume() method call, the device |
| 12844 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 12845 | * state. |
| 12846 | * |
| 12847 | * Return code |
| 12848 | * 0 - driver suspended the device |
| 12849 | * Error otherwise |
| 12850 | **/ |
| 12851 | static int |
| 12852 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 12853 | { |
| 12854 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12855 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12856 | uint32_t intr_mode; |
| 12857 | int error; |
| 12858 | |
| 12859 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12860 | "0292 PCI device Power Management resume.\n"); |
| 12861 | |
| 12862 | /* Restore device state from PCI config space */ |
| 12863 | pci_set_power_state(pdev, PCI_D0); |
| 12864 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12865 | |
| 12866 | /* |
| 12867 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12868 | * device saved_state flag, need to save the restored state again. |
| 12869 | */ |
| 12870 | pci_save_state(pdev); |
| 12871 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12872 | if (pdev->is_busmaster) |
| 12873 | pci_set_master(pdev); |
| 12874 | |
| 12875 | /* Startup the kernel thread for this host adapter. */ |
| 12876 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12877 | "lpfc_worker_%d", phba->brd_no); |
| 12878 | if (IS_ERR(phba->worker_thread)) { |
| 12879 | error = PTR_ERR(phba->worker_thread); |
| 12880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12881 | "0293 PM resume failed to start worker " |
| 12882 | "thread: error=x%x.\n", error); |
| 12883 | return error; |
| 12884 | } |
| 12885 | |
| 12886 | /* Configure and enable interrupt */ |
| 12887 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 12888 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12890 | "0294 PM resume Failed to enable interrupt\n"); |
| 12891 | return -EIO; |
| 12892 | } else |
| 12893 | phba->intr_mode = intr_mode; |
| 12894 | |
| 12895 | /* Restart HBA and bring it online */ |
| 12896 | lpfc_sli_brdrestart(phba); |
| 12897 | lpfc_online(phba); |
| 12898 | |
| 12899 | /* Log the current active interrupt mode */ |
| 12900 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12901 | |
| 12902 | return 0; |
| 12903 | } |
| 12904 | |
| 12905 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12906 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 12907 | * @phba: pointer to lpfc hba data structure. |
| 12908 | * |
| 12909 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 12910 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 12911 | **/ |
| 12912 | static void |
| 12913 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12914 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12915 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12916 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 12917 | /* |
| 12918 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12919 | * and let the SCSI mid-layer to retry them to recover. |
| 12920 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12921 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12922 | } |
| 12923 | |
| 12924 | /** |
| 12925 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 12926 | * @phba: pointer to lpfc hba data structure. |
| 12927 | * |
| 12928 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 12929 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12930 | * pending I/Os. |
| 12931 | **/ |
| 12932 | static void |
| 12933 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12934 | { |
| 12935 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12936 | "2826 PCI channel disable preparing for reset\n"); |
| 12937 | |
| 12938 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12939 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12940 | |
| 12941 | /* Block all SCSI devices' I/Os on the host */ |
| 12942 | lpfc_scsi_dev_block(phba); |
| 12943 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12944 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12945 | lpfc_sli_flush_fcp_rings(phba); |
| 12946 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12947 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12948 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12949 | lpfc_sli_flush_nvme_rings(phba); |
| 12950 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12951 | /* stop all timers */ |
| 12952 | lpfc_stop_hba_timers(phba); |
| 12953 | |
| 12954 | /* Disable interrupt and pci device */ |
| 12955 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12956 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12957 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12958 | } |
| 12959 | |
| 12960 | /** |
| 12961 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 12962 | * @phba: pointer to lpfc hba data structure. |
| 12963 | * |
| 12964 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 12965 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12966 | * pending I/Os. |
| 12967 | **/ |
| 12968 | static void |
| 12969 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 12970 | { |
| 12971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12972 | "2827 PCI channel permanent disable for failure\n"); |
| 12973 | |
| 12974 | /* Block all SCSI devices' I/Os on the host */ |
| 12975 | lpfc_scsi_dev_block(phba); |
| 12976 | |
| 12977 | /* stop all timers */ |
| 12978 | lpfc_stop_hba_timers(phba); |
| 12979 | |
| 12980 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12981 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12982 | |
| 12983 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12984 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12985 | lpfc_sli_flush_nvme_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12986 | } |
| 12987 | |
| 12988 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12989 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 12990 | * @pdev: pointer to PCI device. |
| 12991 | * @state: the current PCI connection state. |
| 12992 | * |
| 12993 | * This routine is called from the PCI subsystem for error handling to device |
| 12994 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 12995 | * after a PCI bus error affecting this device has been detected. When this |
| 12996 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 12997 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 12998 | * for the PCI subsystem to perform proper recovery as desired. |
| 12999 | * |
| 13000 | * Return codes |
| 13001 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13002 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13003 | **/ |
| 13004 | static pci_ers_result_t |
| 13005 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 13006 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13007 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13008 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13009 | |
| 13010 | switch (state) { |
| 13011 | case pci_channel_io_normal: |
| 13012 | /* Non-fatal error, prepare for recovery */ |
| 13013 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13014 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13015 | case pci_channel_io_frozen: |
| 13016 | /* Fatal error, prepare for slot reset */ |
| 13017 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13018 | return PCI_ERS_RESULT_NEED_RESET; |
| 13019 | case pci_channel_io_perm_failure: |
| 13020 | /* Permanent failure, prepare for device down */ |
| 13021 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13022 | return PCI_ERS_RESULT_DISCONNECT; |
| 13023 | default: |
| 13024 | /* Unknown state, prepare and request slot reset */ |
| 13025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13026 | "2825 Unknown PCI error state: x%x\n", state); |
| 13027 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13028 | return PCI_ERS_RESULT_NEED_RESET; |
| 13029 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13030 | } |
| 13031 | |
| 13032 | /** |
| 13033 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13034 | * @pdev: pointer to PCI device. |
| 13035 | * |
| 13036 | * This routine is called from the PCI subsystem for error handling to device |
| 13037 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13038 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13039 | * PCI subsystem error recovery, after the driver returns |
| 13040 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13041 | * recovery and then call this routine before calling the .resume method to |
| 13042 | * recover the device. This function will initialize the HBA device, enable |
| 13043 | * the interrupt, but it will just put the HBA to offline state without |
| 13044 | * passing any I/O traffic. |
| 13045 | * |
| 13046 | * Return codes |
| 13047 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13048 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13049 | */ |
| 13050 | static pci_ers_result_t |
| 13051 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13052 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13053 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13054 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13055 | struct lpfc_sli *psli = &phba->sli; |
| 13056 | uint32_t intr_mode; |
| 13057 | |
| 13058 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13059 | if (pci_enable_device_mem(pdev)) { |
| 13060 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13061 | "PCI device after reset.\n"); |
| 13062 | return PCI_ERS_RESULT_DISCONNECT; |
| 13063 | } |
| 13064 | |
| 13065 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13066 | |
| 13067 | /* |
| 13068 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13069 | * device saved_state flag, need to save the restored state again. |
| 13070 | */ |
| 13071 | pci_save_state(pdev); |
| 13072 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13073 | if (pdev->is_busmaster) |
| 13074 | pci_set_master(pdev); |
| 13075 | |
| 13076 | spin_lock_irq(&phba->hbalock); |
| 13077 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13078 | spin_unlock_irq(&phba->hbalock); |
| 13079 | |
| 13080 | /* Configure and enable interrupt */ |
| 13081 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13082 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13083 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13084 | "2824 Cannot re-enable interrupt after " |
| 13085 | "slot reset.\n"); |
| 13086 | return PCI_ERS_RESULT_DISCONNECT; |
| 13087 | } else |
| 13088 | phba->intr_mode = intr_mode; |
| 13089 | |
| 13090 | /* Log the current active interrupt mode */ |
| 13091 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13092 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13093 | return PCI_ERS_RESULT_RECOVERED; |
| 13094 | } |
| 13095 | |
| 13096 | /** |
| 13097 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13098 | * @pdev: pointer to PCI device |
| 13099 | * |
| 13100 | * This routine is called from the PCI subsystem for error handling to device |
| 13101 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13102 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13103 | * error recovery. After this call, traffic can start to flow from this device |
| 13104 | * again. |
| 13105 | **/ |
| 13106 | static void |
| 13107 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13108 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13109 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13110 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13111 | |
| 13112 | /* |
| 13113 | * In case of slot reset, as function reset is performed through |
| 13114 | * mailbox command which needs DMA to be enabled, this operation |
| 13115 | * has to be moved to the io resume phase. Taking device offline |
| 13116 | * will perform the necessary cleanup. |
| 13117 | */ |
| 13118 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13119 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13120 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13121 | lpfc_offline(phba); |
| 13122 | lpfc_sli_brdrestart(phba); |
| 13123 | /* Bring the device back online */ |
| 13124 | lpfc_online(phba); |
| 13125 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13126 | } |
| 13127 | |
| 13128 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13129 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13130 | * @pdev: pointer to PCI device |
| 13131 | * @pid: pointer to PCI device identifier |
| 13132 | * |
| 13133 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13134 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13135 | * at PCI device-specific information of the device and driver to see if the |
| 13136 | * driver state that it can support this kind of device. If the match is |
| 13137 | * successful, the driver core invokes this routine. This routine dispatches |
| 13138 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13139 | * do all the initialization that it needs to do to handle the HBA device |
| 13140 | * properly. |
| 13141 | * |
| 13142 | * Return code |
| 13143 | * 0 - driver can claim the device |
| 13144 | * negative value - driver can not claim the device |
| 13145 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13146 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13147 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13148 | { |
| 13149 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13150 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13151 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13152 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13153 | return -ENODEV; |
| 13154 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13155 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13156 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13157 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13158 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13159 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13160 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13161 | return rc; |
| 13162 | } |
| 13163 | |
| 13164 | /** |
| 13165 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13166 | * @pdev: pointer to PCI device |
| 13167 | * |
| 13168 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13169 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13170 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13171 | * remove routine, which will perform all the necessary cleanup for the |
| 13172 | * device to be removed from the PCI subsystem properly. |
| 13173 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13174 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13175 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13176 | { |
| 13177 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13178 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13179 | |
| 13180 | switch (phba->pci_dev_grp) { |
| 13181 | case LPFC_PCI_DEV_LP: |
| 13182 | lpfc_pci_remove_one_s3(pdev); |
| 13183 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13184 | case LPFC_PCI_DEV_OC: |
| 13185 | lpfc_pci_remove_one_s4(pdev); |
| 13186 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13187 | default: |
| 13188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13189 | "1424 Invalid PCI device group: 0x%x\n", |
| 13190 | phba->pci_dev_grp); |
| 13191 | break; |
| 13192 | } |
| 13193 | return; |
| 13194 | } |
| 13195 | |
| 13196 | /** |
| 13197 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 13198 | * @pdev: pointer to PCI device |
| 13199 | * @msg: power management message |
| 13200 | * |
| 13201 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13202 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13203 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13204 | * suspend the device. |
| 13205 | * |
| 13206 | * Return code |
| 13207 | * 0 - driver suspended the device |
| 13208 | * Error otherwise |
| 13209 | **/ |
| 13210 | static int |
| 13211 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 13212 | { |
| 13213 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13214 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13215 | int rc = -ENODEV; |
| 13216 | |
| 13217 | switch (phba->pci_dev_grp) { |
| 13218 | case LPFC_PCI_DEV_LP: |
| 13219 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 13220 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13221 | case LPFC_PCI_DEV_OC: |
| 13222 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 13223 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13224 | default: |
| 13225 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13226 | "1425 Invalid PCI device group: 0x%x\n", |
| 13227 | phba->pci_dev_grp); |
| 13228 | break; |
| 13229 | } |
| 13230 | return rc; |
| 13231 | } |
| 13232 | |
| 13233 | /** |
| 13234 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 13235 | * @pdev: pointer to PCI device |
| 13236 | * |
| 13237 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13238 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13239 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13240 | * resume the device. |
| 13241 | * |
| 13242 | * Return code |
| 13243 | * 0 - driver suspended the device |
| 13244 | * Error otherwise |
| 13245 | **/ |
| 13246 | static int |
| 13247 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 13248 | { |
| 13249 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13250 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13251 | int rc = -ENODEV; |
| 13252 | |
| 13253 | switch (phba->pci_dev_grp) { |
| 13254 | case LPFC_PCI_DEV_LP: |
| 13255 | rc = lpfc_pci_resume_one_s3(pdev); |
| 13256 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13257 | case LPFC_PCI_DEV_OC: |
| 13258 | rc = lpfc_pci_resume_one_s4(pdev); |
| 13259 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13260 | default: |
| 13261 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13262 | "1426 Invalid PCI device group: 0x%x\n", |
| 13263 | phba->pci_dev_grp); |
| 13264 | break; |
| 13265 | } |
| 13266 | return rc; |
| 13267 | } |
| 13268 | |
| 13269 | /** |
| 13270 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13271 | * @pdev: pointer to PCI device. |
| 13272 | * @state: the current PCI connection state. |
| 13273 | * |
| 13274 | * This routine is registered to the PCI subsystem for error handling. This |
| 13275 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13276 | * this device has been detected. When this routine is invoked, it dispatches |
| 13277 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13278 | * routine, which will perform the proper error detected operation. |
| 13279 | * |
| 13280 | * Return codes |
| 13281 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13282 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13283 | **/ |
| 13284 | static pci_ers_result_t |
| 13285 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13286 | { |
| 13287 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13288 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13289 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13290 | |
| 13291 | switch (phba->pci_dev_grp) { |
| 13292 | case LPFC_PCI_DEV_LP: |
| 13293 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13294 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13295 | case LPFC_PCI_DEV_OC: |
| 13296 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13297 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13298 | default: |
| 13299 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13300 | "1427 Invalid PCI device group: 0x%x\n", |
| 13301 | phba->pci_dev_grp); |
| 13302 | break; |
| 13303 | } |
| 13304 | return rc; |
| 13305 | } |
| 13306 | |
| 13307 | /** |
| 13308 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13309 | * @pdev: pointer to PCI device. |
| 13310 | * |
| 13311 | * This routine is registered to the PCI subsystem for error handling. This |
| 13312 | * function is called after PCI bus has been reset to restart the PCI card |
| 13313 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13314 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13315 | * routine, which will perform the proper device reset. |
| 13316 | * |
| 13317 | * Return codes |
| 13318 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13319 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13320 | **/ |
| 13321 | static pci_ers_result_t |
| 13322 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13323 | { |
| 13324 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13325 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13326 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13327 | |
| 13328 | switch (phba->pci_dev_grp) { |
| 13329 | case LPFC_PCI_DEV_LP: |
| 13330 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13331 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13332 | case LPFC_PCI_DEV_OC: |
| 13333 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13334 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13335 | default: |
| 13336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13337 | "1428 Invalid PCI device group: 0x%x\n", |
| 13338 | phba->pci_dev_grp); |
| 13339 | break; |
| 13340 | } |
| 13341 | return rc; |
| 13342 | } |
| 13343 | |
| 13344 | /** |
| 13345 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13346 | * @pdev: pointer to PCI device |
| 13347 | * |
| 13348 | * This routine is registered to the PCI subsystem for error handling. It |
| 13349 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13350 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13351 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13352 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13353 | **/ |
| 13354 | static void |
| 13355 | lpfc_io_resume(struct pci_dev *pdev) |
| 13356 | { |
| 13357 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13358 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13359 | |
| 13360 | switch (phba->pci_dev_grp) { |
| 13361 | case LPFC_PCI_DEV_LP: |
| 13362 | lpfc_io_resume_s3(pdev); |
| 13363 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13364 | case LPFC_PCI_DEV_OC: |
| 13365 | lpfc_io_resume_s4(pdev); |
| 13366 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13367 | default: |
| 13368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13369 | "1429 Invalid PCI device group: 0x%x\n", |
| 13370 | phba->pci_dev_grp); |
| 13371 | break; |
| 13372 | } |
| 13373 | return; |
| 13374 | } |
| 13375 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13376 | /** |
| 13377 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13378 | * @phba: pointer to lpfc hba data structure. |
| 13379 | * |
| 13380 | * This routine checks to see if OAS is supported for this adapter. If |
| 13381 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13382 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13383 | * is destroyed. |
| 13384 | * |
| 13385 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13386 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13387 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13388 | { |
| 13389 | |
| 13390 | if (!phba->cfg_EnableXLane) |
| 13391 | return; |
| 13392 | |
| 13393 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13394 | phba->cfg_fof = 1; |
| 13395 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13396 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13397 | if (phba->device_data_mem_pool) |
| 13398 | mempool_destroy(phba->device_data_mem_pool); |
| 13399 | phba->device_data_mem_pool = NULL; |
| 13400 | } |
| 13401 | |
| 13402 | return; |
| 13403 | } |
| 13404 | |
| 13405 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13406 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13407 | * @phba: pointer to lpfc hba data structure. |
| 13408 | * |
| 13409 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13410 | * function through which RAS support enablement is to be done. |
| 13411 | **/ |
| 13412 | void |
| 13413 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 13414 | { |
| 13415 | switch (phba->pcidev->device) { |
| 13416 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 13417 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 13418 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 13419 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 13420 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13421 | phba->ras_fwlog.ras_enabled = true; |
| 13422 | else |
| 13423 | phba->ras_fwlog.ras_enabled = false; |
| 13424 | break; |
| 13425 | default: |
| 13426 | phba->ras_fwlog.ras_hwsupport = false; |
| 13427 | } |
| 13428 | } |
| 13429 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13431 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 13432 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 13433 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 13434 | .error_detected = lpfc_io_error_detected, |
| 13435 | .slot_reset = lpfc_io_slot_reset, |
| 13436 | .resume = lpfc_io_resume, |
| 13437 | }; |
| 13438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13439 | static struct pci_driver lpfc_driver = { |
| 13440 | .name = LPFC_DRIVER_NAME, |
| 13441 | .id_table = lpfc_id_table, |
| 13442 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13443 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 13444 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 13445 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13446 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13447 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13448 | }; |
| 13449 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13450 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 13451 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13452 | }; |
| 13453 | |
| 13454 | static struct miscdevice lpfc_mgmt_dev = { |
| 13455 | .minor = MISC_DYNAMIC_MINOR, |
| 13456 | .name = "lpfcmgmt", |
| 13457 | .fops = &lpfc_mgmt_fop, |
| 13458 | }; |
| 13459 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13460 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13461 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13462 | * |
| 13463 | * This routine is to be invoked when the lpfc module is loaded into the |
| 13464 | * kernel. The special kernel macro module_init() is used to indicate the |
| 13465 | * role of this routine to the kernel as lpfc module entry point. |
| 13466 | * |
| 13467 | * Return codes |
| 13468 | * 0 - successful |
| 13469 | * -ENOMEM - FC attach transport failed |
| 13470 | * all others - failed |
| 13471 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13472 | static int __init |
| 13473 | lpfc_init(void) |
| 13474 | { |
| 13475 | int error = 0; |
| 13476 | |
| 13477 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 13478 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13479 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13480 | error = misc_register(&lpfc_mgmt_dev); |
| 13481 | if (error) |
| 13482 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 13483 | "misc_register returned with status %d", error); |
| 13484 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13485 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 13486 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13487 | lpfc_transport_template = |
| 13488 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13489 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13490 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13491 | lpfc_vport_transport_template = |
| 13492 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 13493 | if (lpfc_vport_transport_template == NULL) { |
| 13494 | fc_release_transport(lpfc_transport_template); |
| 13495 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13496 | } |
James Smart | 5fd1108 | 2018-03-05 12:04:04 -0800 | [diff] [blame] | 13497 | lpfc_nvme_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 13498 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13499 | |
| 13500 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 13501 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13502 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13503 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13504 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13505 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13506 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13507 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13508 | |
| 13509 | return error; |
| 13510 | } |
| 13511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13513 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13514 | * |
| 13515 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 13516 | * The special kernel macro module_exit() is used to indicate the role of |
| 13517 | * this routine to the kernel as lpfc module exit point. |
| 13518 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13519 | static void __exit |
| 13520 | lpfc_exit(void) |
| 13521 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13522 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13523 | pci_unregister_driver(&lpfc_driver); |
| 13524 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13525 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13526 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13527 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 13528 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13529 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 13530 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 13531 | } |
| 13532 | |
| 13533 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13534 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 13535 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13536 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 13537 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 13538 | } |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 13539 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13540 | } |
| 13541 | |
| 13542 | module_init(lpfc_init); |
| 13543 | module_exit(lpfc_exit); |
| 13544 | MODULE_LICENSE("GPL"); |
| 13545 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 13546 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13547 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |