| 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; |
| 1265 | |
| 1266 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1267 | return; |
| 1268 | |
| 1269 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1270 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1271 | goto requeue; |
| 1272 | |
| 1273 | eqcnt = kcalloc(num_possible_cpus(), sizeof(unsigned char), |
| 1274 | GFP_KERNEL); |
| 1275 | if (!eqcnt) |
| 1276 | goto requeue; |
| 1277 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 1278 | /* Loop thru all IRQ vectors */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1279 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 1280 | /* Get the EQ corresponding to the IRQ vector */ |
| 1281 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1282 | if (eq && eqcnt[eq->last_cpu] < 2) |
| 1283 | eqcnt[eq->last_cpu]++; |
| 1284 | continue; |
| 1285 | } |
| 1286 | |
| 1287 | for_each_present_cpu(i) { |
| 1288 | if (phba->cfg_irq_chann > 1 && eqcnt[i] < 2) |
| 1289 | continue; |
| 1290 | |
| 1291 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
| 1292 | |
| 1293 | usdelay = (eqi->icnt / LPFC_IMAX_THRESHOLD) * |
| 1294 | LPFC_EQ_DELAY_STEP; |
| 1295 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1296 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1297 | |
| 1298 | eqi->icnt = 0; |
| 1299 | |
| 1300 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
| 1301 | if (eq->last_cpu != i) { |
| 1302 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1303 | eq->last_cpu); |
| 1304 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1305 | continue; |
| 1306 | } |
| 1307 | if (usdelay != eq->q_mode) |
| 1308 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1309 | usdelay); |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | kfree(eqcnt); |
| 1314 | |
| 1315 | requeue: |
| 1316 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1317 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1318 | } |
| 1319 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1320 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1321 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1322 | * @phba: pointer to lpfc hba data structure. |
| 1323 | * |
| 1324 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1325 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1326 | **/ |
| 1327 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1328 | { |
| 1329 | u32 i; |
| 1330 | u32 hwq_count; |
| 1331 | |
| 1332 | hwq_count = phba->cfg_hdw_queue; |
| 1333 | for (i = 0; i < hwq_count; i++) { |
| 1334 | /* Adjust XRIs in private pool */ |
| 1335 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1336 | |
| 1337 | /* Adjust high watermark */ |
| 1338 | lpfc_adjust_high_watermark(phba, i); |
| 1339 | |
| 1340 | #ifdef LPFC_MXP_STAT |
| 1341 | /* Snapshot pbl, pvt and busy count */ |
| 1342 | lpfc_snapshot_mxp(phba, i); |
| 1343 | #endif |
| 1344 | } |
| 1345 | } |
| 1346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1348 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1349 | * @phba: pointer to lpfc hba data structure. |
| 1350 | * |
| 1351 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1352 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1353 | * handler performs any periodic operations needed for the device. If such |
| 1354 | * periodic event has already been attended to either in the interrupt handler |
| 1355 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1356 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1357 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1358 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1359 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1360 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1361 | * to offline. |
| 1362 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1363 | void |
| 1364 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1365 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1366 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1367 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1368 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1369 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1370 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1371 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1372 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1373 | if (phba->cfg_xri_rebalancing) { |
| 1374 | /* Multi-XRI pools handler */ |
| 1375 | lpfc_hb_mxp_handler(phba); |
| 1376 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1377 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1378 | vports = lpfc_create_vport_work_array(phba); |
| 1379 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1380 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1381 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1382 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1383 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1384 | lpfc_destroy_vport_work_array(phba, vports); |
| 1385 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1386 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1387 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1388 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1389 | return; |
| 1390 | |
| 1391 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1392 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1393 | if (time_after(phba->last_completion_time + |
| 1394 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1395 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1396 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1397 | if (!phba->hb_outstanding) |
| 1398 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1399 | jiffies + |
| 1400 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1401 | else |
| 1402 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1403 | jiffies + |
| 1404 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1405 | return; |
| 1406 | } |
| 1407 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1408 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1409 | if (phba->elsbuf_cnt && |
| 1410 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1411 | spin_lock_irq(&phba->hbalock); |
| 1412 | list_splice_init(&phba->elsbuf, &completions); |
| 1413 | phba->elsbuf_cnt = 0; |
| 1414 | phba->elsbuf_prev_cnt = 0; |
| 1415 | spin_unlock_irq(&phba->hbalock); |
| 1416 | |
| 1417 | while (!list_empty(&completions)) { |
| 1418 | list_remove_head(&completions, buf_ptr, |
| 1419 | struct lpfc_dmabuf, list); |
| 1420 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1421 | kfree(buf_ptr); |
| 1422 | } |
| 1423 | } |
| 1424 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1425 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1426 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1427 | if (phba->cfg_enable_hba_heartbeat) { |
| 1428 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1429 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1430 | (list_empty(&psli->mboxq))) { |
| 1431 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1432 | GFP_KERNEL); |
| 1433 | if (!pmboxq) { |
| 1434 | mod_timer(&phba->hb_tmofunc, |
| 1435 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1436 | msecs_to_jiffies(1000 * |
| 1437 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1438 | return; |
| 1439 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1440 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1441 | lpfc_heart_beat(phba, pmboxq); |
| 1442 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1443 | pmboxq->vport = phba->pport; |
| 1444 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1445 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1446 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1447 | if (retval != MBX_BUSY && |
| 1448 | retval != MBX_SUCCESS) { |
| 1449 | mempool_free(pmboxq, |
| 1450 | phba->mbox_mem_pool); |
| 1451 | mod_timer(&phba->hb_tmofunc, |
| 1452 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1453 | msecs_to_jiffies(1000 * |
| 1454 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1455 | return; |
| 1456 | } |
| 1457 | phba->skipped_hb = 0; |
| 1458 | phba->hb_outstanding = 1; |
| 1459 | } else if (time_before_eq(phba->last_completion_time, |
| 1460 | phba->skipped_hb)) { |
| 1461 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1462 | "2857 Last completion time not " |
| 1463 | " updated in %d ms\n", |
| 1464 | jiffies_to_msecs(jiffies |
| 1465 | - phba->last_completion_time)); |
| 1466 | } else |
| 1467 | phba->skipped_hb = jiffies; |
| 1468 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1469 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1470 | jiffies + |
| 1471 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1472 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1473 | } else { |
| 1474 | /* |
| 1475 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1476 | * we need to give the hb mailbox cmd a chance to |
| 1477 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1478 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1479 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1480 | "0459 Adapter heartbeat still out" |
| 1481 | "standing:last compl time was %d ms.\n", |
| 1482 | jiffies_to_msecs(jiffies |
| 1483 | - phba->last_completion_time)); |
| 1484 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1485 | jiffies + |
| 1486 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1487 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1488 | } else { |
| 1489 | mod_timer(&phba->hb_tmofunc, |
| 1490 | jiffies + |
| 1491 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1496 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1497 | * @phba: pointer to lpfc hba data structure. |
| 1498 | * |
| 1499 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1500 | * other than Port Error 6 has been detected. |
| 1501 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1502 | static void |
| 1503 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1504 | { |
| 1505 | struct lpfc_sli *psli = &phba->sli; |
| 1506 | |
| 1507 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1508 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1509 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1510 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1511 | |
| 1512 | lpfc_offline(phba); |
| 1513 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1514 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1515 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1516 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1517 | lpfc_hba_down_post(phba); |
| 1518 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1519 | lpfc_unblock_mgmt_io(phba); |
| 1520 | phba->link_state = LPFC_HBA_ERROR; |
| 1521 | return; |
| 1522 | } |
| 1523 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1524 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1525 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1526 | * @phba: pointer to lpfc hba data structure. |
| 1527 | * |
| 1528 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1529 | * other than Port Error 6 has been detected. |
| 1530 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1531 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1532 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1533 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1534 | spin_lock_irq(&phba->hbalock); |
| 1535 | phba->link_state = LPFC_HBA_ERROR; |
| 1536 | spin_unlock_irq(&phba->hbalock); |
| 1537 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1538 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1539 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1540 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1541 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1545 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1546 | * @phba: pointer to lpfc hba data structure. |
| 1547 | * |
| 1548 | * This routine is invoked to handle the deferred HBA hardware error |
| 1549 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1550 | * and another ER bit in the host status register. The driver will |
| 1551 | * wait until the ER1 bit clears before handling the error condition. |
| 1552 | **/ |
| 1553 | static void |
| 1554 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1555 | { |
| 1556 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1557 | struct lpfc_sli *psli = &phba->sli; |
| 1558 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1559 | /* If the pci channel is offline, ignore possible errors, |
| 1560 | * since we cannot communicate with the pci card anyway. |
| 1561 | */ |
| 1562 | if (pci_channel_offline(phba->pcidev)) { |
| 1563 | spin_lock_irq(&phba->hbalock); |
| 1564 | phba->hba_flag &= ~DEFER_ERATT; |
| 1565 | spin_unlock_irq(&phba->hbalock); |
| 1566 | return; |
| 1567 | } |
| 1568 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1570 | "0479 Deferred Adapter Hardware Error " |
| 1571 | "Data: x%x x%x x%x\n", |
| 1572 | phba->work_hs, |
| 1573 | phba->work_status[0], phba->work_status[1]); |
| 1574 | |
| 1575 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1576 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1577 | spin_unlock_irq(&phba->hbalock); |
| 1578 | |
| 1579 | |
| 1580 | /* |
| 1581 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1582 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1583 | * SCSI layer retry it after re-establishing link. |
| 1584 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1585 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1586 | |
| 1587 | /* |
| 1588 | * There was a firmware error. Take the hba offline and then |
| 1589 | * attempt to restart it. |
| 1590 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1591 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1592 | lpfc_offline(phba); |
| 1593 | |
| 1594 | /* Wait for the ER1 bit to clear.*/ |
| 1595 | while (phba->work_hs & HS_FFER1) { |
| 1596 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1597 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1598 | phba->work_hs = UNPLUG_ERR ; |
| 1599 | break; |
| 1600 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1601 | /* If driver is unloading let the worker thread continue */ |
| 1602 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1603 | phba->work_hs = 0; |
| 1604 | break; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /* |
| 1609 | * This is to ptrotect against a race condition in which |
| 1610 | * first write to the host attention register clear the |
| 1611 | * host status register. |
| 1612 | */ |
| 1613 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1614 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1615 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1616 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1617 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1618 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1619 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1620 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1621 | } |
| 1622 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1623 | static void |
| 1624 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1625 | { |
| 1626 | struct lpfc_board_event_header board_event; |
| 1627 | struct Scsi_Host *shost; |
| 1628 | |
| 1629 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1630 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1631 | shost = lpfc_shost_from_vport(phba->pport); |
| 1632 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1633 | sizeof(board_event), |
| 1634 | (char *) &board_event, |
| 1635 | LPFC_NL_VENDOR_ID); |
| 1636 | } |
| 1637 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1638 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1639 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1640 | * @phba: pointer to lpfc hba data structure. |
| 1641 | * |
| 1642 | * This routine is invoked to handle the following HBA hardware error |
| 1643 | * conditions: |
| 1644 | * 1 - HBA error attention interrupt |
| 1645 | * 2 - DMA ring index out of range |
| 1646 | * 3 - Mailbox command came back as unknown |
| 1647 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1648 | static void |
| 1649 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1651 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1652 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1653 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1654 | unsigned long temperature; |
| 1655 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1656 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1658 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1659 | * since we cannot communicate with the pci card anyway. |
| 1660 | */ |
| 1661 | if (pci_channel_offline(phba->pcidev)) { |
| 1662 | spin_lock_irq(&phba->hbalock); |
| 1663 | phba->hba_flag &= ~DEFER_ERATT; |
| 1664 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1665 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1668 | /* If resets are disabled then leave the HBA alone and return */ |
| 1669 | if (!phba->cfg_enable_hba_reset) |
| 1670 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1672 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1673 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1674 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1675 | if (phba->hba_flag & DEFER_ERATT) |
| 1676 | lpfc_handle_deferred_eratt(phba); |
| 1677 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1678 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1679 | if (phba->work_hs & HS_FFER6) |
| 1680 | /* Re-establishing Link */ |
| 1681 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1682 | "1301 Re-establishing Link " |
| 1683 | "Data: x%x x%x x%x\n", |
| 1684 | phba->work_hs, phba->work_status[0], |
| 1685 | phba->work_status[1]); |
| 1686 | if (phba->work_hs & HS_FFER8) |
| 1687 | /* Device Zeroization */ |
| 1688 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1689 | "2861 Host Authentication device " |
| 1690 | "zeroization Data:x%x x%x x%x\n", |
| 1691 | phba->work_hs, phba->work_status[0], |
| 1692 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1693 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1694 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1695 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1696 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | |
| 1698 | /* |
| 1699 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1700 | * That could cause the I/Os dropped by the firmware. |
| 1701 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1702 | * retry it after re-establishing link. |
| 1703 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1704 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | /* |
| 1707 | * There was a firmware error. Take the hba offline and then |
| 1708 | * attempt to restart it. |
| 1709 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1710 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1712 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1714 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | return; |
| 1716 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1717 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1718 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1719 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1720 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1721 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1722 | temp_event_data.data = (uint32_t)temperature; |
| 1723 | |
| 1724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1725 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1726 | "(%ld), taking this port offline " |
| 1727 | "Data: x%x x%x x%x\n", |
| 1728 | temperature, phba->work_hs, |
| 1729 | phba->work_status[0], phba->work_status[1]); |
| 1730 | |
| 1731 | shost = lpfc_shost_from_vport(phba->pport); |
| 1732 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1733 | sizeof(temp_event_data), |
| 1734 | (char *) &temp_event_data, |
| 1735 | SCSI_NL_VID_TYPE_PCI |
| 1736 | | PCI_VENDOR_ID_EMULEX); |
| 1737 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1738 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1739 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1740 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1741 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | } else { |
| 1744 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1745 | * failure is a value other than FFER6. Do not call the offline |
| 1746 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | */ |
| 1748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1749 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1751 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | phba->work_status[0], phba->work_status[1]); |
| 1753 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1754 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1755 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1757 | sizeof(event_data), (char *) &event_data, |
| 1758 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1759 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1760 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1762 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1763 | } |
| 1764 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1765 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1766 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1767 | * @phba: pointer to lpfc hba data structure. |
| 1768 | * @mbx_action: flag for mailbox shutdown action. |
| 1769 | * |
| 1770 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1771 | * response to port status register polling attention. It waits for port |
| 1772 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1773 | * During this process, interrupt vectors are freed and later requested |
| 1774 | * for handling possible port resource change. |
| 1775 | **/ |
| 1776 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1777 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1778 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1779 | { |
| 1780 | int rc; |
| 1781 | uint32_t intr_mode; |
| 1782 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1783 | 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] | 1784 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1785 | /* |
| 1786 | * On error status condition, driver need to wait for port |
| 1787 | * ready before performing reset. |
| 1788 | */ |
| 1789 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1790 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1791 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1792 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1793 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1794 | /* need reset: attempt for port recovery */ |
| 1795 | if (en_rn_msg) |
| 1796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1797 | "2887 Reset Needed: Attempting Port " |
| 1798 | "Recovery...\n"); |
| 1799 | lpfc_offline_prep(phba, mbx_action); |
| 1800 | lpfc_offline(phba); |
| 1801 | /* release interrupt for possible resource change */ |
| 1802 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1803 | rc = lpfc_sli_brdrestart(phba); |
| 1804 | if (rc) { |
| 1805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1806 | "6309 Failed to restart board\n"); |
| 1807 | return rc; |
| 1808 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1809 | /* request and enable interrupt */ |
| 1810 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1811 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1812 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1813 | "3175 Failed to enable interrupt\n"); |
| 1814 | return -EIO; |
| 1815 | } |
| 1816 | phba->intr_mode = intr_mode; |
| 1817 | rc = lpfc_online(phba); |
| 1818 | if (rc == 0) |
| 1819 | lpfc_unblock_mgmt_io(phba); |
| 1820 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1821 | return rc; |
| 1822 | } |
| 1823 | |
| 1824 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1825 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1826 | * @phba: pointer to lpfc hba data structure. |
| 1827 | * |
| 1828 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1829 | * conditions. |
| 1830 | **/ |
| 1831 | static void |
| 1832 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1833 | { |
| 1834 | struct lpfc_vport *vport = phba->pport; |
| 1835 | uint32_t event_data; |
| 1836 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1837 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1838 | struct lpfc_register portstat_reg = {0}; |
| 1839 | uint32_t reg_err1, reg_err2; |
| 1840 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1841 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1842 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1843 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1844 | struct lpfc_register portsmphr_reg; |
| 1845 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1846 | |
| 1847 | /* If the pci channel is offline, ignore possible errors, since |
| 1848 | * we cannot communicate with the pci card anyway. |
| 1849 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1850 | if (pci_channel_offline(phba->pcidev)) { |
| 1851 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1852 | "3166 pci channel is offline\n"); |
| 1853 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1854 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1855 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1856 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1857 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1858 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1859 | switch (if_type) { |
| 1860 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1861 | pci_rd_rc1 = lpfc_readl( |
| 1862 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1863 | &uerrlo_reg); |
| 1864 | pci_rd_rc2 = lpfc_readl( |
| 1865 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1866 | &uemasklo_reg); |
| 1867 | /* consider PCI bus read error as pci_channel_offline */ |
| 1868 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1869 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1870 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1871 | lpfc_sli4_offline_eratt(phba); |
| 1872 | return; |
| 1873 | } |
| 1874 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1875 | "7623 Checking UE recoverable"); |
| 1876 | |
| 1877 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1878 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1879 | &portsmphr_reg.word0)) |
| 1880 | continue; |
| 1881 | |
| 1882 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1883 | &portsmphr_reg); |
| 1884 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1885 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1886 | break; |
| 1887 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1888 | msleep(1000); |
| 1889 | } |
| 1890 | |
| 1891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1892 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1893 | smphr_port_status, i); |
| 1894 | |
| 1895 | /* Recoverable UE, reset the HBA device */ |
| 1896 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1897 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1898 | for (i = 0; i < 20; i++) { |
| 1899 | msleep(1000); |
| 1900 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1901 | &portsmphr_reg.word0) && |
| 1902 | (LPFC_POST_STAGE_PORT_READY == |
| 1903 | bf_get(lpfc_port_smphr_port_status, |
| 1904 | &portsmphr_reg))) { |
| 1905 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1906 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1907 | if (rc == 0) |
| 1908 | return; |
| 1909 | lpfc_printf_log(phba, |
| 1910 | KERN_ERR, LOG_INIT, |
| 1911 | "4215 Failed to recover UE"); |
| 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1917 | "7624 Firmware not ready: Failing UE recovery," |
| 1918 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1919 | lpfc_sli4_offline_eratt(phba); |
| 1920 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1921 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1922 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1923 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1924 | pci_rd_rc1 = lpfc_readl( |
| 1925 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1926 | &portstat_reg.word0); |
| 1927 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1928 | if (pci_rd_rc1 == -EIO) { |
| 1929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1930 | "3151 PCI bus read access failure: x%x\n", |
| 1931 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1932 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1933 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1934 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1935 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1936 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1937 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1939 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1940 | "taking port offline Data: x%x x%x\n", |
| 1941 | reg_err1, reg_err2); |
| 1942 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1943 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1944 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1945 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1946 | temp_event_data.data = 0xFFFFFFFF; |
| 1947 | |
| 1948 | shost = lpfc_shost_from_vport(phba->pport); |
| 1949 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1950 | sizeof(temp_event_data), |
| 1951 | (char *)&temp_event_data, |
| 1952 | SCSI_NL_VID_TYPE_PCI |
| 1953 | | PCI_VENDOR_ID_EMULEX); |
| 1954 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1955 | spin_lock_irq(&phba->hbalock); |
| 1956 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1957 | spin_unlock_irq(&phba->hbalock); |
| 1958 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1959 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1960 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1961 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1962 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1963 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1964 | "3143 Port Down: Firmware Update " |
| 1965 | "Detected\n"); |
| 1966 | en_rn_msg = false; |
| 1967 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1968 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1969 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1970 | "3144 Port Down: Debug Dump\n"); |
| 1971 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1972 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1974 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1975 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1976 | /* If resets are disabled then leave the HBA alone and return */ |
| 1977 | if (!phba->cfg_enable_hba_reset) |
| 1978 | return; |
| 1979 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1980 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1981 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1982 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1983 | if (rc == 0) { |
| 1984 | /* don't report event on forced debug dump */ |
| 1985 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1986 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1987 | return; |
| 1988 | else |
| 1989 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1990 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1991 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1993 | "3152 Unrecoverable error, bring the port " |
| 1994 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1995 | lpfc_sli4_offline_eratt(phba); |
| 1996 | break; |
| 1997 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1998 | default: |
| 1999 | break; |
| 2000 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2001 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2002 | "3123 Report dump event to upper layer\n"); |
| 2003 | /* Send an internal error event to mgmt application */ |
| 2004 | lpfc_board_errevt_to_mgmt(phba); |
| 2005 | |
| 2006 | event_data = FC_REG_DUMP_EVENT; |
| 2007 | shost = lpfc_shost_from_vport(vport); |
| 2008 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2009 | sizeof(event_data), (char *) &event_data, |
| 2010 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2015 | * @phba: pointer to lpfc HBA data structure. |
| 2016 | * |
| 2017 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2018 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2019 | * |
| 2020 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2021 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2022 | * Any other value - error. |
| 2023 | **/ |
| 2024 | void |
| 2025 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2026 | { |
| 2027 | (*phba->lpfc_handle_eratt)(phba); |
| 2028 | } |
| 2029 | |
| 2030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2031 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2032 | * @phba: pointer to lpfc hba data structure. |
| 2033 | * |
| 2034 | * 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] | 2035 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2040 | struct lpfc_vport *vport = phba->pport; |
| 2041 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | LPFC_MBOXQ_t *pmb; |
| 2043 | volatile uint32_t control; |
| 2044 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2045 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2046 | |
| 2047 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2048 | if (!pmb) { |
| 2049 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2051 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | |
| 2053 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2054 | if (!mp) { |
| 2055 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2056 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2057 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | |
| 2059 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2060 | if (!mp->virt) { |
| 2061 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2062 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2063 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2064 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2065 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2066 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | |
| 2068 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2069 | lpfc_read_topology(phba, pmb, mp); |
| 2070 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2072 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2073 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2074 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2075 | if (rc == MBX_NOT_FINISHED) { |
| 2076 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2077 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2078 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | |
| 2080 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | writel(HA_LATT, phba->HAregaddr); |
| 2083 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | |
| 2086 | return; |
| 2087 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2088 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2089 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2090 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2091 | lpfc_handle_latt_free_mp: |
| 2092 | kfree(mp); |
| 2093 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2094 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | lpfc_handle_latt_err_exit: |
| 2096 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2097 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2098 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2099 | control = readl(phba->HCregaddr); |
| 2100 | control |= HC_LAINT_ENA; |
| 2101 | writel(control, phba->HCregaddr); |
| 2102 | readl(phba->HCregaddr); /* flush */ |
| 2103 | |
| 2104 | /* Clear Link Attention in HA REG */ |
| 2105 | writel(HA_LATT, phba->HAregaddr); |
| 2106 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2107 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2108 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2109 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2111 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2112 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | |
| 2114 | return; |
| 2115 | } |
| 2116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2117 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2118 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2119 | * @phba: pointer to lpfc hba data structure. |
| 2120 | * @vpd: pointer to the vital product data. |
| 2121 | * @len: length of the vital product data in bytes. |
| 2122 | * |
| 2123 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2124 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2125 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2126 | * |
| 2127 | * Return codes |
| 2128 | * 0 - pointer to the VPD passed in is NULL |
| 2129 | * 1 - success |
| 2130 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2131 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2132 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | { |
| 2134 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2135 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | int i, j; |
| 2137 | int finished = 0; |
| 2138 | int index = 0; |
| 2139 | |
| 2140 | if (!vpd) |
| 2141 | return 0; |
| 2142 | |
| 2143 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2144 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2145 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2147 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2148 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | switch (vpd[index]) { |
| 2150 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2151 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | index += 1; |
| 2153 | lenlo = vpd[index]; |
| 2154 | index += 1; |
| 2155 | lenhi = vpd[index]; |
| 2156 | index += 1; |
| 2157 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2158 | index += i; |
| 2159 | break; |
| 2160 | case 0x90: |
| 2161 | index += 1; |
| 2162 | lenlo = vpd[index]; |
| 2163 | index += 1; |
| 2164 | lenhi = vpd[index]; |
| 2165 | index += 1; |
| 2166 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2167 | if (Length > len - index) |
| 2168 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | while (Length > 0) { |
| 2170 | /* Look for Serial Number */ |
| 2171 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2172 | index += 2; |
| 2173 | i = vpd[index]; |
| 2174 | index += 1; |
| 2175 | j = 0; |
| 2176 | Length -= (3+i); |
| 2177 | while(i--) { |
| 2178 | phba->SerialNumber[j++] = vpd[index++]; |
| 2179 | if (j == 31) |
| 2180 | break; |
| 2181 | } |
| 2182 | phba->SerialNumber[j] = 0; |
| 2183 | continue; |
| 2184 | } |
| 2185 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2186 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2187 | index += 2; |
| 2188 | i = vpd[index]; |
| 2189 | index += 1; |
| 2190 | j = 0; |
| 2191 | Length -= (3+i); |
| 2192 | while(i--) { |
| 2193 | phba->ModelDesc[j++] = vpd[index++]; |
| 2194 | if (j == 255) |
| 2195 | break; |
| 2196 | } |
| 2197 | phba->ModelDesc[j] = 0; |
| 2198 | continue; |
| 2199 | } |
| 2200 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2201 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2202 | index += 2; |
| 2203 | i = vpd[index]; |
| 2204 | index += 1; |
| 2205 | j = 0; |
| 2206 | Length -= (3+i); |
| 2207 | while(i--) { |
| 2208 | phba->ModelName[j++] = vpd[index++]; |
| 2209 | if (j == 79) |
| 2210 | break; |
| 2211 | } |
| 2212 | phba->ModelName[j] = 0; |
| 2213 | continue; |
| 2214 | } |
| 2215 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2216 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2217 | index += 2; |
| 2218 | i = vpd[index]; |
| 2219 | index += 1; |
| 2220 | j = 0; |
| 2221 | Length -= (3+i); |
| 2222 | while(i--) { |
| 2223 | phba->ProgramType[j++] = vpd[index++]; |
| 2224 | if (j == 255) |
| 2225 | break; |
| 2226 | } |
| 2227 | phba->ProgramType[j] = 0; |
| 2228 | continue; |
| 2229 | } |
| 2230 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2231 | phba->vpd_flag |= VPD_PORT; |
| 2232 | index += 2; |
| 2233 | i = vpd[index]; |
| 2234 | index += 1; |
| 2235 | j = 0; |
| 2236 | Length -= (3+i); |
| 2237 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2238 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2239 | (phba->sli4_hba.pport_name_sta == |
| 2240 | LPFC_SLI4_PPNAME_GET)) { |
| 2241 | j++; |
| 2242 | index++; |
| 2243 | } else |
| 2244 | phba->Port[j++] = vpd[index++]; |
| 2245 | if (j == 19) |
| 2246 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | } |
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_NON)) |
| 2251 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | continue; |
| 2253 | } |
| 2254 | else { |
| 2255 | index += 2; |
| 2256 | i = vpd[index]; |
| 2257 | index += 1; |
| 2258 | index += i; |
| 2259 | Length -= (3 + i); |
| 2260 | } |
| 2261 | } |
| 2262 | finished = 0; |
| 2263 | break; |
| 2264 | case 0x78: |
| 2265 | finished = 1; |
| 2266 | break; |
| 2267 | default: |
| 2268 | index ++; |
| 2269 | break; |
| 2270 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2271 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2272 | |
| 2273 | return(1); |
| 2274 | } |
| 2275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2276 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2277 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2278 | * @phba: pointer to lpfc hba data structure. |
| 2279 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2280 | * @descp: pointer to the data structure to hold the derived description. |
| 2281 | * |
| 2282 | * This routine retrieves HBA's description based on its registered PCI device |
| 2283 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2284 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2285 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2286 | * function returns, the @mdp will be filled with the model name. |
| 2287 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2289 | 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] | 2290 | { |
| 2291 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2292 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2293 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2294 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2295 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2296 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2297 | char *name; |
| 2298 | char *bus; |
| 2299 | char *function; |
| 2300 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2301 | |
| 2302 | if (mdp && mdp[0] != '\0' |
| 2303 | && descp && descp[0] != '\0') |
| 2304 | return; |
| 2305 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2306 | if (phba->lmt & LMT_64Gb) |
| 2307 | max_speed = 64; |
| 2308 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2309 | max_speed = 32; |
| 2310 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2311 | max_speed = 16; |
| 2312 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2313 | max_speed = 10; |
| 2314 | else if (phba->lmt & LMT_8Gb) |
| 2315 | max_speed = 8; |
| 2316 | else if (phba->lmt & LMT_4Gb) |
| 2317 | max_speed = 4; |
| 2318 | else if (phba->lmt & LMT_2Gb) |
| 2319 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2320 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2321 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2322 | else |
| 2323 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | |
| 2325 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2327 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2328 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2329 | m = (typeof(m)){"LP6000", "PCI", |
| 2330 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2331 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | case PCI_DEVICE_ID_SUPERFLY: |
| 2333 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2334 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2336 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2337 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | break; |
| 2339 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2340 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2341 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | break; |
| 2343 | case PCI_DEVICE_ID_CENTAUR: |
| 2344 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2345 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2347 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2348 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | break; |
| 2350 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2351 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2352 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | break; |
| 2354 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2355 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2356 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | break; |
| 2358 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2359 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2360 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | break; |
| 2362 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2363 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2364 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | break; |
| 2366 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2367 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2368 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | break; |
| 2370 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2371 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2372 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | break; |
| 2374 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2375 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2376 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2378 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2379 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2380 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2381 | break; |
| 2382 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2383 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2384 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2385 | break; |
| 2386 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2387 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2388 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2389 | break; |
| 2390 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2391 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2392 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2393 | break; |
| 2394 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2395 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2396 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2397 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2399 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | break; |
| 2401 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2402 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2403 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | break; |
| 2405 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2406 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2408 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2409 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2410 | break; |
| 2411 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2412 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2413 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2414 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2416 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | break; |
| 2418 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2419 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | break; |
| 2421 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2422 | m = (typeof(m)){"LP101", "PCI-X", |
| 2423 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | break; |
| 2425 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2426 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2427 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2428 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2429 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2430 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2431 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2432 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2433 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2434 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2435 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2436 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2437 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2438 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2439 | break; |
| 2440 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2441 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2442 | break; |
| 2443 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2444 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2445 | break; |
| 2446 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2447 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2448 | break; |
| 2449 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2450 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2451 | break; |
| 2452 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2453 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2454 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2455 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2456 | m = (typeof(m)){"LP21000", "PCIe", |
| 2457 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2458 | GE = 1; |
| 2459 | break; |
| 2460 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2461 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2462 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2463 | break; |
| 2464 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2465 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2466 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2467 | break; |
| 2468 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2469 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2470 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2471 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2472 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2473 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2474 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2475 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2476 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2477 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2478 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2479 | break; |
| 2480 | case PCI_DEVICE_ID_FALCON: |
| 2481 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2482 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2483 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2484 | case PCI_DEVICE_ID_BALIUS: |
| 2485 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2486 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2487 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2488 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2489 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2490 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2491 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2492 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2493 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2494 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2495 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2496 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2497 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2498 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2499 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2500 | oneConnect = 1; |
| 2501 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2502 | "Obsolete, Unsupported FCoE"}; |
| 2503 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2504 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2505 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2506 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2507 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2508 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2509 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2510 | case PCI_DEVICE_ID_SKYHAWK: |
| 2511 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2512 | oneConnect = 1; |
| 2513 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2514 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2515 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2516 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2517 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2519 | |
| 2520 | if (mdp && mdp[0] == '\0') |
| 2521 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2522 | /* |
| 2523 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2524 | * and we put the port number on the end |
| 2525 | */ |
| 2526 | if (descp && descp[0] == '\0') { |
| 2527 | if (oneConnect) |
| 2528 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2529 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2530 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2531 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2532 | else if (max_speed == 0) |
| 2533 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2534 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2535 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2536 | else |
| 2537 | snprintf(descp, 255, |
| 2538 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2539 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2540 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2541 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2542 | } |
| 2543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2544 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2545 | * 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] | 2546 | * @phba: pointer to lpfc hba data structure. |
| 2547 | * @pring: pointer to a IOCB ring. |
| 2548 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2549 | * |
| 2550 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2551 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2552 | * |
| 2553 | * Return codes |
| 2554 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2555 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2557 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | { |
| 2559 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2560 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | struct lpfc_dmabuf *mp1, *mp2; |
| 2562 | |
| 2563 | cnt += pring->missbufcnt; |
| 2564 | |
| 2565 | /* While there are buffers to post */ |
| 2566 | while (cnt > 0) { |
| 2567 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2568 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | if (iocb == NULL) { |
| 2570 | pring->missbufcnt = cnt; |
| 2571 | return cnt; |
| 2572 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2573 | icmd = &iocb->iocb; |
| 2574 | |
| 2575 | /* 2 buffers can be posted per command */ |
| 2576 | /* Allocate buffer to post */ |
| 2577 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2578 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2579 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2580 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2581 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2582 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | pring->missbufcnt = cnt; |
| 2584 | return cnt; |
| 2585 | } |
| 2586 | |
| 2587 | INIT_LIST_HEAD(&mp1->list); |
| 2588 | /* Allocate buffer to post */ |
| 2589 | if (cnt > 1) { |
| 2590 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2591 | if (mp2) |
| 2592 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2593 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2594 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2595 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2597 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2598 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | pring->missbufcnt = cnt; |
| 2600 | return cnt; |
| 2601 | } |
| 2602 | |
| 2603 | INIT_LIST_HEAD(&mp2->list); |
| 2604 | } else { |
| 2605 | mp2 = NULL; |
| 2606 | } |
| 2607 | |
| 2608 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2609 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2610 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2611 | icmd->ulpBdeCount = 1; |
| 2612 | cnt--; |
| 2613 | if (mp2) { |
| 2614 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2615 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2616 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2617 | cnt--; |
| 2618 | icmd->ulpBdeCount = 2; |
| 2619 | } |
| 2620 | |
| 2621 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2622 | icmd->ulpLe = 1; |
| 2623 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2624 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2625 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2627 | kfree(mp1); |
| 2628 | cnt++; |
| 2629 | if (mp2) { |
| 2630 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2631 | kfree(mp2); |
| 2632 | cnt++; |
| 2633 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2634 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | return cnt; |
| 2637 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2639 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | } |
| 2642 | pring->missbufcnt = 0; |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2647 | * 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] | 2648 | * @phba: pointer to lpfc hba data structure. |
| 2649 | * |
| 2650 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2651 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2652 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2653 | * |
| 2654 | * Return codes |
| 2655 | * 0 - success (currently always success) |
| 2656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | { |
| 2660 | struct lpfc_sli *psli = &phba->sli; |
| 2661 | |
| 2662 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2663 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | /* Ring 2 - FCP no buffers needed */ |
| 2665 | |
| 2666 | return 0; |
| 2667 | } |
| 2668 | |
| 2669 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2671 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2672 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2673 | * @HashResultPointer: pointer to an array as hash table. |
| 2674 | * |
| 2675 | * This routine sets up the initial values to the array of hash table entries |
| 2676 | * for the LC HBAs. |
| 2677 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | static void |
| 2679 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2680 | { |
| 2681 | HashResultPointer[0] = 0x67452301; |
| 2682 | HashResultPointer[1] = 0xEFCDAB89; |
| 2683 | HashResultPointer[2] = 0x98BADCFE; |
| 2684 | HashResultPointer[3] = 0x10325476; |
| 2685 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2686 | } |
| 2687 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2688 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2689 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2690 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2691 | * @HashWorkingPointer: pointer to an working hash table. |
| 2692 | * |
| 2693 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2694 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2695 | * The results are putting back to the initial hash table, returned through |
| 2696 | * the @HashResultPointer as the result hash table. |
| 2697 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | static void |
| 2699 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2700 | { |
| 2701 | int t; |
| 2702 | uint32_t TEMP; |
| 2703 | uint32_t A, B, C, D, E; |
| 2704 | t = 16; |
| 2705 | do { |
| 2706 | HashWorkingPointer[t] = |
| 2707 | S(1, |
| 2708 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2709 | 8] ^ |
| 2710 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2711 | } while (++t <= 79); |
| 2712 | t = 0; |
| 2713 | A = HashResultPointer[0]; |
| 2714 | B = HashResultPointer[1]; |
| 2715 | C = HashResultPointer[2]; |
| 2716 | D = HashResultPointer[3]; |
| 2717 | E = HashResultPointer[4]; |
| 2718 | |
| 2719 | do { |
| 2720 | if (t < 20) { |
| 2721 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2722 | } else if (t < 40) { |
| 2723 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2724 | } else if (t < 60) { |
| 2725 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2726 | } else { |
| 2727 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2728 | } |
| 2729 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2730 | E = D; |
| 2731 | D = C; |
| 2732 | C = S(30, B); |
| 2733 | B = A; |
| 2734 | A = TEMP; |
| 2735 | } while (++t <= 79); |
| 2736 | |
| 2737 | HashResultPointer[0] += A; |
| 2738 | HashResultPointer[1] += B; |
| 2739 | HashResultPointer[2] += C; |
| 2740 | HashResultPointer[3] += D; |
| 2741 | HashResultPointer[4] += E; |
| 2742 | |
| 2743 | } |
| 2744 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2745 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2746 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2747 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2748 | * @HashWorking: pointer to the entry of the working hash array. |
| 2749 | * |
| 2750 | * This routine calculates the working hash array referred by @HashWorking |
| 2751 | * from the challenge random numbers associated with the host, referred by |
| 2752 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2753 | * array and returned by reference through @HashWorking. |
| 2754 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | static void |
| 2756 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2757 | { |
| 2758 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2759 | } |
| 2760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2762 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2763 | * @phba: pointer to lpfc hba data structure. |
| 2764 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2765 | * |
| 2766 | * This routine performs the special handling for LC HBA initialization. |
| 2767 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | void |
| 2769 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2770 | { |
| 2771 | int t; |
| 2772 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2773 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2774 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2775 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | if (!HashWorking) |
| 2777 | return; |
| 2778 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2780 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2781 | |
| 2782 | for (t = 0; t < 7; t++) |
| 2783 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2784 | |
| 2785 | lpfc_sha_init(hbainit); |
| 2786 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2787 | kfree(HashWorking); |
| 2788 | } |
| 2789 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2790 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2791 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2792 | * @vport: pointer to a virtual N_Port data structure. |
| 2793 | * |
| 2794 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2795 | * It invokes the discovery state machine to perform necessary state |
| 2796 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2797 | * the physical port is treated as @vport 0. |
| 2798 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2799 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2802 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2804 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2806 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2807 | lpfc_port_link_failure(vport); |
| 2808 | |
| 2809 | 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] | 2810 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2811 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2812 | NLP_STE_UNUSED_NODE); |
| 2813 | if (!ndlp) |
| 2814 | continue; |
| 2815 | spin_lock_irq(&phba->ndlp_lock); |
| 2816 | NLP_SET_FREE_REQ(ndlp); |
| 2817 | spin_unlock_irq(&phba->ndlp_lock); |
| 2818 | /* Trigger the release of the ndlp memory */ |
| 2819 | lpfc_nlp_put(ndlp); |
| 2820 | continue; |
| 2821 | } |
| 2822 | spin_lock_irq(&phba->ndlp_lock); |
| 2823 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2824 | /* The ndlp should not be in memory free mode already */ |
| 2825 | spin_unlock_irq(&phba->ndlp_lock); |
| 2826 | continue; |
| 2827 | } else |
| 2828 | /* Indicate request for freeing ndlp memory */ |
| 2829 | NLP_SET_FREE_REQ(ndlp); |
| 2830 | spin_unlock_irq(&phba->ndlp_lock); |
| 2831 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2832 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2833 | ndlp->nlp_DID == Fabric_DID) { |
| 2834 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2835 | lpfc_nlp_put(ndlp); |
| 2836 | continue; |
| 2837 | } |
| 2838 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2839 | /* take care of nodes in unused state before the state |
| 2840 | * machine taking action. |
| 2841 | */ |
| 2842 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2843 | lpfc_nlp_put(ndlp); |
| 2844 | continue; |
| 2845 | } |
| 2846 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2847 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2848 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2849 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2850 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2851 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2852 | NLP_EVT_DEVICE_RM); |
| 2853 | } |
| 2854 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2855 | /* At this point, ALL ndlp's should be gone |
| 2856 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2857 | * Lets wait for this to happen, if needed. |
| 2858 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2859 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2860 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2861 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2862 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2863 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2864 | &vport->fc_nodes, nlp_listp) { |
| 2865 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2866 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2867 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2868 | "usgmap:x%x refcnt:%d\n", |
| 2869 | ndlp->nlp_DID, (void *)ndlp, |
| 2870 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2871 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2872 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2873 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2874 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2875 | |
| 2876 | /* Wait for any activity on ndlps to settle */ |
| 2877 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2878 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2879 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | } |
| 2881 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2883 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2884 | * @vport: pointer to a virtual N_Port data structure. |
| 2885 | * |
| 2886 | * This routine stops all the timers associated with a @vport. This function |
| 2887 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2888 | * port is treated as @vport 0. |
| 2889 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2890 | void |
| 2891 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2892 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2893 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2894 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2895 | lpfc_can_disctmo(vport); |
| 2896 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2897 | } |
| 2898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2899 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2900 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2901 | * @phba: pointer to lpfc hba data structure. |
| 2902 | * |
| 2903 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2904 | * caller of this routine should already hold the host lock. |
| 2905 | **/ |
| 2906 | void |
| 2907 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2908 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2909 | /* Clear pending FCF rediscovery wait flag */ |
| 2910 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2911 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2912 | /* Now, try to stop the timer */ |
| 2913 | del_timer(&phba->fcf.redisc_wait); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2918 | * @phba: pointer to lpfc hba data structure. |
| 2919 | * |
| 2920 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2921 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2922 | * lock held before proceeding with disabling the timer and clearing the |
| 2923 | * wait timer pendig flag. |
| 2924 | **/ |
| 2925 | void |
| 2926 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2927 | { |
| 2928 | spin_lock_irq(&phba->hbalock); |
| 2929 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2930 | /* FCF rediscovery timer already fired or stopped */ |
| 2931 | spin_unlock_irq(&phba->hbalock); |
| 2932 | return; |
| 2933 | } |
| 2934 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2935 | /* Clear failover in progress flags */ |
| 2936 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2937 | spin_unlock_irq(&phba->hbalock); |
| 2938 | } |
| 2939 | |
| 2940 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2941 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2942 | * @phba: pointer to lpfc hba data structure. |
| 2943 | * |
| 2944 | * This routine stops all the timers associated with a HBA. This function is |
| 2945 | * invoked before either putting a HBA offline or unloading the driver. |
| 2946 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2947 | void |
| 2948 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 2950 | if (phba->pport) |
| 2951 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 2952 | cancel_delayed_work_sync(&phba->eq_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2953 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2954 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2955 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2956 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2957 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2958 | del_timer_sync(&phba->rrq_tmr); |
| 2959 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2960 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2961 | phba->hb_outstanding = 0; |
| 2962 | |
| 2963 | switch (phba->pci_dev_grp) { |
| 2964 | case LPFC_PCI_DEV_LP: |
| 2965 | /* Stop any LightPulse device specific driver timers */ |
| 2966 | del_timer_sync(&phba->fcp_poll_timer); |
| 2967 | break; |
| 2968 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 2969 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2970 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2971 | break; |
| 2972 | default: |
| 2973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2974 | "0297 Invalid device group (x%x)\n", |
| 2975 | phba->pci_dev_grp); |
| 2976 | break; |
| 2977 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2978 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | } |
| 2980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2982 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2983 | * @phba: pointer to lpfc hba data structure. |
| 2984 | * |
| 2985 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2986 | * management interface is marked as blocked, all the user space access to |
| 2987 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2988 | * all be blocked. The HBA is set to block the management interface when the |
| 2989 | * driver prepares the HBA interface for online or offline. |
| 2990 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2991 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2992 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2993 | { |
| 2994 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2995 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2996 | unsigned long timeout; |
| 2997 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2998 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2999 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3000 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3001 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3002 | return; |
| 3003 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3004 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3005 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3006 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3007 | /* Determine how long we might wait for the active mailbox |
| 3008 | * command to be gracefully completed by firmware. |
| 3009 | */ |
| 3010 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3011 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3012 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3013 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3014 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3015 | /* Wait for the outstnading mailbox command to complete */ |
| 3016 | while (phba->sli.mbox_active) { |
| 3017 | /* Check active mailbox complete status every 2ms */ |
| 3018 | msleep(2); |
| 3019 | if (time_after(jiffies, timeout)) { |
| 3020 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3021 | "2813 Mgmt IO is Blocked %x " |
| 3022 | "- mbox cmd %x still active\n", |
| 3023 | phba->sli.sli_flag, actcmd); |
| 3024 | break; |
| 3025 | } |
| 3026 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3027 | } |
| 3028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3029 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3030 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3031 | * @phba: pointer to lpfc hba data structure. |
| 3032 | * |
| 3033 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3034 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3035 | * is to fixup the temporary rpi assignments. |
| 3036 | **/ |
| 3037 | void |
| 3038 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3039 | { |
| 3040 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3041 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3042 | int i, rpi; |
| 3043 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3044 | |
| 3045 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3046 | return; |
| 3047 | |
| 3048 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3049 | if (vports == NULL) |
| 3050 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3051 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3052 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3053 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3054 | continue; |
| 3055 | |
| 3056 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3057 | &vports[i]->fc_nodes, |
| 3058 | nlp_listp) { |
| 3059 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3060 | continue; |
| 3061 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3062 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3063 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3064 | NLP_CLR_NODE_ACT(ndlp); |
| 3065 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3066 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3067 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3068 | ndlp->nlp_rpi = rpi; |
| 3069 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3070 | "0009 rpi:%x DID:%x " |
| 3071 | "flg:%x map:%x %p\n", ndlp->nlp_rpi, |
| 3072 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3073 | ndlp->nlp_usg_map, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | lpfc_destroy_vport_work_array(phba, vports); |
| 3077 | } |
| 3078 | |
| 3079 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3080 | * lpfc_create_expedite_pool - create expedite pool |
| 3081 | * @phba: pointer to lpfc hba data structure. |
| 3082 | * |
| 3083 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3084 | * to expedite pool. Mark them as expedite. |
| 3085 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3086 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3087 | { |
| 3088 | struct lpfc_sli4_hdw_queue *qp; |
| 3089 | struct lpfc_io_buf *lpfc_ncmd; |
| 3090 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3091 | struct lpfc_epd_pool *epd_pool; |
| 3092 | unsigned long iflag; |
| 3093 | |
| 3094 | epd_pool = &phba->epd_pool; |
| 3095 | qp = &phba->sli4_hba.hdwq[0]; |
| 3096 | |
| 3097 | spin_lock_init(&epd_pool->lock); |
| 3098 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3099 | spin_lock(&epd_pool->lock); |
| 3100 | INIT_LIST_HEAD(&epd_pool->list); |
| 3101 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3102 | &qp->lpfc_io_buf_list_put, list) { |
| 3103 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3104 | lpfc_ncmd->expedite = true; |
| 3105 | qp->put_io_bufs--; |
| 3106 | epd_pool->count++; |
| 3107 | if (epd_pool->count >= XRI_BATCH) |
| 3108 | break; |
| 3109 | } |
| 3110 | spin_unlock(&epd_pool->lock); |
| 3111 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3112 | } |
| 3113 | |
| 3114 | /** |
| 3115 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3116 | * @phba: pointer to lpfc hba data structure. |
| 3117 | * |
| 3118 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3119 | * of HWQ 0. Clear the mark. |
| 3120 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3121 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3122 | { |
| 3123 | struct lpfc_sli4_hdw_queue *qp; |
| 3124 | struct lpfc_io_buf *lpfc_ncmd; |
| 3125 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3126 | struct lpfc_epd_pool *epd_pool; |
| 3127 | unsigned long iflag; |
| 3128 | |
| 3129 | epd_pool = &phba->epd_pool; |
| 3130 | qp = &phba->sli4_hba.hdwq[0]; |
| 3131 | |
| 3132 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3133 | spin_lock(&epd_pool->lock); |
| 3134 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3135 | &epd_pool->list, list) { |
| 3136 | list_move_tail(&lpfc_ncmd->list, |
| 3137 | &qp->lpfc_io_buf_list_put); |
| 3138 | lpfc_ncmd->flags = false; |
| 3139 | qp->put_io_bufs++; |
| 3140 | epd_pool->count--; |
| 3141 | } |
| 3142 | spin_unlock(&epd_pool->lock); |
| 3143 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3148 | * @phba: pointer to lpfc hba data structure. |
| 3149 | * |
| 3150 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3151 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3152 | * Initialized. |
| 3153 | **/ |
| 3154 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3155 | { |
| 3156 | u32 i, j; |
| 3157 | u32 hwq_count; |
| 3158 | u32 count_per_hwq; |
| 3159 | struct lpfc_io_buf *lpfc_ncmd; |
| 3160 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3161 | unsigned long iflag; |
| 3162 | struct lpfc_sli4_hdw_queue *qp; |
| 3163 | struct lpfc_multixri_pool *multixri_pool; |
| 3164 | struct lpfc_pbl_pool *pbl_pool; |
| 3165 | struct lpfc_pvt_pool *pvt_pool; |
| 3166 | |
| 3167 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3168 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3169 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3170 | phba->sli4_hba.io_xri_cnt); |
| 3171 | |
| 3172 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3173 | lpfc_create_expedite_pool(phba); |
| 3174 | |
| 3175 | hwq_count = phba->cfg_hdw_queue; |
| 3176 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3177 | |
| 3178 | for (i = 0; i < hwq_count; i++) { |
| 3179 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3180 | |
| 3181 | if (!multixri_pool) { |
| 3182 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3183 | "1238 Failed to allocate memory for " |
| 3184 | "multixri_pool\n"); |
| 3185 | |
| 3186 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3187 | lpfc_destroy_expedite_pool(phba); |
| 3188 | |
| 3189 | j = 0; |
| 3190 | while (j < i) { |
| 3191 | qp = &phba->sli4_hba.hdwq[j]; |
| 3192 | kfree(qp->p_multixri_pool); |
| 3193 | j++; |
| 3194 | } |
| 3195 | phba->cfg_xri_rebalancing = 0; |
| 3196 | return; |
| 3197 | } |
| 3198 | |
| 3199 | qp = &phba->sli4_hba.hdwq[i]; |
| 3200 | qp->p_multixri_pool = multixri_pool; |
| 3201 | |
| 3202 | multixri_pool->xri_limit = count_per_hwq; |
| 3203 | multixri_pool->rrb_next_hwqid = i; |
| 3204 | |
| 3205 | /* Deal with public free xri pool */ |
| 3206 | pbl_pool = &multixri_pool->pbl_pool; |
| 3207 | spin_lock_init(&pbl_pool->lock); |
| 3208 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3209 | spin_lock(&pbl_pool->lock); |
| 3210 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3211 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3212 | &qp->lpfc_io_buf_list_put, list) { |
| 3213 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3214 | qp->put_io_bufs--; |
| 3215 | pbl_pool->count++; |
| 3216 | } |
| 3217 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3218 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3219 | pbl_pool->count, i); |
| 3220 | spin_unlock(&pbl_pool->lock); |
| 3221 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3222 | |
| 3223 | /* Deal with private free xri pool */ |
| 3224 | pvt_pool = &multixri_pool->pvt_pool; |
| 3225 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3226 | pvt_pool->low_watermark = XRI_BATCH; |
| 3227 | spin_lock_init(&pvt_pool->lock); |
| 3228 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3229 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3230 | pvt_pool->count = 0; |
| 3231 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | /** |
| 3236 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3237 | * @phba: pointer to lpfc hba data structure. |
| 3238 | * |
| 3239 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3240 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3241 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3242 | { |
| 3243 | u32 i; |
| 3244 | u32 hwq_count; |
| 3245 | struct lpfc_io_buf *lpfc_ncmd; |
| 3246 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3247 | unsigned long iflag; |
| 3248 | struct lpfc_sli4_hdw_queue *qp; |
| 3249 | struct lpfc_multixri_pool *multixri_pool; |
| 3250 | struct lpfc_pbl_pool *pbl_pool; |
| 3251 | struct lpfc_pvt_pool *pvt_pool; |
| 3252 | |
| 3253 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3254 | lpfc_destroy_expedite_pool(phba); |
| 3255 | |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3256 | if (!(phba->pport->load_flag & FC_UNLOADING)) { |
| 3257 | lpfc_sli_flush_fcp_rings(phba); |
| 3258 | |
| 3259 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3260 | lpfc_sli_flush_nvme_rings(phba); |
| 3261 | } |
| 3262 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3263 | hwq_count = phba->cfg_hdw_queue; |
| 3264 | |
| 3265 | for (i = 0; i < hwq_count; i++) { |
| 3266 | qp = &phba->sli4_hba.hdwq[i]; |
| 3267 | multixri_pool = qp->p_multixri_pool; |
| 3268 | if (!multixri_pool) |
| 3269 | continue; |
| 3270 | |
| 3271 | qp->p_multixri_pool = NULL; |
| 3272 | |
| 3273 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3274 | |
| 3275 | /* Deal with public free xri pool */ |
| 3276 | pbl_pool = &multixri_pool->pbl_pool; |
| 3277 | spin_lock(&pbl_pool->lock); |
| 3278 | |
| 3279 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3280 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3281 | pbl_pool->count, i); |
| 3282 | |
| 3283 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3284 | &pbl_pool->list, list) { |
| 3285 | list_move_tail(&lpfc_ncmd->list, |
| 3286 | &qp->lpfc_io_buf_list_put); |
| 3287 | qp->put_io_bufs++; |
| 3288 | pbl_pool->count--; |
| 3289 | } |
| 3290 | |
| 3291 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3292 | pbl_pool->count = 0; |
| 3293 | |
| 3294 | spin_unlock(&pbl_pool->lock); |
| 3295 | |
| 3296 | /* Deal with private free xri pool */ |
| 3297 | pvt_pool = &multixri_pool->pvt_pool; |
| 3298 | spin_lock(&pvt_pool->lock); |
| 3299 | |
| 3300 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3301 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3302 | pvt_pool->count, i); |
| 3303 | |
| 3304 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3305 | &pvt_pool->list, list) { |
| 3306 | list_move_tail(&lpfc_ncmd->list, |
| 3307 | &qp->lpfc_io_buf_list_put); |
| 3308 | qp->put_io_bufs++; |
| 3309 | pvt_pool->count--; |
| 3310 | } |
| 3311 | |
| 3312 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3313 | pvt_pool->count = 0; |
| 3314 | |
| 3315 | spin_unlock(&pvt_pool->lock); |
| 3316 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3317 | |
| 3318 | kfree(multixri_pool); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3323 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3324 | * @phba: pointer to lpfc hba data structure. |
| 3325 | * |
| 3326 | * This routine initializes the HBA and brings a HBA online. During this |
| 3327 | * process, the management interface is blocked to prevent user space access |
| 3328 | * to the HBA interfering with the driver initialization. |
| 3329 | * |
| 3330 | * Return codes |
| 3331 | * 0 - successful |
| 3332 | * 1 - failed |
| 3333 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3334 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3335 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3337 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3338 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3339 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3340 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3341 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3342 | if (!phba) |
| 3343 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3344 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3345 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3346 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | return 0; |
| 3348 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3349 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3350 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3352 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3353 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3354 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3355 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3356 | lpfc_unblock_mgmt_io(phba); |
| 3357 | return 1; |
| 3358 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3359 | spin_lock_irq(&phba->hbalock); |
| 3360 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3361 | vpis_cleared = true; |
| 3362 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3363 | |
| 3364 | /* Reestablish the local initiator port. |
| 3365 | * The offline process destroyed the previous lport. |
| 3366 | */ |
| 3367 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3368 | !phba->nvmet_support) { |
| 3369 | error = lpfc_nvme_create_localport(phba->pport); |
| 3370 | if (error) |
| 3371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3372 | "6132 NVME restore reg failed " |
| 3373 | "on nvmei error x%x\n", error); |
| 3374 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3375 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3376 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3377 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3378 | lpfc_unblock_mgmt_io(phba); |
| 3379 | return 1; |
| 3380 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3381 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3383 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3384 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3385 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3386 | struct Scsi_Host *shost; |
| 3387 | shost = lpfc_shost_from_vport(vports[i]); |
| 3388 | spin_lock_irq(shost->host_lock); |
| 3389 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3390 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3391 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3392 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3393 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3394 | if ((vpis_cleared) && |
| 3395 | (vports[i]->port_type != |
| 3396 | LPFC_PHYSICAL_PORT)) |
| 3397 | vports[i]->vpi = 0; |
| 3398 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3399 | spin_unlock_irq(shost->host_lock); |
| 3400 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3401 | } |
| 3402 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3403 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3404 | if (phba->cfg_xri_rebalancing) |
| 3405 | lpfc_create_multixri_pools(phba); |
| 3406 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3407 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | return 0; |
| 3409 | } |
| 3410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3411 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3412 | * 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] | 3413 | * @phba: pointer to lpfc hba data structure. |
| 3414 | * |
| 3415 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3416 | * HBA's management interface is marked as not blocked, all the user space |
| 3417 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3418 | * interface will be allowed. The HBA is set to block the management interface |
| 3419 | * when the driver prepares the HBA interface for online or offline and then |
| 3420 | * set to unblock the management interface afterwards. |
| 3421 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3422 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3423 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3424 | { |
| 3425 | unsigned long iflag; |
| 3426 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3427 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3428 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3429 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3430 | } |
| 3431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3433 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3434 | * @phba: pointer to lpfc hba data structure. |
| 3435 | * |
| 3436 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3437 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3438 | * queue to make it ready to be brought offline. |
| 3439 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3440 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3441 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3442 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3444 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3445 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3446 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3447 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3449 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3450 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3452 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | |
| 3454 | lpfc_linkdown(phba); |
| 3455 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3456 | /* Issue an unreg_login to all nodes on all vports */ |
| 3457 | vports = lpfc_create_vport_work_array(phba); |
| 3458 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3459 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3460 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3461 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3462 | shost = lpfc_shost_from_vport(vports[i]); |
| 3463 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3464 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3465 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3466 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3467 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3468 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3469 | shost = lpfc_shost_from_vport(vports[i]); |
| 3470 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3471 | &vports[i]->fc_nodes, |
| 3472 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3473 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3474 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3475 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3476 | continue; |
| 3477 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3478 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3479 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3480 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3481 | NULL, NLP_EVT_DEVICE_RM); |
| 3482 | } |
| 3483 | spin_lock_irq(shost->host_lock); |
| 3484 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3485 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3486 | /* |
| 3487 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3488 | * RPI. Get a new RPI when the adapter port |
| 3489 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3490 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3491 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3492 | lpfc_printf_vlog(ndlp->vport, |
| 3493 | KERN_INFO, LOG_NODE, |
| 3494 | "0011 lpfc_offline: " |
| 3495 | "ndlp:x%p did %x " |
| 3496 | "usgmap:x%x rpi:%x\n", |
| 3497 | ndlp, ndlp->nlp_DID, |
| 3498 | ndlp->nlp_usg_map, |
| 3499 | ndlp->nlp_rpi); |
| 3500 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3501 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3502 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3503 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3504 | } |
| 3505 | } |
| 3506 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3507 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3509 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3510 | |
| 3511 | if (phba->wq) |
| 3512 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3513 | } |
| 3514 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3515 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3516 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3517 | * @phba: pointer to lpfc hba data structure. |
| 3518 | * |
| 3519 | * This routine actually brings a HBA offline. It stops all the timers |
| 3520 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3521 | * marks the HBA as in offline state for the upper layer protocol. |
| 3522 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3523 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3524 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3525 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3526 | struct Scsi_Host *shost; |
| 3527 | struct lpfc_vport **vports; |
| 3528 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3529 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3530 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3531 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3532 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3533 | /* stop port and all timers associated with this hba */ |
| 3534 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3535 | |
| 3536 | /* Tear down the local and target port registrations. The |
| 3537 | * nvme transports need to cleanup. |
| 3538 | */ |
| 3539 | lpfc_nvmet_destroy_targetport(phba); |
| 3540 | lpfc_nvme_destroy_localport(phba->pport); |
| 3541 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3542 | vports = lpfc_create_vport_work_array(phba); |
| 3543 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3544 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3545 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3546 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3547 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3548 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3549 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3550 | now. */ |
| 3551 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3552 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3553 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3554 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3555 | vports = lpfc_create_vport_work_array(phba); |
| 3556 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3557 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3558 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3559 | spin_lock_irq(shost->host_lock); |
| 3560 | vports[i]->work_port_events = 0; |
| 3561 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3562 | spin_unlock_irq(shost->host_lock); |
| 3563 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3564 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3565 | |
| 3566 | if (phba->cfg_xri_rebalancing) |
| 3567 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3568 | } |
| 3569 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3570 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3571 | * 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] | 3572 | * @phba: pointer to lpfc hba data structure. |
| 3573 | * |
| 3574 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3575 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3576 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3577 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3578 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3579 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3580 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3581 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3583 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3584 | return; |
| 3585 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3586 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3587 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3588 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3589 | |
| 3590 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3591 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3592 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3593 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3594 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3595 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3596 | kfree(sb); |
| 3597 | phba->total_scsi_bufs--; |
| 3598 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3599 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3600 | |
| 3601 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3602 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3603 | list) { |
| 3604 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3605 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3606 | sb->dma_handle); |
| 3607 | kfree(sb); |
| 3608 | phba->total_scsi_bufs--; |
| 3609 | } |
| 3610 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3611 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3612 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3613 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3614 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3615 | * 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] | 3616 | * @phba: pointer to lpfc hba data structure. |
| 3617 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3618 | * 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] | 3619 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3620 | * the internal resources before the device is removed from the system. |
| 3621 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3622 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3623 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3624 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3625 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3626 | struct lpfc_sli4_hdw_queue *qp; |
| 3627 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3628 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3629 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3630 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3631 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3632 | spin_lock(&qp->io_buf_list_put_lock); |
| 3633 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3634 | &qp->lpfc_io_buf_list_put, |
| 3635 | list) { |
| 3636 | list_del(&lpfc_ncmd->list); |
| 3637 | qp->put_io_bufs--; |
| 3638 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3639 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3640 | kfree(lpfc_ncmd); |
| 3641 | qp->total_io_bufs--; |
| 3642 | } |
| 3643 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3644 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3645 | spin_lock(&qp->io_buf_list_get_lock); |
| 3646 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3647 | &qp->lpfc_io_buf_list_get, |
| 3648 | list) { |
| 3649 | list_del(&lpfc_ncmd->list); |
| 3650 | qp->get_io_bufs--; |
| 3651 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3652 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 3653 | kfree(lpfc_ncmd); |
| 3654 | qp->total_io_bufs--; |
| 3655 | } |
| 3656 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3657 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3658 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3659 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3660 | /** |
| 3661 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3662 | * @phba: pointer to lpfc hba data structure. |
| 3663 | * |
| 3664 | * This routine first calculates the sizes of the current els and allocated |
| 3665 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3666 | * XRIs assigned due to port function reset. During port initialization, the |
| 3667 | * current els and allocated scsi sgl lists are 0s. |
| 3668 | * |
| 3669 | * Return codes |
| 3670 | * 0 - successful (for now, it always returns 0) |
| 3671 | **/ |
| 3672 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3673 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3674 | { |
| 3675 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3676 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3677 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3678 | int rc; |
| 3679 | |
| 3680 | /* |
| 3681 | * update on pci function's els xri-sgl list |
| 3682 | */ |
| 3683 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3684 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3685 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3686 | /* els xri-sgl expanded */ |
| 3687 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3688 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3689 | "3157 ELS xri-sgl count increased from " |
| 3690 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3691 | els_xri_cnt); |
| 3692 | /* allocate the additional els sgls */ |
| 3693 | for (i = 0; i < xri_cnt; i++) { |
| 3694 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3695 | GFP_KERNEL); |
| 3696 | if (sglq_entry == NULL) { |
| 3697 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3698 | "2562 Failure to allocate an " |
| 3699 | "ELS sgl entry:%d\n", i); |
| 3700 | rc = -ENOMEM; |
| 3701 | goto out_free_mem; |
| 3702 | } |
| 3703 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3704 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3705 | &sglq_entry->phys); |
| 3706 | if (sglq_entry->virt == NULL) { |
| 3707 | kfree(sglq_entry); |
| 3708 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3709 | "2563 Failure to allocate an " |
| 3710 | "ELS mbuf:%d\n", i); |
| 3711 | rc = -ENOMEM; |
| 3712 | goto out_free_mem; |
| 3713 | } |
| 3714 | sglq_entry->sgl = sglq_entry->virt; |
| 3715 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3716 | sglq_entry->state = SGL_FREED; |
| 3717 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3718 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3719 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3720 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3721 | list_splice_init(&els_sgl_list, |
| 3722 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3723 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3724 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3725 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3726 | /* els xri-sgl shrinked */ |
| 3727 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3728 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3729 | "3158 ELS xri-sgl count decreased from " |
| 3730 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3731 | els_xri_cnt); |
| 3732 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3733 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3734 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3735 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3736 | /* release extra els sgls from list */ |
| 3737 | for (i = 0; i < xri_cnt; i++) { |
| 3738 | list_remove_head(&els_sgl_list, |
| 3739 | sglq_entry, struct lpfc_sglq, list); |
| 3740 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3741 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3742 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3743 | kfree(sglq_entry); |
| 3744 | } |
| 3745 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3746 | list_splice_init(&els_sgl_list, |
| 3747 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3748 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3749 | spin_unlock_irq(&phba->hbalock); |
| 3750 | } else |
| 3751 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3752 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3753 | els_xri_cnt); |
| 3754 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3755 | |
| 3756 | /* update xris to els sgls on the list */ |
| 3757 | sglq_entry = NULL; |
| 3758 | sglq_entry_next = NULL; |
| 3759 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3760 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3761 | lxri = lpfc_sli4_next_xritag(phba); |
| 3762 | if (lxri == NO_XRI) { |
| 3763 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3764 | "2400 Failed to allocate xri for " |
| 3765 | "ELS sgl\n"); |
| 3766 | rc = -ENOMEM; |
| 3767 | goto out_free_mem; |
| 3768 | } |
| 3769 | sglq_entry->sli4_lxritag = lxri; |
| 3770 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3771 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3772 | return 0; |
| 3773 | |
| 3774 | out_free_mem: |
| 3775 | lpfc_free_els_sgl_list(phba); |
| 3776 | return rc; |
| 3777 | } |
| 3778 | |
| 3779 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3780 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3781 | * @phba: pointer to lpfc hba data structure. |
| 3782 | * |
| 3783 | * This routine first calculates the sizes of the current els and allocated |
| 3784 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3785 | * XRIs assigned due to port function reset. During port initialization, the |
| 3786 | * current els and allocated scsi sgl lists are 0s. |
| 3787 | * |
| 3788 | * Return codes |
| 3789 | * 0 - successful (for now, it always returns 0) |
| 3790 | **/ |
| 3791 | int |
| 3792 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3793 | { |
| 3794 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3795 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3796 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3797 | LIST_HEAD(nvmet_sgl_list); |
| 3798 | int rc; |
| 3799 | |
| 3800 | /* |
| 3801 | * update on pci function's nvmet xri-sgl list |
| 3802 | */ |
| 3803 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3804 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3805 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3806 | 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] | 3807 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3808 | /* els xri-sgl expanded */ |
| 3809 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3810 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3811 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3812 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3813 | /* allocate the additional nvmet sgls */ |
| 3814 | for (i = 0; i < xri_cnt; i++) { |
| 3815 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3816 | GFP_KERNEL); |
| 3817 | if (sglq_entry == NULL) { |
| 3818 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3819 | "6303 Failure to allocate an " |
| 3820 | "NVMET sgl entry:%d\n", i); |
| 3821 | rc = -ENOMEM; |
| 3822 | goto out_free_mem; |
| 3823 | } |
| 3824 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3825 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3826 | &sglq_entry->phys); |
| 3827 | if (sglq_entry->virt == NULL) { |
| 3828 | kfree(sglq_entry); |
| 3829 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3830 | "6304 Failure to allocate an " |
| 3831 | "NVMET buf:%d\n", i); |
| 3832 | rc = -ENOMEM; |
| 3833 | goto out_free_mem; |
| 3834 | } |
| 3835 | sglq_entry->sgl = sglq_entry->virt; |
| 3836 | memset(sglq_entry->sgl, 0, |
| 3837 | phba->cfg_sg_dma_buf_size); |
| 3838 | sglq_entry->state = SGL_FREED; |
| 3839 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3840 | } |
| 3841 | spin_lock_irq(&phba->hbalock); |
| 3842 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3843 | list_splice_init(&nvmet_sgl_list, |
| 3844 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3845 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3846 | spin_unlock_irq(&phba->hbalock); |
| 3847 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3848 | /* nvmet xri-sgl shrunk */ |
| 3849 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3850 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3851 | "6305 NVMET xri-sgl count decreased from " |
| 3852 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3853 | nvmet_xri_cnt); |
| 3854 | spin_lock_irq(&phba->hbalock); |
| 3855 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3856 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3857 | &nvmet_sgl_list); |
| 3858 | /* release extra nvmet sgls from list */ |
| 3859 | for (i = 0; i < xri_cnt; i++) { |
| 3860 | list_remove_head(&nvmet_sgl_list, |
| 3861 | sglq_entry, struct lpfc_sglq, list); |
| 3862 | if (sglq_entry) { |
| 3863 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3864 | sglq_entry->phys); |
| 3865 | kfree(sglq_entry); |
| 3866 | } |
| 3867 | } |
| 3868 | list_splice_init(&nvmet_sgl_list, |
| 3869 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3870 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3871 | spin_unlock_irq(&phba->hbalock); |
| 3872 | } else |
| 3873 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3874 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3875 | nvmet_xri_cnt); |
| 3876 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3877 | |
| 3878 | /* update xris to nvmet sgls on the list */ |
| 3879 | sglq_entry = NULL; |
| 3880 | sglq_entry_next = NULL; |
| 3881 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3882 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3883 | lxri = lpfc_sli4_next_xritag(phba); |
| 3884 | if (lxri == NO_XRI) { |
| 3885 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3886 | "6307 Failed to allocate xri for " |
| 3887 | "NVMET sgl\n"); |
| 3888 | rc = -ENOMEM; |
| 3889 | goto out_free_mem; |
| 3890 | } |
| 3891 | sglq_entry->sli4_lxritag = lxri; |
| 3892 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3893 | } |
| 3894 | return 0; |
| 3895 | |
| 3896 | out_free_mem: |
| 3897 | lpfc_free_nvmet_sgl_list(phba); |
| 3898 | return rc; |
| 3899 | } |
| 3900 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3901 | int |
| 3902 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3903 | { |
| 3904 | LIST_HEAD(blist); |
| 3905 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3906 | struct lpfc_io_buf *lpfc_cmd; |
| 3907 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3908 | int idx, cnt, xri, inserted; |
| 3909 | |
| 3910 | cnt = 0; |
| 3911 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3912 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3913 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 3914 | spin_lock(&qp->io_buf_list_put_lock); |
| 3915 | |
| 3916 | /* Take everything off the get and put lists */ |
| 3917 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 3918 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 3919 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 3920 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 3921 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 3922 | qp->get_io_bufs = 0; |
| 3923 | qp->put_io_bufs = 0; |
| 3924 | qp->total_io_bufs = 0; |
| 3925 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3926 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 3927 | } |
| 3928 | |
| 3929 | /* |
| 3930 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 3931 | * This is because POST_SGL takes a sequential range of XRIs |
| 3932 | * to post to the firmware. |
| 3933 | */ |
| 3934 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3935 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3936 | if (!lpfc_cmd) |
| 3937 | return cnt; |
| 3938 | if (idx == 0) { |
| 3939 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3940 | continue; |
| 3941 | } |
| 3942 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 3943 | inserted = 0; |
| 3944 | prev_iobufp = NULL; |
| 3945 | list_for_each_entry(iobufp, cbuf, list) { |
| 3946 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 3947 | if (prev_iobufp) |
| 3948 | list_add(&lpfc_cmd->list, |
| 3949 | &prev_iobufp->list); |
| 3950 | else |
| 3951 | list_add(&lpfc_cmd->list, cbuf); |
| 3952 | inserted = 1; |
| 3953 | break; |
| 3954 | } |
| 3955 | prev_iobufp = iobufp; |
| 3956 | } |
| 3957 | if (!inserted) |
| 3958 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3959 | } |
| 3960 | return cnt; |
| 3961 | } |
| 3962 | |
| 3963 | int |
| 3964 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3965 | { |
| 3966 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3967 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3968 | int idx, cnt; |
| 3969 | |
| 3970 | qp = phba->sli4_hba.hdwq; |
| 3971 | cnt = 0; |
| 3972 | while (!list_empty(cbuf)) { |
| 3973 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3974 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3975 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3976 | if (!lpfc_cmd) |
| 3977 | return cnt; |
| 3978 | cnt++; |
| 3979 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 3980 | lpfc_cmd->hdwq_no = idx; |
| 3981 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3982 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 3983 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 3984 | spin_lock(&qp->io_buf_list_put_lock); |
| 3985 | list_add_tail(&lpfc_cmd->list, |
| 3986 | &qp->lpfc_io_buf_list_put); |
| 3987 | qp->put_io_bufs++; |
| 3988 | qp->total_io_bufs++; |
| 3989 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3990 | } |
| 3991 | } |
| 3992 | return cnt; |
| 3993 | } |
| 3994 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3995 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3996 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3997 | * @phba: pointer to lpfc hba data structure. |
| 3998 | * |
| 3999 | * This routine first calculates the sizes of the current els and allocated |
| 4000 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4001 | * XRIs assigned due to port function reset. During port initialization, the |
| 4002 | * current els and allocated scsi sgl lists are 0s. |
| 4003 | * |
| 4004 | * Return codes |
| 4005 | * 0 - successful (for now, it always returns 0) |
| 4006 | **/ |
| 4007 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4008 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4009 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4010 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4011 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4012 | uint16_t io_xri_cnt, io_xri_max; |
| 4013 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4014 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4015 | |
| 4016 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4017 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4018 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4019 | |
| 4020 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4021 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4022 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4023 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4024 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4025 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4026 | "6074 Current allocated XRI sgl count:%d, " |
| 4027 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4028 | phba->sli4_hba.io_xri_cnt, |
| 4029 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4030 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4031 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4032 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4033 | 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] | 4034 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4035 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4036 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4037 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4038 | for (i = 0; i < io_xri_cnt; i++) { |
| 4039 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4040 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4041 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4042 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4043 | lpfc_ncmd->data, |
| 4044 | lpfc_ncmd->dma_handle); |
| 4045 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4046 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4047 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4048 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4049 | } |
| 4050 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4051 | /* update xris associated to remaining allocated nvme buffers */ |
| 4052 | lpfc_ncmd = NULL; |
| 4053 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4054 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4055 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4056 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4057 | lxri = lpfc_sli4_next_xritag(phba); |
| 4058 | if (lxri == NO_XRI) { |
| 4059 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4060 | "6075 Failed to allocate xri for " |
| 4061 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4062 | rc = -ENOMEM; |
| 4063 | goto out_free_mem; |
| 4064 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4065 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4066 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4067 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4068 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4069 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4070 | |
| 4071 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4072 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4073 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4074 | } |
| 4075 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4076 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4077 | * 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] | 4078 | * @vport: The virtual port for which this call being executed. |
| 4079 | * @num_to_allocate: The requested number of buffers to allocate. |
| 4080 | * |
| 4081 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4082 | * the nvme buffer contains all the necessary information needed to initiate |
| 4083 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4084 | * them on a list, it post them to the port by using SGL block post. |
| 4085 | * |
| 4086 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4087 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4088 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4089 | **/ |
| 4090 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4091 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4092 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4093 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4094 | struct lpfc_iocbq *pwqeq; |
| 4095 | uint16_t iotag, lxri = 0; |
| 4096 | int bcnt, num_posted; |
| 4097 | LIST_HEAD(prep_nblist); |
| 4098 | LIST_HEAD(post_nblist); |
| 4099 | LIST_HEAD(nvme_nblist); |
| 4100 | |
| 4101 | /* 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] | 4102 | if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4103 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
Arnd Bergmann | f996861 | 2019-03-04 20:39:09 +0100 | [diff] [blame] | 4104 | "6426 Common buffer size %zd exceeds %d\n", |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4105 | sizeof(struct lpfc_io_buf), |
| 4106 | LPFC_COMMON_IO_BUF_SZ); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4107 | return 0; |
| 4108 | } |
| 4109 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4110 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4111 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
| 4112 | lpfc_ncmd = kzalloc(LPFC_COMMON_IO_BUF_SZ, GFP_KERNEL); |
| 4113 | if (!lpfc_ncmd) |
| 4114 | break; |
| 4115 | /* |
| 4116 | * Get memory from the pci pool to map the virt space to |
| 4117 | * pci bus space for an I/O. The DMA buffer includes the |
| 4118 | * number of SGE's necessary to support the sg_tablesize. |
| 4119 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4120 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4121 | GFP_KERNEL, |
| 4122 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4123 | if (!lpfc_ncmd->data) { |
| 4124 | kfree(lpfc_ncmd); |
| 4125 | break; |
| 4126 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4127 | |
| 4128 | /* |
| 4129 | * 4K Page alignment is CRITICAL to BlockGuard, double check |
| 4130 | * to be sure. |
| 4131 | */ |
| 4132 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4133 | (((unsigned long)(lpfc_ncmd->data) & |
| 4134 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
| 4135 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
| 4136 | "3369 Memory alignment err: addr=%lx\n", |
| 4137 | (unsigned long)lpfc_ncmd->data); |
| 4138 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4139 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4140 | kfree(lpfc_ncmd); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | lxri = lpfc_sli4_next_xritag(phba); |
| 4145 | if (lxri == NO_XRI) { |
| 4146 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4147 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4148 | kfree(lpfc_ncmd); |
| 4149 | break; |
| 4150 | } |
| 4151 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4152 | |
| 4153 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4154 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4155 | if (iotag == 0) { |
| 4156 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4157 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4158 | kfree(lpfc_ncmd); |
| 4159 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, |
| 4160 | "6121 Failed to allocate IOTAG for" |
| 4161 | " XRI:0x%x\n", lxri); |
| 4162 | lpfc_sli4_free_xri(phba, lxri); |
| 4163 | break; |
| 4164 | } |
| 4165 | pwqeq->sli4_lxritag = lxri; |
| 4166 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4167 | pwqeq->context1 = lpfc_ncmd; |
| 4168 | |
| 4169 | /* Initialize local short-hand pointers. */ |
| 4170 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4171 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4172 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4173 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4174 | |
| 4175 | /* add the nvme buffer to a post list */ |
| 4176 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4177 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4178 | } |
| 4179 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4180 | "6114 Allocate %d out of %d requested new NVME " |
| 4181 | "buffers\n", bcnt, num_to_alloc); |
| 4182 | |
| 4183 | /* post the list of nvme buffer sgls to port if available */ |
| 4184 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4185 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4186 | phba, &post_nblist, bcnt); |
| 4187 | else |
| 4188 | num_posted = 0; |
| 4189 | |
| 4190 | return num_posted; |
| 4191 | } |
| 4192 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4193 | static uint64_t |
| 4194 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4195 | { |
| 4196 | uint64_t wwn; |
| 4197 | int rc; |
| 4198 | LPFC_MBOXQ_t *mboxq; |
| 4199 | MAILBOX_t *mb; |
| 4200 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4201 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4202 | GFP_KERNEL); |
| 4203 | if (!mboxq) |
| 4204 | return (uint64_t)-1; |
| 4205 | |
| 4206 | /* First get WWN of HBA instance */ |
| 4207 | lpfc_read_nv(phba, mboxq); |
| 4208 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4209 | if (rc != MBX_SUCCESS) { |
| 4210 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4211 | "6019 Mailbox failed , mbxCmd x%x " |
| 4212 | "READ_NV, mbxStatus x%x\n", |
| 4213 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4214 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4215 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4216 | return (uint64_t) -1; |
| 4217 | } |
| 4218 | mb = &mboxq->u.mb; |
| 4219 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4220 | /* wwn is WWPN of HBA instance */ |
| 4221 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4222 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4223 | return be64_to_cpu(wwn); |
| 4224 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4225 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4228 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4229 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4230 | * @phba: pointer to lpfc hba data structure. |
| 4231 | * @instance: a unique integer ID to this FC port. |
| 4232 | * @dev: pointer to the device data structure. |
| 4233 | * |
| 4234 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4235 | * can be created on top of either a physical port or a virtual port provided |
| 4236 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4237 | * and associates the FC port created before adding the shost into the SCSI |
| 4238 | * layer. |
| 4239 | * |
| 4240 | * Return codes |
| 4241 | * @vport - pointer to the virtual N_Port data structure. |
| 4242 | * NULL - port create failed. |
| 4243 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4244 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4245 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4246 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4248 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4249 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4250 | int i; |
| 4251 | uint64_t wwn; |
| 4252 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4253 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4254 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4255 | if (lpfc_no_hba_reset_cnt) { |
| 4256 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4257 | dev == &phba->pcidev->dev) { |
| 4258 | /* Reset the port first */ |
| 4259 | lpfc_sli_brdrestart(phba); |
| 4260 | rc = lpfc_sli_chipset_init(phba); |
| 4261 | if (rc) |
| 4262 | return NULL; |
| 4263 | } |
| 4264 | wwn = lpfc_get_wwpn(phba); |
| 4265 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4266 | |
| 4267 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4268 | if (wwn == lpfc_no_hba_reset[i]) { |
| 4269 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4270 | "6020 Setting use_no_reset port=%llx\n", |
| 4271 | wwn); |
| 4272 | use_no_reset_hba = true; |
| 4273 | break; |
| 4274 | } |
| 4275 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4276 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4277 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4278 | if (dev != &phba->pcidev->dev) { |
| 4279 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 4280 | sizeof(struct lpfc_vport)); |
| 4281 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4282 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4283 | shost = scsi_host_alloc(&lpfc_template, |
| 4284 | sizeof(struct lpfc_vport)); |
| 4285 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4286 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4287 | sizeof(struct lpfc_vport)); |
| 4288 | } |
| 4289 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 4290 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4291 | sizeof(struct lpfc_vport)); |
| 4292 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4293 | if (!shost) |
| 4294 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4295 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4296 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4297 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4298 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4299 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4300 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4301 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4302 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4303 | /* Adjust value in vport */ |
| 4304 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4305 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | shost->unique_id = instance; |
| 4307 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4308 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4309 | shost->this_id = -1; |
| 4310 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4311 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4312 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4313 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_HDWQ) |
| 4314 | shost->nr_hw_queues = phba->cfg_hdw_queue; |
| 4315 | else |
| 4316 | shost->nr_hw_queues = phba->sli4_hba.num_present_cpu; |
| 4317 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4318 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4319 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 4320 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4321 | } else |
| 4322 | /* SLI-3 has a limited number of hardware queues (3), |
| 4323 | * thus there is only one for FCP processing. |
| 4324 | */ |
| 4325 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4326 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4327 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4328 | * Set initial can_queue value since 0 is no longer supported and |
| 4329 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4330 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4331 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4332 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4333 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4334 | shost->transportt = lpfc_vport_transport_template; |
| 4335 | vport->port_type = LPFC_NPIV_PORT; |
| 4336 | } else { |
| 4337 | shost->transportt = lpfc_transport_template; |
| 4338 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4339 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4340 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4341 | /* Initialize all internally managed lists. */ |
| 4342 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4343 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4344 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4345 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4346 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4347 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4348 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4349 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4350 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4351 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4352 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4353 | lpfc_setup_bg(phba, shost); |
| 4354 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4355 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | if (error) |
| 4357 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4358 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4359 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4361 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4362 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4363 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | out_put_shost: |
| 4365 | scsi_host_put(shost); |
| 4366 | out: |
| 4367 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4368 | } |
| 4369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4371 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4372 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4373 | * |
| 4374 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4375 | * resources associated with the port are released. |
| 4376 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | void |
| 4378 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4379 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4380 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4381 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4382 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4383 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4384 | fc_remove_host(shost); |
| 4385 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4386 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4387 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4388 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4389 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4391 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4392 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4393 | } |
| 4394 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4395 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4396 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4397 | * |
| 4398 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4399 | * uses the kernel idr facility to perform the task. |
| 4400 | * |
| 4401 | * Return codes: |
| 4402 | * instance - a unique integer ID allocated as the new instance. |
| 4403 | * -1 - lpfc get instance failed. |
| 4404 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | int |
| 4406 | lpfc_get_instance(void) |
| 4407 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4408 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4409 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4410 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4411 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4412 | } |
| 4413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4415 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4416 | * @shost: pointer to SCSI host data structure. |
| 4417 | * @time: elapsed time of the scan in jiffies. |
| 4418 | * |
| 4419 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4420 | * whether the scan host is finished. |
| 4421 | * |
| 4422 | * Note: there is no scan_start function as adapter initialization will have |
| 4423 | * asynchronously kicked off the link initialization. |
| 4424 | * |
| 4425 | * Return codes |
| 4426 | * 0 - SCSI host scan is not over yet. |
| 4427 | * 1 - SCSI host scan is over. |
| 4428 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4429 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4430 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4431 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4432 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4433 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4434 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4435 | spin_lock_irq(shost->host_lock); |
| 4436 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4437 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4438 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4439 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4440 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4441 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4442 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4443 | "0461 Scanning longer than 30 " |
| 4444 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4445 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4446 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4447 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4448 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4449 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4451 | "0465 Link down longer than 15 " |
| 4452 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4453 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4458 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4459 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4460 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4461 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4462 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4464 | goto finished; |
| 4465 | |
| 4466 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4467 | |
| 4468 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4469 | spin_unlock_irq(shost->host_lock); |
| 4470 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4471 | } |
| 4472 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4473 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4476 | struct lpfc_hba *phba = vport->phba; |
| 4477 | |
| 4478 | fc_host_supported_speeds(shost) = 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4479 | if (phba->lmt & LMT_128Gb) |
| 4480 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4481 | if (phba->lmt & LMT_64Gb) |
| 4482 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4483 | if (phba->lmt & LMT_32Gb) |
| 4484 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4485 | if (phba->lmt & LMT_16Gb) |
| 4486 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4487 | if (phba->lmt & LMT_10Gb) |
| 4488 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4489 | if (phba->lmt & LMT_8Gb) |
| 4490 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4491 | if (phba->lmt & LMT_4Gb) |
| 4492 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4493 | if (phba->lmt & LMT_2Gb) |
| 4494 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4495 | if (phba->lmt & LMT_1Gb) |
| 4496 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4497 | } |
| 4498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4499 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4500 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4501 | * @shost: pointer to SCSI host data structure. |
| 4502 | * |
| 4503 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4504 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4505 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4506 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4507 | { |
| 4508 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4509 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4510 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4511 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4512 | */ |
| 4513 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4515 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4516 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4517 | |
| 4518 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4519 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4520 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4521 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4522 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4523 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4524 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4525 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4526 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4527 | |
| 4528 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4530 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4531 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4532 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4533 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4534 | /* This value is also unchanging */ |
| 4535 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4536 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4537 | fc_host_active_fc4s(shost)[2] = 1; |
| 4538 | fc_host_active_fc4s(shost)[7] = 1; |
| 4539 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4540 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4541 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4542 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4543 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4544 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4545 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4546 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4547 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4548 | * @phba: pointer to lpfc hba data structure. |
| 4549 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4550 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4551 | * from generating interrupts and stops the device driver's timers for the |
| 4552 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4553 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4554 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4555 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4556 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4557 | /* Clear all interrupt enable conditions */ |
| 4558 | writel(0, phba->HCregaddr); |
| 4559 | readl(phba->HCregaddr); /* flush */ |
| 4560 | /* Clear all pending interrupts */ |
| 4561 | writel(0xffffffff, phba->HAregaddr); |
| 4562 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4563 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4564 | /* Reset some HBA SLI setup states */ |
| 4565 | lpfc_stop_hba_timers(phba); |
| 4566 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4567 | } |
| 4568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4569 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4570 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4571 | * @phba: pointer to lpfc hba data structure. |
| 4572 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4573 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4574 | * from generating interrupts and stops the device driver's timers for the |
| 4575 | * device. |
| 4576 | **/ |
| 4577 | static void |
| 4578 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4579 | { |
| 4580 | /* Reset some HBA SLI4 setup states */ |
| 4581 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4582 | if (phba->pport) |
| 4583 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4584 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
| 4588 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4589 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4590 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4591 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4592 | * the API jump table function pointer from the lpfc_hba struct. |
| 4593 | **/ |
| 4594 | void |
| 4595 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4596 | { |
| 4597 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4598 | |
| 4599 | if (phba->wq) |
| 4600 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4604 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4605 | * @phba: Pointer to hba for which this call is being executed. |
| 4606 | * |
| 4607 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4608 | **/ |
| 4609 | void |
| 4610 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4611 | { |
| 4612 | unsigned long fcf_redisc_wait_tmo = |
| 4613 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4614 | /* Start fcf rediscovery wait period timer */ |
| 4615 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4616 | spin_lock_irq(&phba->hbalock); |
| 4617 | /* Allow action to new fcf asynchronous event */ |
| 4618 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4619 | /* Mark the FCF rediscovery pending state */ |
| 4620 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4621 | spin_unlock_irq(&phba->hbalock); |
| 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4626 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4627 | * |
| 4628 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4629 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4630 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4631 | * list, and then worker thread shall be waked up for processing from the |
| 4632 | * worker thread context. |
| 4633 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4634 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4635 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4636 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4637 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4638 | |
| 4639 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4640 | spin_lock_irq(&phba->hbalock); |
| 4641 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4642 | spin_unlock_irq(&phba->hbalock); |
| 4643 | return; |
| 4644 | } |
| 4645 | /* Clear FCF rediscovery timer pending flag */ |
| 4646 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4647 | /* FCF rediscovery event to worker thread */ |
| 4648 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4649 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4650 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4651 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4652 | /* wake up worker thread */ |
| 4653 | lpfc_worker_wake_up(phba); |
| 4654 | } |
| 4655 | |
| 4656 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4657 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4658 | * @phba: pointer to lpfc hba data structure. |
| 4659 | * @acqe_link: pointer to the async link completion queue entry. |
| 4660 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4661 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4662 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4663 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4664 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4665 | struct lpfc_acqe_link *acqe_link) |
| 4666 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4667 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4668 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4669 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4670 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4671 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | break; |
| 4673 | default: |
| 4674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4675 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4676 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4677 | break; |
| 4678 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4683 | * @phba: pointer to lpfc hba data structure. |
| 4684 | * @acqe_link: pointer to the async link completion queue entry. |
| 4685 | * |
| 4686 | * This routine is to parse the SLI4 link attention type and translate it |
| 4687 | * into the base driver's link attention type coding. |
| 4688 | * |
| 4689 | * Return: Link attention type in terms of base driver's coding. |
| 4690 | **/ |
| 4691 | static uint8_t |
| 4692 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4693 | struct lpfc_acqe_link *acqe_link) |
| 4694 | { |
| 4695 | uint8_t att_type; |
| 4696 | |
| 4697 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4698 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4699 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4700 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4701 | break; |
| 4702 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4703 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4704 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | break; |
| 4706 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4707 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4708 | break; |
| 4709 | default: |
| 4710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4711 | "0399 Invalid link attention type: x%x\n", |
| 4712 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4713 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4714 | break; |
| 4715 | } |
| 4716 | return att_type; |
| 4717 | } |
| 4718 | |
| 4719 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4720 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4721 | * @phba: pointer to lpfc hba data structure. |
| 4722 | * |
| 4723 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4724 | * |
| 4725 | * Return: link speed in terms of Mbps. |
| 4726 | **/ |
| 4727 | uint32_t |
| 4728 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4729 | { |
| 4730 | uint32_t link_speed; |
| 4731 | |
| 4732 | if (!lpfc_is_link_up(phba)) |
| 4733 | return 0; |
| 4734 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4735 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4736 | switch (phba->fc_linkspeed) { |
| 4737 | case LPFC_LINK_SPEED_1GHZ: |
| 4738 | link_speed = 1000; |
| 4739 | break; |
| 4740 | case LPFC_LINK_SPEED_2GHZ: |
| 4741 | link_speed = 2000; |
| 4742 | break; |
| 4743 | case LPFC_LINK_SPEED_4GHZ: |
| 4744 | link_speed = 4000; |
| 4745 | break; |
| 4746 | case LPFC_LINK_SPEED_8GHZ: |
| 4747 | link_speed = 8000; |
| 4748 | break; |
| 4749 | case LPFC_LINK_SPEED_10GHZ: |
| 4750 | link_speed = 10000; |
| 4751 | break; |
| 4752 | case LPFC_LINK_SPEED_16GHZ: |
| 4753 | link_speed = 16000; |
| 4754 | break; |
| 4755 | default: |
| 4756 | link_speed = 0; |
| 4757 | } |
| 4758 | } else { |
| 4759 | if (phba->sli4_hba.link_state.logical_speed) |
| 4760 | link_speed = |
| 4761 | phba->sli4_hba.link_state.logical_speed; |
| 4762 | else |
| 4763 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4764 | } |
| 4765 | return link_speed; |
| 4766 | } |
| 4767 | |
| 4768 | /** |
| 4769 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4770 | * @phba: pointer to lpfc hba data structure. |
| 4771 | * @evt_code: asynchronous event code. |
| 4772 | * @speed_code: asynchronous event link speed code. |
| 4773 | * |
| 4774 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4775 | * value of Mbps for the link speed. |
| 4776 | * |
| 4777 | * Return: link speed in terms of Mbps. |
| 4778 | **/ |
| 4779 | static uint32_t |
| 4780 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4781 | uint8_t speed_code) |
| 4782 | { |
| 4783 | uint32_t port_speed; |
| 4784 | |
| 4785 | switch (evt_code) { |
| 4786 | case LPFC_TRAILER_CODE_LINK: |
| 4787 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4788 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4789 | port_speed = 0; |
| 4790 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4791 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4792 | port_speed = 10; |
| 4793 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4794 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4795 | port_speed = 100; |
| 4796 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4797 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4798 | port_speed = 1000; |
| 4799 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4800 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4801 | port_speed = 10000; |
| 4802 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4803 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4804 | port_speed = 20000; |
| 4805 | break; |
| 4806 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4807 | port_speed = 25000; |
| 4808 | break; |
| 4809 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4810 | port_speed = 40000; |
| 4811 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4812 | default: |
| 4813 | port_speed = 0; |
| 4814 | } |
| 4815 | break; |
| 4816 | case LPFC_TRAILER_CODE_FC: |
| 4817 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4818 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4819 | port_speed = 0; |
| 4820 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4821 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4822 | port_speed = 1000; |
| 4823 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4824 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4825 | port_speed = 2000; |
| 4826 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4827 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4828 | port_speed = 4000; |
| 4829 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4830 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4831 | port_speed = 8000; |
| 4832 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4833 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4834 | port_speed = 10000; |
| 4835 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4836 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4837 | port_speed = 16000; |
| 4838 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4839 | case LPFC_FC_LA_SPEED_32G: |
| 4840 | port_speed = 32000; |
| 4841 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4842 | case LPFC_FC_LA_SPEED_64G: |
| 4843 | port_speed = 64000; |
| 4844 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4845 | case LPFC_FC_LA_SPEED_128G: |
| 4846 | port_speed = 128000; |
| 4847 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4848 | default: |
| 4849 | port_speed = 0; |
| 4850 | } |
| 4851 | break; |
| 4852 | default: |
| 4853 | port_speed = 0; |
| 4854 | } |
| 4855 | return port_speed; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4859 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4860 | * @phba: pointer to lpfc hba data structure. |
| 4861 | * @acqe_link: pointer to the async link completion queue entry. |
| 4862 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4863 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4864 | **/ |
| 4865 | static void |
| 4866 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4867 | struct lpfc_acqe_link *acqe_link) |
| 4868 | { |
| 4869 | struct lpfc_dmabuf *mp; |
| 4870 | LPFC_MBOXQ_t *pmb; |
| 4871 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4872 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4873 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4874 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4875 | |
| 4876 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4877 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4878 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4879 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4880 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4881 | if (!pmb) { |
| 4882 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4883 | "0395 The mboxq allocation failed\n"); |
| 4884 | return; |
| 4885 | } |
| 4886 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4887 | if (!mp) { |
| 4888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4889 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4890 | goto out_free_pmb; |
| 4891 | } |
| 4892 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4893 | if (!mp->virt) { |
| 4894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4895 | "0397 The mbuf allocation failed\n"); |
| 4896 | goto out_free_dmabuf; |
| 4897 | } |
| 4898 | |
| 4899 | /* Cleanup any outstanding ELS commands */ |
| 4900 | lpfc_els_flush_all_cmd(phba); |
| 4901 | |
| 4902 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4903 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4904 | |
| 4905 | /* Update link event statistics */ |
| 4906 | phba->sli.slistat.link_event++; |
| 4907 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4908 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4909 | lpfc_read_topology(phba, pmb, mp); |
| 4910 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4911 | pmb->vport = phba->pport; |
| 4912 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4914 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4915 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4916 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4917 | phba->sli4_hba.link_state.duplex = |
| 4918 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4919 | phba->sli4_hba.link_state.status = |
| 4920 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4921 | phba->sli4_hba.link_state.type = |
| 4922 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4923 | phba->sli4_hba.link_state.number = |
| 4924 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4925 | phba->sli4_hba.link_state.fault = |
| 4926 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4927 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4928 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4929 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4930 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4931 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4932 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4933 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4934 | phba->sli4_hba.link_state.speed, |
| 4935 | phba->sli4_hba.link_state.topology, |
| 4936 | phba->sli4_hba.link_state.status, |
| 4937 | phba->sli4_hba.link_state.type, |
| 4938 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4939 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4940 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4941 | /* |
| 4942 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4943 | * topology info. Note: Optional for non FC-AL ports. |
| 4944 | */ |
| 4945 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4946 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4947 | if (rc == MBX_NOT_FINISHED) |
| 4948 | goto out_free_dmabuf; |
| 4949 | return; |
| 4950 | } |
| 4951 | /* |
| 4952 | * For FCoE Mode: fill in all the topology information we need and call |
| 4953 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4954 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4955 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4956 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4957 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4958 | mb->mbxStatus = MBX_SUCCESS; |
| 4959 | |
| 4960 | /* Parse port fault information field */ |
| 4961 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4962 | |
| 4963 | /* Parse and translate link attention fields */ |
| 4964 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4965 | la->eventTag = acqe_link->event_tag; |
| 4966 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4967 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4968 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4969 | |
| 4970 | /* Fake the the following irrelvant fields */ |
| 4971 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4972 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4973 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4974 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4975 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4976 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4977 | |
| 4978 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4979 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4980 | |
| 4981 | return; |
| 4982 | |
| 4983 | out_free_dmabuf: |
| 4984 | kfree(mp); |
| 4985 | out_free_pmb: |
| 4986 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4987 | } |
| 4988 | |
| 4989 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4990 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 4991 | * topology. |
| 4992 | * @phba: pointer to lpfc hba data structure. |
| 4993 | * @evt_code: asynchronous event code. |
| 4994 | * @speed_code: asynchronous event link speed code. |
| 4995 | * |
| 4996 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4997 | * value of Read topology link speed. |
| 4998 | * |
| 4999 | * Return: link speed in terms of Read topology. |
| 5000 | **/ |
| 5001 | static uint8_t |
| 5002 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5003 | { |
| 5004 | uint8_t port_speed; |
| 5005 | |
| 5006 | switch (speed_code) { |
| 5007 | case LPFC_FC_LA_SPEED_1G: |
| 5008 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5009 | break; |
| 5010 | case LPFC_FC_LA_SPEED_2G: |
| 5011 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5012 | break; |
| 5013 | case LPFC_FC_LA_SPEED_4G: |
| 5014 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5015 | break; |
| 5016 | case LPFC_FC_LA_SPEED_8G: |
| 5017 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5018 | break; |
| 5019 | case LPFC_FC_LA_SPEED_16G: |
| 5020 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5021 | break; |
| 5022 | case LPFC_FC_LA_SPEED_32G: |
| 5023 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5024 | break; |
| 5025 | case LPFC_FC_LA_SPEED_64G: |
| 5026 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5027 | break; |
| 5028 | case LPFC_FC_LA_SPEED_128G: |
| 5029 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5030 | break; |
| 5031 | case LPFC_FC_LA_SPEED_256G: |
| 5032 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5033 | break; |
| 5034 | default: |
| 5035 | port_speed = 0; |
| 5036 | break; |
| 5037 | } |
| 5038 | |
| 5039 | return port_speed; |
| 5040 | } |
| 5041 | |
| 5042 | #define trunk_link_status(__idx)\ |
| 5043 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5044 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5045 | "Link up" : "Link down") : "NA" |
| 5046 | /* Did port __idx reported an error */ |
| 5047 | #define trunk_port_fault(__idx)\ |
| 5048 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5049 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5050 | |
| 5051 | static void |
| 5052 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5053 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5054 | { |
| 5055 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5056 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5057 | |
| 5058 | phba->sli4_hba.link_state.speed = |
| 5059 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5060 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5061 | |
| 5062 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5063 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5064 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5065 | phba->fc_linkspeed = |
| 5066 | lpfc_async_link_speed_to_read_top( |
| 5067 | phba, |
| 5068 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5069 | |
| 5070 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5071 | phba->trunk_link.link0.state = |
| 5072 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5073 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5074 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5075 | } |
| 5076 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5077 | phba->trunk_link.link1.state = |
| 5078 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5079 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5080 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5081 | } |
| 5082 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5083 | phba->trunk_link.link2.state = |
| 5084 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5085 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5086 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5087 | } |
| 5088 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5089 | phba->trunk_link.link3.state = |
| 5090 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5091 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5092 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5096 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5097 | "\tLogical speed:%d " |
| 5098 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5099 | phba->sli4_hba.link_state.speed, |
| 5100 | phba->sli4_hba.link_state.logical_speed, |
| 5101 | trunk_link_status(0), trunk_link_status(1), |
| 5102 | trunk_link_status(2), trunk_link_status(3)); |
| 5103 | |
| 5104 | if (port_fault) |
| 5105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5106 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5107 | /* |
| 5108 | * SLI-4: We have only 0xA error codes |
| 5109 | * defined as of now. print an appropriate |
| 5110 | * message in case driver needs to be updated. |
| 5111 | */ |
| 5112 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5113 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5114 | trunk_port_fault(0), trunk_port_fault(1), |
| 5115 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5116 | } |
| 5117 | |
| 5118 | |
| 5119 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5120 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5121 | * @phba: pointer to lpfc hba data structure. |
| 5122 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5123 | * |
| 5124 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5125 | * that the event was received and then issue a read_topology mailbox command so |
| 5126 | * that the rest of the driver will treat it the same as SLI3. |
| 5127 | **/ |
| 5128 | static void |
| 5129 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5130 | { |
| 5131 | struct lpfc_dmabuf *mp; |
| 5132 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5133 | MAILBOX_t *mb; |
| 5134 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5135 | int rc; |
| 5136 | |
| 5137 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5138 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 5139 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5140 | "2895 Non FC link Event detected.(%d)\n", |
| 5141 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5142 | return; |
| 5143 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5144 | |
| 5145 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5146 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5147 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5148 | return; |
| 5149 | } |
| 5150 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5151 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5152 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5153 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5154 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5155 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5156 | phba->sli4_hba.link_state.topology = |
| 5157 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5158 | phba->sli4_hba.link_state.status = |
| 5159 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5160 | phba->sli4_hba.link_state.type = |
| 5161 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5162 | phba->sli4_hba.link_state.number = |
| 5163 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5164 | phba->sli4_hba.link_state.fault = |
| 5165 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5166 | |
| 5167 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5168 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5169 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5170 | else if (!phba->sli4_hba.conf_trunk) |
| 5171 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5172 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5173 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5174 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5175 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5176 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5177 | "%dMbps Fault:%d\n", |
| 5178 | phba->sli4_hba.link_state.speed, |
| 5179 | phba->sli4_hba.link_state.topology, |
| 5180 | phba->sli4_hba.link_state.status, |
| 5181 | phba->sli4_hba.link_state.type, |
| 5182 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5183 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5184 | phba->sli4_hba.link_state.fault); |
| 5185 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5186 | if (!pmb) { |
| 5187 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5188 | "2897 The mboxq allocation failed\n"); |
| 5189 | return; |
| 5190 | } |
| 5191 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5192 | if (!mp) { |
| 5193 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5194 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5195 | goto out_free_pmb; |
| 5196 | } |
| 5197 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5198 | if (!mp->virt) { |
| 5199 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5200 | "2899 The mbuf allocation failed\n"); |
| 5201 | goto out_free_dmabuf; |
| 5202 | } |
| 5203 | |
| 5204 | /* Cleanup any outstanding ELS commands */ |
| 5205 | lpfc_els_flush_all_cmd(phba); |
| 5206 | |
| 5207 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5208 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5209 | |
| 5210 | /* Update link event statistics */ |
| 5211 | phba->sli.slistat.link_event++; |
| 5212 | |
| 5213 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5214 | lpfc_read_topology(phba, pmb, mp); |
| 5215 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5216 | pmb->vport = phba->pport; |
| 5217 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5218 | if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) { |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 5219 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5220 | |
| 5221 | switch (phba->sli4_hba.link_state.status) { |
| 5222 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5223 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5224 | break; |
| 5225 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5226 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5227 | break; |
| 5228 | default: |
| 5229 | break; |
| 5230 | } |
| 5231 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5232 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5233 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5234 | mb->mbxStatus = MBX_SUCCESS; |
| 5235 | |
| 5236 | /* Parse port fault information field */ |
| 5237 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5238 | |
| 5239 | /* Parse and translate link attention fields */ |
| 5240 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5241 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5242 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5243 | if (phba->sli4_hba.link_state.status == |
| 5244 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5245 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5246 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5247 | } else { |
| 5248 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5249 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5250 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5251 | /* Invoke the mailbox command callback function */ |
| 5252 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5253 | |
| 5254 | return; |
| 5255 | } |
| 5256 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5257 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5258 | if (rc == MBX_NOT_FINISHED) |
| 5259 | goto out_free_dmabuf; |
| 5260 | return; |
| 5261 | |
| 5262 | out_free_dmabuf: |
| 5263 | kfree(mp); |
| 5264 | out_free_pmb: |
| 5265 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5266 | } |
| 5267 | |
| 5268 | /** |
| 5269 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5270 | * @phba: pointer to lpfc hba data structure. |
| 5271 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 5272 | * |
| 5273 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5274 | **/ |
| 5275 | static void |
| 5276 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5277 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5278 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5279 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5280 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5281 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5282 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5283 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5284 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5285 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5286 | struct lpfc_vport **vports; |
| 5287 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5288 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5289 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5290 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5291 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5292 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5293 | "x%08x SLI Event Type:%d\n", |
| 5294 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5295 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5296 | |
| 5297 | port_name = phba->Port[0]; |
| 5298 | if (port_name == 0x00) |
| 5299 | port_name = '?'; /* get port name is empty */ |
| 5300 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5301 | switch (evt_type) { |
| 5302 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5303 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5304 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5305 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5306 | |
| 5307 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5308 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5309 | acqe_sli->event_data1, port_name); |
| 5310 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5311 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5312 | shost = lpfc_shost_from_vport(phba->pport); |
| 5313 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5314 | sizeof(temp_event_data), |
| 5315 | (char *)&temp_event_data, |
| 5316 | SCSI_NL_VID_TYPE_PCI |
| 5317 | | PCI_VENDOR_ID_EMULEX); |
| 5318 | break; |
| 5319 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5320 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5321 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5322 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5323 | |
| 5324 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5325 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5326 | acqe_sli->event_data1, port_name); |
| 5327 | |
| 5328 | shost = lpfc_shost_from_vport(phba->pport); |
| 5329 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5330 | sizeof(temp_event_data), |
| 5331 | (char *)&temp_event_data, |
| 5332 | SCSI_NL_VID_TYPE_PCI |
| 5333 | | PCI_VENDOR_ID_EMULEX); |
| 5334 | break; |
| 5335 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5336 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5337 | &acqe_sli->event_data1; |
| 5338 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5339 | /* fetch the status for this port */ |
| 5340 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5341 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5342 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5343 | &misconfigured->theEvent); |
| 5344 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5345 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5346 | break; |
| 5347 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5348 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5349 | &misconfigured->theEvent); |
| 5350 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5351 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5352 | break; |
| 5353 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5354 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5355 | &misconfigured->theEvent); |
| 5356 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5357 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5358 | break; |
| 5359 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5360 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5361 | &misconfigured->theEvent); |
| 5362 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5363 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5364 | break; |
| 5365 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5366 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5367 | "3296 " |
| 5368 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5369 | "event: Invalid link %d", |
| 5370 | phba->sli4_hba.lnk_info.lnk_no); |
| 5371 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5372 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5373 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5374 | /* Skip if optic state unchanged */ |
| 5375 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5376 | return; |
| 5377 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5378 | switch (status) { |
| 5379 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5380 | sprintf(message, "Physical Link is functional"); |
| 5381 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5382 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5383 | sprintf(message, "Optics faulted/incorrectly " |
| 5384 | "installed/not installed - Reseat optics, " |
| 5385 | "if issue not resolved, replace."); |
| 5386 | break; |
| 5387 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5388 | sprintf(message, |
| 5389 | "Optics of two types installed - Remove one " |
| 5390 | "optic or install matching pair of optics."); |
| 5391 | break; |
| 5392 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5393 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5394 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5395 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5396 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5397 | sprintf(message, "Unqualified optics - Replace with " |
| 5398 | "Avago optics for Warranty and Technical " |
| 5399 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5400 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5401 | break; |
| 5402 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5403 | sprintf(message, "Uncertified optics - Replace with " |
| 5404 | "Avago-certified optics to enable link " |
| 5405 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5406 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5407 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5408 | default: |
| 5409 | /* firmware is reporting a status we don't know about */ |
| 5410 | sprintf(message, "Unknown event status x%02x", status); |
| 5411 | break; |
| 5412 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5413 | |
| 5414 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5415 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5416 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5417 | phba->lmt = 0; |
| 5418 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5419 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5420 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5421 | } |
| 5422 | vports = lpfc_create_vport_work_array(phba); |
| 5423 | if (vports != NULL) { |
| 5424 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5425 | i++) { |
| 5426 | shost = lpfc_shost_from_vport(vports[i]); |
| 5427 | lpfc_host_supported_speeds_set(shost); |
| 5428 | } |
| 5429 | } |
| 5430 | lpfc_destroy_vport_work_array(phba, vports); |
| 5431 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5432 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5433 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5434 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5435 | break; |
| 5436 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5437 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5438 | "3192 Remote DPort Test Initiated - " |
| 5439 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5440 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5441 | break; |
| 5442 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5443 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5444 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 5445 | "x%08x SLI Event Type:%d\n", |
| 5446 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 5447 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5448 | break; |
| 5449 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5453 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5454 | * @vport: pointer to vport data structure. |
| 5455 | * |
| 5456 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5457 | * response to a CVL event. |
| 5458 | * |
| 5459 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5460 | * return NULL. |
| 5461 | **/ |
| 5462 | static struct lpfc_nodelist * |
| 5463 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5464 | { |
| 5465 | struct lpfc_nodelist *ndlp; |
| 5466 | struct Scsi_Host *shost; |
| 5467 | struct lpfc_hba *phba; |
| 5468 | |
| 5469 | if (!vport) |
| 5470 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5471 | phba = vport->phba; |
| 5472 | if (!phba) |
| 5473 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5474 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5475 | if (!ndlp) { |
| 5476 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5477 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5478 | if (!ndlp) |
| 5479 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5480 | /* Set the node type */ |
| 5481 | ndlp->nlp_type |= NLP_FABRIC; |
| 5482 | /* Put ndlp onto node list */ |
| 5483 | lpfc_enqueue_node(vport, ndlp); |
| 5484 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 5485 | /* re-setup ndlp without removing from node list */ |
| 5486 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 5487 | if (!ndlp) |
| 5488 | return 0; |
| 5489 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5490 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5491 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5492 | return NULL; |
| 5493 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5494 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5495 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5496 | return NULL; |
| 5497 | shost = lpfc_shost_from_vport(vport); |
| 5498 | if (!shost) |
| 5499 | return NULL; |
| 5500 | lpfc_linkdown_port(vport); |
| 5501 | lpfc_cleanup_pending_mbox(vport); |
| 5502 | spin_lock_irq(shost->host_lock); |
| 5503 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5504 | spin_unlock_irq(shost->host_lock); |
| 5505 | |
| 5506 | return ndlp; |
| 5507 | } |
| 5508 | |
| 5509 | /** |
| 5510 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 5511 | * @vport: pointer to lpfc hba data structure. |
| 5512 | * |
| 5513 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5514 | * response to a FCF dead event. |
| 5515 | **/ |
| 5516 | static void |
| 5517 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5518 | { |
| 5519 | struct lpfc_vport **vports; |
| 5520 | int i; |
| 5521 | |
| 5522 | vports = lpfc_create_vport_work_array(phba); |
| 5523 | if (vports) |
| 5524 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5525 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5526 | lpfc_destroy_vport_work_array(phba, vports); |
| 5527 | } |
| 5528 | |
| 5529 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5530 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5531 | * @phba: pointer to lpfc hba data structure. |
| 5532 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 5533 | * |
| 5534 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5535 | **/ |
| 5536 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5537 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5538 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5539 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5540 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5541 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5542 | struct lpfc_vport *vport; |
| 5543 | struct lpfc_nodelist *ndlp; |
| 5544 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5545 | int active_vlink_present; |
| 5546 | struct lpfc_vport **vports; |
| 5547 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5548 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5549 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5550 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5551 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5552 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5553 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5554 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5555 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5556 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5557 | "2546 New FCF event, evt_tag:x%x, " |
| 5558 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5559 | acqe_fip->event_tag, |
| 5560 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5561 | else |
| 5562 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5563 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5564 | "2788 FCF param modified event, " |
| 5565 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5566 | acqe_fip->event_tag, |
| 5567 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5568 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5569 | /* |
| 5570 | * During period of FCF discovery, read the FCF |
| 5571 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5572 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5573 | */ |
| 5574 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5575 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5576 | "2779 Read FCF (x%x) for updating " |
| 5577 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5578 | acqe_fip->index); |
| 5579 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5580 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5581 | |
| 5582 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5583 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5584 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5585 | spin_unlock_irq(&phba->hbalock); |
| 5586 | break; |
| 5587 | } |
| 5588 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5589 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5590 | spin_unlock_irq(&phba->hbalock); |
| 5591 | break; |
| 5592 | } |
| 5593 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5594 | /* If the FCF has been in discovered state, do nothing. */ |
| 5595 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5596 | spin_unlock_irq(&phba->hbalock); |
| 5597 | break; |
| 5598 | } |
| 5599 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5600 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5601 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5602 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5603 | "2770 Start FCF table scan per async FCF " |
| 5604 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5605 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5606 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5607 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5608 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5609 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5610 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5611 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5612 | break; |
| 5613 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5614 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5615 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5616 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5617 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5618 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5619 | break; |
| 5620 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5621 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5622 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5623 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5624 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5625 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5626 | /* |
| 5627 | * If we are in the middle of FCF failover process, clear |
| 5628 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5629 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5630 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5631 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5632 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5633 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5634 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5635 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5636 | break; |
| 5637 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5638 | spin_unlock_irq(&phba->hbalock); |
| 5639 | |
| 5640 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5641 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5642 | break; |
| 5643 | |
| 5644 | /* |
| 5645 | * Otherwise, request the port to rediscover the entire FCF |
| 5646 | * table for a fast recovery from case that the current FCF |
| 5647 | * is no longer valid as we are not in the middle of FCF |
| 5648 | * failover process already. |
| 5649 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5650 | spin_lock_irq(&phba->hbalock); |
| 5651 | /* Mark the fast failover process in progress */ |
| 5652 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5653 | spin_unlock_irq(&phba->hbalock); |
| 5654 | |
| 5655 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5656 | "2771 Start FCF fast failover process due to " |
| 5657 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5658 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5659 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5660 | if (rc) { |
| 5661 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5662 | LOG_DISCOVERY, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5663 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5664 | "command failed, fail through to FCF " |
| 5665 | "dead event\n"); |
| 5666 | spin_lock_irq(&phba->hbalock); |
| 5667 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5668 | spin_unlock_irq(&phba->hbalock); |
| 5669 | /* |
| 5670 | * Last resort will fail over by treating this |
| 5671 | * as a link down to FCF registration. |
| 5672 | */ |
| 5673 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5674 | } else { |
| 5675 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5676 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5677 | /* |
| 5678 | * Handling fast FCF failover to a DEAD FCF event is |
| 5679 | * considered equalivant to receiving CVL to all vports. |
| 5680 | */ |
| 5681 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5682 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5683 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5684 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5685 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5686 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5687 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5688 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5689 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5690 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5691 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5692 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5693 | if (!ndlp) |
| 5694 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5695 | active_vlink_present = 0; |
| 5696 | |
| 5697 | vports = lpfc_create_vport_work_array(phba); |
| 5698 | if (vports) { |
| 5699 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5700 | i++) { |
| 5701 | if ((!(vports[i]->fc_flag & |
| 5702 | FC_VPORT_CVL_RCVD)) && |
| 5703 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5704 | active_vlink_present = 1; |
| 5705 | break; |
| 5706 | } |
| 5707 | } |
| 5708 | lpfc_destroy_vport_work_array(phba, vports); |
| 5709 | } |
| 5710 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5711 | /* |
| 5712 | * Don't re-instantiate if vport is marked for deletion. |
| 5713 | * If we are here first then vport_delete is going to wait |
| 5714 | * for discovery to complete. |
| 5715 | */ |
| 5716 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5717 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5718 | /* |
| 5719 | * If there are other active VLinks present, |
| 5720 | * re-instantiate the Vlink using FDISC. |
| 5721 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5722 | mod_timer(&ndlp->nlp_delayfunc, |
| 5723 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5724 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5725 | spin_lock_irq(shost->host_lock); |
| 5726 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5727 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5728 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5729 | vport->port_state = LPFC_FDISC; |
| 5730 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5731 | /* |
| 5732 | * Otherwise, we request port to rediscover |
| 5733 | * the entire FCF table for a fast recovery |
| 5734 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5735 | * is no longer valid if we are not already |
| 5736 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5737 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5738 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5739 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5740 | spin_unlock_irq(&phba->hbalock); |
| 5741 | break; |
| 5742 | } |
| 5743 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5744 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5745 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5746 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5747 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5748 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5749 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5750 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5751 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5752 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5753 | LOG_DISCOVERY, |
| 5754 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5755 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5756 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5757 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5758 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5759 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5760 | /* |
| 5761 | * Last resort will be re-try on the |
| 5762 | * the current registered FCF entry. |
| 5763 | */ |
| 5764 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5765 | } else |
| 5766 | /* |
| 5767 | * Reset FCF roundrobin bmask for new |
| 5768 | * discovery. |
| 5769 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5770 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5771 | } |
| 5772 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5773 | default: |
| 5774 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5775 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5776 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5777 | break; |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | /** |
| 5782 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5783 | * @phba: pointer to lpfc hba data structure. |
| 5784 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5785 | * |
| 5786 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5787 | **/ |
| 5788 | static void |
| 5789 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5790 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5791 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5792 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5794 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5795 | "handled yet\n"); |
| 5796 | } |
| 5797 | |
| 5798 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5799 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5800 | * @phba: pointer to lpfc hba data structure. |
| 5801 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5802 | * |
| 5803 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5804 | * is an asynchronous notified of a logical link speed change. The Port |
| 5805 | * reports the logical link speed in units of 10Mbps. |
| 5806 | **/ |
| 5807 | static void |
| 5808 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5809 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5810 | { |
| 5811 | uint16_t prev_ll_spd; |
| 5812 | |
| 5813 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5814 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5815 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5816 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5817 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5818 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5819 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5820 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5821 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5825 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5826 | * @phba: pointer to lpfc hba data structure. |
| 5827 | * |
| 5828 | * This routine is invoked by the worker thread to process all the pending |
| 5829 | * SLI4 asynchronous events. |
| 5830 | **/ |
| 5831 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5832 | { |
| 5833 | struct lpfc_cq_event *cq_event; |
| 5834 | |
| 5835 | /* First, declare the async event has been handled */ |
| 5836 | spin_lock_irq(&phba->hbalock); |
| 5837 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5838 | spin_unlock_irq(&phba->hbalock); |
| 5839 | /* Now, handle all the async events */ |
| 5840 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5841 | /* Get the first event from the head of the event queue */ |
| 5842 | spin_lock_irq(&phba->hbalock); |
| 5843 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5844 | cq_event, struct lpfc_cq_event, list); |
| 5845 | spin_unlock_irq(&phba->hbalock); |
| 5846 | /* Process the asynchronous event */ |
| 5847 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5848 | case LPFC_TRAILER_CODE_LINK: |
| 5849 | lpfc_sli4_async_link_evt(phba, |
| 5850 | &cq_event->cqe.acqe_link); |
| 5851 | break; |
| 5852 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5853 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5854 | break; |
| 5855 | case LPFC_TRAILER_CODE_DCBX: |
| 5856 | lpfc_sli4_async_dcbx_evt(phba, |
| 5857 | &cq_event->cqe.acqe_dcbx); |
| 5858 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5859 | case LPFC_TRAILER_CODE_GRP5: |
| 5860 | lpfc_sli4_async_grp5_evt(phba, |
| 5861 | &cq_event->cqe.acqe_grp5); |
| 5862 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5863 | case LPFC_TRAILER_CODE_FC: |
| 5864 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5865 | break; |
| 5866 | case LPFC_TRAILER_CODE_SLI: |
| 5867 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5868 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5869 | default: |
| 5870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5871 | "1804 Invalid asynchrous event code: " |
| 5872 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5873 | &cq_event->cqe.mcqe_cmpl)); |
| 5874 | break; |
| 5875 | } |
| 5876 | /* Free the completion event processed to the free pool */ |
| 5877 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5882 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5883 | * @phba: pointer to lpfc hba data structure. |
| 5884 | * |
| 5885 | * This routine is invoked by the worker thread to process FCF table |
| 5886 | * rediscovery pending completion event. |
| 5887 | **/ |
| 5888 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5889 | { |
| 5890 | int rc; |
| 5891 | |
| 5892 | spin_lock_irq(&phba->hbalock); |
| 5893 | /* Clear FCF rediscovery timeout event */ |
| 5894 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5895 | /* Clear driver fast failover FCF record flag */ |
| 5896 | phba->fcf.failover_rec.flag = 0; |
| 5897 | /* Set state for FCF fast failover */ |
| 5898 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5899 | spin_unlock_irq(&phba->hbalock); |
| 5900 | |
| 5901 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5902 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5903 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5904 | 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] | 5905 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5906 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5907 | "2747 Issue FCF scan read FCF mailbox " |
| 5908 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5912 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5913 | * @phba: pointer to lpfc hba data structure. |
| 5914 | * @dev_grp: The HBA PCI-Device group number. |
| 5915 | * |
| 5916 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5917 | * API jump table entries. |
| 5918 | * |
| 5919 | * Return: 0 if success, otherwise -ENODEV |
| 5920 | **/ |
| 5921 | int |
| 5922 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5923 | { |
| 5924 | int rc; |
| 5925 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5926 | /* Set up lpfc PCI-device group */ |
| 5927 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5928 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5929 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5930 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5931 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5932 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5933 | /* Set up device INIT API function jump table */ |
| 5934 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5935 | if (rc) |
| 5936 | return -ENODEV; |
| 5937 | /* Set up SCSI API function jump table */ |
| 5938 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5939 | if (rc) |
| 5940 | return -ENODEV; |
| 5941 | /* Set up SLI API function jump table */ |
| 5942 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5943 | if (rc) |
| 5944 | return -ENODEV; |
| 5945 | /* Set up MBOX API function jump table */ |
| 5946 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5947 | if (rc) |
| 5948 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5949 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5950 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5954 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5955 | * @phba: pointer to lpfc hba data structure. |
| 5956 | * @intr_mode: active interrupt mode adopted. |
| 5957 | * |
| 5958 | * This routine it invoked to log the currently used active interrupt mode |
| 5959 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5960 | **/ |
| 5961 | 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] | 5962 | { |
| 5963 | switch (intr_mode) { |
| 5964 | case 0: |
| 5965 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5966 | "0470 Enable INTx interrupt mode.\n"); |
| 5967 | break; |
| 5968 | case 1: |
| 5969 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5970 | "0481 Enabled MSI interrupt mode.\n"); |
| 5971 | break; |
| 5972 | case 2: |
| 5973 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5974 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5975 | break; |
| 5976 | default: |
| 5977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5978 | "0482 Illegal interrupt mode.\n"); |
| 5979 | break; |
| 5980 | } |
| 5981 | return; |
| 5982 | } |
| 5983 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5984 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5985 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5986 | * @phba: pointer to lpfc hba data structure. |
| 5987 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5988 | * This routine is invoked to enable the PCI device that is common to all |
| 5989 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5990 | * |
| 5991 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5992 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5993 | * other values - error |
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 | static int |
| 5996 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5997 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5998 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5999 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6000 | /* Obtain PCI device reference */ |
| 6001 | if (!phba->pcidev) |
| 6002 | goto out_error; |
| 6003 | else |
| 6004 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6005 | /* Enable PCI device */ |
| 6006 | if (pci_enable_device_mem(pdev)) |
| 6007 | goto out_error; |
| 6008 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6009 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6010 | goto out_disable_device; |
| 6011 | /* Set up device as PCI master and save state for EEH */ |
| 6012 | pci_set_master(pdev); |
| 6013 | pci_try_set_mwi(pdev); |
| 6014 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6015 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6016 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6017 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6018 | pdev->needs_freset = 1; |
| 6019 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6020 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6021 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6022 | out_disable_device: |
| 6023 | pci_disable_device(pdev); |
| 6024 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 6025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6026 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6027 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6031 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6032 | * @phba: pointer to lpfc hba data structure. |
| 6033 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6034 | * This routine is invoked to disable the PCI device that is common to all |
| 6035 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6036 | **/ |
| 6037 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6038 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6039 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6040 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6041 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6042 | /* Obtain PCI device reference */ |
| 6043 | if (!phba->pcidev) |
| 6044 | return; |
| 6045 | else |
| 6046 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6047 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6048 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6049 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6050 | |
| 6051 | return; |
| 6052 | } |
| 6053 | |
| 6054 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6055 | * lpfc_reset_hba - Reset a hba |
| 6056 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6057 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6058 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6059 | * offline, performs a board restart, and then brings the board back |
| 6060 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6061 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6062 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6063 | void |
| 6064 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6065 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6066 | /* If resets are disabled then set error state and return. */ |
| 6067 | if (!phba->cfg_enable_hba_reset) { |
| 6068 | phba->link_state = LPFC_HBA_ERROR; |
| 6069 | return; |
| 6070 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6071 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 6072 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 6073 | else |
| 6074 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6075 | lpfc_offline(phba); |
| 6076 | lpfc_sli_brdrestart(phba); |
| 6077 | lpfc_online(phba); |
| 6078 | lpfc_unblock_mgmt_io(phba); |
| 6079 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6080 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6081 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6082 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6083 | * @phba: pointer to lpfc hba data structure. |
| 6084 | * |
| 6085 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6086 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6087 | * enable the number of virtual functions to the physical function. As |
| 6088 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6089 | * API call does not considered as an error condition for most of the device. |
| 6090 | **/ |
| 6091 | uint16_t |
| 6092 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6093 | { |
| 6094 | struct pci_dev *pdev = phba->pcidev; |
| 6095 | uint16_t nr_virtfn; |
| 6096 | int pos; |
| 6097 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6098 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6099 | if (pos == 0) |
| 6100 | return 0; |
| 6101 | |
| 6102 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6103 | return nr_virtfn; |
| 6104 | } |
| 6105 | |
| 6106 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6107 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6108 | * @phba: pointer to lpfc hba data structure. |
| 6109 | * @nr_vfn: number of virtual functions to be enabled. |
| 6110 | * |
| 6111 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6112 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6113 | * enable the number of virtual functions to the physical function. As |
| 6114 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6115 | * API call does not considered as an error condition for most of the device. |
| 6116 | **/ |
| 6117 | int |
| 6118 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6119 | { |
| 6120 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6121 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6122 | int rc; |
| 6123 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6124 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6125 | if (nr_vfn > max_nr_vfn) { |
| 6126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6127 | "3057 Requested vfs (%d) greater than " |
| 6128 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6129 | return -EINVAL; |
| 6130 | } |
| 6131 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6132 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6133 | if (rc) { |
| 6134 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6135 | "2806 Failed to enable sriov on this device " |
| 6136 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6137 | nr_vfn, rc); |
| 6138 | } else |
| 6139 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6140 | "2807 Successful enable sriov on this device " |
| 6141 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6142 | return rc; |
| 6143 | } |
| 6144 | |
| 6145 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6146 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6147 | * @phba: pointer to lpfc hba data structure. |
| 6148 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6149 | * This routine is invoked to set up the driver internal resources before the |
| 6150 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6151 | * |
| 6152 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6153 | * 0 - successful |
| 6154 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6155 | **/ |
| 6156 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6157 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6158 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6159 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6160 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6161 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6162 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6163 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6164 | atomic_set(&phba->fast_event_count, 0); |
| 6165 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6166 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6167 | /* Initialize ndlp management spinlock */ |
| 6168 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6169 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6170 | /* Initialize port_list spinlock */ |
| 6171 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6172 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6173 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6174 | INIT_LIST_HEAD(&phba->work_list); |
| 6175 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6176 | |
| 6177 | /* Initialize the wait queue head for the kernel thread */ |
| 6178 | init_waitqueue_head(&phba->work_waitq); |
| 6179 | |
| 6180 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6181 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6182 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6183 | "SCSI" : " "), |
| 6184 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6185 | "NVME" : " "), |
| 6186 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6187 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6188 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6189 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6190 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6191 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6192 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6193 | |
| 6194 | /* Initialize the fabric iocb list */ |
| 6195 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6196 | |
| 6197 | /* Initialize list to save ELS buffers */ |
| 6198 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6199 | |
| 6200 | /* Initialize FCF connection rec list */ |
| 6201 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6202 | |
| 6203 | /* Initialize OAS configuration list */ |
| 6204 | spin_lock_init(&phba->devicelock); |
| 6205 | INIT_LIST_HEAD(&phba->luns); |
| 6206 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6207 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6208 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6209 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6210 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6211 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6212 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6213 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6214 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6215 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6216 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6217 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6218 | return 0; |
| 6219 | } |
| 6220 | |
| 6221 | /** |
| 6222 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6223 | * @phba: pointer to lpfc hba data structure. |
| 6224 | * |
| 6225 | * This routine is invoked to set up the driver internal resources specific to |
| 6226 | * support the SLI-3 HBA device it attached to. |
| 6227 | * |
| 6228 | * Return codes |
| 6229 | * 0 - successful |
| 6230 | * other values - error |
| 6231 | **/ |
| 6232 | static int |
| 6233 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6234 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6235 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6236 | |
| 6237 | /* |
| 6238 | * Initialize timers used by driver |
| 6239 | */ |
| 6240 | |
| 6241 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6242 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6243 | |
| 6244 | /* Host attention work mask setup */ |
| 6245 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6246 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6247 | |
| 6248 | /* Get all the module params for configuring this host */ |
| 6249 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6250 | /* Set up phase-1 common device driver resources */ |
| 6251 | |
| 6252 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6253 | if (rc) |
| 6254 | return -ENODEV; |
| 6255 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6256 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6257 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6258 | /* check for menlo minimum sg count */ |
| 6259 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6260 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6261 | } |
| 6262 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6263 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6264 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6265 | sizeof(struct lpfc_sli_ring), |
| 6266 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6267 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6268 | return -ENOMEM; |
| 6269 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6270 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6271 | * 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] | 6272 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6273 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6274 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6275 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6276 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 6277 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 6278 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6279 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6280 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6281 | entry_sz = sizeof(struct sli4_sge); |
| 6282 | else |
| 6283 | entry_sz = sizeof(struct ulp_bde64); |
| 6284 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6285 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6286 | if (phba->cfg_enable_bg) { |
| 6287 | /* |
| 6288 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6289 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6290 | * over how many protection data segments the SCSI Layer |
| 6291 | * will hand us (ie: there could be one for every block |
| 6292 | * in the IO), we just allocate enough BDEs to accomidate |
| 6293 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6294 | * minimize the risk of running out. |
| 6295 | */ |
| 6296 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6297 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6298 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6299 | |
| 6300 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6301 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6302 | |
| 6303 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6304 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6305 | } else { |
| 6306 | /* |
| 6307 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6308 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6309 | * cfg_sg_seg_cnt data segments. |
| 6310 | */ |
| 6311 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6312 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6313 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6314 | |
| 6315 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6316 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6317 | } |
| 6318 | |
| 6319 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6320 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 6321 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6322 | phba->cfg_total_seg_cnt); |
| 6323 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6324 | phba->max_vpi = LPFC_MAX_VPI; |
| 6325 | /* This will be set to correct value after config_port mbox */ |
| 6326 | phba->max_vports = 0; |
| 6327 | |
| 6328 | /* |
| 6329 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6330 | */ |
| 6331 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6332 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6333 | |
| 6334 | /* Allocate device driver memory */ |
| 6335 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6336 | return -ENOMEM; |
| 6337 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6338 | /* |
| 6339 | * Enable sr-iov virtual functions if supported and configured |
| 6340 | * through the module parameter. |
| 6341 | */ |
| 6342 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6343 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6344 | phba->cfg_sriov_nr_virtfn); |
| 6345 | if (rc) { |
| 6346 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6347 | "2808 Requested number of SR-IOV " |
| 6348 | "virtual functions (%d) is not " |
| 6349 | "supported\n", |
| 6350 | phba->cfg_sriov_nr_virtfn); |
| 6351 | phba->cfg_sriov_nr_virtfn = 0; |
| 6352 | } |
| 6353 | } |
| 6354 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6355 | return 0; |
| 6356 | } |
| 6357 | |
| 6358 | /** |
| 6359 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6360 | * @phba: pointer to lpfc hba data structure. |
| 6361 | * |
| 6362 | * This routine is invoked to unset the driver internal resources set up |
| 6363 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6364 | **/ |
| 6365 | static void |
| 6366 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6367 | { |
| 6368 | /* Free device driver memory allocated */ |
| 6369 | lpfc_mem_free_all(phba); |
| 6370 | |
| 6371 | return; |
| 6372 | } |
| 6373 | |
| 6374 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6375 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6376 | * @phba: pointer to lpfc hba data structure. |
| 6377 | * |
| 6378 | * This routine is invoked to set up the driver internal resources specific to |
| 6379 | * support the SLI-4 HBA device it attached to. |
| 6380 | * |
| 6381 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6382 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6383 | * other values - error |
| 6384 | **/ |
| 6385 | static int |
| 6386 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6387 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6388 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6389 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6390 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6391 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 6392 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6393 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6394 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6395 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6396 | u32 if_type; |
| 6397 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6398 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6399 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6400 | phba->sli4_hba.num_possible_cpu = num_possible_cpus(); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6401 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6402 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6403 | /* Get all the module params for configuring this host */ |
| 6404 | lpfc_get_cfgparam(phba); |
| 6405 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6406 | /* Set up phase-1 common device driver resources */ |
| 6407 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6408 | if (rc) |
| 6409 | return -ENODEV; |
| 6410 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6411 | /* Before proceed, wait for POST done and device ready */ |
| 6412 | rc = lpfc_sli4_post_status_check(phba); |
| 6413 | if (rc) |
| 6414 | return -ENODEV; |
| 6415 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame^] | 6416 | /* Allocate all driver workqueues here */ |
| 6417 | |
| 6418 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6419 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6421 | /* |
| 6422 | * Initialize timers used by driver |
| 6423 | */ |
| 6424 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6425 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6426 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6427 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6428 | 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] | 6429 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6430 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6431 | * Control structure for handling external multi-buffer mailbox |
| 6432 | * command pass-through. |
| 6433 | */ |
| 6434 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6435 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6436 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6437 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6438 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6439 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6440 | /* This will be set to correct value after the read_config mbox */ |
| 6441 | phba->max_vports = 0; |
| 6442 | |
| 6443 | /* Program the default value of vlan_id and fc_map */ |
| 6444 | phba->valid_vlan = 0; |
| 6445 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6446 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6447 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6448 | |
| 6449 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6450 | * 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] | 6451 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6452 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6453 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6454 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6455 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6456 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6457 | * for boundary conditions in its max_sgl_segment template. |
| 6458 | */ |
| 6459 | extra = 2; |
| 6460 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6461 | extra++; |
| 6462 | |
| 6463 | /* |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6464 | * It doesn't matter what family our adapter is in, we are |
| 6465 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6466 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6467 | */ |
| 6468 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6469 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6470 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6471 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6472 | * used to create the sg_dma_buf_pool must be calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6473 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 6474 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6475 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6476 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6477 | * the FCP rsp, and a SGE. Sice we have no control |
| 6478 | * over how many protection segments the SCSI Layer |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6479 | * will hand us (ie: there could be one for every block |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6480 | * in the IO), just allocate enough SGEs to accomidate |
| 6481 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6482 | * to minimize the risk of running out. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6483 | */ |
| 6484 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6485 | sizeof(struct fcp_rsp) + max_buf_size; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6486 | |
| 6487 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6488 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6489 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6490 | /* |
| 6491 | * If supporting DIF, reduce the seg count for scsi to |
| 6492 | * allow room for the DIF sges. |
| 6493 | */ |
| 6494 | if (phba->cfg_enable_bg && |
| 6495 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6496 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6497 | else |
| 6498 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6499 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6500 | } else { |
| 6501 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6502 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6503 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6504 | * cfg_sg_seg_cnt data segments. |
| 6505 | */ |
| 6506 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6507 | sizeof(struct fcp_rsp) + |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6508 | ((phba->cfg_sg_seg_cnt + extra) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6509 | sizeof(struct sli4_sge)); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6510 | |
| 6511 | /* Total SGEs for scsi_sg_list */ |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6512 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6513 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6514 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6515 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6516 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6517 | * need to post 1 page for the SGL. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6518 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6519 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 6520 | |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6521 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6522 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6523 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6524 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6525 | "6300 Reducing NVME sg segment " |
| 6526 | "cnt to %d\n", |
| 6527 | LPFC_MAX_NVME_SEG_CNT); |
| 6528 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6529 | } else |
| 6530 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6531 | } |
| 6532 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6533 | /* Initialize the host templates with the updated values. */ |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6534 | lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6535 | lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 6536 | lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6537 | |
| 6538 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6539 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6540 | else |
| 6541 | phba->cfg_sg_dma_buf_size = |
| 6542 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6543 | |
| 6544 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6545 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6546 | "total:%d scsi:%d nvme:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6547 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
James Smart | 5b9e70b | 2018-09-10 10:30:42 -0700 | [diff] [blame] | 6548 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6549 | phba->cfg_nvme_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6550 | |
| 6551 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6552 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6553 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6554 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6555 | |
| 6556 | /* |
| 6557 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6558 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6559 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 6560 | /* Initialize the Abort scsi buffer list used by driver */ |
| 6561 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 6562 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 6563 | } |
| 6564 | |
| 6565 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6566 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6567 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6568 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6569 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6570 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6571 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6572 | } |
| 6573 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6574 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6575 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6576 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6577 | |
| 6578 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6579 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6580 | */ |
| 6581 | |
| 6582 | /* Driver internel slow-path CQ Event pool */ |
| 6583 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6584 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6585 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6586 | /* Asynchronous event CQ Event work queue list */ |
| 6587 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 6588 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 6589 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 6590 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6591 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6592 | /* Receive queue CQ Event work queue list */ |
| 6593 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6594 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6595 | /* Initialize extent block lists. */ |
| 6596 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6597 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6598 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6599 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6600 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6601 | /* Initialize mboxq lists. If the early init routines fail |
| 6602 | * these lists need to be correctly initialized. |
| 6603 | */ |
| 6604 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6605 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6606 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6607 | /* initialize optic_state to 0xFF */ |
| 6608 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6609 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6610 | /* Allocate device driver memory */ |
| 6611 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6612 | if (rc) |
| 6613 | return -ENOMEM; |
| 6614 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6615 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6616 | 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] | 6617 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6618 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6619 | if (unlikely(rc)) { |
| 6620 | rc = -ENODEV; |
| 6621 | goto out_free_mem; |
| 6622 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6623 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6624 | } |
| 6625 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6626 | /* Create the bootstrap mailbox command */ |
| 6627 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6628 | if (unlikely(rc)) |
| 6629 | goto out_free_mem; |
| 6630 | |
| 6631 | /* Set up the host's endian order with the device. */ |
| 6632 | rc = lpfc_setup_endian_order(phba); |
| 6633 | if (unlikely(rc)) |
| 6634 | goto out_free_bsmbx; |
| 6635 | |
| 6636 | /* Set up the hba's configuration parameters. */ |
| 6637 | rc = lpfc_sli4_read_config(phba); |
| 6638 | if (unlikely(rc)) |
| 6639 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6640 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6641 | if (unlikely(rc)) |
| 6642 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6643 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6644 | /* IF Type 0 ports get initialized now. */ |
| 6645 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6646 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6647 | rc = lpfc_pci_function_reset(phba); |
| 6648 | if (unlikely(rc)) |
| 6649 | goto out_free_bsmbx; |
| 6650 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6651 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6652 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6653 | GFP_KERNEL); |
| 6654 | if (!mboxq) { |
| 6655 | rc = -ENOMEM; |
| 6656 | goto out_free_bsmbx; |
| 6657 | } |
| 6658 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6659 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6660 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6661 | if (lpfc_enable_nvmet_cnt) { |
| 6662 | |
| 6663 | /* First get WWN of HBA instance */ |
| 6664 | lpfc_read_nv(phba, mboxq); |
| 6665 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6666 | if (rc != MBX_SUCCESS) { |
| 6667 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6668 | "6016 Mailbox failed , mbxCmd x%x " |
| 6669 | "READ_NV, mbxStatus x%x\n", |
| 6670 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6671 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6672 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6673 | rc = -EIO; |
| 6674 | goto out_free_bsmbx; |
| 6675 | } |
| 6676 | mb = &mboxq->u.mb; |
| 6677 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6678 | sizeof(uint64_t)); |
| 6679 | wwn = cpu_to_be64(wwn); |
| 6680 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6681 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6682 | sizeof(uint64_t)); |
| 6683 | /* wwn is WWPN of HBA instance */ |
| 6684 | wwn = cpu_to_be64(wwn); |
| 6685 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6686 | |
| 6687 | /* Check to see if it matches any module parameter */ |
| 6688 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6689 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6690 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6691 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6692 | break; |
| 6693 | |
| 6694 | phba->nvmet_support = 1; /* a match */ |
| 6695 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6697 | "6017 NVME Target %016llx\n", |
| 6698 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6699 | #else |
| 6700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6701 | "6021 Can't enable NVME Target." |
| 6702 | " NVME_TARGET_FC infrastructure" |
| 6703 | " is not in kernel\n"); |
| 6704 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6705 | /* Not supported for NVMET */ |
| 6706 | phba->cfg_xri_rebalancing = 0; |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6707 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6708 | } |
| 6709 | } |
| 6710 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6711 | |
| 6712 | lpfc_nvme_mod_param_dep(phba); |
| 6713 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6714 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6715 | lpfc_supported_pages(mboxq); |
| 6716 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6717 | if (!rc) { |
| 6718 | mqe = &mboxq->u.mqe; |
| 6719 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6720 | LPFC_MAX_SUPPORTED_PAGES); |
| 6721 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6722 | switch (pn_page[i]) { |
| 6723 | case LPFC_SLI4_PARAMETERS: |
| 6724 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6725 | break; |
| 6726 | default: |
| 6727 | break; |
| 6728 | } |
| 6729 | } |
| 6730 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6731 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6732 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6733 | if (rc) { |
| 6734 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6735 | rc = -EIO; |
| 6736 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6737 | } |
| 6738 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6739 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6740 | /* |
| 6741 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6742 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6743 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6744 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6745 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6746 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6747 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6748 | &phba->sli4_hba.sli_intf); |
| 6749 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6750 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6751 | if (phba->sli4_hba.extents_in_use && |
| 6752 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6753 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6754 | "2999 Unsupported SLI4 Parameters " |
| 6755 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6756 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6757 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6758 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6759 | rc = -EIO; |
| 6760 | goto out_free_bsmbx; |
| 6761 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6762 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6763 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6764 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6765 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6766 | rc = -EIO; |
| 6767 | goto out_free_bsmbx; |
| 6768 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6769 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6770 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6771 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6772 | |
| 6773 | /* Verify OAS is supported */ |
| 6774 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6775 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6776 | /* Verify RAS support on adapter */ |
| 6777 | lpfc_sli4_ras_init(phba); |
| 6778 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6779 | /* Verify all the SLI4 queues */ |
| 6780 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6781 | if (rc) |
| 6782 | goto out_free_bsmbx; |
| 6783 | |
| 6784 | /* Create driver internal CQE event pool */ |
| 6785 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6786 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6787 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6788 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6789 | /* Initialize sgl lists per host */ |
| 6790 | lpfc_init_sgl_list(phba); |
| 6791 | |
| 6792 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6793 | rc = lpfc_init_active_sgl_array(phba); |
| 6794 | if (rc) { |
| 6795 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6796 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6797 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6798 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6799 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6800 | if (rc) { |
| 6801 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6802 | "1432 Failed to initialize rpi headers.\n"); |
| 6803 | goto out_free_active_sgl; |
| 6804 | } |
| 6805 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6806 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6807 | 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] | 6808 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6809 | GFP_KERNEL); |
| 6810 | if (!phba->fcf.fcf_rr_bmask) { |
| 6811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6812 | "2759 Failed allocate memory for FCF round " |
| 6813 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6814 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6815 | goto out_remove_rpi_hdrs; |
| 6816 | } |
| 6817 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 6818 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6819 | sizeof(struct lpfc_hba_eq_hdl), |
| 6820 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6821 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6822 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6823 | "2572 Failed allocate memory for " |
| 6824 | "fast-path per-EQ handle array\n"); |
| 6825 | rc = -ENOMEM; |
| 6826 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6827 | } |
| 6828 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6829 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6830 | sizeof(struct lpfc_vector_map_info), |
| 6831 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6832 | if (!phba->sli4_hba.cpu_map) { |
| 6833 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6834 | "3327 Failed allocate memory for msi-x " |
| 6835 | "interrupt vector mapping\n"); |
| 6836 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6837 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6838 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6839 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6840 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 6841 | if (!phba->sli4_hba.eq_info) { |
| 6842 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6843 | "3321 Failed allocation for per_cpu stats\n"); |
| 6844 | rc = -ENOMEM; |
| 6845 | goto out_free_hba_cpu_map; |
| 6846 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6847 | /* |
| 6848 | * Enable sr-iov virtual functions if supported and configured |
| 6849 | * through the module parameter. |
| 6850 | */ |
| 6851 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6852 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6853 | phba->cfg_sriov_nr_virtfn); |
| 6854 | if (rc) { |
| 6855 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6856 | "3020 Requested number of SR-IOV " |
| 6857 | "virtual functions (%d) is not " |
| 6858 | "supported\n", |
| 6859 | phba->cfg_sriov_nr_virtfn); |
| 6860 | phba->cfg_sriov_nr_virtfn = 0; |
| 6861 | } |
| 6862 | } |
| 6863 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6864 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6865 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6866 | out_free_hba_cpu_map: |
| 6867 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6868 | out_free_hba_eq_hdl: |
| 6869 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6870 | out_free_fcf_rr_bmask: |
| 6871 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6872 | out_remove_rpi_hdrs: |
| 6873 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6874 | out_free_active_sgl: |
| 6875 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6876 | out_destroy_cq_event_pool: |
| 6877 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6878 | out_free_bsmbx: |
| 6879 | lpfc_destroy_bootstrap_mbox(phba); |
| 6880 | out_free_mem: |
| 6881 | lpfc_mem_free(phba); |
| 6882 | return rc; |
| 6883 | } |
| 6884 | |
| 6885 | /** |
| 6886 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6887 | * @phba: pointer to lpfc hba data structure. |
| 6888 | * |
| 6889 | * This routine is invoked to unset the driver internal resources set up |
| 6890 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6891 | **/ |
| 6892 | static void |
| 6893 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6894 | { |
| 6895 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6896 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6897 | free_percpu(phba->sli4_hba.eq_info); |
| 6898 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6899 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6900 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6901 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6902 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6903 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6904 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6905 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6906 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6907 | |
| 6908 | /* Free the allocated rpi headers. */ |
| 6909 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 6910 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6911 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6912 | /* Free eligible FCF index bmask */ |
| 6913 | kfree(phba->fcf.fcf_rr_bmask); |
| 6914 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6915 | /* Free the ELS sgl list */ |
| 6916 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6917 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6918 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6919 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6920 | /* Free the completion queue EQ event pool */ |
| 6921 | lpfc_sli4_cq_event_release_all(phba); |
| 6922 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 6923 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6924 | /* Release resource identifiers. */ |
| 6925 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6926 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6927 | /* Free the bsmbx region. */ |
| 6928 | lpfc_destroy_bootstrap_mbox(phba); |
| 6929 | |
| 6930 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 6931 | lpfc_mem_free_all(phba); |
| 6932 | |
| 6933 | /* Free the current connect table */ |
| 6934 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6935 | &phba->fcf_conn_rec_list, list) { |
| 6936 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6937 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6938 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6939 | |
| 6940 | return; |
| 6941 | } |
| 6942 | |
| 6943 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6944 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6945 | * @phba: The hba struct for which this call is being executed. |
| 6946 | * @dev_grp: The HBA PCI-Device group number. |
| 6947 | * |
| 6948 | * This routine sets up the device INIT interface API function jump table |
| 6949 | * in @phba struct. |
| 6950 | * |
| 6951 | * Returns: 0 - success, -ENODEV - failure. |
| 6952 | **/ |
| 6953 | int |
| 6954 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 6955 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 6956 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 6957 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 6958 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6959 | switch (dev_grp) { |
| 6960 | case LPFC_PCI_DEV_LP: |
| 6961 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 6962 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 6963 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 6964 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6965 | case LPFC_PCI_DEV_OC: |
| 6966 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 6967 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 6968 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 6969 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6970 | default: |
| 6971 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6972 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 6973 | dev_grp); |
| 6974 | return -ENODEV; |
| 6975 | break; |
| 6976 | } |
| 6977 | return 0; |
| 6978 | } |
| 6979 | |
| 6980 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6981 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 6982 | * @phba: pointer to lpfc hba data structure. |
| 6983 | * |
| 6984 | * This routine is invoked to set up the driver internal resources after the |
| 6985 | * device specific resource setup to support the HBA device it attached to. |
| 6986 | * |
| 6987 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6988 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6989 | * other values - error |
| 6990 | **/ |
| 6991 | static int |
| 6992 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 6993 | { |
| 6994 | int error; |
| 6995 | |
| 6996 | /* Startup the kernel thread for this host adapter. */ |
| 6997 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 6998 | "lpfc_worker_%d", phba->brd_no); |
| 6999 | if (IS_ERR(phba->worker_thread)) { |
| 7000 | error = PTR_ERR(phba->worker_thread); |
| 7001 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7002 | } |
| 7003 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7004 | return 0; |
| 7005 | } |
| 7006 | |
| 7007 | /** |
| 7008 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7009 | * @phba: pointer to lpfc hba data structure. |
| 7010 | * |
| 7011 | * This routine is invoked to unset the driver internal resources set up after |
| 7012 | * the device specific resource setup for supporting the HBA device it |
| 7013 | * attached to. |
| 7014 | **/ |
| 7015 | static void |
| 7016 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7017 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7018 | if (phba->wq) { |
| 7019 | flush_workqueue(phba->wq); |
| 7020 | destroy_workqueue(phba->wq); |
| 7021 | phba->wq = NULL; |
| 7022 | } |
| 7023 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7024 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7025 | if (phba->worker_thread) |
| 7026 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | /** |
| 7030 | * lpfc_free_iocb_list - Free iocb list. |
| 7031 | * @phba: pointer to lpfc hba data structure. |
| 7032 | * |
| 7033 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7034 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7035 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7036 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7037 | { |
| 7038 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7039 | |
| 7040 | spin_lock_irq(&phba->hbalock); |
| 7041 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7042 | &phba->lpfc_iocb_list, list) { |
| 7043 | list_del(&iocbq_entry->list); |
| 7044 | kfree(iocbq_entry); |
| 7045 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7046 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7047 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7048 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7049 | return; |
| 7050 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7051 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7052 | /** |
| 7053 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7054 | * @phba: pointer to lpfc hba data structure. |
| 7055 | * |
| 7056 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7057 | * list and set up the IOCB tag array accordingly. |
| 7058 | * |
| 7059 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7060 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7061 | * other values - error |
| 7062 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7063 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7064 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7065 | { |
| 7066 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7067 | uint16_t iotag; |
| 7068 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7069 | |
| 7070 | /* Initialize and populate the iocb list per host. */ |
| 7071 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7072 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7073 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7074 | if (iocbq_entry == NULL) { |
| 7075 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7076 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 7077 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7078 | goto out_free_iocbq; |
| 7079 | } |
| 7080 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7081 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7082 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7083 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7084 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7085 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7086 | goto out_free_iocbq; |
| 7087 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7088 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7089 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7090 | |
| 7091 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7092 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7093 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7094 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7095 | } |
| 7096 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7097 | return 0; |
| 7098 | |
| 7099 | out_free_iocbq: |
| 7100 | lpfc_free_iocb_list(phba); |
| 7101 | |
| 7102 | return -ENOMEM; |
| 7103 | } |
| 7104 | |
| 7105 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7106 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7107 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7108 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7109 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7110 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7111 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7112 | void |
| 7113 | 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] | 7114 | { |
| 7115 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7116 | |
| 7117 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7118 | list_del(&sglq_entry->list); |
| 7119 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7120 | kfree(sglq_entry); |
| 7121 | } |
| 7122 | } |
| 7123 | |
| 7124 | /** |
| 7125 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7126 | * @phba: pointer to lpfc hba data structure. |
| 7127 | * |
| 7128 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7129 | **/ |
| 7130 | static void |
| 7131 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7132 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7133 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7134 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7135 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7136 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7137 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7138 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 7139 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7140 | spin_unlock_irq(&phba->hbalock); |
| 7141 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7142 | /* Now free the sgl list */ |
| 7143 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7147 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7148 | * @phba: pointer to lpfc hba data structure. |
| 7149 | * |
| 7150 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7151 | **/ |
| 7152 | static void |
| 7153 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7154 | { |
| 7155 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7156 | LIST_HEAD(sglq_list); |
| 7157 | |
| 7158 | /* Retrieve all nvmet sgls from driver list */ |
| 7159 | spin_lock_irq(&phba->hbalock); |
| 7160 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7161 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7162 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7163 | spin_unlock_irq(&phba->hbalock); |
| 7164 | |
| 7165 | /* Now free the sgl list */ |
| 7166 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7167 | list_del(&sglq_entry->list); |
| 7168 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7169 | kfree(sglq_entry); |
| 7170 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7171 | |
| 7172 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7173 | * The next initialization cycle sets the count and allocates |
| 7174 | * the sgls over again. |
| 7175 | */ |
| 7176 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7180 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7181 | * @phba: pointer to lpfc hba data structure. |
| 7182 | * |
| 7183 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7184 | * This array will hold the sglq_entry's for active IOs. |
| 7185 | **/ |
| 7186 | static int |
| 7187 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7188 | { |
| 7189 | int size; |
| 7190 | size = sizeof(struct lpfc_sglq *); |
| 7191 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7192 | |
| 7193 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7194 | kzalloc(size, GFP_KERNEL); |
| 7195 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7196 | return -ENOMEM; |
| 7197 | return 0; |
| 7198 | } |
| 7199 | |
| 7200 | /** |
| 7201 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7202 | * @phba: pointer to lpfc hba data structure. |
| 7203 | * |
| 7204 | * This routine is invoked to walk through the array of active sglq entries |
| 7205 | * and free all of the resources. |
| 7206 | * This is just a place holder for now. |
| 7207 | **/ |
| 7208 | static void |
| 7209 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7210 | { |
| 7211 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7212 | } |
| 7213 | |
| 7214 | /** |
| 7215 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7216 | * @phba: pointer to lpfc hba data structure. |
| 7217 | * |
| 7218 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7219 | * list and set up the sgl xritag tag array accordingly. |
| 7220 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7221 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7222 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7223 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7224 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7225 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7226 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7227 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7228 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7229 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7230 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7231 | /* els xri-sgl book keeping */ |
| 7232 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7233 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7234 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7235 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | /** |
| 7239 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7240 | * @phba: pointer to lpfc hba data structure. |
| 7241 | * |
| 7242 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7243 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7244 | * 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] | 7245 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7246 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7247 | * |
| 7248 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7249 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7250 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7251 | **/ |
| 7252 | int |
| 7253 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7254 | { |
| 7255 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7256 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7257 | |
| 7258 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7259 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7260 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7261 | if (phba->sli4_hba.extents_in_use) |
| 7262 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7263 | |
| 7264 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7265 | if (!rpi_hdr) { |
| 7266 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7267 | "0391 Error during rpi post operation\n"); |
| 7268 | lpfc_sli4_remove_rpis(phba); |
| 7269 | rc = -ENODEV; |
| 7270 | } |
| 7271 | |
| 7272 | return rc; |
| 7273 | } |
| 7274 | |
| 7275 | /** |
| 7276 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7277 | * @phba: pointer to lpfc hba data structure. |
| 7278 | * |
| 7279 | * This routine is invoked to allocate a single 4KB memory region to |
| 7280 | * support rpis and stores them in the phba. This single region |
| 7281 | * provides support for up to 64 rpis. The region is used globally |
| 7282 | * by the device. |
| 7283 | * |
| 7284 | * Returns: |
| 7285 | * A valid rpi hdr on success. |
| 7286 | * A NULL pointer on any failure. |
| 7287 | **/ |
| 7288 | struct lpfc_rpi_hdr * |
| 7289 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7290 | { |
| 7291 | uint16_t rpi_limit, curr_rpi_range; |
| 7292 | struct lpfc_dmabuf *dmabuf; |
| 7293 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7294 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7295 | /* |
| 7296 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7297 | * required. Set the expected maximum count and let the actual value |
| 7298 | * get set when extents are fully allocated. |
| 7299 | */ |
| 7300 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7301 | return NULL; |
| 7302 | if (phba->sli4_hba.extents_in_use) |
| 7303 | return NULL; |
| 7304 | |
| 7305 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7306 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7307 | |
| 7308 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7309 | /* |
| 7310 | * Establish the starting RPI in this header block. The starting |
| 7311 | * rpi is normalized to a zero base because the physical rpi is |
| 7312 | * port based. |
| 7313 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7314 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7315 | spin_unlock_irq(&phba->hbalock); |
| 7316 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7317 | /* Reached full RPI range */ |
| 7318 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7319 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7320 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7321 | /* |
| 7322 | * First allocate the protocol header region for the port. The |
| 7323 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7324 | */ |
| 7325 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7326 | if (!dmabuf) |
| 7327 | return NULL; |
| 7328 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7329 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7330 | LPFC_HDR_TEMPLATE_SIZE, |
| 7331 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7332 | if (!dmabuf->virt) { |
| 7333 | rpi_hdr = NULL; |
| 7334 | goto err_free_dmabuf; |
| 7335 | } |
| 7336 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7337 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7338 | rpi_hdr = NULL; |
| 7339 | goto err_free_coherent; |
| 7340 | } |
| 7341 | |
| 7342 | /* Save the rpi header data for cleanup later. */ |
| 7343 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7344 | if (!rpi_hdr) |
| 7345 | goto err_free_coherent; |
| 7346 | |
| 7347 | rpi_hdr->dmabuf = dmabuf; |
| 7348 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7349 | rpi_hdr->page_count = 1; |
| 7350 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7351 | |
| 7352 | /* The rpi_hdr stores the logical index only. */ |
| 7353 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7354 | 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] | 7355 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7356 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7357 | spin_unlock_irq(&phba->hbalock); |
| 7358 | return rpi_hdr; |
| 7359 | |
| 7360 | err_free_coherent: |
| 7361 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7362 | dmabuf->virt, dmabuf->phys); |
| 7363 | err_free_dmabuf: |
| 7364 | kfree(dmabuf); |
| 7365 | return NULL; |
| 7366 | } |
| 7367 | |
| 7368 | /** |
| 7369 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7370 | * @phba: pointer to lpfc hba data structure. |
| 7371 | * |
| 7372 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7373 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7374 | * presumes the caller has released all rpis consumed by fabric or port |
| 7375 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7376 | **/ |
| 7377 | void |
| 7378 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7379 | { |
| 7380 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7381 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7382 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7383 | goto exit; |
| 7384 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7385 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7386 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7387 | list_del(&rpi_hdr->list); |
| 7388 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7389 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7390 | kfree(rpi_hdr->dmabuf); |
| 7391 | kfree(rpi_hdr); |
| 7392 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7393 | exit: |
| 7394 | /* There are no rpis available to the port now. */ |
| 7395 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7396 | } |
| 7397 | |
| 7398 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7399 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7400 | * @pdev: pointer to pci device data structure. |
| 7401 | * |
| 7402 | * This routine is invoked to allocate the driver hba data structure for an |
| 7403 | * HBA device. If the allocation is successful, the phba reference to the |
| 7404 | * PCI device data structure is set. |
| 7405 | * |
| 7406 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7407 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7408 | * NULL - error |
| 7409 | **/ |
| 7410 | static struct lpfc_hba * |
| 7411 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7412 | { |
| 7413 | struct lpfc_hba *phba; |
| 7414 | |
| 7415 | /* Allocate memory for HBA structure */ |
| 7416 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7417 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7418 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7419 | return NULL; |
| 7420 | } |
| 7421 | |
| 7422 | /* Set reference to PCI device in HBA structure */ |
| 7423 | phba->pcidev = pdev; |
| 7424 | |
| 7425 | /* Assign an unused board number */ |
| 7426 | phba->brd_no = lpfc_get_instance(); |
| 7427 | if (phba->brd_no < 0) { |
| 7428 | kfree(phba); |
| 7429 | return NULL; |
| 7430 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7431 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7432 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7433 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7434 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7435 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7436 | return phba; |
| 7437 | } |
| 7438 | |
| 7439 | /** |
| 7440 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7441 | * @phba: pointer to lpfc hba data structure. |
| 7442 | * |
| 7443 | * This routine is invoked to free the driver hba data structure with an |
| 7444 | * HBA device. |
| 7445 | **/ |
| 7446 | static void |
| 7447 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7448 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7449 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7450 | kfree(phba->sli4_hba.hdwq); |
| 7451 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7452 | /* Release the driver assigned board number */ |
| 7453 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7454 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7455 | /* Free memory allocated with sli3 rings */ |
| 7456 | kfree(phba->sli.sli3_ring); |
| 7457 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7458 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7459 | kfree(phba); |
| 7460 | return; |
| 7461 | } |
| 7462 | |
| 7463 | /** |
| 7464 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7465 | * @phba: pointer to lpfc hba data structure. |
| 7466 | * |
| 7467 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7468 | * host with it. |
| 7469 | * |
| 7470 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7471 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7472 | * other values - error |
| 7473 | **/ |
| 7474 | static int |
| 7475 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7476 | { |
| 7477 | struct lpfc_vport *vport; |
| 7478 | struct Scsi_Host *shost; |
| 7479 | |
| 7480 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7481 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7482 | phba->fc_ratov = FF_DEF_RATOV; |
| 7483 | phba->fc_altov = FF_DEF_ALTOV; |
| 7484 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7485 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7486 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7487 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7488 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7489 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7490 | |
| 7491 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7492 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7493 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7494 | if (phba->nvmet_support) { |
| 7495 | /* Only 1 vport (pport) will support NVME target */ |
| 7496 | if (phba->txrdy_payload_pool == NULL) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 7497 | phba->txrdy_payload_pool = dma_pool_create( |
| 7498 | "txrdy_pool", &phba->pcidev->dev, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7499 | TXRDY_PAYLOAD_LEN, 16, 0); |
| 7500 | if (phba->txrdy_payload_pool) { |
| 7501 | phba->targetport = NULL; |
| 7502 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7503 | lpfc_printf_log(phba, KERN_INFO, |
| 7504 | LOG_INIT | LOG_NVME_DISC, |
| 7505 | "6076 NVME Target Found\n"); |
| 7506 | } |
| 7507 | } |
| 7508 | } |
| 7509 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7510 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7511 | /* Put reference to SCSI host to driver's device private data */ |
| 7512 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7513 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7514 | /* |
| 7515 | * At this point we are fully registered with PSA. In addition, |
| 7516 | * any initial discovery should be completed. |
| 7517 | */ |
| 7518 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7519 | if (phba->cfg_enable_SmartSAN || |
| 7520 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7521 | |
| 7522 | /* Setup appropriate attribute masks */ |
| 7523 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7524 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7525 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7526 | else |
| 7527 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7528 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7529 | return 0; |
| 7530 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7531 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7532 | /** |
| 7533 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7534 | * @phba: pointer to lpfc hba data structure. |
| 7535 | * |
| 7536 | * This routine is invoked to destroy HBA physical port and the associated |
| 7537 | * SCSI host. |
| 7538 | **/ |
| 7539 | static void |
| 7540 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7541 | { |
| 7542 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7543 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7544 | /* Destroy physical port that associated with the SCSI host */ |
| 7545 | destroy_port(vport); |
| 7546 | |
| 7547 | return; |
| 7548 | } |
| 7549 | |
| 7550 | /** |
| 7551 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7552 | * @phba: pointer to lpfc hba data structure. |
| 7553 | * @shost: the shost to be used to detect Block guard settings. |
| 7554 | * |
| 7555 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7556 | * This routine also allocates memory for debugging bg buffers. |
| 7557 | **/ |
| 7558 | static void |
| 7559 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7560 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7561 | uint32_t old_mask; |
| 7562 | uint32_t old_guard; |
| 7563 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7564 | int pagecnt = 10; |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7565 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7566 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7567 | "1478 Registering BlockGuard with the " |
| 7568 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7569 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7570 | old_mask = phba->cfg_prot_mask; |
| 7571 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7572 | |
| 7573 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7574 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7575 | SHOST_DIX_TYPE0_PROTECTION | |
| 7576 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7577 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7578 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7579 | |
| 7580 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7581 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7582 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7583 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7584 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7585 | if ((old_mask != phba->cfg_prot_mask) || |
| 7586 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7587 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7588 | "1475 Registering BlockGuard with the " |
| 7589 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7590 | phba->cfg_prot_mask, |
| 7591 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7592 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7593 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7594 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7595 | } else |
| 7596 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7597 | "1479 Not Registering BlockGuard with the SCSI " |
| 7598 | "layer, Bad protection parameters: %d %d\n", |
| 7599 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7600 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7601 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7602 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7603 | while (pagecnt) { |
| 7604 | spin_lock_init(&_dump_buf_lock); |
| 7605 | _dump_buf_data = |
| 7606 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7607 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7608 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7609 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7610 | "_dump_buf_data at 0x%p\n", |
| 7611 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7612 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7613 | memset(_dump_buf_data, 0, |
| 7614 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7615 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7616 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7617 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7618 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7619 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7620 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7621 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7622 | "memory for hexdump\n"); |
| 7623 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7624 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7625 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7626 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7627 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7628 | while (pagecnt) { |
| 7629 | _dump_buf_dif = |
| 7630 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7631 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7632 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7633 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7634 | "_dump_buf_dif at 0x%p\n", |
| 7635 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7636 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7637 | memset(_dump_buf_dif, 0, |
| 7638 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7639 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7640 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7641 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7642 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7643 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7644 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7645 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7646 | "memory for hexdump\n"); |
| 7647 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7648 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7649 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7650 | _dump_buf_dif); |
| 7651 | } |
| 7652 | |
| 7653 | /** |
| 7654 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7655 | * @phba: pointer to lpfc hba data structure. |
| 7656 | * |
| 7657 | * This routine is invoked to perform all the necessary post initialization |
| 7658 | * setup for the device. |
| 7659 | **/ |
| 7660 | static void |
| 7661 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7662 | { |
| 7663 | struct Scsi_Host *shost; |
| 7664 | struct lpfc_adapter_event_header adapter_event; |
| 7665 | |
| 7666 | /* Get the default values for Model Name and Description */ |
| 7667 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7668 | |
| 7669 | /* |
| 7670 | * hba setup may have changed the hba_queue_depth so we need to |
| 7671 | * adjust the value of can_queue. |
| 7672 | */ |
| 7673 | shost = pci_get_drvdata(phba->pcidev); |
| 7674 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7675 | |
| 7676 | lpfc_host_attrib_init(shost); |
| 7677 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7678 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7679 | spin_lock_irq(shost->host_lock); |
| 7680 | lpfc_poll_start_timer(phba); |
| 7681 | spin_unlock_irq(shost->host_lock); |
| 7682 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7683 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7684 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7685 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7686 | /* Send board arrival event to upper layer */ |
| 7687 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7688 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7689 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7690 | sizeof(adapter_event), |
| 7691 | (char *) &adapter_event, |
| 7692 | LPFC_NL_VENDOR_ID); |
| 7693 | return; |
| 7694 | } |
| 7695 | |
| 7696 | /** |
| 7697 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7698 | * @phba: pointer to lpfc hba data structure. |
| 7699 | * |
| 7700 | * This routine is invoked to set up the PCI device memory space for device |
| 7701 | * with SLI-3 interface spec. |
| 7702 | * |
| 7703 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7704 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7705 | * other values - error |
| 7706 | **/ |
| 7707 | static int |
| 7708 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7709 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7710 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7711 | unsigned long bar0map_len, bar2map_len; |
| 7712 | int i, hbq_count; |
| 7713 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7714 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7715 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7716 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7717 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7718 | |
| 7719 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7720 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7721 | if (error) |
| 7722 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7723 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7724 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7725 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7726 | |
| 7727 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7728 | * required by each mapping. |
| 7729 | */ |
| 7730 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7731 | bar0map_len = pci_resource_len(pdev, 0); |
| 7732 | |
| 7733 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7734 | bar2map_len = pci_resource_len(pdev, 2); |
| 7735 | |
| 7736 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7737 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7738 | if (!phba->slim_memmap_p) { |
| 7739 | dev_printk(KERN_ERR, &pdev->dev, |
| 7740 | "ioremap failed for SLIM memory.\n"); |
| 7741 | goto out; |
| 7742 | } |
| 7743 | |
| 7744 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7745 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7746 | if (!phba->ctrl_regs_memmap_p) { |
| 7747 | dev_printk(KERN_ERR, &pdev->dev, |
| 7748 | "ioremap failed for HBA control registers.\n"); |
| 7749 | goto out_iounmap_slim; |
| 7750 | } |
| 7751 | |
| 7752 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7753 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7754 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7755 | if (!phba->slim2p.virt) |
| 7756 | goto out_iounmap; |
| 7757 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7758 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7759 | phba->mbox_ext = (phba->slim2p.virt + |
| 7760 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7761 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7762 | phba->IOCBs = (phba->slim2p.virt + |
| 7763 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7764 | |
| 7765 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7766 | lpfc_sli_hbq_size(), |
| 7767 | &phba->hbqslimp.phys, |
| 7768 | GFP_KERNEL); |
| 7769 | if (!phba->hbqslimp.virt) |
| 7770 | goto out_free_slim; |
| 7771 | |
| 7772 | hbq_count = lpfc_sli_hbq_count(); |
| 7773 | ptr = phba->hbqslimp.virt; |
| 7774 | for (i = 0; i < hbq_count; ++i) { |
| 7775 | phba->hbqs[i].hbq_virt = ptr; |
| 7776 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7777 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7778 | sizeof(struct lpfc_hbq_entry)); |
| 7779 | } |
| 7780 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7781 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7782 | |
| 7783 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7784 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7785 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7786 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7787 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7788 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7789 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7791 | return 0; |
| 7792 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7793 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7794 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7795 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7796 | out_iounmap: |
| 7797 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7798 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7799 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7800 | out: |
| 7801 | return error; |
| 7802 | } |
| 7803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7804 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7805 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7806 | * @phba: pointer to lpfc hba data structure. |
| 7807 | * |
| 7808 | * This routine is invoked to unset the PCI device memory space for device |
| 7809 | * with SLI-3 interface spec. |
| 7810 | **/ |
| 7811 | static void |
| 7812 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7813 | { |
| 7814 | struct pci_dev *pdev; |
| 7815 | |
| 7816 | /* Obtain PCI device reference */ |
| 7817 | if (!phba->pcidev) |
| 7818 | return; |
| 7819 | else |
| 7820 | pdev = phba->pcidev; |
| 7821 | |
| 7822 | /* Free coherent DMA memory allocated */ |
| 7823 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7824 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7825 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7826 | phba->slim2p.virt, phba->slim2p.phys); |
| 7827 | |
| 7828 | /* I/O memory unmap */ |
| 7829 | iounmap(phba->ctrl_regs_memmap_p); |
| 7830 | iounmap(phba->slim_memmap_p); |
| 7831 | |
| 7832 | return; |
| 7833 | } |
| 7834 | |
| 7835 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7836 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7837 | * @phba: pointer to lpfc hba data structure. |
| 7838 | * |
| 7839 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7840 | * done and check status. |
| 7841 | * |
| 7842 | * Return 0 if successful, otherwise -ENODEV. |
| 7843 | **/ |
| 7844 | int |
| 7845 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7846 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7847 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7848 | struct lpfc_register reg_data; |
| 7849 | int i, port_error = 0; |
| 7850 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7851 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7852 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7853 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7854 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7855 | return -ENODEV; |
| 7856 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7857 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7858 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7859 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7860 | &portsmphr_reg.word0) || |
| 7861 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7862 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7863 | port_error = -ENODEV; |
| 7864 | break; |
| 7865 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7866 | if (LPFC_POST_STAGE_PORT_READY == |
| 7867 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7868 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7869 | msleep(10); |
| 7870 | } |
| 7871 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7872 | /* |
| 7873 | * If there was a port error during POST, then don't proceed with |
| 7874 | * other register reads as the data may not be valid. Just exit. |
| 7875 | */ |
| 7876 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7878 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7879 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7880 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7881 | portsmphr_reg.word0, |
| 7882 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7883 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7884 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7885 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7886 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7887 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7888 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7889 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7890 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7891 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7892 | "2534 Device Info: SLIFamily=0x%x, " |
| 7893 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7894 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7895 | bf_get(lpfc_sli_intf_sli_family, |
| 7896 | &phba->sli4_hba.sli_intf), |
| 7897 | bf_get(lpfc_sli_intf_slirev, |
| 7898 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7899 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7900 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7901 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7902 | &phba->sli4_hba.sli_intf), |
| 7903 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7904 | &phba->sli4_hba.sli_intf), |
| 7905 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7906 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7907 | /* |
| 7908 | * Check for other Port errors during the initialization |
| 7909 | * process. Fail the load if the port did not come up |
| 7910 | * correctly. |
| 7911 | */ |
| 7912 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7913 | &phba->sli4_hba.sli_intf); |
| 7914 | switch (if_type) { |
| 7915 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7916 | phba->sli4_hba.ue_mask_lo = |
| 7917 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7918 | phba->sli4_hba.ue_mask_hi = |
| 7919 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7920 | uerrlo_reg.word0 = |
| 7921 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7922 | uerrhi_reg.word0 = |
| 7923 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7924 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7925 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7926 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7927 | "1422 Unrecoverable Error " |
| 7928 | "Detected during POST " |
| 7929 | "uerr_lo_reg=0x%x, " |
| 7930 | "uerr_hi_reg=0x%x, " |
| 7931 | "ue_mask_lo_reg=0x%x, " |
| 7932 | "ue_mask_hi_reg=0x%x\n", |
| 7933 | uerrlo_reg.word0, |
| 7934 | uerrhi_reg.word0, |
| 7935 | phba->sli4_hba.ue_mask_lo, |
| 7936 | phba->sli4_hba.ue_mask_hi); |
| 7937 | port_error = -ENODEV; |
| 7938 | } |
| 7939 | break; |
| 7940 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7941 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7942 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7943 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7944 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7945 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7946 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7947 | phba->work_status[0] = |
| 7948 | readl(phba->sli4_hba.u.if_type2. |
| 7949 | ERR1regaddr); |
| 7950 | phba->work_status[1] = |
| 7951 | readl(phba->sli4_hba.u.if_type2. |
| 7952 | ERR2regaddr); |
| 7953 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7954 | "2888 Unrecoverable port error " |
| 7955 | "following POST: port status reg " |
| 7956 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7957 | "error 1=0x%x, error 2=0x%x\n", |
| 7958 | reg_data.word0, |
| 7959 | portsmphr_reg.word0, |
| 7960 | phba->work_status[0], |
| 7961 | phba->work_status[1]); |
| 7962 | port_error = -ENODEV; |
| 7963 | } |
| 7964 | break; |
| 7965 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7966 | default: |
| 7967 | break; |
| 7968 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7969 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7970 | return port_error; |
| 7971 | } |
| 7972 | |
| 7973 | /** |
| 7974 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 7975 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7976 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7977 | * |
| 7978 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 7979 | * memory map. |
| 7980 | **/ |
| 7981 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7982 | 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] | 7983 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7984 | switch (if_type) { |
| 7985 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7986 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 7987 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 7988 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 7989 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 7990 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 7991 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 7992 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 7993 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 7994 | phba->sli4_hba.SLIINTFregaddr = |
| 7995 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7996 | break; |
| 7997 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 7998 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 7999 | phba->sli4_hba.conf_regs_memmap_p + |
| 8000 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8001 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8002 | phba->sli4_hba.conf_regs_memmap_p + |
| 8003 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8004 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8005 | phba->sli4_hba.conf_regs_memmap_p + |
| 8006 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8007 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8008 | phba->sli4_hba.conf_regs_memmap_p + |
| 8009 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8010 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8011 | phba->sli4_hba.conf_regs_memmap_p + |
| 8012 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8013 | phba->sli4_hba.SLIINTFregaddr = |
| 8014 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8015 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8016 | phba->sli4_hba.conf_regs_memmap_p + |
| 8017 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8018 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8019 | phba->sli4_hba.conf_regs_memmap_p + |
| 8020 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8021 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8022 | phba->sli4_hba.conf_regs_memmap_p + |
| 8023 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8024 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8025 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8026 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8027 | phba->sli4_hba.MQDBregaddr = |
| 8028 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8029 | phba->sli4_hba.BMBXregaddr = |
| 8030 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8031 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8032 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8033 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8034 | phba->sli4_hba.conf_regs_memmap_p + |
| 8035 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8036 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8037 | phba->sli4_hba.conf_regs_memmap_p + |
| 8038 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8039 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8040 | phba->sli4_hba.conf_regs_memmap_p + |
| 8041 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8042 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8043 | phba->sli4_hba.conf_regs_memmap_p + |
| 8044 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8045 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8046 | phba->sli4_hba.conf_regs_memmap_p + |
| 8047 | LPFC_CTL_PORT_STA_OFFSET; |
| 8048 | phba->sli4_hba.PSMPHRregaddr = |
| 8049 | phba->sli4_hba.conf_regs_memmap_p + |
| 8050 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8051 | phba->sli4_hba.BMBXregaddr = |
| 8052 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8053 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8054 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8055 | default: |
| 8056 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8057 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8058 | if_type); |
| 8059 | break; |
| 8060 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8061 | } |
| 8062 | |
| 8063 | /** |
| 8064 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8065 | * @phba: pointer to lpfc hba data structure. |
| 8066 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8067 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8068 | **/ |
| 8069 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8070 | 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] | 8071 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8072 | switch (if_type) { |
| 8073 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8074 | phba->sli4_hba.PSMPHRregaddr = |
| 8075 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8076 | LPFC_SLIPORT_IF0_SMPHR; |
| 8077 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8078 | LPFC_HST_ISR0; |
| 8079 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8080 | LPFC_HST_IMR0; |
| 8081 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8082 | LPFC_HST_ISCR0; |
| 8083 | break; |
| 8084 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8085 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8086 | LPFC_IF6_RQ_DOORBELL; |
| 8087 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8088 | LPFC_IF6_WQ_DOORBELL; |
| 8089 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8090 | LPFC_IF6_CQ_DOORBELL; |
| 8091 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8092 | LPFC_IF6_EQ_DOORBELL; |
| 8093 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8094 | LPFC_IF6_MQ_DOORBELL; |
| 8095 | break; |
| 8096 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8097 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8098 | default: |
| 8099 | dev_err(&phba->pcidev->dev, |
| 8100 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8101 | if_type); |
| 8102 | break; |
| 8103 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8104 | } |
| 8105 | |
| 8106 | /** |
| 8107 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8108 | * @phba: pointer to lpfc hba data structure. |
| 8109 | * @vf: virtual function number |
| 8110 | * |
| 8111 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8112 | * based on the given viftual function number, @vf. |
| 8113 | * |
| 8114 | * Return 0 if successful, otherwise -ENODEV. |
| 8115 | **/ |
| 8116 | static int |
| 8117 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8118 | { |
| 8119 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8120 | return -ENODEV; |
| 8121 | |
| 8122 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8123 | vf * LPFC_VFR_PAGE_SIZE + |
| 8124 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8125 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8126 | vf * LPFC_VFR_PAGE_SIZE + |
| 8127 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8128 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8129 | vf * LPFC_VFR_PAGE_SIZE + |
| 8130 | LPFC_EQCQ_DOORBELL); |
| 8131 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8132 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8133 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8134 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8135 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8136 | return 0; |
| 8137 | } |
| 8138 | |
| 8139 | /** |
| 8140 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8141 | * @phba: pointer to lpfc hba data structure. |
| 8142 | * |
| 8143 | * This routine is invoked to create the bootstrap mailbox |
| 8144 | * region consistent with the SLI-4 interface spec. This |
| 8145 | * routine allocates all memory necessary to communicate |
| 8146 | * mailbox commands to the port and sets up all alignment |
| 8147 | * needs. No locks are expected to be held when calling |
| 8148 | * this routine. |
| 8149 | * |
| 8150 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8151 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8152 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8153 | **/ |
| 8154 | static int |
| 8155 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8156 | { |
| 8157 | uint32_t bmbx_size; |
| 8158 | struct lpfc_dmabuf *dmabuf; |
| 8159 | struct dma_address *dma_address; |
| 8160 | uint32_t pa_addr; |
| 8161 | uint64_t phys_addr; |
| 8162 | |
| 8163 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8164 | if (!dmabuf) |
| 8165 | return -ENOMEM; |
| 8166 | |
| 8167 | /* |
| 8168 | * The bootstrap mailbox region is comprised of 2 parts |
| 8169 | * plus an alignment restriction of 16 bytes. |
| 8170 | */ |
| 8171 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8172 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8173 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8174 | if (!dmabuf->virt) { |
| 8175 | kfree(dmabuf); |
| 8176 | return -ENOMEM; |
| 8177 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8178 | |
| 8179 | /* |
| 8180 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8181 | * operations are simple later. The mailbox dma address is required |
| 8182 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8183 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8184 | * command to the port. |
| 8185 | */ |
| 8186 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8187 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8188 | |
| 8189 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8190 | LPFC_ALIGN_16_BYTE); |
| 8191 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8192 | LPFC_ALIGN_16_BYTE); |
| 8193 | |
| 8194 | /* |
| 8195 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8196 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8197 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8198 | * the 30-bit address is the high or low address. |
| 8199 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8200 | * clean on 32 bit machines. |
| 8201 | */ |
| 8202 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8203 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8204 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8205 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8206 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8207 | |
| 8208 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8209 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8210 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8211 | return 0; |
| 8212 | } |
| 8213 | |
| 8214 | /** |
| 8215 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8216 | * @phba: pointer to lpfc hba data structure. |
| 8217 | * |
| 8218 | * This routine is invoked to teardown the bootstrap mailbox |
| 8219 | * region and release all host resources. This routine requires |
| 8220 | * the caller to ensure all mailbox commands recovered, no |
| 8221 | * additional mailbox comands are sent, and interrupts are disabled |
| 8222 | * before calling this routine. |
| 8223 | * |
| 8224 | **/ |
| 8225 | static void |
| 8226 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8227 | { |
| 8228 | dma_free_coherent(&phba->pcidev->dev, |
| 8229 | phba->sli4_hba.bmbx.bmbx_size, |
| 8230 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8231 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8232 | |
| 8233 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8234 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8235 | } |
| 8236 | |
| 8237 | /** |
| 8238 | * lpfc_sli4_read_config - Get the config parameters. |
| 8239 | * @phba: pointer to lpfc hba data structure. |
| 8240 | * |
| 8241 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8242 | * The configuration parameters are used to set the base and maximum values |
| 8243 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8244 | * allocation for the port. |
| 8245 | * |
| 8246 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8247 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8248 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8249 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8250 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8251 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8252 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8253 | { |
| 8254 | LPFC_MBOXQ_t *pmb; |
| 8255 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8256 | union lpfc_sli4_cfg_shdr *shdr; |
| 8257 | uint32_t shdr_status, shdr_add_status; |
| 8258 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8259 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8260 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8261 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8262 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8263 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8264 | |
| 8265 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8266 | if (!pmb) { |
| 8267 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8268 | "2011 Unable to allocate memory for issuing " |
| 8269 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8270 | return -ENOMEM; |
| 8271 | } |
| 8272 | |
| 8273 | lpfc_read_config(phba, pmb); |
| 8274 | |
| 8275 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8276 | if (rc != MBX_SUCCESS) { |
| 8277 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8278 | "2012 Mailbox failed , mbxCmd x%x " |
| 8279 | "READ_CONFIG, mbxStatus x%x\n", |
| 8280 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8281 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 8282 | rc = -EIO; |
| 8283 | } else { |
| 8284 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8285 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8286 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8287 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8288 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8289 | phba->sli4_hba.lnk_info.lnk_no = |
| 8290 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8291 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8292 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8293 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8294 | phba->sli4_hba.lnk_info.lnk_no); |
| 8295 | } else |
| 8296 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8297 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8298 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8299 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8300 | phba->bbcredit_support = 1; |
| 8301 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8302 | } |
| 8303 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8304 | phba->sli4_hba.conf_trunk = |
| 8305 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8306 | phba->sli4_hba.extents_in_use = |
| 8307 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8308 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8309 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8310 | /* Reduce resource usage in kdump environment */ |
| 8311 | if (is_kdump_kernel() && |
| 8312 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8313 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8314 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8315 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8316 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8317 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8318 | /* Limit the max we support */ |
| 8319 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8320 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8321 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8322 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8323 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8324 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8325 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8326 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8327 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8328 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8329 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8330 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8331 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8332 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8333 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8334 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8335 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8336 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8337 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8338 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8339 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8340 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8341 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8342 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8343 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8344 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8345 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8346 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8347 | phba->max_vports = phba->max_vpi; |
| 8348 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8349 | "2003 cfg params Extents? %d " |
| 8350 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8351 | "VPI(B:%d M:%d) " |
| 8352 | "VFI(B:%d M:%d) " |
| 8353 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8354 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8355 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8356 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8357 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8358 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8359 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8360 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8361 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8362 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8363 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8364 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8365 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8366 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8367 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8368 | phba->sli4_hba.max_cfg_param.max_rq); |
| 8369 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8370 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8371 | * Calculate queue resources based on how |
| 8372 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8373 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8374 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8375 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8376 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8377 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8378 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8379 | /* |
| 8380 | * Whats left after this can go toward NVME / FCP. |
| 8381 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8382 | * plus one extra. When configured for |
| 8383 | * NVMET, FCP io channel WQs are not created. |
| 8384 | */ |
| 8385 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8386 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8387 | /* If NVME is configured, double the number of CQ/WQs needed */ |
| 8388 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 8389 | !phba->nvmet_support) |
| 8390 | qmin /= 2; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8391 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8392 | /* Check to see if there is enough for NVME */ |
| 8393 | if ((phba->cfg_irq_chann > qmin) || |
| 8394 | (phba->cfg_hdw_queue > qmin)) { |
| 8395 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8396 | "2005 Reducing Queues: " |
| 8397 | "WQ %d CQ %d EQ %d: min %d: " |
| 8398 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8399 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8400 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8401 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8402 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8403 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8404 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8405 | if (phba->cfg_irq_chann > qmin) |
| 8406 | phba->cfg_irq_chann = qmin; |
| 8407 | if (phba->cfg_hdw_queue > qmin) |
| 8408 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8409 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8410 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8411 | |
| 8412 | if (rc) |
| 8413 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8414 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8415 | /* Update link speed if forced link speed is supported */ |
| 8416 | 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] | 8417 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8418 | forced_link_speed = |
| 8419 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8420 | if (forced_link_speed) { |
| 8421 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8422 | |
| 8423 | switch (forced_link_speed) { |
| 8424 | case LINK_SPEED_1G: |
| 8425 | phba->cfg_link_speed = |
| 8426 | LPFC_USER_LINK_SPEED_1G; |
| 8427 | break; |
| 8428 | case LINK_SPEED_2G: |
| 8429 | phba->cfg_link_speed = |
| 8430 | LPFC_USER_LINK_SPEED_2G; |
| 8431 | break; |
| 8432 | case LINK_SPEED_4G: |
| 8433 | phba->cfg_link_speed = |
| 8434 | LPFC_USER_LINK_SPEED_4G; |
| 8435 | break; |
| 8436 | case LINK_SPEED_8G: |
| 8437 | phba->cfg_link_speed = |
| 8438 | LPFC_USER_LINK_SPEED_8G; |
| 8439 | break; |
| 8440 | case LINK_SPEED_10G: |
| 8441 | phba->cfg_link_speed = |
| 8442 | LPFC_USER_LINK_SPEED_10G; |
| 8443 | break; |
| 8444 | case LINK_SPEED_16G: |
| 8445 | phba->cfg_link_speed = |
| 8446 | LPFC_USER_LINK_SPEED_16G; |
| 8447 | break; |
| 8448 | case LINK_SPEED_32G: |
| 8449 | phba->cfg_link_speed = |
| 8450 | LPFC_USER_LINK_SPEED_32G; |
| 8451 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8452 | case LINK_SPEED_64G: |
| 8453 | phba->cfg_link_speed = |
| 8454 | LPFC_USER_LINK_SPEED_64G; |
| 8455 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8456 | case 0xffff: |
| 8457 | phba->cfg_link_speed = |
| 8458 | LPFC_USER_LINK_SPEED_AUTO; |
| 8459 | break; |
| 8460 | default: |
| 8461 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8462 | "0047 Unrecognized link " |
| 8463 | "speed : %d\n", |
| 8464 | forced_link_speed); |
| 8465 | phba->cfg_link_speed = |
| 8466 | LPFC_USER_LINK_SPEED_AUTO; |
| 8467 | } |
| 8468 | } |
| 8469 | } |
| 8470 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8471 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8472 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8473 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8474 | if (phba->cfg_hba_queue_depth > length) { |
| 8475 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8476 | "3361 HBA queue depth changed from %d to %d\n", |
| 8477 | phba->cfg_hba_queue_depth, length); |
| 8478 | phba->cfg_hba_queue_depth = length; |
| 8479 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8480 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8481 | 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] | 8482 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8483 | goto read_cfg_out; |
| 8484 | |
| 8485 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8486 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8487 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8488 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8489 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8490 | length, LPFC_SLI4_MBX_EMBED); |
| 8491 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8492 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8493 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8494 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8495 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8496 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8497 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8498 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8499 | "3026 Mailbox failed , mbxCmd x%x " |
| 8500 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8501 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8502 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8503 | goto read_cfg_out; |
| 8504 | } |
| 8505 | |
| 8506 | /* search for fc_fcoe resrouce descriptor */ |
| 8507 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8508 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8509 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8510 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8511 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8512 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8513 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8514 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8515 | goto read_cfg_out; |
| 8516 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8517 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8518 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8519 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8520 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8521 | phba->sli4_hba.iov.pf_number = |
| 8522 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8523 | phba->sli4_hba.iov.vf_number = |
| 8524 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8525 | break; |
| 8526 | } |
| 8527 | } |
| 8528 | |
| 8529 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8530 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8531 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8532 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8533 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8534 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8535 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8536 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8537 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8538 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8539 | |
| 8540 | read_cfg_out: |
| 8541 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8542 | return rc; |
| 8543 | } |
| 8544 | |
| 8545 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8546 | * 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] | 8547 | * @phba: pointer to lpfc hba data structure. |
| 8548 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8549 | * This routine is invoked to setup the port-side endian order when |
| 8550 | * the port if_type is 0. This routine has no function for other |
| 8551 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8552 | * |
| 8553 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8554 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8555 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8556 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8557 | **/ |
| 8558 | static int |
| 8559 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8560 | { |
| 8561 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8562 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8563 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8564 | HOST_ENDIAN_HIGH_WORD1}; |
| 8565 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8566 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8567 | switch (if_type) { |
| 8568 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8569 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8570 | GFP_KERNEL); |
| 8571 | if (!mboxq) { |
| 8572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8573 | "0492 Unable to allocate memory for " |
| 8574 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8575 | "command\n"); |
| 8576 | return -ENOMEM; |
| 8577 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8578 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8579 | /* |
| 8580 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8581 | * two words to contain special data values and no other data. |
| 8582 | */ |
| 8583 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8584 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8585 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8586 | if (rc != MBX_SUCCESS) { |
| 8587 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8588 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8589 | "failed with status x%x\n", |
| 8590 | rc); |
| 8591 | rc = -EIO; |
| 8592 | } |
| 8593 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8594 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8595 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8596 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8597 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8598 | default: |
| 8599 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8600 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | return rc; |
| 8602 | } |
| 8603 | |
| 8604 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8605 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8606 | * @phba: pointer to lpfc hba data structure. |
| 8607 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8608 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8609 | * 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] | 8610 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8611 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8612 | * |
| 8613 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8614 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8615 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8616 | **/ |
| 8617 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8618 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8619 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8620 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8621 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8622 | * device parameters |
| 8623 | */ |
| 8624 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8625 | if (phba->nvmet_support) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8626 | if (phba->cfg_irq_chann < phba->cfg_nvmet_mrq) |
| 8627 | phba->cfg_nvmet_mrq = phba->cfg_irq_chann; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8628 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8629 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8630 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8631 | |
| 8632 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8633 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8634 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8635 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8636 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8637 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8638 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8639 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8640 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8641 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8642 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8643 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8644 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8645 | } |
| 8646 | |
| 8647 | static int |
| 8648 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8649 | { |
| 8650 | struct lpfc_queue *qdesc; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8651 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8652 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8653 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8654 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8655 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8656 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8657 | if (!qdesc) { |
| 8658 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8659 | "0508 Failed allocate fast-path NVME CQ (%d)\n", |
| 8660 | wqidx); |
| 8661 | return 1; |
| 8662 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8663 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8664 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8665 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8666 | phba->sli4_hba.hdwq[wqidx].nvme_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8667 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8668 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8669 | LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT, |
| 8670 | cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8671 | if (!qdesc) { |
| 8672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8673 | "0509 Failed allocate fast-path NVME WQ (%d)\n", |
| 8674 | wqidx); |
| 8675 | return 1; |
| 8676 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8677 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8678 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8679 | phba->sli4_hba.hdwq[wqidx].nvme_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8680 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8681 | return 0; |
| 8682 | } |
| 8683 | |
| 8684 | static int |
| 8685 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8686 | { |
| 8687 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8688 | uint32_t wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8689 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8690 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8691 | cpu = lpfc_find_cpu_handle(phba, wqidx, LPFC_FIND_BY_HDWQ); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8692 | /* Create Fast Path FCP CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8693 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8694 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8695 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8696 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8697 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8698 | |
| 8699 | else |
| 8700 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8701 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8702 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8703 | if (!qdesc) { |
| 8704 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8705 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); |
| 8706 | return 1; |
| 8707 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8708 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8709 | qdesc->hdwq = wqidx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8710 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8711 | phba->sli4_hba.hdwq[wqidx].fcp_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8712 | |
| 8713 | /* Create Fast Path FCP WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8714 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8715 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8716 | wqesize = (phba->fcp_embed_io) ? |
| 8717 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8718 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8719 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8720 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8721 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8722 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8723 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8724 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8725 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8726 | if (!qdesc) { |
| 8727 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8728 | "0503 Failed allocate fast-path FCP WQ (%d)\n", |
| 8729 | wqidx); |
| 8730 | return 1; |
| 8731 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8732 | qdesc->hdwq = wqidx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8733 | qdesc->chann = wqidx; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8734 | phba->sli4_hba.hdwq[wqidx].fcp_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8735 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8736 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8737 | } |
| 8738 | |
| 8739 | /** |
| 8740 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8741 | * @phba: pointer to lpfc hba data structure. |
| 8742 | * |
| 8743 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8744 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8745 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8746 | * we just use some constant number as place holder. |
| 8747 | * |
| 8748 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8749 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8750 | * -ENOMEM - No availble memory |
| 8751 | * -EIO - The mailbox failed to complete successfully. |
| 8752 | **/ |
| 8753 | int |
| 8754 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8755 | { |
| 8756 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8757 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8758 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8759 | struct lpfc_vector_map_info *cpup; |
| 8760 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8761 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8762 | |
| 8763 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8764 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8765 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8766 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8767 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8768 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8769 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8770 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8771 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8772 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8773 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8774 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8775 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8776 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8777 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8778 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8779 | phba->sli4_hba.hdwq = kcalloc( |
| 8780 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8781 | GFP_KERNEL); |
| 8782 | if (!phba->sli4_hba.hdwq) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8784 | "6427 Failed allocate memory for " |
| 8785 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8786 | goto out_error; |
| 8787 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8788 | /* Prepare hardware queues to take IO buffers */ |
| 8789 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8790 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8791 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8792 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8793 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 8794 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 8795 | qp->get_io_bufs = 0; |
| 8796 | qp->put_io_bufs = 0; |
| 8797 | qp->total_io_bufs = 0; |
| 8798 | spin_lock_init(&qp->abts_scsi_buf_list_lock); |
| 8799 | INIT_LIST_HEAD(&qp->lpfc_abts_scsi_buf_list); |
| 8800 | qp->abts_scsi_io_bufs = 0; |
| 8801 | spin_lock_init(&qp->abts_nvme_buf_list_lock); |
| 8802 | INIT_LIST_HEAD(&qp->lpfc_abts_nvme_buf_list); |
| 8803 | qp->abts_nvme_io_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8804 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8805 | } |
| 8806 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8807 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8808 | if (phba->nvmet_support) { |
| 8809 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8810 | phba->cfg_nvmet_mrq, |
| 8811 | sizeof(struct lpfc_queue *), |
| 8812 | GFP_KERNEL); |
| 8813 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8814 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8815 | "3121 Fail allocate memory for " |
| 8816 | "fast-path CQ set array\n"); |
| 8817 | goto out_error; |
| 8818 | } |
| 8819 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8820 | phba->cfg_nvmet_mrq, |
| 8821 | sizeof(struct lpfc_queue *), |
| 8822 | GFP_KERNEL); |
| 8823 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8825 | "3122 Fail allocate memory for " |
| 8826 | "fast-path RQ set hdr array\n"); |
| 8827 | goto out_error; |
| 8828 | } |
| 8829 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8830 | phba->cfg_nvmet_mrq, |
| 8831 | sizeof(struct lpfc_queue *), |
| 8832 | GFP_KERNEL); |
| 8833 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8835 | "3124 Fail allocate memory for " |
| 8836 | "fast-path RQ set data array\n"); |
| 8837 | goto out_error; |
| 8838 | } |
| 8839 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8840 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8841 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8842 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8843 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8844 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8845 | for_each_present_cpu(cpu) { |
| 8846 | /* We only want to create 1 EQ per vector, even though |
| 8847 | * multiple CPUs might be using that vector. so only |
| 8848 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8849 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8850 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8851 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8852 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8853 | |
| 8854 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 8855 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8856 | |
| 8857 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8858 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8859 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8860 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8861 | if (!qdesc) { |
| 8862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8863 | "0497 Failed allocate EQ (%d)\n", |
| 8864 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8865 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8866 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8867 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8868 | qdesc->hdwq = cpup->hdwq; |
| 8869 | qdesc->chann = cpu; /* First CPU this EQ is affinitised to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8870 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8871 | |
| 8872 | /* Save the allocated EQ in the Hardware Queue */ |
| 8873 | qp->hba_eq = qdesc; |
| 8874 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8875 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 8876 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8877 | } |
| 8878 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8879 | /* Now we need to populate the other Hardware Queues, that share |
| 8880 | * an IRQ vector, with the associated EQ ptr. |
| 8881 | */ |
| 8882 | for_each_present_cpu(cpu) { |
| 8883 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 8884 | |
| 8885 | /* Check for EQ already allocated in previous loop */ |
| 8886 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 8887 | continue; |
| 8888 | |
| 8889 | /* Check for multiple CPUs per hdwq */ |
| 8890 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 8891 | if (qp->hba_eq) |
| 8892 | continue; |
| 8893 | |
| 8894 | /* We need to share an EQ for this hdwq */ |
| 8895 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 8896 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 8897 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 8898 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8899 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8900 | /* Allocate SCSI SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8901 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8902 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) |
| 8903 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8904 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8905 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8906 | /* Allocate NVME SLI4 CQ/WQs */ |
| 8907 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8908 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8909 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) |
| 8910 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8911 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8912 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8913 | if (phba->nvmet_support) { |
| 8914 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8915 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 8916 | LPFC_FIND_BY_HDWQ); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8917 | qdesc = lpfc_sli4_queue_alloc( |
| 8918 | phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8919 | LPFC_DEFAULT_PAGE_SIZE, |
| 8920 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8921 | phba->sli4_hba.cq_ecount, |
| 8922 | cpu); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8923 | if (!qdesc) { |
| 8924 | lpfc_printf_log( |
| 8925 | phba, KERN_ERR, LOG_INIT, |
| 8926 | "3142 Failed allocate NVME " |
| 8927 | "CQ Set (%d)\n", idx); |
| 8928 | goto out_error; |
| 8929 | } |
| 8930 | qdesc->qe_valid = 1; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8931 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8932 | qdesc->chann = cpu; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8933 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8934 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8935 | } |
| 8936 | } |
| 8937 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8938 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8939 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8940 | */ |
| 8941 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8942 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8943 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8944 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8945 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8946 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8947 | if (!qdesc) { |
| 8948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8949 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8950 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8951 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8952 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8953 | phba->sli4_hba.mbx_cq = qdesc; |
| 8954 | |
| 8955 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8956 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8957 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8958 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8959 | if (!qdesc) { |
| 8960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8961 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8962 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8964 | qdesc->qe_valid = 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8965 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8966 | phba->sli4_hba.els_cq = qdesc; |
| 8967 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8968 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8969 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8970 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8971 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8972 | |
| 8973 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8974 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8975 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8976 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8977 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8978 | if (!qdesc) { |
| 8979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8980 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8981 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8982 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8983 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8984 | phba->sli4_hba.mbx_wq = qdesc; |
| 8985 | |
| 8986 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8987 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8988 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8989 | |
| 8990 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8991 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8992 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8993 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8994 | if (!qdesc) { |
| 8995 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8996 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8997 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8998 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8999 | qdesc->chann = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9000 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9001 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9002 | |
| 9003 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9004 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9005 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9006 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9007 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9008 | if (!qdesc) { |
| 9009 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9010 | "6079 Failed allocate NVME LS CQ\n"); |
| 9011 | goto out_error; |
| 9012 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9013 | qdesc->chann = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9014 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9015 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9016 | |
| 9017 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9018 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9019 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9020 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9021 | if (!qdesc) { |
| 9022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9023 | "6080 Failed allocate NVME LS WQ\n"); |
| 9024 | goto out_error; |
| 9025 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9026 | qdesc->chann = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9027 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9028 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9029 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9030 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9031 | /* |
| 9032 | * Create Receive Queue (RQ) |
| 9033 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9034 | |
| 9035 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9036 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9037 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9038 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9039 | if (!qdesc) { |
| 9040 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9041 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9042 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9043 | } |
| 9044 | phba->sli4_hba.hdr_rq = qdesc; |
| 9045 | |
| 9046 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9047 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9048 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9049 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9050 | if (!qdesc) { |
| 9051 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9052 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9053 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9054 | } |
| 9055 | phba->sli4_hba.dat_rq = qdesc; |
| 9056 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9057 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9058 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9059 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9060 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9061 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9062 | /* Create NVMET Receive Queue for header */ |
| 9063 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9064 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9065 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9066 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9067 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9068 | if (!qdesc) { |
| 9069 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9070 | "3146 Failed allocate " |
| 9071 | "receive HRQ\n"); |
| 9072 | goto out_error; |
| 9073 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9074 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9075 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9076 | |
| 9077 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9078 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9079 | GFP_KERNEL, |
| 9080 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9081 | if (qdesc->rqbp == NULL) { |
| 9082 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9083 | "6131 Failed allocate " |
| 9084 | "Header RQBP\n"); |
| 9085 | goto out_error; |
| 9086 | } |
| 9087 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9088 | /* Put list in known state in case driver load fails. */ |
| 9089 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9090 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9091 | /* Create NVMET Receive Queue for data */ |
| 9092 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9093 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9094 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9095 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9096 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9097 | if (!qdesc) { |
| 9098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9099 | "3156 Failed allocate " |
| 9100 | "receive DRQ\n"); |
| 9101 | goto out_error; |
| 9102 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9103 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9104 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9105 | } |
| 9106 | } |
| 9107 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9108 | #if defined(BUILD_NVME) |
| 9109 | /* Clear NVME stats */ |
| 9110 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9111 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9112 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9113 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9114 | } |
| 9115 | } |
| 9116 | #endif |
| 9117 | |
| 9118 | /* Clear SCSI stats */ |
| 9119 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9120 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9121 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9122 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9123 | } |
| 9124 | } |
| 9125 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9126 | return 0; |
| 9127 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9128 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9129 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9130 | return -ENOMEM; |
| 9131 | } |
| 9132 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9133 | static inline void |
| 9134 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9135 | { |
| 9136 | if (*qp != NULL) { |
| 9137 | lpfc_sli4_queue_free(*qp); |
| 9138 | *qp = NULL; |
| 9139 | } |
| 9140 | } |
| 9141 | |
| 9142 | static inline void |
| 9143 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9144 | { |
| 9145 | int idx; |
| 9146 | |
| 9147 | if (*qs == NULL) |
| 9148 | return; |
| 9149 | |
| 9150 | for (idx = 0; idx < max; idx++) |
| 9151 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9152 | |
| 9153 | kfree(*qs); |
| 9154 | *qs = NULL; |
| 9155 | } |
| 9156 | |
| 9157 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9158 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9159 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9160 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9161 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9162 | uint32_t idx; |
| 9163 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9164 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9165 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9166 | /* Loop thru all Hardware Queues */ |
| 9167 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9168 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9169 | lpfc_sli4_queue_free(hdwq[idx].fcp_cq); |
| 9170 | lpfc_sli4_queue_free(hdwq[idx].nvme_cq); |
| 9171 | lpfc_sli4_queue_free(hdwq[idx].fcp_wq); |
| 9172 | lpfc_sli4_queue_free(hdwq[idx].nvme_wq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9173 | hdwq[idx].hba_eq = NULL; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9174 | hdwq[idx].fcp_cq = NULL; |
| 9175 | hdwq[idx].nvme_cq = NULL; |
| 9176 | hdwq[idx].fcp_wq = NULL; |
| 9177 | hdwq[idx].nvme_wq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9178 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9179 | /* Loop thru all IRQ vectors */ |
| 9180 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9181 | /* Free the EQ corresponding to the IRQ vector */ |
| 9182 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9183 | lpfc_sli4_queue_free(eq); |
| 9184 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9185 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9186 | } |
| 9187 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9188 | /** |
| 9189 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9190 | * @phba: pointer to lpfc hba data structure. |
| 9191 | * |
| 9192 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9193 | * operation. |
| 9194 | * |
| 9195 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9196 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9197 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9198 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9199 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9200 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9201 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9202 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9203 | /* |
| 9204 | * Set FREE_INIT before beginning to free the queues. |
| 9205 | * Wait until the users of queues to acknowledge to |
| 9206 | * release queues by clearing FREE_WAIT. |
| 9207 | */ |
| 9208 | spin_lock_irq(&phba->hbalock); |
| 9209 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9210 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9211 | spin_unlock_irq(&phba->hbalock); |
| 9212 | msleep(20); |
| 9213 | spin_lock_irq(&phba->hbalock); |
| 9214 | } |
| 9215 | spin_unlock_irq(&phba->hbalock); |
| 9216 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9217 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9218 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9219 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9220 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9221 | if (phba->nvmet_support) { |
| 9222 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9223 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9224 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9225 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9226 | phba->cfg_nvmet_mrq); |
| 9227 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9228 | phba->cfg_nvmet_mrq); |
| 9229 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9230 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9231 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9232 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9233 | |
| 9234 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9235 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9236 | |
| 9237 | /* Release ELS work queue */ |
| 9238 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9239 | |
| 9240 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9241 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9242 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9243 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9244 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9245 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9246 | |
| 9247 | /* Release NVME LS complete queue */ |
| 9248 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9249 | |
| 9250 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9251 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9252 | |
| 9253 | /* Everything on this list has been freed */ |
| 9254 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9255 | |
| 9256 | /* Done with freeing the queues */ |
| 9257 | spin_lock_irq(&phba->hbalock); |
| 9258 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9259 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9260 | } |
| 9261 | |
| 9262 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9263 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9264 | { |
| 9265 | struct lpfc_rqb *rqbp; |
| 9266 | struct lpfc_dmabuf *h_buf; |
| 9267 | struct rqb_dmabuf *rqb_buffer; |
| 9268 | |
| 9269 | rqbp = rq->rqbp; |
| 9270 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9271 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9272 | struct lpfc_dmabuf, list); |
| 9273 | |
| 9274 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9275 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9276 | rqbp->buffer_count--; |
| 9277 | } |
| 9278 | return 1; |
| 9279 | } |
| 9280 | |
| 9281 | static int |
| 9282 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9283 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9284 | int qidx, uint32_t qtype) |
| 9285 | { |
| 9286 | struct lpfc_sli_ring *pring; |
| 9287 | int rc; |
| 9288 | |
| 9289 | if (!eq || !cq || !wq) { |
| 9290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9291 | "6085 Fast-path %s (%d) not allocated\n", |
| 9292 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9293 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9294 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9295 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9296 | /* create the Cq first */ |
| 9297 | rc = lpfc_cq_create(phba, cq, eq, |
| 9298 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9299 | if (rc) { |
| 9300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9301 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9302 | qidx, (uint32_t)rc); |
| 9303 | return rc; |
| 9304 | } |
| 9305 | |
| 9306 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9307 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9308 | if (cq_map) |
| 9309 | *cq_map = cq->queue_id; |
| 9310 | |
| 9311 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9312 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9313 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9314 | |
| 9315 | /* create the wq */ |
| 9316 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9317 | if (rc) { |
| 9318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9319 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9320 | qidx, (uint32_t)rc); |
| 9321 | /* no need to tear down cq - caller will do so */ |
| 9322 | return rc; |
| 9323 | } |
| 9324 | |
| 9325 | /* Bind this CQ/WQ to the NVME ring */ |
| 9326 | pring = wq->pring; |
| 9327 | pring->sli.sli4.wqp = (void *)wq; |
| 9328 | cq->pring = pring; |
| 9329 | |
| 9330 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9331 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9332 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9333 | } else { |
| 9334 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9335 | if (rc) { |
| 9336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9337 | "0539 Failed setup of slow-path MQ: " |
| 9338 | "rc = 0x%x\n", rc); |
| 9339 | /* no need to tear down cq - caller will do so */ |
| 9340 | return rc; |
| 9341 | } |
| 9342 | |
| 9343 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9344 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9345 | phba->sli4_hba.mbx_wq->queue_id, |
| 9346 | phba->sli4_hba.mbx_cq->queue_id); |
| 9347 | } |
| 9348 | |
| 9349 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9350 | } |
| 9351 | |
| 9352 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9353 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9354 | * @phba: pointer to lpfc hba data structure. |
| 9355 | * |
| 9356 | * This routine will populate the cq_lookup table by all |
| 9357 | * available CQ queue_id's. |
| 9358 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9359 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9360 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9361 | { |
| 9362 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9363 | int qidx; |
| 9364 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9365 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9366 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9367 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9368 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9369 | /* Get the EQ corresponding to the IRQ vector */ |
| 9370 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9371 | if (!eq) |
| 9372 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9373 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9374 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9375 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9376 | continue; |
| 9377 | if ((childq->subtype == LPFC_FCP) || |
| 9378 | (childq->subtype == LPFC_NVME)) |
| 9379 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9380 | childq; |
| 9381 | } |
| 9382 | } |
| 9383 | } |
| 9384 | |
| 9385 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9386 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9387 | * @phba: pointer to lpfc hba data structure. |
| 9388 | * |
| 9389 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9390 | * operation. |
| 9391 | * |
| 9392 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9393 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9394 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9395 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9396 | **/ |
| 9397 | int |
| 9398 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9399 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9400 | uint32_t shdr_status, shdr_add_status; |
| 9401 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9402 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9403 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9404 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9405 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9406 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9407 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9408 | |
| 9409 | /* Check for dual-ULP support */ |
| 9410 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9411 | if (!mboxq) { |
| 9412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9413 | "3249 Unable to allocate memory for " |
| 9414 | "QUERY_FW_CFG mailbox command\n"); |
| 9415 | return -ENOMEM; |
| 9416 | } |
| 9417 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9418 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9419 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9420 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9421 | length, LPFC_SLI4_MBX_EMBED); |
| 9422 | |
| 9423 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9424 | |
| 9425 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9426 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9427 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9428 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9429 | if (shdr_status || shdr_add_status || rc) { |
| 9430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9431 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9432 | "x%x add_status x%x, mbx status x%x\n", |
| 9433 | shdr_status, shdr_add_status, rc); |
| 9434 | if (rc != MBX_TIMEOUT) |
| 9435 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9436 | rc = -ENXIO; |
| 9437 | goto out_error; |
| 9438 | } |
| 9439 | |
| 9440 | phba->sli4_hba.fw_func_mode = |
| 9441 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9442 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9443 | 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] | 9444 | phba->sli4_hba.physical_port = |
| 9445 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9446 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9447 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9448 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9449 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9450 | |
| 9451 | if (rc != MBX_TIMEOUT) |
| 9452 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9453 | |
| 9454 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9455 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9456 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9457 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9458 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9459 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9460 | if (!qp) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9462 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9463 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9464 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9465 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9466 | |
| 9467 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9468 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9469 | /* Create HBA Event Queues (EQs) in order */ |
| 9470 | for_each_present_cpu(cpu) { |
| 9471 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9472 | |
| 9473 | /* Look for the CPU thats using that vector with |
| 9474 | * LPFC_CPU_FIRST_IRQ set. |
| 9475 | */ |
| 9476 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9477 | continue; |
| 9478 | if (qidx != cpup->eq) |
| 9479 | continue; |
| 9480 | |
| 9481 | /* Create an EQ for that vector */ |
| 9482 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9483 | phba->cfg_fcp_imax); |
| 9484 | if (rc) { |
| 9485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9486 | "0523 Failed setup of fast-path" |
| 9487 | " EQ (%d), rc = 0x%x\n", |
| 9488 | cpup->eq, (uint32_t)rc); |
| 9489 | goto out_destroy; |
| 9490 | } |
| 9491 | |
| 9492 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9493 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9494 | qp[cpup->hdwq].hba_eq; |
| 9495 | |
| 9496 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9497 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9498 | cpup->eq, |
| 9499 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9500 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9501 | } |
| 9502 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9503 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9504 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9505 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9506 | cpu = lpfc_find_cpu_handle(phba, qidx, |
| 9507 | LPFC_FIND_BY_HDWQ); |
| 9508 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9509 | |
| 9510 | /* Create the CQ/WQ corresponding to the |
| 9511 | * Hardware Queue |
| 9512 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9513 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9514 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9515 | qp[qidx].nvme_cq, |
| 9516 | qp[qidx].nvme_wq, |
| 9517 | &phba->sli4_hba.hdwq[qidx].nvme_cq_map, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9518 | qidx, LPFC_NVME); |
| 9519 | if (rc) { |
| 9520 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9521 | "6123 Failed to setup fastpath " |
| 9522 | "NVME WQ/CQ (%d), rc = 0x%x\n", |
| 9523 | qidx, (uint32_t)rc); |
| 9524 | goto out_destroy; |
| 9525 | } |
| 9526 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9527 | } |
| 9528 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9529 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9530 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9531 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9532 | |
| 9533 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9534 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9535 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9536 | qp[qidx].fcp_cq, |
| 9537 | qp[qidx].fcp_wq, |
| 9538 | &phba->sli4_hba.hdwq[qidx].fcp_cq_map, |
| 9539 | qidx, LPFC_FCP); |
| 9540 | if (rc) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9542 | "0535 Failed to setup fastpath " |
| 9543 | "FCP WQ/CQ (%d), rc = 0x%x\n", |
| 9544 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9545 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9546 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9547 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9548 | |
| 9549 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9550 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9551 | */ |
| 9552 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9553 | /* Set up slow-path MBOX CQ/MQ */ |
| 9554 | |
| 9555 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9557 | "0528 %s not allocated\n", |
| 9558 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9559 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9560 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9561 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9562 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9563 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9564 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9565 | phba->sli4_hba.mbx_cq, |
| 9566 | phba->sli4_hba.mbx_wq, |
| 9567 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9568 | if (rc) { |
| 9569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9570 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9571 | (uint32_t)rc); |
| 9572 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9573 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9574 | if (phba->nvmet_support) { |
| 9575 | if (!phba->sli4_hba.nvmet_cqset) { |
| 9576 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9577 | "3165 Fast-path NVME CQ Set " |
| 9578 | "array not allocated\n"); |
| 9579 | rc = -ENOMEM; |
| 9580 | goto out_destroy; |
| 9581 | } |
| 9582 | if (phba->cfg_nvmet_mrq > 1) { |
| 9583 | rc = lpfc_cq_create_set(phba, |
| 9584 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9585 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9586 | LPFC_WCQ, LPFC_NVMET); |
| 9587 | if (rc) { |
| 9588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9589 | "3164 Failed setup of NVME CQ " |
| 9590 | "Set, rc = 0x%x\n", |
| 9591 | (uint32_t)rc); |
| 9592 | goto out_destroy; |
| 9593 | } |
| 9594 | } else { |
| 9595 | /* Set up NVMET Receive Complete Queue */ |
| 9596 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9597 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9598 | LPFC_WCQ, LPFC_NVMET); |
| 9599 | if (rc) { |
| 9600 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9601 | "6089 Failed setup NVMET CQ: " |
| 9602 | "rc = 0x%x\n", (uint32_t)rc); |
| 9603 | goto out_destroy; |
| 9604 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9605 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9606 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9607 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9608 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9609 | "parent eq-id=%d\n", |
| 9610 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9611 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9612 | } |
| 9613 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9614 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9615 | /* Set up slow-path ELS WQ/CQ */ |
| 9616 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9617 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9618 | "0530 ELS %s not allocated\n", |
| 9619 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9620 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9621 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9622 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9623 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9624 | phba->sli4_hba.els_cq, |
| 9625 | phba->sli4_hba.els_wq, |
| 9626 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9627 | if (rc) { |
| 9628 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9629 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9630 | (uint32_t)rc); |
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 | } |
| 9633 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9634 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9635 | phba->sli4_hba.els_wq->queue_id, |
| 9636 | phba->sli4_hba.els_cq->queue_id); |
| 9637 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9638 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9639 | /* Set up NVME LS Complete Queue */ |
| 9640 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 9641 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9642 | "6091 LS %s not allocated\n", |
| 9643 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9644 | rc = -ENOMEM; |
| 9645 | goto out_destroy; |
| 9646 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9647 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9648 | phba->sli4_hba.nvmels_cq, |
| 9649 | phba->sli4_hba.nvmels_wq, |
| 9650 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9651 | if (rc) { |
| 9652 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9653 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9654 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9655 | goto out_destroy; |
| 9656 | } |
| 9657 | |
| 9658 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9659 | "6096 ELS WQ setup: wq-id=%d, " |
| 9660 | "parent cq-id=%d\n", |
| 9661 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9662 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9663 | } |
| 9664 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9665 | /* |
| 9666 | * Create NVMET Receive Queue (RQ) |
| 9667 | */ |
| 9668 | if (phba->nvmet_support) { |
| 9669 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9670 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9671 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 9672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9673 | "6130 MRQ CQ Queues not " |
| 9674 | "allocated\n"); |
| 9675 | rc = -ENOMEM; |
| 9676 | goto out_destroy; |
| 9677 | } |
| 9678 | if (phba->cfg_nvmet_mrq > 1) { |
| 9679 | rc = lpfc_mrq_create(phba, |
| 9680 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9681 | phba->sli4_hba.nvmet_mrq_data, |
| 9682 | phba->sli4_hba.nvmet_cqset, |
| 9683 | LPFC_NVMET); |
| 9684 | if (rc) { |
| 9685 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9686 | "6098 Failed setup of NVMET " |
| 9687 | "MRQ: rc = 0x%x\n", |
| 9688 | (uint32_t)rc); |
| 9689 | goto out_destroy; |
| 9690 | } |
| 9691 | |
| 9692 | } else { |
| 9693 | rc = lpfc_rq_create(phba, |
| 9694 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9695 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9696 | phba->sli4_hba.nvmet_cqset[0], |
| 9697 | LPFC_NVMET); |
| 9698 | if (rc) { |
| 9699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9700 | "6057 Failed setup of NVMET " |
| 9701 | "Receive Queue: rc = 0x%x\n", |
| 9702 | (uint32_t)rc); |
| 9703 | goto out_destroy; |
| 9704 | } |
| 9705 | |
| 9706 | lpfc_printf_log( |
| 9707 | phba, KERN_INFO, LOG_INIT, |
| 9708 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9709 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9710 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9711 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9712 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9713 | |
| 9714 | } |
| 9715 | } |
| 9716 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9717 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 9718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9719 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9720 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9721 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9722 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9723 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9724 | 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] | 9725 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9726 | if (rc) { |
| 9727 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9728 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9729 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9730 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9731 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9732 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9733 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9734 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9735 | "parent cq-id=%d\n", |
| 9736 | phba->sli4_hba.hdr_rq->queue_id, |
| 9737 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9738 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9739 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9740 | if (phba->cfg_fcp_imax) |
| 9741 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9742 | else |
| 9743 | usdelay = 0; |
| 9744 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9745 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9746 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9747 | 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] | 9748 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9749 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9750 | if (phba->sli4_hba.cq_max) { |
| 9751 | kfree(phba->sli4_hba.cq_lookup); |
| 9752 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9753 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9754 | if (!phba->sli4_hba.cq_lookup) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9755 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9756 | "0549 Failed setup of CQ Lookup table: " |
| 9757 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9758 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9759 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9760 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9761 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9762 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9763 | return 0; |
| 9764 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9765 | out_destroy: |
| 9766 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9767 | out_error: |
| 9768 | return rc; |
| 9769 | } |
| 9770 | |
| 9771 | /** |
| 9772 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9773 | * @phba: pointer to lpfc hba data structure. |
| 9774 | * |
| 9775 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9776 | * operation. |
| 9777 | * |
| 9778 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9779 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9780 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9781 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9782 | **/ |
| 9783 | void |
| 9784 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9785 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9786 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9787 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9788 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9789 | |
| 9790 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9791 | if (phba->sli4_hba.mbx_wq) |
| 9792 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9793 | |
| 9794 | /* Unset NVME LS work queue */ |
| 9795 | if (phba->sli4_hba.nvmels_wq) |
| 9796 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9797 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9798 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9799 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9800 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9801 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9802 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9803 | if (phba->sli4_hba.hdr_rq) |
| 9804 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9805 | phba->sli4_hba.dat_rq); |
| 9806 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9807 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9808 | if (phba->sli4_hba.mbx_cq) |
| 9809 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9810 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9811 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9812 | if (phba->sli4_hba.els_cq) |
| 9813 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9814 | |
| 9815 | /* Unset NVME LS complete queue */ |
| 9816 | if (phba->sli4_hba.nvmels_cq) |
| 9817 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9818 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9819 | if (phba->nvmet_support) { |
| 9820 | /* Unset NVMET MRQ queue */ |
| 9821 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9822 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9823 | lpfc_rq_destroy( |
| 9824 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9825 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9826 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9827 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9828 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9829 | /* Unset NVMET CQ Set complete queue */ |
| 9830 | if (phba->sli4_hba.nvmet_cqset) { |
| 9831 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9832 | lpfc_cq_destroy( |
| 9833 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9834 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9835 | } |
| 9836 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9837 | /* Unset fast-path SLI4 queues */ |
| 9838 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9839 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9840 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9841 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9842 | qp = &phba->sli4_hba.hdwq[qidx]; |
| 9843 | lpfc_wq_destroy(phba, qp->fcp_wq); |
| 9844 | lpfc_wq_destroy(phba, qp->nvme_wq); |
| 9845 | lpfc_cq_destroy(phba, qp->fcp_cq); |
| 9846 | lpfc_cq_destroy(phba, qp->nvme_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9847 | } |
| 9848 | /* Loop thru all IRQ vectors */ |
| 9849 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 9850 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 9851 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 9852 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9853 | } |
| 9854 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9855 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9856 | kfree(phba->sli4_hba.cq_lookup); |
| 9857 | phba->sli4_hba.cq_lookup = NULL; |
| 9858 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9859 | } |
| 9860 | |
| 9861 | /** |
| 9862 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9863 | * @phba: pointer to lpfc hba data structure. |
| 9864 | * |
| 9865 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9866 | * events. The body of the completion queue event is a completion queue entry |
| 9867 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9868 | * the following HBA completion queue events for the worker thread to process: |
| 9869 | * - Mailbox asynchronous events |
| 9870 | * - Receive queue completion unsolicited events |
| 9871 | * Later, this can be used for all the slow-path events. |
| 9872 | * |
| 9873 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9874 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9875 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9876 | **/ |
| 9877 | static int |
| 9878 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9879 | { |
| 9880 | struct lpfc_cq_event *cq_event; |
| 9881 | int i; |
| 9882 | |
| 9883 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9884 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9885 | if (!cq_event) |
| 9886 | goto out_pool_create_fail; |
| 9887 | list_add_tail(&cq_event->list, |
| 9888 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9889 | } |
| 9890 | return 0; |
| 9891 | |
| 9892 | out_pool_create_fail: |
| 9893 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9894 | return -ENOMEM; |
| 9895 | } |
| 9896 | |
| 9897 | /** |
| 9898 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9899 | * @phba: pointer to lpfc hba data structure. |
| 9900 | * |
| 9901 | * This routine is invoked to free the pool of completion queue events at |
| 9902 | * driver unload time. Note that, it is the responsibility of the driver |
| 9903 | * cleanup routine to free all the outstanding completion-queue events |
| 9904 | * allocated from this pool back into the pool before invoking this routine |
| 9905 | * to destroy the pool. |
| 9906 | **/ |
| 9907 | static void |
| 9908 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9909 | { |
| 9910 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9911 | |
| 9912 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9913 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9914 | list_del(&cq_event->list); |
| 9915 | kfree(cq_event); |
| 9916 | } |
| 9917 | } |
| 9918 | |
| 9919 | /** |
| 9920 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9921 | * @phba: pointer to lpfc hba data structure. |
| 9922 | * |
| 9923 | * This routine is the lock free version of the API invoked to allocate a |
| 9924 | * completion-queue event from the free pool. |
| 9925 | * |
| 9926 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9927 | * NULL otherwise. |
| 9928 | **/ |
| 9929 | struct lpfc_cq_event * |
| 9930 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9931 | { |
| 9932 | struct lpfc_cq_event *cq_event = NULL; |
| 9933 | |
| 9934 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9935 | struct lpfc_cq_event, list); |
| 9936 | return cq_event; |
| 9937 | } |
| 9938 | |
| 9939 | /** |
| 9940 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9941 | * @phba: pointer to lpfc hba data structure. |
| 9942 | * |
| 9943 | * This routine is the lock version of the API invoked to allocate a |
| 9944 | * completion-queue event from the free pool. |
| 9945 | * |
| 9946 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9947 | * NULL otherwise. |
| 9948 | **/ |
| 9949 | struct lpfc_cq_event * |
| 9950 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9951 | { |
| 9952 | struct lpfc_cq_event *cq_event; |
| 9953 | unsigned long iflags; |
| 9954 | |
| 9955 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9956 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9957 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9958 | return cq_event; |
| 9959 | } |
| 9960 | |
| 9961 | /** |
| 9962 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9963 | * @phba: pointer to lpfc hba data structure. |
| 9964 | * @cq_event: pointer to the completion queue event to be freed. |
| 9965 | * |
| 9966 | * This routine is the lock free version of the API invoked to release a |
| 9967 | * completion-queue event back into the free pool. |
| 9968 | **/ |
| 9969 | void |
| 9970 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9971 | struct lpfc_cq_event *cq_event) |
| 9972 | { |
| 9973 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 9974 | } |
| 9975 | |
| 9976 | /** |
| 9977 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9978 | * @phba: pointer to lpfc hba data structure. |
| 9979 | * @cq_event: pointer to the completion queue event to be freed. |
| 9980 | * |
| 9981 | * This routine is the lock version of the API invoked to release a |
| 9982 | * completion-queue event back into the free pool. |
| 9983 | **/ |
| 9984 | void |
| 9985 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9986 | struct lpfc_cq_event *cq_event) |
| 9987 | { |
| 9988 | unsigned long iflags; |
| 9989 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9990 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 9991 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9992 | } |
| 9993 | |
| 9994 | /** |
| 9995 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 9996 | * @phba: pointer to lpfc hba data structure. |
| 9997 | * |
| 9998 | * This routine is to free all the pending completion-queue events to the |
| 9999 | * back into the free pool for device reset. |
| 10000 | **/ |
| 10001 | static void |
| 10002 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10003 | { |
| 10004 | LIST_HEAD(cqelist); |
| 10005 | struct lpfc_cq_event *cqe; |
| 10006 | unsigned long iflags; |
| 10007 | |
| 10008 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 10009 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10010 | /* Pending FCP XRI abort events */ |
| 10011 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 10012 | &cqelist); |
| 10013 | /* Pending ELS XRI abort events */ |
| 10014 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10015 | &cqelist); |
| 10016 | /* Pending asynnc events */ |
| 10017 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10018 | &cqelist); |
| 10019 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10020 | |
| 10021 | while (!list_empty(&cqelist)) { |
| 10022 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 10023 | lpfc_sli4_cq_event_release(phba, cqe); |
| 10024 | } |
| 10025 | } |
| 10026 | |
| 10027 | /** |
| 10028 | * lpfc_pci_function_reset - Reset pci function. |
| 10029 | * @phba: pointer to lpfc hba data structure. |
| 10030 | * |
| 10031 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10032 | * all resources assigned to the PCI function which originates this request. |
| 10033 | * |
| 10034 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10035 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10036 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10037 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10038 | **/ |
| 10039 | int |
| 10040 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10041 | { |
| 10042 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10043 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10044 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10045 | uint32_t rdy_chk; |
| 10046 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10047 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10048 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10049 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10050 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10051 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10052 | switch (if_type) { |
| 10053 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10054 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10055 | GFP_KERNEL); |
| 10056 | if (!mboxq) { |
| 10057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10058 | "0494 Unable to allocate memory for " |
| 10059 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10060 | "command\n"); |
| 10061 | return -ENOMEM; |
| 10062 | } |
| 10063 | |
| 10064 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10065 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10066 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10067 | LPFC_SLI4_MBX_EMBED); |
| 10068 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10069 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10070 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10071 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10072 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10073 | &shdr->response); |
| 10074 | if (rc != MBX_TIMEOUT) |
| 10075 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10076 | if (shdr_status || shdr_add_status || rc) { |
| 10077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10078 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10079 | "failed with status x%x add_status x%x," |
| 10080 | " mbx status x%x\n", |
| 10081 | shdr_status, shdr_add_status, rc); |
| 10082 | rc = -ENXIO; |
| 10083 | } |
| 10084 | break; |
| 10085 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10086 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10087 | wait: |
| 10088 | /* |
| 10089 | * Poll the Port Status Register and wait for RDY for |
| 10090 | * up to 30 seconds. If the port doesn't respond, treat |
| 10091 | * it as an error. |
| 10092 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10093 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10094 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10095 | STATUSregaddr, ®_data.word0)) { |
| 10096 | rc = -ENODEV; |
| 10097 | goto out; |
| 10098 | } |
| 10099 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10100 | break; |
| 10101 | msleep(20); |
| 10102 | } |
| 10103 | |
| 10104 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10105 | phba->work_status[0] = readl( |
| 10106 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10107 | phba->work_status[1] = readl( |
| 10108 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 10109 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10110 | "2890 Port not ready, port status reg " |
| 10111 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10112 | reg_data.word0, |
| 10113 | phba->work_status[0], |
| 10114 | phba->work_status[1]); |
| 10115 | rc = -ENODEV; |
| 10116 | goto out; |
| 10117 | } |
| 10118 | |
| 10119 | if (!port_reset) { |
| 10120 | /* |
| 10121 | * Reset the port now |
| 10122 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10123 | reg_data.word0 = 0; |
| 10124 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10125 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10126 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10127 | LPFC_SLIPORT_INIT_PORT); |
| 10128 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10129 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10130 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10131 | pci_read_config_word(phba->pcidev, |
| 10132 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10133 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10134 | port_reset = 1; |
| 10135 | msleep(20); |
| 10136 | goto wait; |
| 10137 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10138 | rc = -ENODEV; |
| 10139 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10140 | } |
| 10141 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10142 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10143 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10144 | default: |
| 10145 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10146 | } |
| 10147 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10148 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10149 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10150 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10152 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10153 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10154 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10155 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10156 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10157 | return rc; |
| 10158 | } |
| 10159 | |
| 10160 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10161 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10162 | * @phba: pointer to lpfc hba data structure. |
| 10163 | * |
| 10164 | * This routine is invoked to set up the PCI device memory space for device |
| 10165 | * with SLI-4 interface spec. |
| 10166 | * |
| 10167 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10168 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10169 | * other values - error |
| 10170 | **/ |
| 10171 | static int |
| 10172 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10173 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10174 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10175 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10176 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10177 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10178 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10179 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10180 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10181 | |
| 10182 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10183 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10184 | if (error) |
| 10185 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10186 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10187 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10188 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10189 | /* |
| 10190 | * The BARs and register set definitions and offset locations are |
| 10191 | * dependent on the if_type. |
| 10192 | */ |
| 10193 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10194 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10195 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10196 | } |
| 10197 | |
| 10198 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10199 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10200 | LPFC_SLI_INTF_VALID) { |
| 10201 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10202 | "2894 SLI_INTF reg contents invalid " |
| 10203 | "sli_intf reg 0x%x\n", |
| 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 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10209 | /* |
| 10210 | * Get the bus address of SLI4 device Bar regions and the |
| 10211 | * number of bytes required by each mapping. The mapping of the |
| 10212 | * particular PCI BARs regions is dependent on the type of |
| 10213 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10214 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10215 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10216 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10217 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10218 | |
| 10219 | /* |
| 10220 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10221 | * addr |
| 10222 | */ |
| 10223 | phba->sli4_hba.conf_regs_memmap_p = |
| 10224 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10225 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10226 | dev_printk(KERN_ERR, &pdev->dev, |
| 10227 | "ioremap failed for SLI4 PCI config " |
| 10228 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10229 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10230 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10231 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10232 | /* Set up BAR0 PCI config space register memory map */ |
| 10233 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10234 | } else { |
| 10235 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10236 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10237 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10238 | dev_printk(KERN_ERR, &pdev->dev, |
| 10239 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10240 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10241 | } |
| 10242 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10243 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10244 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10245 | dev_printk(KERN_ERR, &pdev->dev, |
| 10246 | "ioremap failed for SLI4 PCI config " |
| 10247 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10248 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10249 | } |
| 10250 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10251 | } |
| 10252 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10253 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10254 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10255 | /* |
| 10256 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10257 | * kernel virtual address and setup the registers. |
| 10258 | */ |
| 10259 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10260 | PCI_64BIT_BAR2); |
| 10261 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10262 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10263 | ioremap(phba->pci_bar1_map, |
| 10264 | bar1map_len); |
| 10265 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10266 | dev_err(&pdev->dev, |
| 10267 | "ioremap failed for SLI4 HBA " |
| 10268 | "control registers.\n"); |
| 10269 | error = -ENOMEM; |
| 10270 | goto out_iounmap_conf; |
| 10271 | } |
| 10272 | phba->pci_bar2_memmap_p = |
| 10273 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10274 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10275 | } else { |
| 10276 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10277 | goto out_iounmap_conf; |
| 10278 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10279 | } |
| 10280 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10281 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10282 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10283 | /* |
| 10284 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10285 | * virtual address and setup the registers. |
| 10286 | */ |
| 10287 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10288 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10289 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10290 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10291 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10292 | dev_err(&pdev->dev, |
| 10293 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10294 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10295 | goto out_iounmap_conf; |
| 10296 | } |
| 10297 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10298 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10299 | } |
| 10300 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10301 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10302 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10303 | /* |
| 10304 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10305 | * a kernel virtual address and setup the registers. |
| 10306 | */ |
| 10307 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10308 | PCI_64BIT_BAR4); |
| 10309 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10310 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10311 | ioremap(phba->pci_bar2_map, |
| 10312 | bar2map_len); |
| 10313 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10314 | dev_err(&pdev->dev, |
| 10315 | "ioremap failed for SLI4 HBA" |
| 10316 | " doorbell registers.\n"); |
| 10317 | error = -ENOMEM; |
| 10318 | goto out_iounmap_ctrl; |
| 10319 | } |
| 10320 | phba->pci_bar4_memmap_p = |
| 10321 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10322 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10323 | if (error) |
| 10324 | goto out_iounmap_all; |
| 10325 | } else { |
| 10326 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10327 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10328 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10329 | } |
| 10330 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10331 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10332 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10333 | /* |
| 10334 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10335 | * virtual address and setup the registers. |
| 10336 | */ |
| 10337 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10338 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10339 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10340 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10341 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10342 | dev_err(&pdev->dev, |
| 10343 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10344 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10345 | goto out_iounmap_ctrl; |
| 10346 | } |
| 10347 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10348 | } |
| 10349 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10350 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10351 | switch (if_type) { |
| 10352 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10353 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10354 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10355 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10356 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10357 | break; |
| 10358 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10359 | 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] | 10360 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10361 | 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] | 10362 | break; |
| 10363 | default: |
| 10364 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10365 | } |
| 10366 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10367 | return 0; |
| 10368 | |
| 10369 | out_iounmap_all: |
| 10370 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10371 | out_iounmap_ctrl: |
| 10372 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10373 | out_iounmap_conf: |
| 10374 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10375 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10376 | return error; |
| 10377 | } |
| 10378 | |
| 10379 | /** |
| 10380 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10381 | * @phba: pointer to lpfc hba data structure. |
| 10382 | * |
| 10383 | * This routine is invoked to unset the PCI device memory space for device |
| 10384 | * with SLI-4 interface spec. |
| 10385 | **/ |
| 10386 | static void |
| 10387 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10388 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10389 | uint32_t if_type; |
| 10390 | 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] | 10391 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10392 | switch (if_type) { |
| 10393 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10394 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10395 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10396 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10397 | break; |
| 10398 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10399 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10400 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10401 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10402 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10403 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10404 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10405 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10406 | default: |
| 10407 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10408 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10409 | if_type); |
| 10410 | break; |
| 10411 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10412 | } |
| 10413 | |
| 10414 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10415 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10416 | * @phba: pointer to lpfc hba data structure. |
| 10417 | * |
| 10418 | * 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] | 10419 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10420 | * |
| 10421 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10422 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10423 | * other values - error |
| 10424 | **/ |
| 10425 | static int |
| 10426 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10427 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10428 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10429 | LPFC_MBOXQ_t *pmb; |
| 10430 | |
| 10431 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10432 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10433 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10434 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10435 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10436 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10437 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10438 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10439 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10440 | /* |
| 10441 | * Assign MSI-X vectors to interrupt handlers |
| 10442 | */ |
| 10443 | |
| 10444 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10445 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10446 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10447 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10448 | if (rc) { |
| 10449 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10450 | "0421 MSI-X slow-path request_irq failed " |
| 10451 | "(%d)\n", rc); |
| 10452 | goto msi_fail_out; |
| 10453 | } |
| 10454 | |
| 10455 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10456 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10457 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10458 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10459 | |
| 10460 | if (rc) { |
| 10461 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10462 | "0429 MSI-X fast-path request_irq failed " |
| 10463 | "(%d)\n", rc); |
| 10464 | goto irq_fail_out; |
| 10465 | } |
| 10466 | |
| 10467 | /* |
| 10468 | * Configure HBA MSI-X attention conditions to messages |
| 10469 | */ |
| 10470 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10471 | |
| 10472 | if (!pmb) { |
| 10473 | rc = -ENOMEM; |
| 10474 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10475 | "0474 Unable to allocate memory for issuing " |
| 10476 | "MBOX_CONFIG_MSI command\n"); |
| 10477 | goto mem_fail_out; |
| 10478 | } |
| 10479 | rc = lpfc_config_msi(phba, pmb); |
| 10480 | if (rc) |
| 10481 | goto mbx_fail_out; |
| 10482 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10483 | if (rc != MBX_SUCCESS) { |
| 10484 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10485 | "0351 Config MSI mailbox command failed, " |
| 10486 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10487 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10488 | goto mbx_fail_out; |
| 10489 | } |
| 10490 | |
| 10491 | /* Free memory allocated for mailbox command */ |
| 10492 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10493 | return rc; |
| 10494 | |
| 10495 | mbx_fail_out: |
| 10496 | /* Free memory allocated for mailbox command */ |
| 10497 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10498 | |
| 10499 | mem_fail_out: |
| 10500 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10501 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10502 | |
| 10503 | irq_fail_out: |
| 10504 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10505 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10506 | |
| 10507 | msi_fail_out: |
| 10508 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10509 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10510 | |
| 10511 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10512 | return rc; |
| 10513 | } |
| 10514 | |
| 10515 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10516 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10517 | * @phba: pointer to lpfc hba data structure. |
| 10518 | * |
| 10519 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10520 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10521 | * enable the MSI vector. The device driver is responsible for calling the |
| 10522 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10523 | * is done in this function. |
| 10524 | * |
| 10525 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10526 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10527 | * other values - error |
| 10528 | */ |
| 10529 | static int |
| 10530 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10531 | { |
| 10532 | int rc; |
| 10533 | |
| 10534 | rc = pci_enable_msi(phba->pcidev); |
| 10535 | if (!rc) |
| 10536 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10537 | "0462 PCI enable MSI mode success.\n"); |
| 10538 | else { |
| 10539 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10540 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10541 | return rc; |
| 10542 | } |
| 10543 | |
| 10544 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10545 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10546 | if (rc) { |
| 10547 | pci_disable_msi(phba->pcidev); |
| 10548 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10549 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10550 | } |
| 10551 | return rc; |
| 10552 | } |
| 10553 | |
| 10554 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10555 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10556 | * @phba: pointer to lpfc hba data structure. |
| 10557 | * |
| 10558 | * This routine is invoked to enable device interrupt and associate driver's |
| 10559 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10560 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10561 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10562 | * mode which is supported by the platform, kernel, and device in the order |
| 10563 | * of: |
| 10564 | * MSI-X -> MSI -> IRQ. |
| 10565 | * |
| 10566 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10567 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10568 | * other values - error |
| 10569 | **/ |
| 10570 | static uint32_t |
| 10571 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10572 | { |
| 10573 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10574 | int retval; |
| 10575 | |
| 10576 | if (cfg_mode == 2) { |
| 10577 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10578 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10579 | if (!retval) { |
| 10580 | /* Now, try to enable MSI-X interrupt mode */ |
| 10581 | retval = lpfc_sli_enable_msix(phba); |
| 10582 | if (!retval) { |
| 10583 | /* Indicate initialization to MSI-X mode */ |
| 10584 | phba->intr_type = MSIX; |
| 10585 | intr_mode = 2; |
| 10586 | } |
| 10587 | } |
| 10588 | } |
| 10589 | |
| 10590 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10591 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10592 | retval = lpfc_sli_enable_msi(phba); |
| 10593 | if (!retval) { |
| 10594 | /* Indicate initialization to MSI mode */ |
| 10595 | phba->intr_type = MSI; |
| 10596 | intr_mode = 1; |
| 10597 | } |
| 10598 | } |
| 10599 | |
| 10600 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10601 | if (phba->intr_type == NONE) { |
| 10602 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10603 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10604 | if (!retval) { |
| 10605 | /* Indicate initialization to INTx mode */ |
| 10606 | phba->intr_type = INTx; |
| 10607 | intr_mode = 0; |
| 10608 | } |
| 10609 | } |
| 10610 | return intr_mode; |
| 10611 | } |
| 10612 | |
| 10613 | /** |
| 10614 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10615 | * @phba: pointer to lpfc hba data structure. |
| 10616 | * |
| 10617 | * This routine is invoked to disable device interrupt and disassociate the |
| 10618 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10619 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10620 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10621 | **/ |
| 10622 | static void |
| 10623 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10624 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10625 | int nr_irqs, i; |
| 10626 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10627 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10628 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10629 | else |
| 10630 | nr_irqs = 1; |
| 10631 | |
| 10632 | for (i = 0; i < nr_irqs; i++) |
| 10633 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10634 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10635 | |
| 10636 | /* Reset interrupt management states */ |
| 10637 | phba->intr_type = NONE; |
| 10638 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10639 | } |
| 10640 | |
| 10641 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10642 | * 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] | 10643 | * @phba: pointer to lpfc hba data structure. |
| 10644 | * @id: EQ vector index or Hardware Queue index |
| 10645 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10646 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10647 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10648 | */ |
| 10649 | static uint16_t |
| 10650 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10651 | { |
| 10652 | struct lpfc_vector_map_info *cpup; |
| 10653 | int cpu; |
| 10654 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10655 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10656 | for_each_present_cpu(cpu) { |
| 10657 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10658 | |
| 10659 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10660 | * using the same vector, so select the one with |
| 10661 | * LPFC_CPU_FIRST_IRQ set. |
| 10662 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10663 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10664 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10665 | (cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10666 | (cpup->eq == id)) |
| 10667 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10668 | |
| 10669 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10670 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10671 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10672 | } |
| 10673 | return 0; |
| 10674 | } |
| 10675 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10676 | #ifdef CONFIG_X86 |
| 10677 | /** |
| 10678 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10679 | * @phba: pointer to lpfc hba data structure. |
| 10680 | * @cpu: CPU map index |
| 10681 | * @phys_id: CPU package physical id |
| 10682 | * @core_id: CPU core id |
| 10683 | */ |
| 10684 | static int |
| 10685 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10686 | uint16_t phys_id, uint16_t core_id) |
| 10687 | { |
| 10688 | struct lpfc_vector_map_info *cpup; |
| 10689 | int idx; |
| 10690 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10691 | for_each_present_cpu(idx) { |
| 10692 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10693 | /* Does the cpup match the one we are looking for */ |
| 10694 | if ((cpup->phys_id == phys_id) && |
| 10695 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10696 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10697 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10698 | } |
| 10699 | return 0; |
| 10700 | } |
| 10701 | #endif |
| 10702 | |
| 10703 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10704 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10705 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10706 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10707 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10708 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10709 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10710 | * In addition, the CPU to IO channel mapping will be calculated |
| 10711 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10712 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10713 | static void |
| 10714 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10715 | { |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10716 | int i, cpu, idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10717 | int max_phys_id, min_phys_id; |
| 10718 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10719 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10720 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10721 | const struct cpumask *maskp; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10722 | #ifdef CONFIG_X86 |
| 10723 | struct cpuinfo_x86 *cpuinfo; |
| 10724 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10725 | |
| 10726 | /* Init cpu_map array */ |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10727 | for_each_possible_cpu(cpu) { |
| 10728 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10729 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10730 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10731 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10732 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10733 | cpup->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10734 | cpup->flag = 0; |
| 10735 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10736 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10737 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10738 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10739 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10740 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10741 | |
| 10742 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10743 | for_each_present_cpu(cpu) { |
| 10744 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10745 | #ifdef CONFIG_X86 |
| 10746 | cpuinfo = &cpu_data(cpu); |
| 10747 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10748 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10749 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10750 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10751 | #else |
| 10752 | /* No distinction between CPUs for other platforms */ |
| 10753 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10754 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10755 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10756 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10757 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10758 | "3328 CPU physid %d coreid %d\n", |
| 10759 | cpup->phys_id, cpup->core_id); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10760 | |
| 10761 | if (cpup->phys_id > max_phys_id) |
| 10762 | max_phys_id = cpup->phys_id; |
| 10763 | if (cpup->phys_id < min_phys_id) |
| 10764 | min_phys_id = cpup->phys_id; |
| 10765 | |
| 10766 | if (cpup->core_id > max_core_id) |
| 10767 | max_core_id = cpup->core_id; |
| 10768 | if (cpup->core_id < min_core_id) |
| 10769 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10770 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10771 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10772 | for_each_possible_cpu(i) { |
| 10773 | struct lpfc_eq_intr_info *eqi = |
| 10774 | per_cpu_ptr(phba->sli4_hba.eq_info, i); |
| 10775 | |
| 10776 | INIT_LIST_HEAD(&eqi->list); |
| 10777 | eqi->icnt = 0; |
| 10778 | } |
| 10779 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10780 | /* This loop sets up all CPUs that are affinitized with a |
| 10781 | * irq vector assigned to the driver. All affinitized CPUs |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10782 | * will get a link to that vectors IRQ and EQ. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10783 | */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10784 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10785 | /* Get a CPU mask for all CPUs affinitized to this vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10786 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 10787 | if (!maskp) |
| 10788 | continue; |
| 10789 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10790 | i = 0; |
| 10791 | /* Loop through all CPUs associated with vector idx */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10792 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10793 | /* Set the EQ index and IRQ for that vector */ |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 10794 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10795 | cpup->eq = idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10796 | cpup->irq = pci_irq_vector(phba->pcidev, idx); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10797 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10798 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10799 | "3336 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10800 | "irq %d eq %d\n", |
| 10801 | cpu, cpup->irq, cpup->eq); |
| 10802 | |
| 10803 | /* If this is the first CPU thats assigned to this |
| 10804 | * vector, set LPFC_CPU_FIRST_IRQ. |
| 10805 | */ |
| 10806 | if (!i) |
| 10807 | cpup->flag |= LPFC_CPU_FIRST_IRQ; |
| 10808 | i++; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10809 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10810 | } |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10811 | |
| 10812 | /* After looking at each irq vector assigned to this pcidev, its |
| 10813 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10814 | * Next we will set any unassigned (unaffinitized) cpu map |
| 10815 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10816 | */ |
| 10817 | first_cpu = cpumask_first(cpu_present_mask); |
| 10818 | start_cpu = first_cpu; |
| 10819 | |
| 10820 | for_each_present_cpu(cpu) { |
| 10821 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10822 | |
| 10823 | /* Is this CPU entry unassigned */ |
| 10824 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10825 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 10826 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10827 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10828 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10829 | * phys_id as cpup. start_cpu will start where we |
| 10830 | * left off so all unassigned entries don't get assgined |
| 10831 | * the IRQ of the first entry. |
| 10832 | */ |
| 10833 | new_cpu = start_cpu; |
| 10834 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10835 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10836 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10837 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY) && |
| 10838 | (new_cpup->phys_id == cpup->phys_id)) |
| 10839 | goto found_same; |
| 10840 | new_cpu = cpumask_next( |
| 10841 | new_cpu, cpu_present_mask); |
| 10842 | if (new_cpu == nr_cpumask_bits) |
| 10843 | new_cpu = first_cpu; |
| 10844 | } |
| 10845 | /* At this point, we leave the CPU as unassigned */ |
| 10846 | continue; |
| 10847 | found_same: |
| 10848 | /* We found a matching phys_id, so copy the IRQ info */ |
| 10849 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10850 | cpup->irq = new_cpup->irq; |
| 10851 | |
| 10852 | /* Bump start_cpu to the next slot to minmize the |
| 10853 | * chance of having multiple unassigned CPU entries |
| 10854 | * selecting the same IRQ. |
| 10855 | */ |
| 10856 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10857 | if (start_cpu == nr_cpumask_bits) |
| 10858 | start_cpu = first_cpu; |
| 10859 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10860 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10861 | "3337 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10862 | "irq %d from id %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10863 | "phys_id (%d)\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10864 | cpu, cpup->irq, new_cpu, cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10865 | } |
| 10866 | } |
| 10867 | |
| 10868 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 10869 | start_cpu = first_cpu; |
| 10870 | |
| 10871 | for_each_present_cpu(cpu) { |
| 10872 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10873 | |
| 10874 | /* Is this entry unassigned */ |
| 10875 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 10876 | /* Mark it as IRQ not assigned by the kernel */ |
| 10877 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 10878 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10879 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10880 | * as the cpup. start_cpu will start where we |
| 10881 | * left off so all unassigned entries don't get |
| 10882 | * assigned the IRQ of the first entry. |
| 10883 | */ |
| 10884 | new_cpu = start_cpu; |
| 10885 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10886 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10887 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
| 10888 | (new_cpup->irq != LPFC_VECTOR_MAP_EMPTY)) |
| 10889 | goto found_any; |
| 10890 | new_cpu = cpumask_next( |
| 10891 | new_cpu, cpu_present_mask); |
| 10892 | if (new_cpu == nr_cpumask_bits) |
| 10893 | new_cpu = first_cpu; |
| 10894 | } |
| 10895 | /* We should never leave an entry unassigned */ |
| 10896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10897 | "3339 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10898 | "irq %d UNASSIGNED\n", |
| 10899 | cpup->hdwq, cpup->irq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10900 | continue; |
| 10901 | found_any: |
| 10902 | /* We found an available entry, copy the IRQ info */ |
| 10903 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10904 | cpup->irq = new_cpup->irq; |
| 10905 | |
| 10906 | /* Bump start_cpu to the next slot to minmize the |
| 10907 | * chance of having multiple unassigned CPU entries |
| 10908 | * selecting the same IRQ. |
| 10909 | */ |
| 10910 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10911 | if (start_cpu == nr_cpumask_bits) |
| 10912 | start_cpu = first_cpu; |
| 10913 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10914 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10915 | "3338 Set Affinity: CPU %d " |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10916 | "irq %d from id %d (%d/%d)\n", |
| 10917 | cpu, cpup->irq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10918 | new_cpup->phys_id, new_cpup->core_id); |
| 10919 | } |
| 10920 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10921 | |
| 10922 | /* Finally we need to associate a hdwq with each cpu_map entry |
| 10923 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 10924 | * hardware queues then CPUs. For that case we will just round-robin |
| 10925 | * the available hardware queues as they get assigned to CPUs. |
| 10926 | */ |
| 10927 | idx = 0; |
| 10928 | start_cpu = 0; |
| 10929 | for_each_present_cpu(cpu) { |
| 10930 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10931 | if (idx >= phba->cfg_hdw_queue) { |
| 10932 | /* We need to reuse a Hardware Queue for another CPU, |
| 10933 | * so be smart about it and pick one that has its |
| 10934 | * IRQ/EQ mapped to the same phys_id (CPU package). |
| 10935 | * and core_id. |
| 10936 | */ |
| 10937 | new_cpu = start_cpu; |
| 10938 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10939 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10940 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10941 | (new_cpup->phys_id == cpup->phys_id) && |
| 10942 | (new_cpup->core_id == cpup->core_id)) |
| 10943 | goto found_hdwq; |
| 10944 | new_cpu = cpumask_next( |
| 10945 | new_cpu, cpu_present_mask); |
| 10946 | if (new_cpu == nr_cpumask_bits) |
| 10947 | new_cpu = first_cpu; |
| 10948 | } |
| 10949 | |
| 10950 | /* If we can't match both phys_id and core_id, |
| 10951 | * settle for just a phys_id match. |
| 10952 | */ |
| 10953 | new_cpu = start_cpu; |
| 10954 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 10955 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 10956 | if ((new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) && |
| 10957 | (new_cpup->phys_id == cpup->phys_id)) |
| 10958 | goto found_hdwq; |
| 10959 | new_cpu = cpumask_next( |
| 10960 | new_cpu, cpu_present_mask); |
| 10961 | if (new_cpu == nr_cpumask_bits) |
| 10962 | new_cpu = first_cpu; |
| 10963 | } |
| 10964 | |
| 10965 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 10966 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 10967 | goto logit; |
| 10968 | found_hdwq: |
| 10969 | /* We found an available entry, copy the IRQ info */ |
| 10970 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 10971 | if (start_cpu == nr_cpumask_bits) |
| 10972 | start_cpu = first_cpu; |
| 10973 | cpup->hdwq = new_cpup->hdwq; |
| 10974 | } else { |
| 10975 | /* 1 to 1, CPU to hdwq */ |
| 10976 | cpup->hdwq = idx; |
| 10977 | } |
| 10978 | logit: |
| 10979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10980 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
| 10981 | "hdwq %d eq %d irq %d flg x%x\n", |
| 10982 | cpu, cpup->phys_id, cpup->core_id, |
| 10983 | cpup->hdwq, cpup->eq, cpup->irq, cpup->flag); |
| 10984 | idx++; |
| 10985 | } |
| 10986 | |
| 10987 | /* The cpu_map array will be used later during initialization |
| 10988 | * when EQ / CQ / WQs are allocated and configured. |
| 10989 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10990 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10991 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10992 | |
| 10993 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10994 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 10995 | * @phba: pointer to lpfc hba data structure. |
| 10996 | * |
| 10997 | * 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] | 10998 | * with SLI-4 interface spec. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10999 | * |
| 11000 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11001 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11002 | * other values - error |
| 11003 | **/ |
| 11004 | static int |
| 11005 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11006 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11007 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11008 | char *name; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11009 | |
| 11010 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11011 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11012 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11013 | rc = pci_alloc_irq_vectors(phba->pcidev, |
James Smart | 75508a8 | 2019-01-28 11:14:34 -0800 | [diff] [blame] | 11014 | 1, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11015 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11016 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11017 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11018 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11019 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11020 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11021 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11022 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11023 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11024 | for (index = 0; index < vectors; index++) { |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11025 | name = phba->sli4_hba.hba_eq_hdl[index].handler_name; |
| 11026 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11027 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11028 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11029 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11030 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11031 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11032 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11033 | &lpfc_sli4_hba_intr_handler, 0, |
| 11034 | name, |
| 11035 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11036 | if (rc) { |
| 11037 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11038 | "0486 MSI-X fast-path (%d) " |
| 11039 | "request_irq failed (%d)\n", index, rc); |
| 11040 | goto cfg_fail_out; |
| 11041 | } |
| 11042 | } |
| 11043 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11044 | if (vectors != phba->cfg_irq_chann) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11046 | "3238 Reducing IO channels to match number of " |
| 11047 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11048 | phba->cfg_irq_chann, vectors); |
| 11049 | if (phba->cfg_irq_chann > vectors) |
| 11050 | phba->cfg_irq_chann = vectors; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 11051 | if (phba->nvmet_support && (phba->cfg_nvmet_mrq > vectors)) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11052 | phba->cfg_nvmet_mrq = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11053 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11054 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11055 | return rc; |
| 11056 | |
| 11057 | cfg_fail_out: |
| 11058 | /* free the irq already requested */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11059 | for (--index; index >= 0; index--) |
| 11060 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11061 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11062 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11063 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11064 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11065 | |
| 11066 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11067 | return rc; |
| 11068 | } |
| 11069 | |
| 11070 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11071 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11072 | * @phba: pointer to lpfc hba data structure. |
| 11073 | * |
| 11074 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 11075 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 11076 | * to enable the MSI vector. The device driver is responsible for calling |
| 11077 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 11078 | * which is done in this function. |
| 11079 | * |
| 11080 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11081 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11082 | * other values - error |
| 11083 | **/ |
| 11084 | static int |
| 11085 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11086 | { |
| 11087 | int rc, index; |
| 11088 | |
| 11089 | rc = pci_enable_msi(phba->pcidev); |
| 11090 | if (!rc) |
| 11091 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11092 | "0487 PCI enable MSI mode success.\n"); |
| 11093 | else { |
| 11094 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11095 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 11096 | return rc; |
| 11097 | } |
| 11098 | |
| 11099 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11100 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11101 | if (rc) { |
| 11102 | pci_disable_msi(phba->pcidev); |
| 11103 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11104 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11105 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11106 | } |
| 11107 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11108 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11109 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 11110 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11111 | } |
| 11112 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11113 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11114 | } |
| 11115 | |
| 11116 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11117 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11118 | * @phba: pointer to lpfc hba data structure. |
| 11119 | * |
| 11120 | * This routine is invoked to enable device interrupt and associate driver's |
| 11121 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11122 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11123 | * the driver will try to fallback from the configured interrupt mode to an |
| 11124 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11125 | * the order of: |
| 11126 | * MSI-X -> MSI -> IRQ. |
| 11127 | * |
| 11128 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11129 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11130 | * other values - error |
| 11131 | **/ |
| 11132 | static uint32_t |
| 11133 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11134 | { |
| 11135 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11136 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11137 | |
| 11138 | if (cfg_mode == 2) { |
| 11139 | /* Preparation before conf_msi mbox cmd */ |
| 11140 | retval = 0; |
| 11141 | if (!retval) { |
| 11142 | /* Now, try to enable MSI-X interrupt mode */ |
| 11143 | retval = lpfc_sli4_enable_msix(phba); |
| 11144 | if (!retval) { |
| 11145 | /* Indicate initialization to MSI-X mode */ |
| 11146 | phba->intr_type = MSIX; |
| 11147 | intr_mode = 2; |
| 11148 | } |
| 11149 | } |
| 11150 | } |
| 11151 | |
| 11152 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11153 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11154 | retval = lpfc_sli4_enable_msi(phba); |
| 11155 | if (!retval) { |
| 11156 | /* Indicate initialization to MSI mode */ |
| 11157 | phba->intr_type = MSI; |
| 11158 | intr_mode = 1; |
| 11159 | } |
| 11160 | } |
| 11161 | |
| 11162 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11163 | if (phba->intr_type == NONE) { |
| 11164 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11165 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11166 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11167 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11168 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11169 | /* Indicate initialization to INTx mode */ |
| 11170 | phba->intr_type = INTx; |
| 11171 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11172 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11173 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11174 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 11175 | eqhdl->idx = idx; |
| 11176 | eqhdl->phba = phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11177 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11178 | } |
| 11179 | } |
| 11180 | return intr_mode; |
| 11181 | } |
| 11182 | |
| 11183 | /** |
| 11184 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11185 | * @phba: pointer to lpfc hba data structure. |
| 11186 | * |
| 11187 | * This routine is invoked to disable device interrupt and disassociate |
| 11188 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11189 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11190 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11191 | **/ |
| 11192 | static void |
| 11193 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11194 | { |
| 11195 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11196 | if (phba->intr_type == MSIX) { |
| 11197 | int index; |
| 11198 | |
| 11199 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11200 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11201 | irq_set_affinity_hint( |
| 11202 | pci_irq_vector(phba->pcidev, index), |
| 11203 | NULL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11204 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 11205 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11206 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11207 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11208 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11209 | } |
| 11210 | |
| 11211 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11212 | |
| 11213 | /* Reset interrupt management states */ |
| 11214 | phba->intr_type = NONE; |
| 11215 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11216 | } |
| 11217 | |
| 11218 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11219 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11220 | * @phba: pointer to lpfc hba data structure. |
| 11221 | * |
| 11222 | * This routine is invoked to unset the HBA device initialization steps to |
| 11223 | * a device with SLI-3 interface spec. |
| 11224 | **/ |
| 11225 | static void |
| 11226 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11227 | { |
| 11228 | struct lpfc_vport *vport = phba->pport; |
| 11229 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11230 | |
| 11231 | spin_lock_irq(shost->host_lock); |
| 11232 | vport->load_flag |= FC_UNLOADING; |
| 11233 | spin_unlock_irq(shost->host_lock); |
| 11234 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11235 | kfree(phba->vpi_bmask); |
| 11236 | kfree(phba->vpi_ids); |
| 11237 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11238 | lpfc_stop_hba_timers(phba); |
| 11239 | |
| 11240 | phba->pport->work_port_events = 0; |
| 11241 | |
| 11242 | lpfc_sli_hba_down(phba); |
| 11243 | |
| 11244 | lpfc_sli_brdrestart(phba); |
| 11245 | |
| 11246 | lpfc_sli_disable_intr(phba); |
| 11247 | |
| 11248 | return; |
| 11249 | } |
| 11250 | |
| 11251 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11252 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11253 | * @phba: Pointer to HBA context object. |
| 11254 | * |
| 11255 | * This function is called in the SLI4 code path to wait for completion |
| 11256 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11257 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11258 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11259 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11260 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11261 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11262 | * the rest of the driver unload resource release. |
| 11263 | **/ |
| 11264 | static void |
| 11265 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11266 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11267 | struct lpfc_sli4_hdw_queue *qp; |
| 11268 | int idx, ccnt, fcnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11269 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11270 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11271 | int nvmet_xri_cmpl = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11272 | int fcp_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11273 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11274 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11275 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11276 | * here to give the HBA time to complete the IO and get entries |
| 11277 | * into the abts lists. |
| 11278 | */ |
| 11279 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11280 | |
| 11281 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11282 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11283 | lpfc_nvme_wait_for_io_drain(phba); |
| 11284 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11285 | ccnt = 0; |
| 11286 | fcnt = 0; |
| 11287 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11288 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11289 | fcp_xri_cmpl = list_empty( |
| 11290 | &qp->lpfc_abts_scsi_buf_list); |
| 11291 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11292 | fcnt++; |
| 11293 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11294 | io_xri_cmpl = list_empty( |
| 11295 | &qp->lpfc_abts_nvme_buf_list); |
| 11296 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11297 | ccnt++; |
| 11298 | } |
| 11299 | } |
| 11300 | if (ccnt) |
| 11301 | io_xri_cmpl = 0; |
| 11302 | if (fcnt) |
| 11303 | fcp_xri_cmpl = 0; |
| 11304 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11305 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11306 | nvmet_xri_cmpl = |
| 11307 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11308 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11309 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11310 | while (!fcp_xri_cmpl || !els_xri_cmpl || !io_xri_cmpl || |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11311 | !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11312 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11313 | if (!nvmet_xri_cmpl) |
| 11314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11315 | "6424 NVMET XRI exchange busy " |
| 11316 | "wait time: %d seconds.\n", |
| 11317 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11318 | if (!io_xri_cmpl) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11320 | "6100 NVME XRI exchange busy " |
| 11321 | "wait time: %d seconds.\n", |
| 11322 | wait_time/1000); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11323 | if (!fcp_xri_cmpl) |
| 11324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11325 | "2877 FCP XRI exchange busy " |
| 11326 | "wait time: %d seconds.\n", |
| 11327 | wait_time/1000); |
| 11328 | if (!els_xri_cmpl) |
| 11329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11330 | "2878 ELS XRI exchange busy " |
| 11331 | "wait time: %d seconds.\n", |
| 11332 | wait_time/1000); |
| 11333 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11334 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11335 | } else { |
| 11336 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11337 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11338 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11339 | |
| 11340 | ccnt = 0; |
| 11341 | fcnt = 0; |
| 11342 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11343 | qp = &phba->sli4_hba.hdwq[idx]; |
| 11344 | fcp_xri_cmpl = list_empty( |
| 11345 | &qp->lpfc_abts_scsi_buf_list); |
| 11346 | if (!fcp_xri_cmpl) /* if list is NOT empty */ |
| 11347 | fcnt++; |
| 11348 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11349 | io_xri_cmpl = list_empty( |
| 11350 | &qp->lpfc_abts_nvme_buf_list); |
| 11351 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11352 | ccnt++; |
| 11353 | } |
| 11354 | } |
| 11355 | if (ccnt) |
| 11356 | io_xri_cmpl = 0; |
| 11357 | if (fcnt) |
| 11358 | fcp_xri_cmpl = 0; |
| 11359 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11360 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11361 | nvmet_xri_cmpl = list_empty( |
| 11362 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11363 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11364 | els_xri_cmpl = |
| 11365 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11366 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11367 | } |
| 11368 | } |
| 11369 | |
| 11370 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11371 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11372 | * @phba: Pointer to HBA context object. |
| 11373 | * |
| 11374 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11375 | * function. The caller is not required to hold any lock. This routine |
| 11376 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11377 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11378 | * free any pending commands. |
| 11379 | **/ |
| 11380 | static void |
| 11381 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11382 | { |
| 11383 | int wait_cnt = 0; |
| 11384 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11385 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11386 | |
| 11387 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11388 | if (phba->pport) |
| 11389 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11390 | |
| 11391 | /* |
| 11392 | * Gracefully wait out the potential current outstanding asynchronous |
| 11393 | * mailbox command. |
| 11394 | */ |
| 11395 | |
| 11396 | /* First, block any pending async mailbox command from posted */ |
| 11397 | spin_lock_irq(&phba->hbalock); |
| 11398 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11399 | spin_unlock_irq(&phba->hbalock); |
| 11400 | /* Now, trying to wait it out if we can */ |
| 11401 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11402 | msleep(10); |
| 11403 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11404 | break; |
| 11405 | } |
| 11406 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11407 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11408 | spin_lock_irq(&phba->hbalock); |
| 11409 | mboxq = phba->sli.mbox_active; |
| 11410 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11411 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11412 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11413 | phba->sli.mbox_active = NULL; |
| 11414 | spin_unlock_irq(&phba->hbalock); |
| 11415 | } |
| 11416 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11417 | /* Abort all iocbs associated with the hba */ |
| 11418 | lpfc_sli_hba_iocb_abort(phba); |
| 11419 | |
| 11420 | /* Wait for completion of device XRI exchange busy */ |
| 11421 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 11422 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11423 | /* Disable PCI subsystem interrupt */ |
| 11424 | lpfc_sli4_disable_intr(phba); |
| 11425 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11426 | /* Disable SR-IOV if enabled */ |
| 11427 | if (phba->cfg_sriov_nr_virtfn) |
| 11428 | pci_disable_sriov(pdev); |
| 11429 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11430 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11431 | kthread_stop(phba->worker_thread); |
| 11432 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11433 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11434 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11435 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11436 | /* Unset the queues shared with the hardware then release all |
| 11437 | * allocated resources. |
| 11438 | */ |
| 11439 | lpfc_sli4_queue_unset(phba); |
| 11440 | lpfc_sli4_queue_destroy(phba); |
| 11441 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11442 | /* Reset SLI4 HBA FCoE function */ |
| 11443 | lpfc_pci_function_reset(phba); |
| 11444 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 11445 | /* Free RAS DMA memory */ |
| 11446 | if (phba->ras_fwlog.ras_enabled) |
| 11447 | lpfc_sli4_ras_dma_free(phba); |
| 11448 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11449 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 11450 | if (phba->pport) |
| 11451 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11452 | } |
| 11453 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11454 | /** |
| 11455 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 11456 | * @phba: Pointer to HBA context object. |
| 11457 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11458 | * |
| 11459 | * This function is called in the SLI4 code path to read the port's |
| 11460 | * sli4 capabilities. |
| 11461 | * |
| 11462 | * This function may be be called from any context that can block-wait |
| 11463 | * for the completion. The expectation is that this routine is called |
| 11464 | * typically from probe_one or from the online routine. |
| 11465 | **/ |
| 11466 | int |
| 11467 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11468 | { |
| 11469 | int rc; |
| 11470 | struct lpfc_mqe *mqe; |
| 11471 | struct lpfc_pc_sli4_params *sli4_params; |
| 11472 | uint32_t mbox_tmo; |
| 11473 | |
| 11474 | rc = 0; |
| 11475 | mqe = &mboxq->u.mqe; |
| 11476 | |
| 11477 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11478 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11479 | if (!phba->sli4_hba.intr_enable) |
| 11480 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 11481 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11482 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11483 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11484 | } |
| 11485 | |
| 11486 | if (unlikely(rc)) |
| 11487 | return 1; |
| 11488 | |
| 11489 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11490 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 11491 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 11492 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 11493 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 11494 | &mqe->un.sli4_params); |
| 11495 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 11496 | &mqe->un.sli4_params); |
| 11497 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 11498 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 11499 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 11500 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 11501 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 11502 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 11503 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 11504 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 11505 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 11506 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 11507 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 11508 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 11509 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 11510 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 11511 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 11512 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 11513 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 11514 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 11515 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 11516 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 11517 | 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] | 11518 | |
| 11519 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11520 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11521 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11522 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11523 | return rc; |
| 11524 | } |
| 11525 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11526 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11527 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 11528 | * @phba: Pointer to HBA context object. |
| 11529 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 11530 | * |
| 11531 | * This function is called in the SLI4 code path to read the port's |
| 11532 | * sli4 capabilities. |
| 11533 | * |
| 11534 | * This function may be be called from any context that can block-wait |
| 11535 | * for the completion. The expectation is that this routine is called |
| 11536 | * typically from probe_one or from the online routine. |
| 11537 | **/ |
| 11538 | int |
| 11539 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 11540 | { |
| 11541 | int rc; |
| 11542 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 11543 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11544 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11545 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11546 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11547 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 11548 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11549 | /* |
| 11550 | * By default, the driver assumes the SLI4 port requires RPI |
| 11551 | * header postings. The SLI4_PARAM response will correct this |
| 11552 | * assumption. |
| 11553 | */ |
| 11554 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 11555 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11556 | /* Read the port's SLI4 Config Parameters */ |
| 11557 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 11558 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 11559 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11560 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 11561 | length, LPFC_SLI4_MBX_EMBED); |
| 11562 | if (!phba->sli4_hba.intr_enable) |
| 11563 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11564 | else { |
| 11565 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 11566 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 11567 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11568 | if (unlikely(rc)) |
| 11569 | return rc; |
| 11570 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 11571 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 11572 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 11573 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 11574 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 11575 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 11576 | mbx_sli4_parameters); |
| 11577 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 11578 | mbx_sli4_parameters); |
| 11579 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 11580 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 11581 | else |
| 11582 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 11583 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 11584 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11585 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11586 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 11587 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 11588 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 11589 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 11590 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 11591 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 11592 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 11593 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11594 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 11595 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11596 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11597 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 11598 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 11599 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 11600 | 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] | 11601 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11602 | /* Check for firmware nvme support */ |
| 11603 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 11604 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11605 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 11606 | if (rc) { |
| 11607 | /* Save this to indicate the Firmware supports NVME */ |
| 11608 | sli4_params->nvme = 1; |
| 11609 | |
| 11610 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 11611 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 11612 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 11613 | "6133 Disabling NVME support: " |
| 11614 | "FC4 type not supported: x%x\n", |
| 11615 | phba->cfg_enable_fc4_type); |
| 11616 | goto fcponly; |
| 11617 | } |
| 11618 | } else { |
| 11619 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 11620 | sli4_params->nvme = 0; |
| 11621 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 11622 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 11623 | "6101 Disabling NVME support: Not " |
| 11624 | "supported by firmware (%d %d) x%x\n", |
| 11625 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 11626 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 11627 | phba->cfg_enable_fc4_type); |
| 11628 | fcponly: |
| 11629 | phba->nvme_support = 0; |
| 11630 | phba->nvmet_support = 0; |
| 11631 | phba->cfg_nvmet_mrq = 0; |
| 11632 | |
| 11633 | /* If no FC4 type support, move to just SCSI support */ |
| 11634 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 11635 | return -ENODEV; |
| 11636 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 11637 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11638 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11639 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11640 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 11641 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 11642 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 11643 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11644 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11645 | /* |
| 11646 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 11647 | * lpfc_suppress_rsp module parameter must be set (default). |
| 11648 | * In SLI4-Parameters Descriptor: |
| 11649 | * Extended Inline Buffers (XIB) must be supported. |
| 11650 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 11651 | * (double negative). |
| 11652 | */ |
| 11653 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 11654 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11655 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 11656 | else |
| 11657 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11658 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 11659 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 11660 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 11661 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 11662 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 11663 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 11664 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 11665 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11666 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11667 | * Check whether the adapter supports an embedded copy of the |
| 11668 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 11669 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 11670 | */ |
| 11671 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 11672 | phba->fcp_embed_io = 1; |
| 11673 | else |
| 11674 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11675 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11676 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11677 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11678 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 11679 | phba->cfg_enable_pbde, |
| 11680 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 11681 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 11682 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11683 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 11684 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 11685 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 11686 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11687 | exp_wqcq_pages = false; |
| 11688 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11689 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 11690 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 11691 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 11692 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 11693 | phba->enab_exp_wqcq_pages = 1; |
| 11694 | else |
| 11695 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 11696 | /* |
| 11697 | * Check if the SLI port supports MDS Diagnostics |
| 11698 | */ |
| 11699 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 11700 | phba->mds_diags_support = 1; |
| 11701 | else |
| 11702 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 11703 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 11704 | return 0; |
| 11705 | } |
| 11706 | |
| 11707 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11708 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 11709 | * @pdev: pointer to PCI device |
| 11710 | * @pid: pointer to PCI device identifier |
| 11711 | * |
| 11712 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 11713 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11714 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 11715 | * information of the device and driver to see if the driver state that it can |
| 11716 | * support this kind of device. If the match is successful, the driver core |
| 11717 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 11718 | * does all the initialization that it needs to do to handle the HBA properly. |
| 11719 | * |
| 11720 | * Return code |
| 11721 | * 0 - driver can claim the device |
| 11722 | * negative value - driver can not claim the device |
| 11723 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11724 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11725 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11726 | { |
| 11727 | struct lpfc_hba *phba; |
| 11728 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11729 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11730 | int error; |
| 11731 | uint32_t cfg_mode, intr_mode; |
| 11732 | |
| 11733 | /* Allocate memory for HBA structure */ |
| 11734 | phba = lpfc_hba_alloc(pdev); |
| 11735 | if (!phba) |
| 11736 | return -ENOMEM; |
| 11737 | |
| 11738 | /* Perform generic PCI device enabling operation */ |
| 11739 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11740 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11741 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11742 | |
| 11743 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 11744 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 11745 | if (error) |
| 11746 | goto out_disable_pci_dev; |
| 11747 | |
| 11748 | /* Set up SLI-3 specific device PCI memory space */ |
| 11749 | error = lpfc_sli_pci_mem_setup(phba); |
| 11750 | if (error) { |
| 11751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11752 | "1402 Failed to set up pci memory space.\n"); |
| 11753 | goto out_disable_pci_dev; |
| 11754 | } |
| 11755 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11756 | /* Set up SLI-3 specific device driver resources */ |
| 11757 | error = lpfc_sli_driver_resource_setup(phba); |
| 11758 | if (error) { |
| 11759 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11760 | "1404 Failed to set up driver resource.\n"); |
| 11761 | goto out_unset_pci_mem_s3; |
| 11762 | } |
| 11763 | |
| 11764 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11765 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11766 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 11767 | if (error) { |
| 11768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11769 | "1405 Failed to initialize iocb list.\n"); |
| 11770 | goto out_unset_driver_resource_s3; |
| 11771 | } |
| 11772 | |
| 11773 | /* Set up common device driver resources */ |
| 11774 | error = lpfc_setup_driver_resource_phase2(phba); |
| 11775 | if (error) { |
| 11776 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11777 | "1406 Failed to set up driver resource.\n"); |
| 11778 | goto out_free_iocb_list; |
| 11779 | } |
| 11780 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11781 | /* Get the default values for Model Name and Description */ |
| 11782 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 11783 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11784 | /* Create SCSI host to the physical port */ |
| 11785 | error = lpfc_create_shost(phba); |
| 11786 | if (error) { |
| 11787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11788 | "1407 Failed to create scsi host.\n"); |
| 11789 | goto out_unset_driver_resource; |
| 11790 | } |
| 11791 | |
| 11792 | /* Configure sysfs attributes */ |
| 11793 | vport = phba->pport; |
| 11794 | error = lpfc_alloc_sysfs_attr(vport); |
| 11795 | if (error) { |
| 11796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11797 | "1476 Failed to allocate sysfs attr\n"); |
| 11798 | goto out_destroy_shost; |
| 11799 | } |
| 11800 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11801 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11802 | /* Now, trying to enable interrupt and bring up the device */ |
| 11803 | cfg_mode = phba->cfg_use_msi; |
| 11804 | while (true) { |
| 11805 | /* Put device to a known state before enabling interrupt */ |
| 11806 | lpfc_stop_port(phba); |
| 11807 | /* Configure and enable interrupt */ |
| 11808 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 11809 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11811 | "0431 Failed to enable interrupt.\n"); |
| 11812 | error = -ENODEV; |
| 11813 | goto out_free_sysfs_attr; |
| 11814 | } |
| 11815 | /* SLI-3 HBA setup */ |
| 11816 | if (lpfc_sli_hba_setup(phba)) { |
| 11817 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11818 | "1477 Failed to set up hba\n"); |
| 11819 | error = -ENODEV; |
| 11820 | goto out_remove_device; |
| 11821 | } |
| 11822 | |
| 11823 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 11824 | msleep(50); |
| 11825 | /* Check active interrupts on message signaled interrupts */ |
| 11826 | if (intr_mode == 0 || |
| 11827 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 11828 | /* Log the current active interrupt mode */ |
| 11829 | phba->intr_mode = intr_mode; |
| 11830 | lpfc_log_intr_mode(phba, intr_mode); |
| 11831 | break; |
| 11832 | } else { |
| 11833 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11834 | "0447 Configure interrupt mode (%d) " |
| 11835 | "failed active interrupt test.\n", |
| 11836 | intr_mode); |
| 11837 | /* Disable the current interrupt mode */ |
| 11838 | lpfc_sli_disable_intr(phba); |
| 11839 | /* Try next level of interrupt mode */ |
| 11840 | cfg_mode = --intr_mode; |
| 11841 | } |
| 11842 | } |
| 11843 | |
| 11844 | /* Perform post initialization setup */ |
| 11845 | lpfc_post_init_setup(phba); |
| 11846 | |
| 11847 | /* Check if there are static vports to be created. */ |
| 11848 | lpfc_create_static_vport(phba); |
| 11849 | |
| 11850 | return 0; |
| 11851 | |
| 11852 | out_remove_device: |
| 11853 | lpfc_unset_hba(phba); |
| 11854 | out_free_sysfs_attr: |
| 11855 | lpfc_free_sysfs_attr(vport); |
| 11856 | out_destroy_shost: |
| 11857 | lpfc_destroy_shost(phba); |
| 11858 | out_unset_driver_resource: |
| 11859 | lpfc_unset_driver_resource_phase2(phba); |
| 11860 | out_free_iocb_list: |
| 11861 | lpfc_free_iocb_list(phba); |
| 11862 | out_unset_driver_resource_s3: |
| 11863 | lpfc_sli_driver_resource_unset(phba); |
| 11864 | out_unset_pci_mem_s3: |
| 11865 | lpfc_sli_pci_mem_unset(phba); |
| 11866 | out_disable_pci_dev: |
| 11867 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11868 | if (shost) |
| 11869 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11870 | out_free_phba: |
| 11871 | lpfc_hba_free(phba); |
| 11872 | return error; |
| 11873 | } |
| 11874 | |
| 11875 | /** |
| 11876 | * 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] | 11877 | * @pdev: pointer to PCI device |
| 11878 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11879 | * This routine is to be called to disattach a device with SLI-3 interface |
| 11880 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 11881 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 11882 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11883 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11884 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11885 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11886 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11887 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11888 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11889 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11890 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11891 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 11892 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11893 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11894 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 11895 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11896 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11897 | lpfc_free_sysfs_attr(vport); |
| 11898 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11899 | /* Release all the vports against this physical port */ |
| 11900 | vports = lpfc_create_vport_work_array(phba); |
| 11901 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11902 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 11903 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 11904 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11905 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11906 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 11907 | lpfc_destroy_vport_work_array(phba, vports); |
| 11908 | |
| 11909 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11910 | fc_remove_host(shost); |
| 11911 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 11912 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 11913 | lpfc_cleanup(vport); |
| 11914 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11915 | /* |
| 11916 | * Bring down the SLI Layer. This step disable all interrupts, |
| 11917 | * clears the rings, discards all mailbox commands, and resets |
| 11918 | * the HBA. |
| 11919 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11920 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 11921 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11922 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11923 | /* Stop kthread signal shall trigger work_done one more time */ |
| 11924 | kthread_stop(phba->worker_thread); |
| 11925 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11926 | lpfc_sli_brdrestart(phba); |
| 11927 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11928 | kfree(phba->vpi_bmask); |
| 11929 | kfree(phba->vpi_ids); |
| 11930 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11931 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11932 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11933 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 11934 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11935 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11936 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11937 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11938 | /* Disable SR-IOV if enabled */ |
| 11939 | if (phba->cfg_sriov_nr_virtfn) |
| 11940 | pci_disable_sriov(pdev); |
| 11941 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11942 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11943 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11944 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11945 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11946 | |
| 11947 | /* |
| 11948 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 11949 | * corresponding pools here. |
| 11950 | */ |
| 11951 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 11952 | lpfc_free_iocb_list(phba); |
| 11953 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11954 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11955 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11956 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 11957 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11959 | /* Free resources associated with SLI2 interface */ |
| 11960 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11961 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11962 | |
| 11963 | /* unmap adapter SLIM and Control Registers */ |
| 11964 | iounmap(phba->ctrl_regs_memmap_p); |
| 11965 | iounmap(phba->slim_memmap_p); |
| 11966 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11967 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11968 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 11969 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11970 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11971 | } |
| 11972 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11973 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11974 | * 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] | 11975 | * @pdev: pointer to PCI device |
| 11976 | * @msg: power management message |
| 11977 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11978 | * This routine is to be called from the kernel's PCI subsystem to support |
| 11979 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 11980 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 11981 | * worker thread for the device, turning off device's interrupt and DMA, |
| 11982 | * and bring the device offline. Note that as the driver implements the |
| 11983 | * minimum PM requirements to a power-aware driver's PM support for the |
| 11984 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11985 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 11986 | * fully reinitialize its device during resume() method call, the driver will |
| 11987 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 11988 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11989 | * |
| 11990 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11991 | * 0 - driver suspended the device |
| 11992 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11993 | **/ |
| 11994 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11995 | 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] | 11996 | { |
| 11997 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11998 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11999 | |
| 12000 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12001 | "0473 PCI device Power Management suspend.\n"); |
| 12002 | |
| 12003 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12004 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12005 | lpfc_offline(phba); |
| 12006 | kthread_stop(phba->worker_thread); |
| 12007 | |
| 12008 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12009 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12010 | |
| 12011 | /* Save device state to PCI config space */ |
| 12012 | pci_save_state(pdev); |
| 12013 | pci_set_power_state(pdev, PCI_D3hot); |
| 12014 | |
| 12015 | return 0; |
| 12016 | } |
| 12017 | |
| 12018 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12019 | * 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] | 12020 | * @pdev: pointer to PCI device |
| 12021 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12022 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12023 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12024 | * invokes this method, it restores the device's PCI config space state and |
| 12025 | * fully reinitializes the device and brings it online. Note that as the |
| 12026 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12027 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12028 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12029 | * driver will fully reinitialize its device during resume() method call, |
| 12030 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12031 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12032 | * |
| 12033 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12034 | * 0 - driver suspended the device |
| 12035 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12036 | **/ |
| 12037 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12038 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12039 | { |
| 12040 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12041 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12042 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12043 | int error; |
| 12044 | |
| 12045 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12046 | "0452 PCI device Power Management resume.\n"); |
| 12047 | |
| 12048 | /* Restore device state from PCI config space */ |
| 12049 | pci_set_power_state(pdev, PCI_D0); |
| 12050 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12051 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12052 | /* |
| 12053 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12054 | * device saved_state flag, need to save the restored state again. |
| 12055 | */ |
| 12056 | pci_save_state(pdev); |
| 12057 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12058 | if (pdev->is_busmaster) |
| 12059 | pci_set_master(pdev); |
| 12060 | |
| 12061 | /* Startup the kernel thread for this host adapter. */ |
| 12062 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12063 | "lpfc_worker_%d", phba->brd_no); |
| 12064 | if (IS_ERR(phba->worker_thread)) { |
| 12065 | error = PTR_ERR(phba->worker_thread); |
| 12066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12067 | "0434 PM resume failed to start worker " |
| 12068 | "thread: error=x%x.\n", error); |
| 12069 | return error; |
| 12070 | } |
| 12071 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12072 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12073 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12074 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12076 | "0430 PM resume Failed to enable interrupt\n"); |
| 12077 | return -EIO; |
| 12078 | } else |
| 12079 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12080 | |
| 12081 | /* Restart HBA and bring it online */ |
| 12082 | lpfc_sli_brdrestart(phba); |
| 12083 | lpfc_online(phba); |
| 12084 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12085 | /* Log the current active interrupt mode */ |
| 12086 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12087 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12088 | return 0; |
| 12089 | } |
| 12090 | |
| 12091 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12092 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12093 | * @phba: pointer to lpfc hba data structure. |
| 12094 | * |
| 12095 | * 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] | 12096 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12097 | **/ |
| 12098 | static void |
| 12099 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12100 | { |
| 12101 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12102 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12103 | |
| 12104 | /* |
| 12105 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12106 | * and let the SCSI mid-layer to retry them to recover. |
| 12107 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12108 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12109 | } |
| 12110 | |
| 12111 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12112 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12113 | * @phba: pointer to lpfc hba data structure. |
| 12114 | * |
| 12115 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12116 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12117 | * pending I/Os. |
| 12118 | **/ |
| 12119 | static void |
| 12120 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12121 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12123 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12124 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12125 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12126 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12127 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12128 | /* Block all SCSI devices' I/Os on the host */ |
| 12129 | lpfc_scsi_dev_block(phba); |
| 12130 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12131 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12132 | lpfc_sli_flush_fcp_rings(phba); |
| 12133 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12134 | /* stop all timers */ |
| 12135 | lpfc_stop_hba_timers(phba); |
| 12136 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12137 | /* Disable interrupt and pci device */ |
| 12138 | lpfc_sli_disable_intr(phba); |
| 12139 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12140 | } |
| 12141 | |
| 12142 | /** |
| 12143 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12144 | * @phba: pointer to lpfc hba data structure. |
| 12145 | * |
| 12146 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12147 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12148 | * pending I/Os. |
| 12149 | **/ |
| 12150 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12151 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12152 | { |
| 12153 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12154 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12155 | /* Block all SCSI devices' I/Os on the host */ |
| 12156 | lpfc_scsi_dev_block(phba); |
| 12157 | |
| 12158 | /* stop all timers */ |
| 12159 | lpfc_stop_hba_timers(phba); |
| 12160 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12161 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12162 | lpfc_sli_flush_fcp_rings(phba); |
| 12163 | } |
| 12164 | |
| 12165 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12166 | * 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] | 12167 | * @pdev: pointer to PCI device. |
| 12168 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12169 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12170 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12171 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12172 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12173 | * When this function is invoked, it will need to stop all the I/Os and |
| 12174 | * interrupt(s) to the device. Once that is done, it will return |
| 12175 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12176 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12177 | * |
| 12178 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12179 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12180 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12181 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12182 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12183 | static pci_ers_result_t |
| 12184 | 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] | 12185 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12186 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12187 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12188 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12189 | switch (state) { |
| 12190 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12191 | /* Non-fatal error, prepare for recovery */ |
| 12192 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12193 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12194 | case pci_channel_io_frozen: |
| 12195 | /* Fatal error, prepare for slot reset */ |
| 12196 | lpfc_sli_prep_dev_for_reset(phba); |
| 12197 | return PCI_ERS_RESULT_NEED_RESET; |
| 12198 | case pci_channel_io_perm_failure: |
| 12199 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12200 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12201 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12202 | default: |
| 12203 | /* Unknown state, prepare and request slot reset */ |
| 12204 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12205 | "0472 Unknown PCI error state: x%x\n", state); |
| 12206 | lpfc_sli_prep_dev_for_reset(phba); |
| 12207 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12208 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12209 | } |
| 12210 | |
| 12211 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12212 | * 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] | 12213 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12214 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12215 | * This routine is called from the PCI subsystem for error handling to |
| 12216 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12217 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12218 | * During the PCI subsystem error recovery, after driver returns |
| 12219 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12220 | * recovery and then call this routine before calling the .resume method |
| 12221 | * to recover the device. This function will initialize the HBA device, |
| 12222 | * enable the interrupt, but it will just put the HBA to offline state |
| 12223 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12224 | * |
| 12225 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12226 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12227 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12228 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12229 | static pci_ers_result_t |
| 12230 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12231 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12232 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12233 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12234 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12235 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12236 | |
| 12237 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12238 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12239 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12240 | "PCI device after reset.\n"); |
| 12241 | return PCI_ERS_RESULT_DISCONNECT; |
| 12242 | } |
| 12243 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12244 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12245 | |
| 12246 | /* |
| 12247 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12248 | * device saved_state flag, need to save the restored state again. |
| 12249 | */ |
| 12250 | pci_save_state(pdev); |
| 12251 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12252 | if (pdev->is_busmaster) |
| 12253 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12254 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12255 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12256 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12257 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12258 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12259 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12260 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12261 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12263 | "0427 Cannot re-enable interrupt after " |
| 12264 | "slot reset.\n"); |
| 12265 | return PCI_ERS_RESULT_DISCONNECT; |
| 12266 | } else |
| 12267 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12268 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12269 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12270 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12271 | lpfc_offline(phba); |
| 12272 | lpfc_sli_brdrestart(phba); |
| 12273 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12274 | /* Log the current active interrupt mode */ |
| 12275 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12276 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12277 | return PCI_ERS_RESULT_RECOVERED; |
| 12278 | } |
| 12279 | |
| 12280 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12281 | * 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] | 12282 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12283 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12284 | * This routine is called from the PCI subsystem for error handling to device |
| 12285 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12286 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12287 | * error recovery. After this call, traffic can start to flow from this device |
| 12288 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12289 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12290 | static void |
| 12291 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12292 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12293 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12294 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12295 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12296 | /* 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] | 12297 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12298 | } |
| 12299 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12300 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12301 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12302 | * @phba: pointer to lpfc hba data structure. |
| 12303 | * |
| 12304 | * returns the number of ELS/CT IOCBs to reserve |
| 12305 | **/ |
| 12306 | int |
| 12307 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12308 | { |
| 12309 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12310 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12311 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12312 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12313 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12314 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12315 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12316 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12317 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12318 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12319 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12320 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12321 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12322 | else if (max_xri <= 2048) |
| 12323 | return 200; |
| 12324 | else |
| 12325 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12326 | } else |
| 12327 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12328 | } |
| 12329 | |
| 12330 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12331 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12332 | * @phba: pointer to lpfc hba data structure. |
| 12333 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12334 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12335 | **/ |
| 12336 | int |
| 12337 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12338 | { |
| 12339 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12340 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12341 | if (phba->nvmet_support) |
| 12342 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12343 | return max_xri; |
| 12344 | } |
| 12345 | |
| 12346 | |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12347 | static void |
| 12348 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12349 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12350 | const struct firmware *fw) |
| 12351 | { |
James Smart | a72d56b | 2018-05-04 20:37:52 -0700 | [diff] [blame] | 12352 | if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) || |
| 12353 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
| 12354 | magic_number != MAGIC_NUMER_G6) || |
| 12355 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
| 12356 | magic_number != MAGIC_NUMER_G7)) |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12358 | "3030 This firmware version is not supported on " |
| 12359 | "this HBA model. Device:%x Magic:%x Type:%x " |
| 12360 | "ID:%x Size %d %zd\n", |
| 12361 | phba->pcidev->device, magic_number, ftype, fid, |
| 12362 | fsize, fw->size); |
| 12363 | else |
| 12364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12365 | "3022 FW Download failed. Device:%x Magic:%x Type:%x " |
| 12366 | "ID:%x Size %d %zd\n", |
| 12367 | phba->pcidev->device, magic_number, ftype, fid, |
| 12368 | fsize, fw->size); |
| 12369 | } |
| 12370 | |
| 12371 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12372 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12373 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12374 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12375 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12376 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12377 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12378 | static void |
| 12379 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12380 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12381 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12382 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12383 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12384 | struct list_head dma_buffer_list; |
| 12385 | int i, rc = 0; |
| 12386 | struct lpfc_dmabuf *dmabuf, *next; |
| 12387 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12388 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12389 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12390 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12391 | if (!fw) { |
| 12392 | rc = -ENXIO; |
| 12393 | goto out; |
| 12394 | } |
| 12395 | image = (struct lpfc_grp_hdr *)fw->data; |
| 12396 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12397 | magic_number = be32_to_cpu(image->magic_number); |
| 12398 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12399 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12400 | fsize = be32_to_cpu(image->size); |
| 12401 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12402 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12403 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12404 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12405 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12406 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12407 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12408 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12409 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 12410 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 12411 | GFP_KERNEL); |
| 12412 | if (!dmabuf) { |
| 12413 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12414 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12415 | } |
| 12416 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 12417 | SLI4_PAGE_SIZE, |
| 12418 | &dmabuf->phys, |
| 12419 | GFP_KERNEL); |
| 12420 | if (!dmabuf->virt) { |
| 12421 | kfree(dmabuf); |
| 12422 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12423 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12424 | } |
| 12425 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 12426 | } |
| 12427 | while (offset < fw->size) { |
| 12428 | temp_offset = offset; |
| 12429 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12430 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12431 | memcpy(dmabuf->virt, |
| 12432 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12433 | fw->size - temp_offset); |
| 12434 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12435 | break; |
| 12436 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12437 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 12438 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12439 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12440 | } |
| 12441 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 12442 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12443 | if (rc) { |
| 12444 | lpfc_log_write_firmware_error(phba, offset, |
| 12445 | magic_number, ftype, fid, fsize, fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12446 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12447 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12448 | } |
| 12449 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12450 | } else |
| 12451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12452 | "3029 Skipped Firmware update, Current " |
| 12453 | "Version:%s New Version:%s\n", |
| 12454 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12455 | |
| 12456 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12457 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 12458 | list_del(&dmabuf->list); |
| 12459 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 12460 | dmabuf->virt, dmabuf->phys); |
| 12461 | kfree(dmabuf); |
| 12462 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12463 | release_firmware(fw); |
| 12464 | out: |
| 12465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12466 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12467 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12468 | } |
| 12469 | |
| 12470 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12471 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 12472 | * @phba: pointer to lpfc hba data structure. |
| 12473 | * |
| 12474 | * This routine is called to perform Linux generic firmware upgrade on device |
| 12475 | * that supports such feature. |
| 12476 | **/ |
| 12477 | int |
| 12478 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 12479 | { |
| 12480 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 12481 | int ret; |
| 12482 | const struct firmware *fw; |
| 12483 | |
| 12484 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12485 | 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] | 12486 | LPFC_SLI_INTF_IF_TYPE_2) |
| 12487 | return -EPERM; |
| 12488 | |
| 12489 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 12490 | |
| 12491 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 12492 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 12493 | file_name, &phba->pcidev->dev, |
| 12494 | GFP_KERNEL, (void *)phba, |
| 12495 | lpfc_write_firmware); |
| 12496 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 12497 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 12498 | if (!ret) |
| 12499 | lpfc_write_firmware(fw, (void *)phba); |
| 12500 | } else { |
| 12501 | ret = -EINVAL; |
| 12502 | } |
| 12503 | |
| 12504 | return ret; |
| 12505 | } |
| 12506 | |
| 12507 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12508 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 12509 | * @pdev: pointer to PCI device |
| 12510 | * @pid: pointer to PCI device identifier |
| 12511 | * |
| 12512 | * This routine is called from the kernel's PCI subsystem to device with |
| 12513 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12514 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12515 | * information of the device and driver to see if the driver state that it |
| 12516 | * can support this kind of device. If the match is successful, the driver |
| 12517 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 12518 | * it does all the initialization that it needs to do to handle the HBA |
| 12519 | * properly. |
| 12520 | * |
| 12521 | * Return code |
| 12522 | * 0 - driver can claim the device |
| 12523 | * negative value - driver can not claim the device |
| 12524 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12525 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12526 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12527 | { |
| 12528 | struct lpfc_hba *phba; |
| 12529 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12530 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12531 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12532 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12533 | |
| 12534 | /* Allocate memory for HBA structure */ |
| 12535 | phba = lpfc_hba_alloc(pdev); |
| 12536 | if (!phba) |
| 12537 | return -ENOMEM; |
| 12538 | |
| 12539 | /* Perform generic PCI device enabling operation */ |
| 12540 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12541 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12542 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12543 | |
| 12544 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 12545 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 12546 | if (error) |
| 12547 | goto out_disable_pci_dev; |
| 12548 | |
| 12549 | /* Set up SLI-4 specific device PCI memory space */ |
| 12550 | error = lpfc_sli4_pci_mem_setup(phba); |
| 12551 | if (error) { |
| 12552 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12553 | "1410 Failed to set up pci memory space.\n"); |
| 12554 | goto out_disable_pci_dev; |
| 12555 | } |
| 12556 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12557 | /* Set up SLI-4 Specific device driver resources */ |
| 12558 | error = lpfc_sli4_driver_resource_setup(phba); |
| 12559 | if (error) { |
| 12560 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12561 | "1412 Failed to set up driver resource.\n"); |
| 12562 | goto out_unset_pci_mem_s4; |
| 12563 | } |
| 12564 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12565 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 12566 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 12567 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12568 | /* Set up common device driver resources */ |
| 12569 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12570 | if (error) { |
| 12571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12572 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 12573 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12574 | } |
| 12575 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12576 | /* Get the default values for Model Name and Description */ |
| 12577 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12578 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12579 | /* Now, trying to enable interrupt and bring up the device */ |
| 12580 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12581 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12582 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12583 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12584 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12585 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12586 | /* Configure and enable interrupt */ |
| 12587 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 12588 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12590 | "0426 Failed to enable interrupt.\n"); |
| 12591 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12592 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12593 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12594 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12595 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12596 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12597 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 12598 | if (phba->nvmet_support) |
| 12599 | phba->cfg_nvmet_mrq = 1; |
| 12600 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12601 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12602 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12603 | |
| 12604 | /* Create SCSI host to the physical port */ |
| 12605 | error = lpfc_create_shost(phba); |
| 12606 | if (error) { |
| 12607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12608 | "1415 Failed to create scsi host.\n"); |
| 12609 | goto out_disable_intr; |
| 12610 | } |
| 12611 | vport = phba->pport; |
| 12612 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 12613 | |
| 12614 | /* Configure sysfs attributes */ |
| 12615 | error = lpfc_alloc_sysfs_attr(vport); |
| 12616 | if (error) { |
| 12617 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12618 | "1416 Failed to allocate sysfs attr\n"); |
| 12619 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12620 | } |
| 12621 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12622 | /* Set up SLI-4 HBA */ |
| 12623 | if (lpfc_sli4_hba_setup(phba)) { |
| 12624 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12625 | "1421 Failed to set up hba\n"); |
| 12626 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12627 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 12628 | } |
| 12629 | |
| 12630 | /* Log the current active interrupt mode */ |
| 12631 | phba->intr_mode = intr_mode; |
| 12632 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12633 | |
| 12634 | /* Perform post initialization setup */ |
| 12635 | lpfc_post_init_setup(phba); |
| 12636 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12637 | /* NVME support in FW earlier in the driver load corrects the |
| 12638 | * FC4 type making a check for nvme_support unnecessary. |
| 12639 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12640 | if (phba->nvmet_support == 0) { |
| 12641 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12642 | /* Create NVME binding with nvme_fc_transport. This |
| 12643 | * ensures the vport is initialized. If the localport |
| 12644 | * create fails, it should not unload the driver to |
| 12645 | * support field issues. |
| 12646 | */ |
| 12647 | error = lpfc_nvme_create_localport(vport); |
| 12648 | if (error) { |
| 12649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12650 | "6004 NVME registration " |
| 12651 | "failed, error x%x\n", |
| 12652 | error); |
| 12653 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12654 | } |
| 12655 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12656 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12657 | /* check for firmware upgrade or downgrade */ |
| 12658 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 12659 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12660 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 12661 | /* Check if there are static vports to be created. */ |
| 12662 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12663 | |
| 12664 | /* Enable RAS FW log support */ |
| 12665 | lpfc_sli4_ras_setup(phba); |
| 12666 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12667 | return 0; |
| 12668 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12669 | out_free_sysfs_attr: |
| 12670 | lpfc_free_sysfs_attr(vport); |
| 12671 | out_destroy_shost: |
| 12672 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12673 | out_disable_intr: |
| 12674 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12675 | out_unset_driver_resource: |
| 12676 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12677 | out_unset_driver_resource_s4: |
| 12678 | lpfc_sli4_driver_resource_unset(phba); |
| 12679 | out_unset_pci_mem_s4: |
| 12680 | lpfc_sli4_pci_mem_unset(phba); |
| 12681 | out_disable_pci_dev: |
| 12682 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12683 | if (shost) |
| 12684 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12685 | out_free_phba: |
| 12686 | lpfc_hba_free(phba); |
| 12687 | return error; |
| 12688 | } |
| 12689 | |
| 12690 | /** |
| 12691 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 12692 | * @pdev: pointer to PCI device |
| 12693 | * |
| 12694 | * This routine is called from the kernel's PCI subsystem to device with |
| 12695 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 12696 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12697 | * device to be removed from the PCI subsystem properly. |
| 12698 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12699 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12700 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 12701 | { |
| 12702 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12703 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 12704 | struct lpfc_vport **vports; |
| 12705 | struct lpfc_hba *phba = vport->phba; |
| 12706 | int i; |
| 12707 | |
| 12708 | /* Mark the device unloading flag */ |
| 12709 | spin_lock_irq(&phba->hbalock); |
| 12710 | vport->load_flag |= FC_UNLOADING; |
| 12711 | spin_unlock_irq(&phba->hbalock); |
| 12712 | |
| 12713 | /* Free the HBA sysfs attributes */ |
| 12714 | lpfc_free_sysfs_attr(vport); |
| 12715 | |
| 12716 | /* Release all the vports against this physical port */ |
| 12717 | vports = lpfc_create_vport_work_array(phba); |
| 12718 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12719 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12720 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12721 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12722 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12723 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12724 | lpfc_destroy_vport_work_array(phba, vports); |
| 12725 | |
| 12726 | /* Remove FC host and then SCSI host with the physical port */ |
| 12727 | fc_remove_host(shost); |
| 12728 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12729 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12730 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 12731 | * localports are destroyed after to cleanup all transport memory. |
| 12732 | */ |
| 12733 | lpfc_cleanup(vport); |
| 12734 | lpfc_nvmet_destroy_targetport(phba); |
| 12735 | lpfc_nvme_destroy_localport(vport); |
| 12736 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 12737 | /* De-allocate multi-XRI pools */ |
| 12738 | if (phba->cfg_xri_rebalancing) |
| 12739 | lpfc_destroy_multixri_pools(phba); |
| 12740 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 12741 | /* |
| 12742 | * Bring down the SLI Layer. This step disables all interrupts, |
| 12743 | * clears the rings, discards all mailbox commands, and resets |
| 12744 | * the HBA FCoE function. |
| 12745 | */ |
| 12746 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12747 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 12748 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12749 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12750 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12751 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12752 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12753 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12754 | * buffers are released to their corresponding pools here. |
| 12755 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12756 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 12757 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12758 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12759 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 12760 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12761 | lpfc_sli4_driver_resource_unset(phba); |
| 12762 | |
| 12763 | /* Unmap adapter Control and Doorbell registers */ |
| 12764 | lpfc_sli4_pci_mem_unset(phba); |
| 12765 | |
| 12766 | /* Release PCI resources and disable device's PCI function */ |
| 12767 | scsi_host_put(shost); |
| 12768 | lpfc_disable_pci_dev(phba); |
| 12769 | |
| 12770 | /* Finally, free the driver's device data structure */ |
| 12771 | lpfc_hba_free(phba); |
| 12772 | |
| 12773 | return; |
| 12774 | } |
| 12775 | |
| 12776 | /** |
| 12777 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 12778 | * @pdev: pointer to PCI device |
| 12779 | * @msg: power management message |
| 12780 | * |
| 12781 | * This routine is called from the kernel's PCI subsystem to support system |
| 12782 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 12783 | * this method, it quiesces the device by stopping the driver's worker |
| 12784 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 12785 | * the device offline. Note that as the driver implements the minimum PM |
| 12786 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 12787 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 12788 | * method call will be treated as SUSPEND and the driver will fully |
| 12789 | * reinitialize its device during resume() method call, the driver will set |
| 12790 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 12791 | * according to the @msg provided by the PM. |
| 12792 | * |
| 12793 | * Return code |
| 12794 | * 0 - driver suspended the device |
| 12795 | * Error otherwise |
| 12796 | **/ |
| 12797 | static int |
| 12798 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 12799 | { |
| 12800 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12801 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12802 | |
| 12803 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12804 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12805 | |
| 12806 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12807 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12808 | lpfc_offline(phba); |
| 12809 | kthread_stop(phba->worker_thread); |
| 12810 | |
| 12811 | /* Disable interrupt from device */ |
| 12812 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12813 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12814 | |
| 12815 | /* Save device state to PCI config space */ |
| 12816 | pci_save_state(pdev); |
| 12817 | pci_set_power_state(pdev, PCI_D3hot); |
| 12818 | |
| 12819 | return 0; |
| 12820 | } |
| 12821 | |
| 12822 | /** |
| 12823 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 12824 | * @pdev: pointer to PCI device |
| 12825 | * |
| 12826 | * This routine is called from the kernel's PCI subsystem to support system |
| 12827 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 12828 | * this method, it restores the device's PCI config space state and fully |
| 12829 | * reinitializes the device and brings it online. Note that as the driver |
| 12830 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 12831 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12832 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 12833 | * will fully reinitialize its device during resume() method call, the device |
| 12834 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 12835 | * state. |
| 12836 | * |
| 12837 | * Return code |
| 12838 | * 0 - driver suspended the device |
| 12839 | * Error otherwise |
| 12840 | **/ |
| 12841 | static int |
| 12842 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 12843 | { |
| 12844 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12845 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12846 | uint32_t intr_mode; |
| 12847 | int error; |
| 12848 | |
| 12849 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12850 | "0292 PCI device Power Management resume.\n"); |
| 12851 | |
| 12852 | /* Restore device state from PCI config space */ |
| 12853 | pci_set_power_state(pdev, PCI_D0); |
| 12854 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12855 | |
| 12856 | /* |
| 12857 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12858 | * device saved_state flag, need to save the restored state again. |
| 12859 | */ |
| 12860 | pci_save_state(pdev); |
| 12861 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12862 | if (pdev->is_busmaster) |
| 12863 | pci_set_master(pdev); |
| 12864 | |
| 12865 | /* Startup the kernel thread for this host adapter. */ |
| 12866 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12867 | "lpfc_worker_%d", phba->brd_no); |
| 12868 | if (IS_ERR(phba->worker_thread)) { |
| 12869 | error = PTR_ERR(phba->worker_thread); |
| 12870 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12871 | "0293 PM resume failed to start worker " |
| 12872 | "thread: error=x%x.\n", error); |
| 12873 | return error; |
| 12874 | } |
| 12875 | |
| 12876 | /* Configure and enable interrupt */ |
| 12877 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 12878 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12879 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12880 | "0294 PM resume Failed to enable interrupt\n"); |
| 12881 | return -EIO; |
| 12882 | } else |
| 12883 | phba->intr_mode = intr_mode; |
| 12884 | |
| 12885 | /* Restart HBA and bring it online */ |
| 12886 | lpfc_sli_brdrestart(phba); |
| 12887 | lpfc_online(phba); |
| 12888 | |
| 12889 | /* Log the current active interrupt mode */ |
| 12890 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12891 | |
| 12892 | return 0; |
| 12893 | } |
| 12894 | |
| 12895 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12896 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 12897 | * @phba: pointer to lpfc hba data structure. |
| 12898 | * |
| 12899 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 12900 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 12901 | **/ |
| 12902 | static void |
| 12903 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12904 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12905 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12906 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 12907 | /* |
| 12908 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12909 | * and let the SCSI mid-layer to retry them to recover. |
| 12910 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12911 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12912 | } |
| 12913 | |
| 12914 | /** |
| 12915 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 12916 | * @phba: pointer to lpfc hba data structure. |
| 12917 | * |
| 12918 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 12919 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12920 | * pending I/Os. |
| 12921 | **/ |
| 12922 | static void |
| 12923 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12924 | { |
| 12925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12926 | "2826 PCI channel disable preparing for reset\n"); |
| 12927 | |
| 12928 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12929 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12930 | |
| 12931 | /* Block all SCSI devices' I/Os on the host */ |
| 12932 | lpfc_scsi_dev_block(phba); |
| 12933 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12934 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 12935 | lpfc_sli_flush_fcp_rings(phba); |
| 12936 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12937 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12938 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12939 | lpfc_sli_flush_nvme_rings(phba); |
| 12940 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12941 | /* stop all timers */ |
| 12942 | lpfc_stop_hba_timers(phba); |
| 12943 | |
| 12944 | /* Disable interrupt and pci device */ |
| 12945 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 12946 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12947 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12948 | } |
| 12949 | |
| 12950 | /** |
| 12951 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 12952 | * @phba: pointer to lpfc hba data structure. |
| 12953 | * |
| 12954 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 12955 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12956 | * pending I/Os. |
| 12957 | **/ |
| 12958 | static void |
| 12959 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 12960 | { |
| 12961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12962 | "2827 PCI channel permanent disable for failure\n"); |
| 12963 | |
| 12964 | /* Block all SCSI devices' I/Os on the host */ |
| 12965 | lpfc_scsi_dev_block(phba); |
| 12966 | |
| 12967 | /* stop all timers */ |
| 12968 | lpfc_stop_hba_timers(phba); |
| 12969 | |
| 12970 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 12971 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 12972 | |
| 12973 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 12974 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 12975 | lpfc_sli_flush_nvme_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12976 | } |
| 12977 | |
| 12978 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12979 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 12980 | * @pdev: pointer to PCI device. |
| 12981 | * @state: the current PCI connection state. |
| 12982 | * |
| 12983 | * This routine is called from the PCI subsystem for error handling to device |
| 12984 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 12985 | * after a PCI bus error affecting this device has been detected. When this |
| 12986 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 12987 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 12988 | * for the PCI subsystem to perform proper recovery as desired. |
| 12989 | * |
| 12990 | * Return codes |
| 12991 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12992 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12993 | **/ |
| 12994 | static pci_ers_result_t |
| 12995 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 12996 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12997 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12998 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12999 | |
| 13000 | switch (state) { |
| 13001 | case pci_channel_io_normal: |
| 13002 | /* Non-fatal error, prepare for recovery */ |
| 13003 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13004 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13005 | case pci_channel_io_frozen: |
| 13006 | /* Fatal error, prepare for slot reset */ |
| 13007 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13008 | return PCI_ERS_RESULT_NEED_RESET; |
| 13009 | case pci_channel_io_perm_failure: |
| 13010 | /* Permanent failure, prepare for device down */ |
| 13011 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13012 | return PCI_ERS_RESULT_DISCONNECT; |
| 13013 | default: |
| 13014 | /* Unknown state, prepare and request slot reset */ |
| 13015 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13016 | "2825 Unknown PCI error state: x%x\n", state); |
| 13017 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13018 | return PCI_ERS_RESULT_NEED_RESET; |
| 13019 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13020 | } |
| 13021 | |
| 13022 | /** |
| 13023 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13024 | * @pdev: pointer to PCI device. |
| 13025 | * |
| 13026 | * This routine is called from the PCI subsystem for error handling to device |
| 13027 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13028 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13029 | * PCI subsystem error recovery, after the driver returns |
| 13030 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13031 | * recovery and then call this routine before calling the .resume method to |
| 13032 | * recover the device. This function will initialize the HBA device, enable |
| 13033 | * the interrupt, but it will just put the HBA to offline state without |
| 13034 | * passing any I/O traffic. |
| 13035 | * |
| 13036 | * Return codes |
| 13037 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13038 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13039 | */ |
| 13040 | static pci_ers_result_t |
| 13041 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13042 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13043 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13044 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13045 | struct lpfc_sli *psli = &phba->sli; |
| 13046 | uint32_t intr_mode; |
| 13047 | |
| 13048 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13049 | if (pci_enable_device_mem(pdev)) { |
| 13050 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13051 | "PCI device after reset.\n"); |
| 13052 | return PCI_ERS_RESULT_DISCONNECT; |
| 13053 | } |
| 13054 | |
| 13055 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13056 | |
| 13057 | /* |
| 13058 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13059 | * device saved_state flag, need to save the restored state again. |
| 13060 | */ |
| 13061 | pci_save_state(pdev); |
| 13062 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13063 | if (pdev->is_busmaster) |
| 13064 | pci_set_master(pdev); |
| 13065 | |
| 13066 | spin_lock_irq(&phba->hbalock); |
| 13067 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13068 | spin_unlock_irq(&phba->hbalock); |
| 13069 | |
| 13070 | /* Configure and enable interrupt */ |
| 13071 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13072 | if (intr_mode == LPFC_INTR_ERROR) { |
| 13073 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13074 | "2824 Cannot re-enable interrupt after " |
| 13075 | "slot reset.\n"); |
| 13076 | return PCI_ERS_RESULT_DISCONNECT; |
| 13077 | } else |
| 13078 | phba->intr_mode = intr_mode; |
| 13079 | |
| 13080 | /* Log the current active interrupt mode */ |
| 13081 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13082 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13083 | return PCI_ERS_RESULT_RECOVERED; |
| 13084 | } |
| 13085 | |
| 13086 | /** |
| 13087 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13088 | * @pdev: pointer to PCI device |
| 13089 | * |
| 13090 | * This routine is called from the PCI subsystem for error handling to device |
| 13091 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13092 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13093 | * error recovery. After this call, traffic can start to flow from this device |
| 13094 | * again. |
| 13095 | **/ |
| 13096 | static void |
| 13097 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13098 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13099 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13100 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13101 | |
| 13102 | /* |
| 13103 | * In case of slot reset, as function reset is performed through |
| 13104 | * mailbox command which needs DMA to be enabled, this operation |
| 13105 | * has to be moved to the io resume phase. Taking device offline |
| 13106 | * will perform the necessary cleanup. |
| 13107 | */ |
| 13108 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13109 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13110 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13111 | lpfc_offline(phba); |
| 13112 | lpfc_sli_brdrestart(phba); |
| 13113 | /* Bring the device back online */ |
| 13114 | lpfc_online(phba); |
| 13115 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13116 | } |
| 13117 | |
| 13118 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13119 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13120 | * @pdev: pointer to PCI device |
| 13121 | * @pid: pointer to PCI device identifier |
| 13122 | * |
| 13123 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13124 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13125 | * at PCI device-specific information of the device and driver to see if the |
| 13126 | * driver state that it can support this kind of device. If the match is |
| 13127 | * successful, the driver core invokes this routine. This routine dispatches |
| 13128 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13129 | * do all the initialization that it needs to do to handle the HBA device |
| 13130 | * properly. |
| 13131 | * |
| 13132 | * Return code |
| 13133 | * 0 - driver can claim the device |
| 13134 | * negative value - driver can not claim the device |
| 13135 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13136 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13137 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13138 | { |
| 13139 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13140 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13141 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13142 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13143 | return -ENODEV; |
| 13144 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13145 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13146 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13147 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13148 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13149 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13150 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13151 | return rc; |
| 13152 | } |
| 13153 | |
| 13154 | /** |
| 13155 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13156 | * @pdev: pointer to PCI device |
| 13157 | * |
| 13158 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13159 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13160 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13161 | * remove routine, which will perform all the necessary cleanup for the |
| 13162 | * device to be removed from the PCI subsystem properly. |
| 13163 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13164 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13165 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13166 | { |
| 13167 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13168 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13169 | |
| 13170 | switch (phba->pci_dev_grp) { |
| 13171 | case LPFC_PCI_DEV_LP: |
| 13172 | lpfc_pci_remove_one_s3(pdev); |
| 13173 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13174 | case LPFC_PCI_DEV_OC: |
| 13175 | lpfc_pci_remove_one_s4(pdev); |
| 13176 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13177 | default: |
| 13178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13179 | "1424 Invalid PCI device group: 0x%x\n", |
| 13180 | phba->pci_dev_grp); |
| 13181 | break; |
| 13182 | } |
| 13183 | return; |
| 13184 | } |
| 13185 | |
| 13186 | /** |
| 13187 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 13188 | * @pdev: pointer to PCI device |
| 13189 | * @msg: power management message |
| 13190 | * |
| 13191 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13192 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13193 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13194 | * suspend the device. |
| 13195 | * |
| 13196 | * Return code |
| 13197 | * 0 - driver suspended the device |
| 13198 | * Error otherwise |
| 13199 | **/ |
| 13200 | static int |
| 13201 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 13202 | { |
| 13203 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13204 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13205 | int rc = -ENODEV; |
| 13206 | |
| 13207 | switch (phba->pci_dev_grp) { |
| 13208 | case LPFC_PCI_DEV_LP: |
| 13209 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 13210 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13211 | case LPFC_PCI_DEV_OC: |
| 13212 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 13213 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13214 | default: |
| 13215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13216 | "1425 Invalid PCI device group: 0x%x\n", |
| 13217 | phba->pci_dev_grp); |
| 13218 | break; |
| 13219 | } |
| 13220 | return rc; |
| 13221 | } |
| 13222 | |
| 13223 | /** |
| 13224 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 13225 | * @pdev: pointer to PCI device |
| 13226 | * |
| 13227 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13228 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13229 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13230 | * resume the device. |
| 13231 | * |
| 13232 | * Return code |
| 13233 | * 0 - driver suspended the device |
| 13234 | * Error otherwise |
| 13235 | **/ |
| 13236 | static int |
| 13237 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 13238 | { |
| 13239 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13240 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13241 | int rc = -ENODEV; |
| 13242 | |
| 13243 | switch (phba->pci_dev_grp) { |
| 13244 | case LPFC_PCI_DEV_LP: |
| 13245 | rc = lpfc_pci_resume_one_s3(pdev); |
| 13246 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13247 | case LPFC_PCI_DEV_OC: |
| 13248 | rc = lpfc_pci_resume_one_s4(pdev); |
| 13249 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13250 | default: |
| 13251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13252 | "1426 Invalid PCI device group: 0x%x\n", |
| 13253 | phba->pci_dev_grp); |
| 13254 | break; |
| 13255 | } |
| 13256 | return rc; |
| 13257 | } |
| 13258 | |
| 13259 | /** |
| 13260 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13261 | * @pdev: pointer to PCI device. |
| 13262 | * @state: the current PCI connection state. |
| 13263 | * |
| 13264 | * This routine is registered to the PCI subsystem for error handling. This |
| 13265 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13266 | * this device has been detected. When this routine is invoked, it dispatches |
| 13267 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13268 | * routine, which will perform the proper error detected operation. |
| 13269 | * |
| 13270 | * Return codes |
| 13271 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13272 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13273 | **/ |
| 13274 | static pci_ers_result_t |
| 13275 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13276 | { |
| 13277 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13278 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13279 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13280 | |
| 13281 | switch (phba->pci_dev_grp) { |
| 13282 | case LPFC_PCI_DEV_LP: |
| 13283 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13284 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13285 | case LPFC_PCI_DEV_OC: |
| 13286 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13287 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13288 | default: |
| 13289 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13290 | "1427 Invalid PCI device group: 0x%x\n", |
| 13291 | phba->pci_dev_grp); |
| 13292 | break; |
| 13293 | } |
| 13294 | return rc; |
| 13295 | } |
| 13296 | |
| 13297 | /** |
| 13298 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13299 | * @pdev: pointer to PCI device. |
| 13300 | * |
| 13301 | * This routine is registered to the PCI subsystem for error handling. This |
| 13302 | * function is called after PCI bus has been reset to restart the PCI card |
| 13303 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13304 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13305 | * routine, which will perform the proper device reset. |
| 13306 | * |
| 13307 | * Return codes |
| 13308 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13309 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13310 | **/ |
| 13311 | static pci_ers_result_t |
| 13312 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13313 | { |
| 13314 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13315 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13316 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13317 | |
| 13318 | switch (phba->pci_dev_grp) { |
| 13319 | case LPFC_PCI_DEV_LP: |
| 13320 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13321 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13322 | case LPFC_PCI_DEV_OC: |
| 13323 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13324 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13325 | default: |
| 13326 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13327 | "1428 Invalid PCI device group: 0x%x\n", |
| 13328 | phba->pci_dev_grp); |
| 13329 | break; |
| 13330 | } |
| 13331 | return rc; |
| 13332 | } |
| 13333 | |
| 13334 | /** |
| 13335 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13336 | * @pdev: pointer to PCI device |
| 13337 | * |
| 13338 | * This routine is registered to the PCI subsystem for error handling. It |
| 13339 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13340 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13341 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13342 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13343 | **/ |
| 13344 | static void |
| 13345 | lpfc_io_resume(struct pci_dev *pdev) |
| 13346 | { |
| 13347 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13348 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13349 | |
| 13350 | switch (phba->pci_dev_grp) { |
| 13351 | case LPFC_PCI_DEV_LP: |
| 13352 | lpfc_io_resume_s3(pdev); |
| 13353 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13354 | case LPFC_PCI_DEV_OC: |
| 13355 | lpfc_io_resume_s4(pdev); |
| 13356 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13357 | default: |
| 13358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13359 | "1429 Invalid PCI device group: 0x%x\n", |
| 13360 | phba->pci_dev_grp); |
| 13361 | break; |
| 13362 | } |
| 13363 | return; |
| 13364 | } |
| 13365 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13366 | /** |
| 13367 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13368 | * @phba: pointer to lpfc hba data structure. |
| 13369 | * |
| 13370 | * This routine checks to see if OAS is supported for this adapter. If |
| 13371 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13372 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13373 | * is destroyed. |
| 13374 | * |
| 13375 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13376 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13377 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13378 | { |
| 13379 | |
| 13380 | if (!phba->cfg_EnableXLane) |
| 13381 | return; |
| 13382 | |
| 13383 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13384 | phba->cfg_fof = 1; |
| 13385 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13386 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13387 | if (phba->device_data_mem_pool) |
| 13388 | mempool_destroy(phba->device_data_mem_pool); |
| 13389 | phba->device_data_mem_pool = NULL; |
| 13390 | } |
| 13391 | |
| 13392 | return; |
| 13393 | } |
| 13394 | |
| 13395 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13396 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13397 | * @phba: pointer to lpfc hba data structure. |
| 13398 | * |
| 13399 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13400 | * function through which RAS support enablement is to be done. |
| 13401 | **/ |
| 13402 | void |
| 13403 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 13404 | { |
| 13405 | switch (phba->pcidev->device) { |
| 13406 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 13407 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 13408 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 13409 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 13410 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13411 | phba->ras_fwlog.ras_enabled = true; |
| 13412 | else |
| 13413 | phba->ras_fwlog.ras_enabled = false; |
| 13414 | break; |
| 13415 | default: |
| 13416 | phba->ras_fwlog.ras_hwsupport = false; |
| 13417 | } |
| 13418 | } |
| 13419 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13420 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13421 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 13422 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 13423 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 13424 | .error_detected = lpfc_io_error_detected, |
| 13425 | .slot_reset = lpfc_io_slot_reset, |
| 13426 | .resume = lpfc_io_resume, |
| 13427 | }; |
| 13428 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13429 | static struct pci_driver lpfc_driver = { |
| 13430 | .name = LPFC_DRIVER_NAME, |
| 13431 | .id_table = lpfc_id_table, |
| 13432 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13433 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 13434 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 13435 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13436 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13437 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13438 | }; |
| 13439 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13440 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 13441 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13442 | }; |
| 13443 | |
| 13444 | static struct miscdevice lpfc_mgmt_dev = { |
| 13445 | .minor = MISC_DYNAMIC_MINOR, |
| 13446 | .name = "lpfcmgmt", |
| 13447 | .fops = &lpfc_mgmt_fop, |
| 13448 | }; |
| 13449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13451 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13452 | * |
| 13453 | * This routine is to be invoked when the lpfc module is loaded into the |
| 13454 | * kernel. The special kernel macro module_init() is used to indicate the |
| 13455 | * role of this routine to the kernel as lpfc module entry point. |
| 13456 | * |
| 13457 | * Return codes |
| 13458 | * 0 - successful |
| 13459 | * -ENOMEM - FC attach transport failed |
| 13460 | * all others - failed |
| 13461 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13462 | static int __init |
| 13463 | lpfc_init(void) |
| 13464 | { |
| 13465 | int error = 0; |
| 13466 | |
| 13467 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 13468 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13469 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13470 | error = misc_register(&lpfc_mgmt_dev); |
| 13471 | if (error) |
| 13472 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 13473 | "misc_register returned with status %d", error); |
| 13474 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13475 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 13476 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13477 | lpfc_transport_template = |
| 13478 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13479 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13480 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13481 | lpfc_vport_transport_template = |
| 13482 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 13483 | if (lpfc_vport_transport_template == NULL) { |
| 13484 | fc_release_transport(lpfc_transport_template); |
| 13485 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 13486 | } |
James Smart | 5fd1108 | 2018-03-05 12:04:04 -0800 | [diff] [blame] | 13487 | lpfc_nvme_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 13488 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13489 | |
| 13490 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 13491 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 13492 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13493 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13494 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13495 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13496 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 13497 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13498 | |
| 13499 | return error; |
| 13500 | } |
| 13501 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13502 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13503 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13504 | * |
| 13505 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 13506 | * The special kernel macro module_exit() is used to indicate the role of |
| 13507 | * this routine to the kernel as lpfc module exit point. |
| 13508 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13509 | static void __exit |
| 13510 | lpfc_exit(void) |
| 13511 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13512 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13513 | pci_unregister_driver(&lpfc_driver); |
| 13514 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 13515 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13516 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13517 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 13518 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13519 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 13520 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 13521 | } |
| 13522 | |
| 13523 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 13524 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 13525 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 13526 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 13527 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 13528 | } |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 13529 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13530 | } |
| 13531 | |
| 13532 | module_init(lpfc_init); |
| 13533 | module_exit(lpfc_exit); |
| 13534 | MODULE_LICENSE("GPL"); |
| 13535 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 13536 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13537 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |