| 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 | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * 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] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/idr.h> |
| 26 | #include <linux/interrupt.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <linux/kthread.h> |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 31 | #include <linux/ctype.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 32 | #include <linux/aer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 34 | #include <linux/firmware.h> |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 35 | #include <linux/miscdevice.h> |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 36 | #include <linux/percpu.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 38 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include <scsi/scsi_device.h> |
| 40 | #include <scsi/scsi_host.h> |
| 41 | #include <scsi/scsi_transport_fc.h> |
| 42 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 43 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc_hw.h" |
| 45 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 46 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 47 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc_disc.h" |
| 49 | #include "lpfc_scsi.h" |
| 50 | #include "lpfc.h" |
| 51 | #include "lpfc_logmsg.h" |
| 52 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_version.h" |
| 55 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 56 | char *_dump_buf_data; |
| 57 | unsigned long _dump_buf_data_order; |
| 58 | char *_dump_buf_dif; |
| 59 | unsigned long _dump_buf_dif_order; |
| 60 | spinlock_t _dump_buf_lock; |
| 61 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 62 | /* Used when mapping IRQ vectors in a driver centric manner */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 63 | uint16_t *lpfc_used_cpu; |
| 64 | uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 65 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 66 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 67 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 68 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 69 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 70 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 71 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 72 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
| 73 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 74 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 75 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 76 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 77 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 78 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 79 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 80 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 81 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 82 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 83 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 84 | |
| 85 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 86 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 87 | static DEFINE_IDR(lpfc_hba_index); |
| 88 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 89 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 90 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 91 | * @phba: pointer to lpfc hba data structure. |
| 92 | * |
| 93 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 94 | * mailbox command. It retrieves the revision information from the HBA and |
| 95 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 96 | * configuration of the HBA. |
| 97 | * |
| 98 | * Return codes: |
| 99 | * 0 - success. |
| 100 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 101 | * Any other value - indicates an error. |
| 102 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 104 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 105 | { |
| 106 | lpfc_vpd_t *vp = &phba->vpd; |
| 107 | int i = 0, rc; |
| 108 | LPFC_MBOXQ_t *pmb; |
| 109 | MAILBOX_t *mb; |
| 110 | char *lpfc_vpd_data = NULL; |
| 111 | uint16_t offset = 0; |
| 112 | static char licensed[56] = |
| 113 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 114 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 115 | |
| 116 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 117 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 118 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | return -ENOMEM; |
| 120 | } |
| 121 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 122 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 123 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 124 | |
| 125 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 126 | if (init_key) { |
| 127 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 129 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 130 | *ptext = cpu_to_be32(*ptext); |
| 131 | init_key = 0; |
| 132 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 133 | |
| 134 | lpfc_read_nv(phba, pmb); |
| 135 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 136 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 137 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 138 | sizeof (licensed)); |
| 139 | |
| 140 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 141 | |
| 142 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 143 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 144 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 145 | "error, mbxCmd x%x READ_NVPARM, " |
| 146 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | mb->mbxCommand, mb->mbxStatus); |
| 148 | mempool_free(pmb, phba->mbox_mem_pool); |
| 149 | return -ERESTART; |
| 150 | } |
| 151 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 152 | sizeof(phba->wwnn)); |
| 153 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 154 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | } |
| 156 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 157 | phba->sli3_options = 0x0; |
| 158 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | /* Setup and issue mailbox READ REV command */ |
| 160 | lpfc_read_rev(phba, pmb); |
| 161 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 162 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 164 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 166 | mb->mbxCommand, mb->mbxStatus); |
| 167 | mempool_free( pmb, phba->mbox_mem_pool); |
| 168 | return -ERESTART; |
| 169 | } |
| 170 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 171 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 172 | /* |
| 173 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 174 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 175 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 176 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 179 | "0440 Adapter failed to init, READ_REV has " |
| 180 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 181 | mempool_free(pmb, phba->mbox_mem_pool); |
| 182 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | } |
| 184 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 185 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 186 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 187 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 188 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 189 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 191 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 192 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 193 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 194 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 195 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 196 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 197 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 198 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 199 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 200 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 201 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 202 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 203 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 204 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 205 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 206 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 207 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 208 | /* If the sli feature level is less then 9, we must |
| 209 | * tear down all RPIs and VPIs on link down if NPIV |
| 210 | * is enabled. |
| 211 | */ |
| 212 | if (vp->rev.feaLevelHigh < 9) |
| 213 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 214 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 216 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 217 | sizeof (phba->RandomData)); |
| 218 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 220 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 221 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 222 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 224 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 226 | |
| 227 | if (rc != MBX_SUCCESS) { |
| 228 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 229 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 231 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 232 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 234 | /* dump mem may return a zero when finished or we got a |
| 235 | * mailbox error, either way we are done. |
| 236 | */ |
| 237 | if (mb->un.varDmp.word_cnt == 0) |
| 238 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 239 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 240 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 241 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 242 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 243 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 245 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 246 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | |
| 248 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | out_free_mbox: |
| 250 | mempool_free(pmb, phba->mbox_mem_pool); |
| 251 | return 0; |
| 252 | } |
| 253 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 254 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 255 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 256 | * @phba: pointer to lpfc hba data structure. |
| 257 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 258 | * |
| 259 | * This is the completion handler for driver's configuring asynchronous event |
| 260 | * mailbox command to the device. If the mailbox command returns successfully, |
| 261 | * it will set internal async event support flag to 1; otherwise, it will |
| 262 | * set internal async event support flag to 0. |
| 263 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 264 | static void |
| 265 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 266 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 267 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 268 | phba->temp_sensor_support = 1; |
| 269 | else |
| 270 | phba->temp_sensor_support = 0; |
| 271 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 272 | return; |
| 273 | } |
| 274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 276 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 277 | * @phba: pointer to lpfc hba data structure. |
| 278 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 279 | * |
| 280 | * This is the completion handler for dump mailbox command for getting |
| 281 | * wake up parameters. When this command complete, the response contain |
| 282 | * Option rom version of the HBA. This function translate the version number |
| 283 | * into a human readable string and store it in OptionROMVersion. |
| 284 | **/ |
| 285 | static void |
| 286 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 287 | { |
| 288 | struct prog_id *prg; |
| 289 | uint32_t prog_id_word; |
| 290 | char dist = ' '; |
| 291 | /* character array used for decoding dist type. */ |
| 292 | char dist_char[] = "nabx"; |
| 293 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 294 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 295 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 296 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 297 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 298 | |
| 299 | prg = (struct prog_id *) &prog_id_word; |
| 300 | |
| 301 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 302 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 303 | |
| 304 | /* Decode the Option rom version word to a readable string */ |
| 305 | if (prg->dist < 4) |
| 306 | dist = dist_char[prg->dist]; |
| 307 | |
| 308 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 309 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 310 | prg->ver, prg->rev, prg->lev); |
| 311 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 312 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 313 | prg->ver, prg->rev, prg->lev, |
| 314 | dist, prg->num); |
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; |
| 317 | } |
| 318 | |
| 319 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 320 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 321 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 322 | * @vport: pointer to lpfc vport data structure. |
| 323 | * |
| 324 | * |
| 325 | * Return codes |
| 326 | * None. |
| 327 | **/ |
| 328 | void |
| 329 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 330 | { |
| 331 | /* If the soft name exists then update it using the service params */ |
| 332 | if (vport->phba->cfg_soft_wwnn) |
| 333 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 334 | vport->fc_sparam.nodeName.u.wwn); |
| 335 | if (vport->phba->cfg_soft_wwpn) |
| 336 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 337 | vport->fc_sparam.portName.u.wwn); |
| 338 | |
| 339 | /* |
| 340 | * If the name is empty or there exists a soft name |
| 341 | * then copy the service params name, otherwise use the fc name |
| 342 | */ |
| 343 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 344 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 345 | sizeof(struct lpfc_name)); |
| 346 | else |
| 347 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 348 | sizeof(struct lpfc_name)); |
| 349 | |
| 350 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) |
| 351 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 352 | sizeof(struct lpfc_name)); |
| 353 | else |
| 354 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 355 | sizeof(struct lpfc_name)); |
| 356 | } |
| 357 | |
| 358 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 359 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 360 | * @phba: pointer to lpfc hba data structure. |
| 361 | * |
| 362 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 363 | * command call. It performs all internal resource and state setups on the |
| 364 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 365 | * ELS ring timers, etc. |
| 366 | * |
| 367 | * Return codes |
| 368 | * 0 - success. |
| 369 | * Any other value - error. |
| 370 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 371 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 372 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 374 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 375 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 376 | LPFC_MBOXQ_t *pmb; |
| 377 | MAILBOX_t *mb; |
| 378 | struct lpfc_dmabuf *mp; |
| 379 | struct lpfc_sli *psli = &phba->sli; |
| 380 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 381 | int i, j; |
| 382 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 383 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 384 | spin_lock_irq(&phba->hbalock); |
| 385 | /* |
| 386 | * If the Config port completed correctly the HBA is not |
| 387 | * over heated any more. |
| 388 | */ |
| 389 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 390 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 391 | spin_unlock_irq(&phba->hbalock); |
| 392 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 393 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 394 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 395 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 396 | return -ENOMEM; |
| 397 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 398 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 400 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 401 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 402 | if (rc) { |
| 403 | mempool_free(pmb, phba->mbox_mem_pool); |
| 404 | return -ENOMEM; |
| 405 | } |
| 406 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 407 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 410 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 415 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 417 | kfree(mp); |
| 418 | return -EIO; |
| 419 | } |
| 420 | |
| 421 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 422 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 423 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 425 | kfree(mp); |
| 426 | pmb->context1 = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 427 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 428 | |
| 429 | /* Update the fc_host data structures with new wwn. */ |
| 430 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 431 | 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] | 432 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 435 | /* This should be consolidated into parse_vpd ? - mr */ |
| 436 | if (phba->SerialNumber[0] == 0) { |
| 437 | uint8_t *outptr; |
| 438 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 439 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | for (i = 0; i < 12; i++) { |
| 441 | status = *outptr++; |
| 442 | j = ((status & 0xf0) >> 4); |
| 443 | if (j <= 9) |
| 444 | phba->SerialNumber[i] = |
| 445 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 446 | else |
| 447 | phba->SerialNumber[i] = |
| 448 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 449 | i++; |
| 450 | j = (status & 0xf); |
| 451 | if (j <= 9) |
| 452 | phba->SerialNumber[i] = |
| 453 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 454 | else |
| 455 | phba->SerialNumber[i] = |
| 456 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 457 | } |
| 458 | } |
| 459 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 461 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 464 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 465 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 466 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 467 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 468 | mempool_free( pmb, phba->mbox_mem_pool); |
| 469 | return -EIO; |
| 470 | } |
| 471 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 472 | /* Check if the port is disabled */ |
| 473 | lpfc_sli_read_link_ste(phba); |
| 474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 475 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 476 | i = (mb->un.varRdConfig.max_xri + 1); |
| 477 | if (phba->cfg_hba_queue_depth > i) { |
| 478 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 479 | "3359 HBA queue depth changed from %d to %d\n", |
| 480 | phba->cfg_hba_queue_depth, i); |
| 481 | phba->cfg_hba_queue_depth = i; |
| 482 | } |
| 483 | |
| 484 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 485 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 486 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 487 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 488 | "3360 LUN queue depth changed from %d to %d\n", |
| 489 | phba->pport->cfg_lun_queue_depth, i); |
| 490 | phba->pport->cfg_lun_queue_depth = i; |
| 491 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 492 | |
| 493 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 494 | |
| 495 | /* Get the default values for Model Name and Description */ |
| 496 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 498 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 500 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 501 | if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr) |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 502 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 503 | if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 505 | if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 507 | |
| 508 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 509 | if (phba->sli_rev != 3) |
| 510 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 512 | /* |
| 513 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 514 | */ |
| 515 | if (phba->intr_type == MSIX) { |
| 516 | rc = lpfc_config_msi(phba, pmb); |
| 517 | if (rc) { |
| 518 | mempool_free(pmb, phba->mbox_mem_pool); |
| 519 | return -EIO; |
| 520 | } |
| 521 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 522 | if (rc != MBX_SUCCESS) { |
| 523 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 524 | "0352 Config MSI mailbox command " |
| 525 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 526 | pmb->u.mb.mbxCommand, |
| 527 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 528 | mempool_free(pmb, phba->mbox_mem_pool); |
| 529 | return -EIO; |
| 530 | } |
| 531 | } |
| 532 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 533 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 534 | /* Initialize ERATT handling flag */ |
| 535 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 536 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 538 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 539 | spin_unlock_irq(&phba->hbalock); |
| 540 | return -EIO; |
| 541 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 543 | if (psli->num_rings > 0) |
| 544 | status |= HC_R0INT_ENA; |
| 545 | if (psli->num_rings > 1) |
| 546 | status |= HC_R1INT_ENA; |
| 547 | if (psli->num_rings > 2) |
| 548 | status |= HC_R2INT_ENA; |
| 549 | if (psli->num_rings > 3) |
| 550 | status |= HC_R3INT_ENA; |
| 551 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 552 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 553 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 554 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 555 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | writel(status, phba->HCregaddr); |
| 557 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 558 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 559 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 560 | /* Set up ring-0 (ELS) timer */ |
| 561 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 562 | mod_timer(&vport->els_tmofunc, |
| 563 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 564 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 565 | mod_timer(&phba->hb_tmofunc, |
| 566 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 567 | phba->hb_outstanding = 0; |
| 568 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 569 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 570 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 571 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 573 | if (phba->hba_flag & LINK_DISABLED) { |
| 574 | lpfc_printf_log(phba, |
| 575 | KERN_ERR, LOG_INIT, |
| 576 | "2598 Adapter Link is disabled.\n"); |
| 577 | lpfc_down_link(phba, pmb); |
| 578 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 579 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 580 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 581 | lpfc_printf_log(phba, |
| 582 | KERN_ERR, LOG_INIT, |
| 583 | "2599 Adapter failed to issue DOWN_LINK" |
| 584 | " mbox command rc 0x%x\n", rc); |
| 585 | |
| 586 | mempool_free(pmb, phba->mbox_mem_pool); |
| 587 | return -EIO; |
| 588 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 589 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 590 | mempool_free(pmb, phba->mbox_mem_pool); |
| 591 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 592 | if (rc) |
| 593 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | } |
| 595 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 596 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 597 | if (!pmb) { |
| 598 | phba->link_state = LPFC_HBA_ERROR; |
| 599 | return -ENOMEM; |
| 600 | } |
| 601 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 602 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 603 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 604 | pmb->vport = phba->pport; |
| 605 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 606 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 607 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 608 | lpfc_printf_log(phba, |
| 609 | KERN_ERR, |
| 610 | LOG_INIT, |
| 611 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 612 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 613 | rc); |
| 614 | mempool_free(pmb, phba->mbox_mem_pool); |
| 615 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 616 | |
| 617 | /* Get Option rom version */ |
| 618 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 619 | if (!pmb) { |
| 620 | phba->link_state = LPFC_HBA_ERROR; |
| 621 | return -ENOMEM; |
| 622 | } |
| 623 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 624 | lpfc_dump_wakeup_param(phba, pmb); |
| 625 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 626 | pmb->vport = phba->pport; |
| 627 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 628 | |
| 629 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 631 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 632 | mempool_free(pmb, phba->mbox_mem_pool); |
| 633 | } |
| 634 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 635 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 636 | } |
| 637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 638 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 639 | * lpfc_hba_init_link - Initialize the FC link |
| 640 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 641 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 642 | * |
| 643 | * This routine will issue the INIT_LINK mailbox command call. |
| 644 | * It is available to other drivers through the lpfc_hba data |
| 645 | * structure for use as a delayed link up mechanism with the |
| 646 | * module parameter lpfc_suppress_link_up. |
| 647 | * |
| 648 | * Return code |
| 649 | * 0 - success |
| 650 | * Any other value - error |
| 651 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 652 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 653 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 654 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 655 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 660 | * @phba: pointer to lpfc hba data structure. |
| 661 | * @fc_topology: desired fc topology. |
| 662 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 663 | * |
| 664 | * This routine will issue the INIT_LINK mailbox command call. |
| 665 | * It is available to other drivers through the lpfc_hba data |
| 666 | * structure for use as a delayed link up mechanism with the |
| 667 | * module parameter lpfc_suppress_link_up. |
| 668 | * |
| 669 | * Return code |
| 670 | * 0 - success |
| 671 | * Any other value - error |
| 672 | **/ |
| 673 | int |
| 674 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 675 | uint32_t flag) |
| 676 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 677 | struct lpfc_vport *vport = phba->pport; |
| 678 | LPFC_MBOXQ_t *pmb; |
| 679 | MAILBOX_t *mb; |
| 680 | int rc; |
| 681 | |
| 682 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 683 | if (!pmb) { |
| 684 | phba->link_state = LPFC_HBA_ERROR; |
| 685 | return -ENOMEM; |
| 686 | } |
| 687 | mb = &pmb->u.mb; |
| 688 | pmb->vport = vport; |
| 689 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 690 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 691 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 692 | !(phba->lmt & LMT_1Gb)) || |
| 693 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 694 | !(phba->lmt & LMT_2Gb)) || |
| 695 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 696 | !(phba->lmt & LMT_4Gb)) || |
| 697 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 698 | !(phba->lmt & LMT_8Gb)) || |
| 699 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 700 | !(phba->lmt & LMT_10Gb)) || |
| 701 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 702 | !(phba->lmt & LMT_16Gb)) || |
| 703 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
| 704 | !(phba->lmt & LMT_32Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 705 | /* Reset link speed to auto */ |
| 706 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 707 | "1302 Invalid speed for this board:%d " |
| 708 | "Reset link speed to auto.\n", |
| 709 | phba->cfg_link_speed); |
| 710 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 711 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 712 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 713 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 714 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 715 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 716 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 717 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 719 | "0498 Adapter failed to init, mbxCmd x%x " |
| 720 | "INIT_LINK, mbxStatus x%x\n", |
| 721 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 722 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 723 | /* Clear all interrupt enable conditions */ |
| 724 | writel(0, phba->HCregaddr); |
| 725 | readl(phba->HCregaddr); /* flush */ |
| 726 | /* Clear all pending interrupts */ |
| 727 | writel(0xffffffff, phba->HAregaddr); |
| 728 | readl(phba->HAregaddr); /* flush */ |
| 729 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 730 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 731 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 732 | mempool_free(pmb, phba->mbox_mem_pool); |
| 733 | return -EIO; |
| 734 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 735 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 736 | if (flag == MBX_POLL) |
| 737 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 744 | * @phba: pointer to lpfc hba data structure. |
| 745 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 746 | * |
| 747 | * This routine will issue the DOWN_LINK mailbox command call. |
| 748 | * It is available to other drivers through the lpfc_hba data |
| 749 | * structure for use to stop the link. |
| 750 | * |
| 751 | * Return code |
| 752 | * 0 - success |
| 753 | * Any other value - error |
| 754 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 755 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 756 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 757 | { |
| 758 | LPFC_MBOXQ_t *pmb; |
| 759 | int rc; |
| 760 | |
| 761 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 762 | if (!pmb) { |
| 763 | phba->link_state = LPFC_HBA_ERROR; |
| 764 | return -ENOMEM; |
| 765 | } |
| 766 | |
| 767 | lpfc_printf_log(phba, |
| 768 | KERN_ERR, LOG_INIT, |
| 769 | "0491 Adapter Link is disabled.\n"); |
| 770 | lpfc_down_link(phba, pmb); |
| 771 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 772 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 773 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 774 | lpfc_printf_log(phba, |
| 775 | KERN_ERR, LOG_INIT, |
| 776 | "2522 Adapter failed to issue DOWN_LINK" |
| 777 | " mbox command rc 0x%x\n", rc); |
| 778 | |
| 779 | mempool_free(pmb, phba->mbox_mem_pool); |
| 780 | return -EIO; |
| 781 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 782 | if (flag == MBX_POLL) |
| 783 | mempool_free(pmb, phba->mbox_mem_pool); |
| 784 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 789 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 790 | * @phba: pointer to lpfc HBA data structure. |
| 791 | * |
| 792 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 793 | * bringing down the SLI Layer. |
| 794 | * |
| 795 | * Return codes |
| 796 | * 0 - success. |
| 797 | * Any other value - error. |
| 798 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 800 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 802 | struct lpfc_vport **vports; |
| 803 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 804 | |
| 805 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 806 | /* Disable interrupts */ |
| 807 | writel(0, phba->HCregaddr); |
| 808 | readl(phba->HCregaddr); /* flush */ |
| 809 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 811 | if (phba->pport->load_flag & FC_UNLOADING) |
| 812 | lpfc_cleanup_discovery_resources(phba->pport); |
| 813 | else { |
| 814 | vports = lpfc_create_vport_work_array(phba); |
| 815 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 816 | for (i = 0; i <= phba->max_vports && |
| 817 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 818 | lpfc_cleanup_discovery_resources(vports[i]); |
| 819 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 820 | } |
| 821 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 822 | } |
| 823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 824 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 825 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 826 | * rspiocb which got deferred |
| 827 | * |
| 828 | * @phba: pointer to lpfc HBA data structure. |
| 829 | * |
| 830 | * This routine will cleanup completed slow path events after HBA is reset |
| 831 | * when bringing down the SLI Layer. |
| 832 | * |
| 833 | * |
| 834 | * Return codes |
| 835 | * void. |
| 836 | **/ |
| 837 | static void |
| 838 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 839 | { |
| 840 | struct lpfc_iocbq *rspiocbq; |
| 841 | struct hbq_dmabuf *dmabuf; |
| 842 | struct lpfc_cq_event *cq_event; |
| 843 | |
| 844 | spin_lock_irq(&phba->hbalock); |
| 845 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 846 | spin_unlock_irq(&phba->hbalock); |
| 847 | |
| 848 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 849 | /* Get the response iocb from the head of work queue */ |
| 850 | spin_lock_irq(&phba->hbalock); |
| 851 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 852 | cq_event, struct lpfc_cq_event, list); |
| 853 | spin_unlock_irq(&phba->hbalock); |
| 854 | |
| 855 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 856 | case CQE_CODE_COMPL_WQE: |
| 857 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 858 | cq_event); |
| 859 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 860 | break; |
| 861 | case CQE_CODE_RECEIVE: |
| 862 | case CQE_CODE_RECEIVE_V1: |
| 863 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 864 | cq_event); |
| 865 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 871 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 872 | * @phba: pointer to lpfc HBA data structure. |
| 873 | * |
| 874 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 875 | * when bringing down the SLI Layer. |
| 876 | * |
| 877 | * |
| 878 | * Return codes |
| 879 | * void. |
| 880 | **/ |
| 881 | static void |
| 882 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 883 | { |
| 884 | struct lpfc_sli *psli = &phba->sli; |
| 885 | struct lpfc_sli_ring *pring; |
| 886 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 887 | LIST_HEAD(buflist); |
| 888 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 889 | |
| 890 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 891 | lpfc_sli_hbqbuf_free_all(phba); |
| 892 | else { |
| 893 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 894 | pring = &psli->ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 895 | spin_lock_irq(&phba->hbalock); |
| 896 | list_splice_init(&pring->postbufq, &buflist); |
| 897 | spin_unlock_irq(&phba->hbalock); |
| 898 | |
| 899 | count = 0; |
| 900 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 901 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 902 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 903 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 904 | kfree(mp); |
| 905 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 906 | |
| 907 | spin_lock_irq(&phba->hbalock); |
| 908 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 909 | spin_unlock_irq(&phba->hbalock); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | /** |
| 914 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 915 | * @phba: pointer to lpfc HBA data structure. |
| 916 | * |
| 917 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 918 | * down the SLI Layer. |
| 919 | * |
| 920 | * Return codes |
| 921 | * void |
| 922 | **/ |
| 923 | static void |
| 924 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 925 | { |
| 926 | struct lpfc_sli *psli = &phba->sli; |
| 927 | struct lpfc_sli_ring *pring; |
| 928 | LIST_HEAD(completions); |
| 929 | int i; |
| 930 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 931 | for (i = 0; i < psli->num_rings; i++) { |
| 932 | pring = &psli->ring[i]; |
| 933 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 934 | spin_lock_irq(&pring->ring_lock); |
| 935 | else |
| 936 | spin_lock_irq(&phba->hbalock); |
| 937 | /* At this point in time the HBA is either reset or DOA. Either |
| 938 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 939 | */ |
| 940 | list_splice_init(&pring->txcmplq, &completions); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 941 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 942 | |
| 943 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 944 | spin_unlock_irq(&pring->ring_lock); |
| 945 | else |
| 946 | spin_unlock_irq(&phba->hbalock); |
| 947 | |
| 948 | /* Cancel all the IOCBs from the completions list */ |
| 949 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 950 | IOERR_SLI_ABORTED); |
| 951 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 956 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 957 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 958 | * @phba: pointer to lpfc HBA data structure. |
| 959 | * |
| 960 | * This routine will do uninitialization after the HBA is reset when bring |
| 961 | * down the SLI Layer. |
| 962 | * |
| 963 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 964 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 965 | * Any other value - error. |
| 966 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 967 | static int |
| 968 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 969 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 970 | lpfc_hba_free_post_buf(phba); |
| 971 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 972 | return 0; |
| 973 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 974 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 975 | /** |
| 976 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 977 | * @phba: pointer to lpfc HBA data structure. |
| 978 | * |
| 979 | * This routine will do uninitialization after the HBA is reset when bring |
| 980 | * down the SLI Layer. |
| 981 | * |
| 982 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 983 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 984 | * Any other value - error. |
| 985 | **/ |
| 986 | static int |
| 987 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 988 | { |
| 989 | struct lpfc_scsi_buf *psb, *psb_next; |
| 990 | LIST_HEAD(aborts); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 991 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 992 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 993 | struct lpfc_sli *psli = &phba->sli; |
| 994 | struct lpfc_sli_ring *pring; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 995 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 996 | lpfc_hba_free_post_buf(phba); |
| 997 | lpfc_hba_clean_txcmplq(phba); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 998 | pring = &psli->ring[LPFC_ELS_RING]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 999 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1000 | /* At this point in time the HBA is either reset or DOA. Either |
| 1001 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 1002 | * on the lpfc_sgl_list so that it can either be freed if the |
| 1003 | * driver is unloading or reposted if the driver is restarting |
| 1004 | * the port. |
| 1005 | */ |
| 1006 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 1007 | /* scsl_buf_list */ |
| 1008 | /* abts_sgl_list_lock required because worker thread uses this |
| 1009 | * list. |
| 1010 | */ |
| 1011 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1012 | list_for_each_entry(sglq_entry, |
| 1013 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1014 | sglq_entry->state = SGL_FREED; |
| 1015 | |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1016 | spin_lock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1017 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 1018 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1019 | spin_unlock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1020 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 1021 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 1022 | * list. |
| 1023 | */ |
| 1024 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1025 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 1026 | &aborts); |
| 1027 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1028 | spin_unlock_irq(&phba->hbalock); |
| 1029 | |
| 1030 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 1031 | psb->pCmd = NULL; |
| 1032 | psb->status = IOSTAT_SUCCESS; |
| 1033 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1034 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1035 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 1036 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1037 | |
| 1038 | lpfc_sli4_free_sp_events(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1044 | * @phba: pointer to lpfc HBA data structure. |
| 1045 | * |
| 1046 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1047 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1048 | * |
| 1049 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1050 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1051 | * Any other value - error. |
| 1052 | **/ |
| 1053 | int |
| 1054 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1055 | { |
| 1056 | return (*phba->lpfc_hba_down_post)(phba); |
| 1057 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1058 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1059 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1060 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1061 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1062 | * |
| 1063 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1064 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1065 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1066 | * event will be used by the worker thread to invoke the actual timeout |
| 1067 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1068 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1069 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1070 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1071 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1072 | lpfc_hb_timeout(unsigned long ptr) |
| 1073 | { |
| 1074 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1075 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1076 | unsigned long iflag; |
| 1077 | |
| 1078 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1079 | |
| 1080 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1081 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1082 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1083 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1084 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1085 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1086 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1087 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1088 | if (!tmo_posted) |
| 1089 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1090 | return; |
| 1091 | } |
| 1092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1093 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1094 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1095 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1096 | * |
| 1097 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1098 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1099 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1100 | * event will be used by the worker thread to invoke the actual timeout |
| 1101 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1102 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1103 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1104 | **/ |
| 1105 | static void |
| 1106 | lpfc_rrq_timeout(unsigned long ptr) |
| 1107 | { |
| 1108 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1109 | unsigned long iflag; |
| 1110 | |
| 1111 | phba = (struct lpfc_hba *)ptr; |
| 1112 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1113 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1114 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1115 | else |
| 1116 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1117 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1118 | |
| 1119 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1120 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1124 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1125 | * @phba: pointer to lpfc hba data structure. |
| 1126 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1127 | * |
| 1128 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1129 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1130 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1131 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1132 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1133 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1134 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1135 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1136 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1137 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1138 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1139 | static void |
| 1140 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1141 | { |
| 1142 | unsigned long drvr_flag; |
| 1143 | |
| 1144 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1145 | phba->hb_outstanding = 0; |
| 1146 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1147 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1148 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1149 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1150 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1151 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1152 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1153 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1154 | jiffies + |
| 1155 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1156 | return; |
| 1157 | } |
| 1158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1160 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1161 | * @phba: pointer to lpfc hba data structure. |
| 1162 | * |
| 1163 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1164 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1165 | * handler performs any periodic operations needed for the device. If such |
| 1166 | * periodic event has already been attended to either in the interrupt handler |
| 1167 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1168 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1169 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1170 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1171 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1172 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1173 | * to offline. |
| 1174 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1175 | void |
| 1176 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1177 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1178 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1179 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1180 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1181 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1182 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1183 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1184 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1185 | vports = lpfc_create_vport_work_array(phba); |
| 1186 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1187 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1188 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1189 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1190 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1191 | lpfc_destroy_vport_work_array(phba, vports); |
| 1192 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1193 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1194 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1195 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1196 | return; |
| 1197 | |
| 1198 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1199 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1200 | if (time_after(phba->last_completion_time + |
| 1201 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1202 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1203 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1204 | if (!phba->hb_outstanding) |
| 1205 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1206 | jiffies + |
| 1207 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1208 | else |
| 1209 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1210 | jiffies + |
| 1211 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1212 | return; |
| 1213 | } |
| 1214 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1215 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1216 | if (phba->elsbuf_cnt && |
| 1217 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1218 | spin_lock_irq(&phba->hbalock); |
| 1219 | list_splice_init(&phba->elsbuf, &completions); |
| 1220 | phba->elsbuf_cnt = 0; |
| 1221 | phba->elsbuf_prev_cnt = 0; |
| 1222 | spin_unlock_irq(&phba->hbalock); |
| 1223 | |
| 1224 | while (!list_empty(&completions)) { |
| 1225 | list_remove_head(&completions, buf_ptr, |
| 1226 | struct lpfc_dmabuf, list); |
| 1227 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1228 | kfree(buf_ptr); |
| 1229 | } |
| 1230 | } |
| 1231 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1232 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1233 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1234 | if (phba->cfg_enable_hba_heartbeat) { |
| 1235 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1236 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1237 | (list_empty(&psli->mboxq))) { |
| 1238 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1239 | GFP_KERNEL); |
| 1240 | if (!pmboxq) { |
| 1241 | mod_timer(&phba->hb_tmofunc, |
| 1242 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1243 | msecs_to_jiffies(1000 * |
| 1244 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1245 | return; |
| 1246 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1247 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1248 | lpfc_heart_beat(phba, pmboxq); |
| 1249 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1250 | pmboxq->vport = phba->pport; |
| 1251 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1252 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1253 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1254 | if (retval != MBX_BUSY && |
| 1255 | retval != MBX_SUCCESS) { |
| 1256 | mempool_free(pmboxq, |
| 1257 | phba->mbox_mem_pool); |
| 1258 | mod_timer(&phba->hb_tmofunc, |
| 1259 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1260 | msecs_to_jiffies(1000 * |
| 1261 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1262 | return; |
| 1263 | } |
| 1264 | phba->skipped_hb = 0; |
| 1265 | phba->hb_outstanding = 1; |
| 1266 | } else if (time_before_eq(phba->last_completion_time, |
| 1267 | phba->skipped_hb)) { |
| 1268 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1269 | "2857 Last completion time not " |
| 1270 | " updated in %d ms\n", |
| 1271 | jiffies_to_msecs(jiffies |
| 1272 | - phba->last_completion_time)); |
| 1273 | } else |
| 1274 | phba->skipped_hb = jiffies; |
| 1275 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1276 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1277 | jiffies + |
| 1278 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1279 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1280 | } else { |
| 1281 | /* |
| 1282 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1283 | * we need to give the hb mailbox cmd a chance to |
| 1284 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1285 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1286 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1287 | "0459 Adapter heartbeat still out" |
| 1288 | "standing:last compl time was %d ms.\n", |
| 1289 | jiffies_to_msecs(jiffies |
| 1290 | - phba->last_completion_time)); |
| 1291 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1292 | jiffies + |
| 1293 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1294 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1295 | } else { |
| 1296 | mod_timer(&phba->hb_tmofunc, |
| 1297 | jiffies + |
| 1298 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1302 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1303 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1304 | * @phba: pointer to lpfc hba data structure. |
| 1305 | * |
| 1306 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1307 | * other than Port Error 6 has been detected. |
| 1308 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1309 | static void |
| 1310 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1311 | { |
| 1312 | struct lpfc_sli *psli = &phba->sli; |
| 1313 | |
| 1314 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1315 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1316 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1317 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1318 | |
| 1319 | lpfc_offline(phba); |
| 1320 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1321 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1322 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1323 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1324 | lpfc_hba_down_post(phba); |
| 1325 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1326 | lpfc_unblock_mgmt_io(phba); |
| 1327 | phba->link_state = LPFC_HBA_ERROR; |
| 1328 | return; |
| 1329 | } |
| 1330 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1331 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1332 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1333 | * @phba: pointer to lpfc hba data structure. |
| 1334 | * |
| 1335 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1336 | * other than Port Error 6 has been detected. |
| 1337 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1338 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1339 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1340 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1341 | spin_lock_irq(&phba->hbalock); |
| 1342 | phba->link_state = LPFC_HBA_ERROR; |
| 1343 | spin_unlock_irq(&phba->hbalock); |
| 1344 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1345 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1346 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1347 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1348 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1352 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1353 | * @phba: pointer to lpfc hba data structure. |
| 1354 | * |
| 1355 | * This routine is invoked to handle the deferred HBA hardware error |
| 1356 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1357 | * and another ER bit in the host status register. The driver will |
| 1358 | * wait until the ER1 bit clears before handling the error condition. |
| 1359 | **/ |
| 1360 | static void |
| 1361 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1362 | { |
| 1363 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1364 | struct lpfc_sli *psli = &phba->sli; |
| 1365 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1366 | /* If the pci channel is offline, ignore possible errors, |
| 1367 | * since we cannot communicate with the pci card anyway. |
| 1368 | */ |
| 1369 | if (pci_channel_offline(phba->pcidev)) { |
| 1370 | spin_lock_irq(&phba->hbalock); |
| 1371 | phba->hba_flag &= ~DEFER_ERATT; |
| 1372 | spin_unlock_irq(&phba->hbalock); |
| 1373 | return; |
| 1374 | } |
| 1375 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1377 | "0479 Deferred Adapter Hardware Error " |
| 1378 | "Data: x%x x%x x%x\n", |
| 1379 | phba->work_hs, |
| 1380 | phba->work_status[0], phba->work_status[1]); |
| 1381 | |
| 1382 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1383 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1384 | spin_unlock_irq(&phba->hbalock); |
| 1385 | |
| 1386 | |
| 1387 | /* |
| 1388 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1389 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1390 | * SCSI layer retry it after re-establishing link. |
| 1391 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1392 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1393 | |
| 1394 | /* |
| 1395 | * There was a firmware error. Take the hba offline and then |
| 1396 | * attempt to restart it. |
| 1397 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1398 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1399 | lpfc_offline(phba); |
| 1400 | |
| 1401 | /* Wait for the ER1 bit to clear.*/ |
| 1402 | while (phba->work_hs & HS_FFER1) { |
| 1403 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1404 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1405 | phba->work_hs = UNPLUG_ERR ; |
| 1406 | break; |
| 1407 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1408 | /* If driver is unloading let the worker thread continue */ |
| 1409 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1410 | phba->work_hs = 0; |
| 1411 | break; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * This is to ptrotect against a race condition in which |
| 1417 | * first write to the host attention register clear the |
| 1418 | * host status register. |
| 1419 | */ |
| 1420 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1421 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1422 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1423 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1424 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1425 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1426 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1427 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1428 | } |
| 1429 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1430 | static void |
| 1431 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1432 | { |
| 1433 | struct lpfc_board_event_header board_event; |
| 1434 | struct Scsi_Host *shost; |
| 1435 | |
| 1436 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1437 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1438 | shost = lpfc_shost_from_vport(phba->pport); |
| 1439 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1440 | sizeof(board_event), |
| 1441 | (char *) &board_event, |
| 1442 | LPFC_NL_VENDOR_ID); |
| 1443 | } |
| 1444 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1445 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1446 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1447 | * @phba: pointer to lpfc hba data structure. |
| 1448 | * |
| 1449 | * This routine is invoked to handle the following HBA hardware error |
| 1450 | * conditions: |
| 1451 | * 1 - HBA error attention interrupt |
| 1452 | * 2 - DMA ring index out of range |
| 1453 | * 3 - Mailbox command came back as unknown |
| 1454 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1455 | static void |
| 1456 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1458 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1459 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1460 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1461 | unsigned long temperature; |
| 1462 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1463 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1464 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1465 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1466 | * since we cannot communicate with the pci card anyway. |
| 1467 | */ |
| 1468 | if (pci_channel_offline(phba->pcidev)) { |
| 1469 | spin_lock_irq(&phba->hbalock); |
| 1470 | phba->hba_flag &= ~DEFER_ERATT; |
| 1471 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1472 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1475 | /* If resets are disabled then leave the HBA alone and return */ |
| 1476 | if (!phba->cfg_enable_hba_reset) |
| 1477 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1478 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1479 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1480 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1481 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1482 | if (phba->hba_flag & DEFER_ERATT) |
| 1483 | lpfc_handle_deferred_eratt(phba); |
| 1484 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1485 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1486 | if (phba->work_hs & HS_FFER6) |
| 1487 | /* Re-establishing Link */ |
| 1488 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1489 | "1301 Re-establishing Link " |
| 1490 | "Data: x%x x%x x%x\n", |
| 1491 | phba->work_hs, phba->work_status[0], |
| 1492 | phba->work_status[1]); |
| 1493 | if (phba->work_hs & HS_FFER8) |
| 1494 | /* Device Zeroization */ |
| 1495 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1496 | "2861 Host Authentication device " |
| 1497 | "zeroization Data:x%x x%x x%x\n", |
| 1498 | phba->work_hs, phba->work_status[0], |
| 1499 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1500 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1501 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1502 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1503 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | |
| 1505 | /* |
| 1506 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1507 | * That could cause the I/Os dropped by the firmware. |
| 1508 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1509 | * retry it after re-establishing link. |
| 1510 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1511 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | /* |
| 1514 | * There was a firmware error. Take the hba offline and then |
| 1515 | * attempt to restart it. |
| 1516 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1517 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1519 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1520 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1521 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1522 | return; |
| 1523 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1524 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1525 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1526 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1527 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1528 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1529 | temp_event_data.data = (uint32_t)temperature; |
| 1530 | |
| 1531 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1532 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1533 | "(%ld), taking this port offline " |
| 1534 | "Data: x%x x%x x%x\n", |
| 1535 | temperature, phba->work_hs, |
| 1536 | phba->work_status[0], phba->work_status[1]); |
| 1537 | |
| 1538 | shost = lpfc_shost_from_vport(phba->pport); |
| 1539 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1540 | sizeof(temp_event_data), |
| 1541 | (char *) &temp_event_data, |
| 1542 | SCSI_NL_VID_TYPE_PCI |
| 1543 | | PCI_VENDOR_ID_EMULEX); |
| 1544 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1545 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1546 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1547 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1548 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1549 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | } else { |
| 1551 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1552 | * failure is a value other than FFER6. Do not call the offline |
| 1553 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | */ |
| 1555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1556 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1558 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | phba->work_status[0], phba->work_status[1]); |
| 1560 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1561 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1562 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1563 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1564 | sizeof(event_data), (char *) &event_data, |
| 1565 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1566 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1567 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1569 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1570 | } |
| 1571 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1572 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1573 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1574 | * @phba: pointer to lpfc hba data structure. |
| 1575 | * @mbx_action: flag for mailbox shutdown action. |
| 1576 | * |
| 1577 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1578 | * response to port status register polling attention. It waits for port |
| 1579 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1580 | * During this process, interrupt vectors are freed and later requested |
| 1581 | * for handling possible port resource change. |
| 1582 | **/ |
| 1583 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1584 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1585 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1586 | { |
| 1587 | int rc; |
| 1588 | uint32_t intr_mode; |
| 1589 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1590 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1591 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1592 | /* |
| 1593 | * On error status condition, driver need to wait for port |
| 1594 | * ready before performing reset. |
| 1595 | */ |
| 1596 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1597 | if (!rc) |
| 1598 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1599 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1600 | /* need reset: attempt for port recovery */ |
| 1601 | if (en_rn_msg) |
| 1602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1603 | "2887 Reset Needed: Attempting Port " |
| 1604 | "Recovery...\n"); |
| 1605 | lpfc_offline_prep(phba, mbx_action); |
| 1606 | lpfc_offline(phba); |
| 1607 | /* release interrupt for possible resource change */ |
| 1608 | lpfc_sli4_disable_intr(phba); |
| 1609 | lpfc_sli_brdrestart(phba); |
| 1610 | /* request and enable interrupt */ |
| 1611 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1612 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1614 | "3175 Failed to enable interrupt\n"); |
| 1615 | return -EIO; |
| 1616 | } |
| 1617 | phba->intr_mode = intr_mode; |
| 1618 | rc = lpfc_online(phba); |
| 1619 | if (rc == 0) |
| 1620 | lpfc_unblock_mgmt_io(phba); |
| 1621 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1622 | return rc; |
| 1623 | } |
| 1624 | |
| 1625 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1626 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1627 | * @phba: pointer to lpfc hba data structure. |
| 1628 | * |
| 1629 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1630 | * conditions. |
| 1631 | **/ |
| 1632 | static void |
| 1633 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1634 | { |
| 1635 | struct lpfc_vport *vport = phba->pport; |
| 1636 | uint32_t event_data; |
| 1637 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1638 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1639 | struct lpfc_register portstat_reg = {0}; |
| 1640 | uint32_t reg_err1, reg_err2; |
| 1641 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1642 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1643 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1644 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1645 | struct lpfc_register portsmphr_reg; |
| 1646 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1647 | |
| 1648 | /* If the pci channel is offline, ignore possible errors, since |
| 1649 | * we cannot communicate with the pci card anyway. |
| 1650 | */ |
| 1651 | if (pci_channel_offline(phba->pcidev)) |
| 1652 | return; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1653 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1654 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1655 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1656 | switch (if_type) { |
| 1657 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1658 | pci_rd_rc1 = lpfc_readl( |
| 1659 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1660 | &uerrlo_reg); |
| 1661 | pci_rd_rc2 = lpfc_readl( |
| 1662 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1663 | &uemasklo_reg); |
| 1664 | /* consider PCI bus read error as pci_channel_offline */ |
| 1665 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1666 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1667 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1668 | lpfc_sli4_offline_eratt(phba); |
| 1669 | return; |
| 1670 | } |
| 1671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1672 | "7623 Checking UE recoverable"); |
| 1673 | |
| 1674 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1675 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1676 | &portsmphr_reg.word0)) |
| 1677 | continue; |
| 1678 | |
| 1679 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1680 | &portsmphr_reg); |
| 1681 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1682 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1683 | break; |
| 1684 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1685 | msleep(1000); |
| 1686 | } |
| 1687 | |
| 1688 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1689 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1690 | smphr_port_status, i); |
| 1691 | |
| 1692 | /* Recoverable UE, reset the HBA device */ |
| 1693 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1694 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1695 | for (i = 0; i < 20; i++) { |
| 1696 | msleep(1000); |
| 1697 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1698 | &portsmphr_reg.word0) && |
| 1699 | (LPFC_POST_STAGE_PORT_READY == |
| 1700 | bf_get(lpfc_port_smphr_port_status, |
| 1701 | &portsmphr_reg))) { |
| 1702 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1703 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1704 | if (rc == 0) |
| 1705 | return; |
| 1706 | lpfc_printf_log(phba, |
| 1707 | KERN_ERR, LOG_INIT, |
| 1708 | "4215 Failed to recover UE"); |
| 1709 | break; |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1714 | "7624 Firmware not ready: Failing UE recovery," |
| 1715 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1716 | lpfc_sli4_offline_eratt(phba); |
| 1717 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1718 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1719 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1720 | pci_rd_rc1 = lpfc_readl( |
| 1721 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1722 | &portstat_reg.word0); |
| 1723 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1724 | if (pci_rd_rc1 == -EIO) { |
| 1725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1726 | "3151 PCI bus read access failure: x%x\n", |
| 1727 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1728 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1729 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1730 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1731 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1732 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1734 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1735 | "taking port offline Data: x%x x%x\n", |
| 1736 | reg_err1, reg_err2); |
| 1737 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1738 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1739 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1740 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1741 | temp_event_data.data = 0xFFFFFFFF; |
| 1742 | |
| 1743 | shost = lpfc_shost_from_vport(phba->pport); |
| 1744 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1745 | sizeof(temp_event_data), |
| 1746 | (char *)&temp_event_data, |
| 1747 | SCSI_NL_VID_TYPE_PCI |
| 1748 | | PCI_VENDOR_ID_EMULEX); |
| 1749 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1750 | spin_lock_irq(&phba->hbalock); |
| 1751 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1752 | spin_unlock_irq(&phba->hbalock); |
| 1753 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1754 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1755 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1756 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1757 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1759 | "3143 Port Down: Firmware Update " |
| 1760 | "Detected\n"); |
| 1761 | en_rn_msg = false; |
| 1762 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1763 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1765 | "3144 Port Down: Debug Dump\n"); |
| 1766 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1767 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1769 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1770 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1771 | /* If resets are disabled then leave the HBA alone and return */ |
| 1772 | if (!phba->cfg_enable_hba_reset) |
| 1773 | return; |
| 1774 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1775 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1776 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1777 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1778 | if (rc == 0) { |
| 1779 | /* don't report event on forced debug dump */ |
| 1780 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1781 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1782 | return; |
| 1783 | else |
| 1784 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1785 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1786 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1788 | "3152 Unrecoverable error, bring the port " |
| 1789 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1790 | lpfc_sli4_offline_eratt(phba); |
| 1791 | break; |
| 1792 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1793 | default: |
| 1794 | break; |
| 1795 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1796 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1797 | "3123 Report dump event to upper layer\n"); |
| 1798 | /* Send an internal error event to mgmt application */ |
| 1799 | lpfc_board_errevt_to_mgmt(phba); |
| 1800 | |
| 1801 | event_data = FC_REG_DUMP_EVENT; |
| 1802 | shost = lpfc_shost_from_vport(vport); |
| 1803 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1804 | sizeof(event_data), (char *) &event_data, |
| 1805 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | /** |
| 1809 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1810 | * @phba: pointer to lpfc HBA data structure. |
| 1811 | * |
| 1812 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1813 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1814 | * |
| 1815 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1816 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1817 | * Any other value - error. |
| 1818 | **/ |
| 1819 | void |
| 1820 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1821 | { |
| 1822 | (*phba->lpfc_handle_eratt)(phba); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1826 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1827 | * @phba: pointer to lpfc hba data structure. |
| 1828 | * |
| 1829 | * This routine is invoked from the worker thread to handle a HBA host |
| 1830 | * attention link event. |
| 1831 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1835 | struct lpfc_vport *vport = phba->pport; |
| 1836 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1837 | LPFC_MBOXQ_t *pmb; |
| 1838 | volatile uint32_t control; |
| 1839 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1840 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | |
| 1842 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1843 | if (!pmb) { |
| 1844 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1846 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1847 | |
| 1848 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1849 | if (!mp) { |
| 1850 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1852 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | |
| 1854 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1855 | if (!mp->virt) { |
| 1856 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1857 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1858 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1860 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1861 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | |
| 1863 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1864 | lpfc_read_topology(phba, pmb, mp); |
| 1865 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1866 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1867 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1868 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1869 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1870 | if (rc == MBX_NOT_FINISHED) { |
| 1871 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1872 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1873 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | |
| 1875 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | writel(HA_LATT, phba->HAregaddr); |
| 1878 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1879 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1880 | |
| 1881 | return; |
| 1882 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1883 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1884 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1885 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | lpfc_handle_latt_free_mp: |
| 1887 | kfree(mp); |
| 1888 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1889 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | lpfc_handle_latt_err_exit: |
| 1891 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1894 | control = readl(phba->HCregaddr); |
| 1895 | control |= HC_LAINT_ENA; |
| 1896 | writel(control, phba->HCregaddr); |
| 1897 | readl(phba->HCregaddr); /* flush */ |
| 1898 | |
| 1899 | /* Clear Link Attention in HA REG */ |
| 1900 | writel(HA_LATT, phba->HAregaddr); |
| 1901 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1902 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1906 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1907 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | |
| 1909 | return; |
| 1910 | } |
| 1911 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1912 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1913 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | * @phba: pointer to lpfc hba data structure. |
| 1915 | * @vpd: pointer to the vital product data. |
| 1916 | * @len: length of the vital product data in bytes. |
| 1917 | * |
| 1918 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1919 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1920 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1921 | * |
| 1922 | * Return codes |
| 1923 | * 0 - pointer to the VPD passed in is NULL |
| 1924 | * 1 - success |
| 1925 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1926 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | { |
| 1929 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1930 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | int i, j; |
| 1932 | int finished = 0; |
| 1933 | int index = 0; |
| 1934 | |
| 1935 | if (!vpd) |
| 1936 | return 0; |
| 1937 | |
| 1938 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1939 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1940 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1942 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1943 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | switch (vpd[index]) { |
| 1945 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1946 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | index += 1; |
| 1948 | lenlo = vpd[index]; |
| 1949 | index += 1; |
| 1950 | lenhi = vpd[index]; |
| 1951 | index += 1; |
| 1952 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1953 | index += i; |
| 1954 | break; |
| 1955 | case 0x90: |
| 1956 | index += 1; |
| 1957 | lenlo = vpd[index]; |
| 1958 | index += 1; |
| 1959 | lenhi = vpd[index]; |
| 1960 | index += 1; |
| 1961 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1962 | if (Length > len - index) |
| 1963 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | while (Length > 0) { |
| 1965 | /* Look for Serial Number */ |
| 1966 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1967 | index += 2; |
| 1968 | i = vpd[index]; |
| 1969 | index += 1; |
| 1970 | j = 0; |
| 1971 | Length -= (3+i); |
| 1972 | while(i--) { |
| 1973 | phba->SerialNumber[j++] = vpd[index++]; |
| 1974 | if (j == 31) |
| 1975 | break; |
| 1976 | } |
| 1977 | phba->SerialNumber[j] = 0; |
| 1978 | continue; |
| 1979 | } |
| 1980 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1981 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1982 | index += 2; |
| 1983 | i = vpd[index]; |
| 1984 | index += 1; |
| 1985 | j = 0; |
| 1986 | Length -= (3+i); |
| 1987 | while(i--) { |
| 1988 | phba->ModelDesc[j++] = vpd[index++]; |
| 1989 | if (j == 255) |
| 1990 | break; |
| 1991 | } |
| 1992 | phba->ModelDesc[j] = 0; |
| 1993 | continue; |
| 1994 | } |
| 1995 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1996 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1997 | index += 2; |
| 1998 | i = vpd[index]; |
| 1999 | index += 1; |
| 2000 | j = 0; |
| 2001 | Length -= (3+i); |
| 2002 | while(i--) { |
| 2003 | phba->ModelName[j++] = vpd[index++]; |
| 2004 | if (j == 79) |
| 2005 | break; |
| 2006 | } |
| 2007 | phba->ModelName[j] = 0; |
| 2008 | continue; |
| 2009 | } |
| 2010 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2011 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2012 | index += 2; |
| 2013 | i = vpd[index]; |
| 2014 | index += 1; |
| 2015 | j = 0; |
| 2016 | Length -= (3+i); |
| 2017 | while(i--) { |
| 2018 | phba->ProgramType[j++] = vpd[index++]; |
| 2019 | if (j == 255) |
| 2020 | break; |
| 2021 | } |
| 2022 | phba->ProgramType[j] = 0; |
| 2023 | continue; |
| 2024 | } |
| 2025 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2026 | phba->vpd_flag |= VPD_PORT; |
| 2027 | index += 2; |
| 2028 | i = vpd[index]; |
| 2029 | index += 1; |
| 2030 | j = 0; |
| 2031 | Length -= (3+i); |
| 2032 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2033 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2034 | (phba->sli4_hba.pport_name_sta == |
| 2035 | LPFC_SLI4_PPNAME_GET)) { |
| 2036 | j++; |
| 2037 | index++; |
| 2038 | } else |
| 2039 | phba->Port[j++] = vpd[index++]; |
| 2040 | if (j == 19) |
| 2041 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2042 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2043 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2044 | (phba->sli4_hba.pport_name_sta == |
| 2045 | LPFC_SLI4_PPNAME_NON)) |
| 2046 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | continue; |
| 2048 | } |
| 2049 | else { |
| 2050 | index += 2; |
| 2051 | i = vpd[index]; |
| 2052 | index += 1; |
| 2053 | index += i; |
| 2054 | Length -= (3 + i); |
| 2055 | } |
| 2056 | } |
| 2057 | finished = 0; |
| 2058 | break; |
| 2059 | case 0x78: |
| 2060 | finished = 1; |
| 2061 | break; |
| 2062 | default: |
| 2063 | index ++; |
| 2064 | break; |
| 2065 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2066 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | |
| 2068 | return(1); |
| 2069 | } |
| 2070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2071 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2072 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2073 | * @phba: pointer to lpfc hba data structure. |
| 2074 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2075 | * @descp: pointer to the data structure to hold the derived description. |
| 2076 | * |
| 2077 | * This routine retrieves HBA's description based on its registered PCI device |
| 2078 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2079 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2080 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2081 | * function returns, the @mdp will be filled with the model name. |
| 2082 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | 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] | 2085 | { |
| 2086 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2087 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2088 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2089 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2090 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2091 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2092 | char *name; |
| 2093 | char *bus; |
| 2094 | char *function; |
| 2095 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2096 | |
| 2097 | if (mdp && mdp[0] != '\0' |
| 2098 | && descp && descp[0] != '\0') |
| 2099 | return; |
| 2100 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2101 | if (phba->lmt & LMT_32Gb) |
| 2102 | max_speed = 32; |
| 2103 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2104 | max_speed = 16; |
| 2105 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2106 | max_speed = 10; |
| 2107 | else if (phba->lmt & LMT_8Gb) |
| 2108 | max_speed = 8; |
| 2109 | else if (phba->lmt & LMT_4Gb) |
| 2110 | max_speed = 4; |
| 2111 | else if (phba->lmt & LMT_2Gb) |
| 2112 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2113 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2114 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2115 | else |
| 2116 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | |
| 2118 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2120 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2121 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2122 | m = (typeof(m)){"LP6000", "PCI", |
| 2123 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2124 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | case PCI_DEVICE_ID_SUPERFLY: |
| 2126 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2127 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2129 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2130 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | break; |
| 2132 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2133 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2134 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | break; |
| 2136 | case PCI_DEVICE_ID_CENTAUR: |
| 2137 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2138 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2140 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2141 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | break; |
| 2143 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2144 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2145 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | break; |
| 2147 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2148 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2149 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | break; |
| 2151 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2152 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2153 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | break; |
| 2155 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2156 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2157 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2158 | break; |
| 2159 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2160 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2161 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | break; |
| 2163 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2164 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2165 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | break; |
| 2167 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2168 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2169 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2171 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2172 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2173 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2174 | break; |
| 2175 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2176 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2177 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2178 | break; |
| 2179 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2180 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2181 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2182 | break; |
| 2183 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2184 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2185 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2186 | break; |
| 2187 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2188 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2189 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2190 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2192 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | break; |
| 2194 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2195 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2196 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2197 | break; |
| 2198 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2199 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2201 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2202 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2203 | break; |
| 2204 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2205 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2206 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2207 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2209 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2210 | break; |
| 2211 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2212 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | break; |
| 2214 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2215 | m = (typeof(m)){"LP101", "PCI-X", |
| 2216 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | break; |
| 2218 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2219 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2220 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2221 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2222 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2223 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2224 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2225 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2226 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2227 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2228 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2229 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2230 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2231 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2232 | break; |
| 2233 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2234 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2235 | break; |
| 2236 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2237 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2238 | break; |
| 2239 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2240 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2241 | break; |
| 2242 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2243 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2244 | break; |
| 2245 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2246 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2247 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2248 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2249 | m = (typeof(m)){"LP21000", "PCIe", |
| 2250 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2251 | GE = 1; |
| 2252 | break; |
| 2253 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2254 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2255 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2256 | break; |
| 2257 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2258 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2259 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2260 | break; |
| 2261 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2262 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2263 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2264 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2265 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2266 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2267 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2268 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2269 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2270 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2271 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2272 | break; |
| 2273 | case PCI_DEVICE_ID_FALCON: |
| 2274 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2275 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2276 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2277 | case PCI_DEVICE_ID_BALIUS: |
| 2278 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2279 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2280 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2281 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2282 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2283 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2284 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2285 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2286 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2287 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2288 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2289 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2290 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2291 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2292 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2293 | oneConnect = 1; |
| 2294 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2295 | "Obsolete, Unsupported FCoE"}; |
| 2296 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2297 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2298 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2299 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2300 | case PCI_DEVICE_ID_SKYHAWK: |
| 2301 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2302 | oneConnect = 1; |
| 2303 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2304 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2305 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2306 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2307 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2309 | |
| 2310 | if (mdp && mdp[0] == '\0') |
| 2311 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2312 | /* |
| 2313 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2314 | * and we put the port number on the end |
| 2315 | */ |
| 2316 | if (descp && descp[0] == '\0') { |
| 2317 | if (oneConnect) |
| 2318 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2319 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2320 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2321 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2322 | else if (max_speed == 0) |
| 2323 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2324 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2325 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2326 | else |
| 2327 | snprintf(descp, 255, |
| 2328 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2329 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2330 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2331 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | } |
| 2333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2335 | * 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] | 2336 | * @phba: pointer to lpfc hba data structure. |
| 2337 | * @pring: pointer to a IOCB ring. |
| 2338 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2339 | * |
| 2340 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2341 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2342 | * |
| 2343 | * Return codes |
| 2344 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2345 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2347 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | { |
| 2349 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2350 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | struct lpfc_dmabuf *mp1, *mp2; |
| 2352 | |
| 2353 | cnt += pring->missbufcnt; |
| 2354 | |
| 2355 | /* While there are buffers to post */ |
| 2356 | while (cnt > 0) { |
| 2357 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2358 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | if (iocb == NULL) { |
| 2360 | pring->missbufcnt = cnt; |
| 2361 | return cnt; |
| 2362 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | icmd = &iocb->iocb; |
| 2364 | |
| 2365 | /* 2 buffers can be posted per command */ |
| 2366 | /* Allocate buffer to post */ |
| 2367 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2368 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2369 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2370 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2371 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2372 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | pring->missbufcnt = cnt; |
| 2374 | return cnt; |
| 2375 | } |
| 2376 | |
| 2377 | INIT_LIST_HEAD(&mp1->list); |
| 2378 | /* Allocate buffer to post */ |
| 2379 | if (cnt > 1) { |
| 2380 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2381 | if (mp2) |
| 2382 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2383 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2384 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2385 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2387 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2388 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | pring->missbufcnt = cnt; |
| 2390 | return cnt; |
| 2391 | } |
| 2392 | |
| 2393 | INIT_LIST_HEAD(&mp2->list); |
| 2394 | } else { |
| 2395 | mp2 = NULL; |
| 2396 | } |
| 2397 | |
| 2398 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2399 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2400 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2401 | icmd->ulpBdeCount = 1; |
| 2402 | cnt--; |
| 2403 | if (mp2) { |
| 2404 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2405 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2406 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2407 | cnt--; |
| 2408 | icmd->ulpBdeCount = 2; |
| 2409 | } |
| 2410 | |
| 2411 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2412 | icmd->ulpLe = 1; |
| 2413 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2414 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2415 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2417 | kfree(mp1); |
| 2418 | cnt++; |
| 2419 | if (mp2) { |
| 2420 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2421 | kfree(mp2); |
| 2422 | cnt++; |
| 2423 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2424 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | return cnt; |
| 2427 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | } |
| 2432 | pring->missbufcnt = 0; |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2436 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2437 | * 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] | 2438 | * @phba: pointer to lpfc hba data structure. |
| 2439 | * |
| 2440 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2441 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2442 | * set to 64 IOCBs. |
| 2443 | * |
| 2444 | * Return codes |
| 2445 | * 0 - success (currently always success) |
| 2446 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2448 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | { |
| 2450 | struct lpfc_sli *psli = &phba->sli; |
| 2451 | |
| 2452 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2453 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | /* Ring 2 - FCP no buffers needed */ |
| 2455 | |
| 2456 | return 0; |
| 2457 | } |
| 2458 | |
| 2459 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2461 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2462 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2463 | * @HashResultPointer: pointer to an array as hash table. |
| 2464 | * |
| 2465 | * This routine sets up the initial values to the array of hash table entries |
| 2466 | * for the LC HBAs. |
| 2467 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2468 | static void |
| 2469 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2470 | { |
| 2471 | HashResultPointer[0] = 0x67452301; |
| 2472 | HashResultPointer[1] = 0xEFCDAB89; |
| 2473 | HashResultPointer[2] = 0x98BADCFE; |
| 2474 | HashResultPointer[3] = 0x10325476; |
| 2475 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2476 | } |
| 2477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2479 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2480 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2481 | * @HashWorkingPointer: pointer to an working hash table. |
| 2482 | * |
| 2483 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2484 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2485 | * The results are putting back to the initial hash table, returned through |
| 2486 | * the @HashResultPointer as the result hash table. |
| 2487 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | static void |
| 2489 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2490 | { |
| 2491 | int t; |
| 2492 | uint32_t TEMP; |
| 2493 | uint32_t A, B, C, D, E; |
| 2494 | t = 16; |
| 2495 | do { |
| 2496 | HashWorkingPointer[t] = |
| 2497 | S(1, |
| 2498 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2499 | 8] ^ |
| 2500 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2501 | } while (++t <= 79); |
| 2502 | t = 0; |
| 2503 | A = HashResultPointer[0]; |
| 2504 | B = HashResultPointer[1]; |
| 2505 | C = HashResultPointer[2]; |
| 2506 | D = HashResultPointer[3]; |
| 2507 | E = HashResultPointer[4]; |
| 2508 | |
| 2509 | do { |
| 2510 | if (t < 20) { |
| 2511 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2512 | } else if (t < 40) { |
| 2513 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2514 | } else if (t < 60) { |
| 2515 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2516 | } else { |
| 2517 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2518 | } |
| 2519 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2520 | E = D; |
| 2521 | D = C; |
| 2522 | C = S(30, B); |
| 2523 | B = A; |
| 2524 | A = TEMP; |
| 2525 | } while (++t <= 79); |
| 2526 | |
| 2527 | HashResultPointer[0] += A; |
| 2528 | HashResultPointer[1] += B; |
| 2529 | HashResultPointer[2] += C; |
| 2530 | HashResultPointer[3] += D; |
| 2531 | HashResultPointer[4] += E; |
| 2532 | |
| 2533 | } |
| 2534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2536 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2537 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2538 | * @HashWorking: pointer to the entry of the working hash array. |
| 2539 | * |
| 2540 | * This routine calculates the working hash array referred by @HashWorking |
| 2541 | * from the challenge random numbers associated with the host, referred by |
| 2542 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2543 | * array and returned by reference through @HashWorking. |
| 2544 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | static void |
| 2546 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2547 | { |
| 2548 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2549 | } |
| 2550 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2551 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2552 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2553 | * @phba: pointer to lpfc hba data structure. |
| 2554 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2555 | * |
| 2556 | * This routine performs the special handling for LC HBA initialization. |
| 2557 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | void |
| 2559 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2560 | { |
| 2561 | int t; |
| 2562 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2563 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2565 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2566 | if (!HashWorking) |
| 2567 | return; |
| 2568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2570 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2571 | |
| 2572 | for (t = 0; t < 7; t++) |
| 2573 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2574 | |
| 2575 | lpfc_sha_init(hbainit); |
| 2576 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2577 | kfree(HashWorking); |
| 2578 | } |
| 2579 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2580 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2581 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2582 | * @vport: pointer to a virtual N_Port data structure. |
| 2583 | * |
| 2584 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2585 | * It invokes the discovery state machine to perform necessary state |
| 2586 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2587 | * the physical port is treated as @vport 0. |
| 2588 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2589 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2590 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2592 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2594 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2596 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2597 | lpfc_port_link_failure(vport); |
| 2598 | |
| 2599 | 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] | 2600 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2601 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2602 | NLP_STE_UNUSED_NODE); |
| 2603 | if (!ndlp) |
| 2604 | continue; |
| 2605 | spin_lock_irq(&phba->ndlp_lock); |
| 2606 | NLP_SET_FREE_REQ(ndlp); |
| 2607 | spin_unlock_irq(&phba->ndlp_lock); |
| 2608 | /* Trigger the release of the ndlp memory */ |
| 2609 | lpfc_nlp_put(ndlp); |
| 2610 | continue; |
| 2611 | } |
| 2612 | spin_lock_irq(&phba->ndlp_lock); |
| 2613 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2614 | /* The ndlp should not be in memory free mode already */ |
| 2615 | spin_unlock_irq(&phba->ndlp_lock); |
| 2616 | continue; |
| 2617 | } else |
| 2618 | /* Indicate request for freeing ndlp memory */ |
| 2619 | NLP_SET_FREE_REQ(ndlp); |
| 2620 | spin_unlock_irq(&phba->ndlp_lock); |
| 2621 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2622 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2623 | ndlp->nlp_DID == Fabric_DID) { |
| 2624 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2625 | lpfc_nlp_put(ndlp); |
| 2626 | continue; |
| 2627 | } |
| 2628 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2629 | /* take care of nodes in unused state before the state |
| 2630 | * machine taking action. |
| 2631 | */ |
| 2632 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2633 | lpfc_nlp_put(ndlp); |
| 2634 | continue; |
| 2635 | } |
| 2636 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2637 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2638 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2639 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2640 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2641 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2642 | NLP_EVT_DEVICE_RM); |
| 2643 | } |
| 2644 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2645 | /* At this point, ALL ndlp's should be gone |
| 2646 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2647 | * Lets wait for this to happen, if needed. |
| 2648 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2649 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2650 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2651 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2652 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2653 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2654 | &vport->fc_nodes, nlp_listp) { |
| 2655 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2656 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2657 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2658 | "usgmap:x%x refcnt:%d\n", |
| 2659 | ndlp->nlp_DID, (void *)ndlp, |
| 2660 | ndlp->nlp_usg_map, |
| 2661 | atomic_read( |
| 2662 | &ndlp->kref.refcount)); |
| 2663 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2664 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2665 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2666 | |
| 2667 | /* Wait for any activity on ndlps to settle */ |
| 2668 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2669 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2670 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | } |
| 2672 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2673 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2674 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2675 | * @vport: pointer to a virtual N_Port data structure. |
| 2676 | * |
| 2677 | * This routine stops all the timers associated with a @vport. This function |
| 2678 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2679 | * port is treated as @vport 0. |
| 2680 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2681 | void |
| 2682 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2684 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2685 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2686 | lpfc_can_disctmo(vport); |
| 2687 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | } |
| 2689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2690 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2691 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2692 | * @phba: pointer to lpfc hba data structure. |
| 2693 | * |
| 2694 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2695 | * caller of this routine should already hold the host lock. |
| 2696 | **/ |
| 2697 | void |
| 2698 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2699 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2700 | /* Clear pending FCF rediscovery wait flag */ |
| 2701 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2702 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2703 | /* Now, try to stop the timer */ |
| 2704 | del_timer(&phba->fcf.redisc_wait); |
| 2705 | } |
| 2706 | |
| 2707 | /** |
| 2708 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2709 | * @phba: pointer to lpfc hba data structure. |
| 2710 | * |
| 2711 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2712 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2713 | * lock held before proceeding with disabling the timer and clearing the |
| 2714 | * wait timer pendig flag. |
| 2715 | **/ |
| 2716 | void |
| 2717 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2718 | { |
| 2719 | spin_lock_irq(&phba->hbalock); |
| 2720 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2721 | /* FCF rediscovery timer already fired or stopped */ |
| 2722 | spin_unlock_irq(&phba->hbalock); |
| 2723 | return; |
| 2724 | } |
| 2725 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2726 | /* Clear failover in progress flags */ |
| 2727 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2728 | spin_unlock_irq(&phba->hbalock); |
| 2729 | } |
| 2730 | |
| 2731 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2732 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2733 | * @phba: pointer to lpfc hba data structure. |
| 2734 | * |
| 2735 | * This routine stops all the timers associated with a HBA. This function is |
| 2736 | * invoked before either putting a HBA offline or unloading the driver. |
| 2737 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2738 | void |
| 2739 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2741 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2744 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2745 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2746 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2747 | del_timer_sync(&phba->rrq_tmr); |
| 2748 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2749 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2750 | phba->hb_outstanding = 0; |
| 2751 | |
| 2752 | switch (phba->pci_dev_grp) { |
| 2753 | case LPFC_PCI_DEV_LP: |
| 2754 | /* Stop any LightPulse device specific driver timers */ |
| 2755 | del_timer_sync(&phba->fcp_poll_timer); |
| 2756 | break; |
| 2757 | case LPFC_PCI_DEV_OC: |
| 2758 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2759 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2760 | break; |
| 2761 | default: |
| 2762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2763 | "0297 Invalid device group (x%x)\n", |
| 2764 | phba->pci_dev_grp); |
| 2765 | break; |
| 2766 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2767 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | } |
| 2769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2770 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2771 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | * @phba: pointer to lpfc hba data structure. |
| 2773 | * |
| 2774 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2775 | * management interface is marked as blocked, all the user space access to |
| 2776 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2777 | * all be blocked. The HBA is set to block the management interface when the |
| 2778 | * driver prepares the HBA interface for online or offline. |
| 2779 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2780 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2781 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2782 | { |
| 2783 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2784 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2785 | unsigned long timeout; |
| 2786 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2787 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2788 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2789 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2790 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2791 | return; |
| 2792 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2793 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2794 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2795 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2796 | /* Determine how long we might wait for the active mailbox |
| 2797 | * command to be gracefully completed by firmware. |
| 2798 | */ |
| 2799 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2800 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2801 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2802 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2803 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2804 | /* Wait for the outstnading mailbox command to complete */ |
| 2805 | while (phba->sli.mbox_active) { |
| 2806 | /* Check active mailbox complete status every 2ms */ |
| 2807 | msleep(2); |
| 2808 | if (time_after(jiffies, timeout)) { |
| 2809 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2810 | "2813 Mgmt IO is Blocked %x " |
| 2811 | "- mbox cmd %x still active\n", |
| 2812 | phba->sli.sli_flag, actcmd); |
| 2813 | break; |
| 2814 | } |
| 2815 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2818 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2819 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2820 | * @phba: pointer to lpfc hba data structure. |
| 2821 | * |
| 2822 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2823 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2824 | * is to fixup the temporary rpi assignments. |
| 2825 | **/ |
| 2826 | void |
| 2827 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2828 | { |
| 2829 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2830 | struct lpfc_vport **vports; |
| 2831 | int i; |
| 2832 | |
| 2833 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2834 | return; |
| 2835 | |
| 2836 | vports = lpfc_create_vport_work_array(phba); |
| 2837 | if (vports != NULL) { |
| 2838 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2839 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2840 | continue; |
| 2841 | |
| 2842 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2843 | &vports[i]->fc_nodes, |
| 2844 | nlp_listp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2845 | if (NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2846 | ndlp->nlp_rpi = |
| 2847 | lpfc_sli4_alloc_rpi(phba); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2848 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 2849 | LOG_NODE, |
| 2850 | "0009 rpi:%x DID:%x " |
| 2851 | "flg:%x map:%x %p\n", |
| 2852 | ndlp->nlp_rpi, |
| 2853 | ndlp->nlp_DID, |
| 2854 | ndlp->nlp_flag, |
| 2855 | ndlp->nlp_usg_map, |
| 2856 | ndlp); |
| 2857 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2858 | } |
| 2859 | } |
| 2860 | } |
| 2861 | lpfc_destroy_vport_work_array(phba, vports); |
| 2862 | } |
| 2863 | |
| 2864 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2865 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2866 | * @phba: pointer to lpfc hba data structure. |
| 2867 | * |
| 2868 | * This routine initializes the HBA and brings a HBA online. During this |
| 2869 | * process, the management interface is blocked to prevent user space access |
| 2870 | * to the HBA interfering with the driver initialization. |
| 2871 | * |
| 2872 | * Return codes |
| 2873 | * 0 - successful |
| 2874 | * 1 - failed |
| 2875 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2879 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2880 | struct lpfc_vport **vports; |
| 2881 | int i; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2882 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | if (!phba) |
| 2885 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2886 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2888 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2889 | return 0; |
| 2890 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2891 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2892 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2893 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2894 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2896 | if (!lpfc_sli_queue_setup(phba)) { |
| 2897 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2899 | } |
| 2900 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2901 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2902 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2903 | lpfc_unblock_mgmt_io(phba); |
| 2904 | return 1; |
| 2905 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2906 | spin_lock_irq(&phba->hbalock); |
| 2907 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 2908 | vpis_cleared = true; |
| 2909 | spin_unlock_irq(&phba->hbalock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2910 | } else { |
| 2911 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2912 | lpfc_unblock_mgmt_io(phba); |
| 2913 | return 1; |
| 2914 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2915 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2917 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 2918 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2919 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2920 | struct Scsi_Host *shost; |
| 2921 | shost = lpfc_shost_from_vport(vports[i]); |
| 2922 | spin_lock_irq(shost->host_lock); |
| 2923 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2924 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2925 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2926 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2927 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2928 | if ((vpis_cleared) && |
| 2929 | (vports[i]->port_type != |
| 2930 | LPFC_PHYSICAL_PORT)) |
| 2931 | vports[i]->vpi = 0; |
| 2932 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2933 | spin_unlock_irq(shost->host_lock); |
| 2934 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 2935 | } |
| 2936 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2937 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2938 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2939 | return 0; |
| 2940 | } |
| 2941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2942 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2943 | * 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] | 2944 | * @phba: pointer to lpfc hba data structure. |
| 2945 | * |
| 2946 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2947 | * HBA's management interface is marked as not blocked, all the user space |
| 2948 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2949 | * interface will be allowed. The HBA is set to block the management interface |
| 2950 | * when the driver prepares the HBA interface for online or offline and then |
| 2951 | * set to unblock the management interface afterwards. |
| 2952 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2953 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2954 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2955 | { |
| 2956 | unsigned long iflag; |
| 2957 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2958 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2959 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2960 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2961 | } |
| 2962 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2963 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2964 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2965 | * @phba: pointer to lpfc hba data structure. |
| 2966 | * |
| 2967 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2968 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2969 | * queue to make it ready to be brought offline. |
| 2970 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2971 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2972 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2973 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2975 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2976 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2977 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2978 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2980 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2981 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2983 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | |
| 2985 | lpfc_linkdown(phba); |
| 2986 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2987 | /* Issue an unreg_login to all nodes on all vports */ |
| 2988 | vports = lpfc_create_vport_work_array(phba); |
| 2989 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2990 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2991 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2992 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2993 | shost = lpfc_shost_from_vport(vports[i]); |
| 2994 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2995 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2996 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2997 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2998 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2999 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3000 | shost = lpfc_shost_from_vport(vports[i]); |
| 3001 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3002 | &vports[i]->fc_nodes, |
| 3003 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3004 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3005 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3006 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3007 | continue; |
| 3008 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3009 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3010 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3011 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3012 | NULL, NLP_EVT_DEVICE_RM); |
| 3013 | } |
| 3014 | spin_lock_irq(shost->host_lock); |
| 3015 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3016 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3017 | /* |
| 3018 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3019 | * RPI. Get a new RPI when the adapter port |
| 3020 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3021 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3022 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3023 | lpfc_printf_vlog(ndlp->vport, |
| 3024 | KERN_INFO, LOG_NODE, |
| 3025 | "0011 lpfc_offline: " |
| 3026 | "ndlp:x%p did %x " |
| 3027 | "usgmap:x%x rpi:%x\n", |
| 3028 | ndlp, ndlp->nlp_DID, |
| 3029 | ndlp->nlp_usg_map, |
| 3030 | ndlp->nlp_rpi); |
| 3031 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3032 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3033 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3034 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3035 | } |
| 3036 | } |
| 3037 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3038 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3039 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3040 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3043 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3044 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3045 | * @phba: pointer to lpfc hba data structure. |
| 3046 | * |
| 3047 | * This routine actually brings a HBA offline. It stops all the timers |
| 3048 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3049 | * marks the HBA as in offline state for the upper layer protocol. |
| 3050 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3051 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3052 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3053 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3054 | struct Scsi_Host *shost; |
| 3055 | struct lpfc_vport **vports; |
| 3056 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3057 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3058 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3059 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3060 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3061 | /* stop port and all timers associated with this hba */ |
| 3062 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3063 | vports = lpfc_create_vport_work_array(phba); |
| 3064 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3065 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3066 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3067 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3068 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3069 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3070 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3071 | now. */ |
| 3072 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3073 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3074 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3075 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3076 | vports = lpfc_create_vport_work_array(phba); |
| 3077 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3078 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3079 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3080 | spin_lock_irq(shost->host_lock); |
| 3081 | vports[i]->work_port_events = 0; |
| 3082 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3083 | spin_unlock_irq(shost->host_lock); |
| 3084 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3085 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | } |
| 3087 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3088 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3089 | * 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] | 3090 | * @phba: pointer to lpfc hba data structure. |
| 3091 | * |
| 3092 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3093 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3094 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3095 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3096 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3097 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3098 | { |
| 3099 | struct lpfc_scsi_buf *sb, *sb_next; |
| 3100 | struct lpfc_iocbq *io, *io_next; |
| 3101 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3102 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3104 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3105 | |
| 3106 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3107 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3108 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | list_del(&sb->list); |
| 3110 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3111 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | kfree(sb); |
| 3113 | phba->total_scsi_bufs--; |
| 3114 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3115 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3116 | |
| 3117 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3118 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3119 | list) { |
| 3120 | list_del(&sb->list); |
| 3121 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
| 3122 | sb->dma_handle); |
| 3123 | kfree(sb); |
| 3124 | phba->total_scsi_bufs--; |
| 3125 | } |
| 3126 | spin_unlock(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3127 | |
| 3128 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 3129 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 3130 | list_del(&io->list); |
| 3131 | kfree(io); |
| 3132 | phba->total_iocbq_bufs--; |
| 3133 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3134 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3135 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | /** |
| 3139 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 3140 | * @phba: pointer to lpfc hba data structure. |
| 3141 | * |
| 3142 | * This routine first calculates the sizes of the current els and allocated |
| 3143 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3144 | * XRIs assigned due to port function reset. During port initialization, the |
| 3145 | * current els and allocated scsi sgl lists are 0s. |
| 3146 | * |
| 3147 | * Return codes |
| 3148 | * 0 - successful (for now, it always returns 0) |
| 3149 | **/ |
| 3150 | int |
| 3151 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 3152 | { |
| 3153 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3154 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 3155 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 3156 | LIST_HEAD(els_sgl_list); |
| 3157 | LIST_HEAD(scsi_sgl_list); |
| 3158 | int rc; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3159 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3160 | |
| 3161 | /* |
| 3162 | * update on pci function's els xri-sgl list |
| 3163 | */ |
| 3164 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3165 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3166 | /* els xri-sgl expanded */ |
| 3167 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3168 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3169 | "3157 ELS xri-sgl count increased from " |
| 3170 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3171 | els_xri_cnt); |
| 3172 | /* allocate the additional els sgls */ |
| 3173 | for (i = 0; i < xri_cnt; i++) { |
| 3174 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3175 | GFP_KERNEL); |
| 3176 | if (sglq_entry == NULL) { |
| 3177 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3178 | "2562 Failure to allocate an " |
| 3179 | "ELS sgl entry:%d\n", i); |
| 3180 | rc = -ENOMEM; |
| 3181 | goto out_free_mem; |
| 3182 | } |
| 3183 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3184 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3185 | &sglq_entry->phys); |
| 3186 | if (sglq_entry->virt == NULL) { |
| 3187 | kfree(sglq_entry); |
| 3188 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3189 | "2563 Failure to allocate an " |
| 3190 | "ELS mbuf:%d\n", i); |
| 3191 | rc = -ENOMEM; |
| 3192 | goto out_free_mem; |
| 3193 | } |
| 3194 | sglq_entry->sgl = sglq_entry->virt; |
| 3195 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3196 | sglq_entry->state = SGL_FREED; |
| 3197 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3198 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3199 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3200 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3201 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3202 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3203 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3204 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3205 | /* els xri-sgl shrinked */ |
| 3206 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3207 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3208 | "3158 ELS xri-sgl count decreased from " |
| 3209 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3210 | els_xri_cnt); |
| 3211 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3212 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3213 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3214 | spin_unlock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3215 | spin_unlock_irq(&phba->hbalock); |
| 3216 | /* release extra els sgls from list */ |
| 3217 | for (i = 0; i < xri_cnt; i++) { |
| 3218 | list_remove_head(&els_sgl_list, |
| 3219 | sglq_entry, struct lpfc_sglq, list); |
| 3220 | if (sglq_entry) { |
| 3221 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3222 | sglq_entry->phys); |
| 3223 | kfree(sglq_entry); |
| 3224 | } |
| 3225 | } |
| 3226 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3227 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3228 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3229 | spin_unlock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3230 | spin_unlock_irq(&phba->hbalock); |
| 3231 | } else |
| 3232 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3233 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3234 | els_xri_cnt); |
| 3235 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3236 | |
| 3237 | /* update xris to els sgls on the list */ |
| 3238 | sglq_entry = NULL; |
| 3239 | sglq_entry_next = NULL; |
| 3240 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3241 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 3242 | lxri = lpfc_sli4_next_xritag(phba); |
| 3243 | if (lxri == NO_XRI) { |
| 3244 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3245 | "2400 Failed to allocate xri for " |
| 3246 | "ELS sgl\n"); |
| 3247 | rc = -ENOMEM; |
| 3248 | goto out_free_mem; |
| 3249 | } |
| 3250 | sglq_entry->sli4_lxritag = lxri; |
| 3251 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3252 | } |
| 3253 | |
| 3254 | /* |
| 3255 | * update on pci function's allocated scsi xri-sgl list |
| 3256 | */ |
| 3257 | phba->total_scsi_bufs = 0; |
| 3258 | |
| 3259 | /* maximum number of xris available for scsi buffers */ |
| 3260 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3261 | els_xri_cnt; |
| 3262 | |
| 3263 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3264 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 3265 | "maximum SCSI xri count:%d\n", |
| 3266 | phba->sli4_hba.scsi_xri_cnt, |
| 3267 | phba->sli4_hba.scsi_xri_max); |
| 3268 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3269 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3270 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3271 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3272 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3273 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3274 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3275 | |
| 3276 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3277 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3278 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3279 | phba->sli4_hba.scsi_xri_max; |
| 3280 | /* release the extra allocated scsi buffers */ |
| 3281 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3282 | list_remove_head(&scsi_sgl_list, psb, |
| 3283 | struct lpfc_scsi_buf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3284 | if (psb) { |
| 3285 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 3286 | psb->data, psb->dma_handle); |
| 3287 | kfree(psb); |
| 3288 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3289 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3290 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3291 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3292 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | /* update xris associated to remaining allocated scsi buffers */ |
| 3296 | psb = NULL; |
| 3297 | psb_next = NULL; |
| 3298 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3299 | lxri = lpfc_sli4_next_xritag(phba); |
| 3300 | if (lxri == NO_XRI) { |
| 3301 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3302 | "2560 Failed to allocate xri for " |
| 3303 | "scsi buffer\n"); |
| 3304 | rc = -ENOMEM; |
| 3305 | goto out_free_mem; |
| 3306 | } |
| 3307 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3308 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3309 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3310 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3311 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3312 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3313 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3314 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3315 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3317 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3318 | |
| 3319 | out_free_mem: |
| 3320 | lpfc_free_els_sgl_list(phba); |
| 3321 | lpfc_scsi_free(phba); |
| 3322 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | } |
| 3324 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3326 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3327 | * @phba: pointer to lpfc hba data structure. |
| 3328 | * @instance: a unique integer ID to this FC port. |
| 3329 | * @dev: pointer to the device data structure. |
| 3330 | * |
| 3331 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3332 | * can be created on top of either a physical port or a virtual port provided |
| 3333 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3334 | * and associates the FC port created before adding the shost into the SCSI |
| 3335 | * layer. |
| 3336 | * |
| 3337 | * Return codes |
| 3338 | * @vport - pointer to the virtual N_Port data structure. |
| 3339 | * NULL - port create failed. |
| 3340 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3341 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3342 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3343 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | struct lpfc_vport *vport; |
| 3345 | struct Scsi_Host *shost; |
| 3346 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3347 | |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3348 | if (dev != &phba->pcidev->dev) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3349 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3350 | sizeof(struct lpfc_vport)); |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3351 | } else { |
| 3352 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3353 | shost = scsi_host_alloc(&lpfc_template, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3354 | sizeof(struct lpfc_vport)); |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3355 | else |
| 3356 | shost = scsi_host_alloc(&lpfc_template_s3, |
| 3357 | sizeof(struct lpfc_vport)); |
| 3358 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3359 | if (!shost) |
| 3360 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3363 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3364 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3365 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3366 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3367 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3368 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3369 | shost->unique_id = instance; |
| 3370 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3371 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3372 | shost->this_id = -1; |
| 3373 | shost->max_cmd_len = 16; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3374 | shost->nr_hw_queues = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3375 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3376 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3377 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3378 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3379 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3380 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3381 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3382 | * Set initial can_queue value since 0 is no longer supported and |
| 3383 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3384 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3385 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3386 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3387 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3388 | shost->transportt = lpfc_vport_transport_template; |
| 3389 | vport->port_type = LPFC_NPIV_PORT; |
| 3390 | } else { |
| 3391 | shost->transportt = lpfc_transport_template; |
| 3392 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3393 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3394 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3395 | /* Initialize all internally managed lists. */ |
| 3396 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3397 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3398 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3399 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3400 | init_timer(&vport->fc_disctmo); |
| 3401 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3402 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3403 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3404 | init_timer(&vport->els_tmofunc); |
| 3405 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3406 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3407 | |
| 3408 | init_timer(&vport->delayed_disc_tmo); |
| 3409 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3410 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3411 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3412 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3413 | if (error) |
| 3414 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3415 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3416 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3417 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3418 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3419 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3420 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3421 | out_put_shost: |
| 3422 | scsi_host_put(shost); |
| 3423 | out: |
| 3424 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3425 | } |
| 3426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3428 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3429 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3430 | * |
| 3431 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3432 | * resources associated with the port are released. |
| 3433 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3434 | void |
| 3435 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3436 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3437 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3438 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3439 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3440 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3441 | fc_remove_host(shost); |
| 3442 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3443 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | spin_lock_irq(&phba->hbalock); |
| 3445 | list_del_init(&vport->listentry); |
| 3446 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3447 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3448 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3449 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3450 | } |
| 3451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3452 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3453 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3454 | * |
| 3455 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3456 | * uses the kernel idr facility to perform the task. |
| 3457 | * |
| 3458 | * Return codes: |
| 3459 | * instance - a unique integer ID allocated as the new instance. |
| 3460 | * -1 - lpfc get instance failed. |
| 3461 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3462 | int |
| 3463 | lpfc_get_instance(void) |
| 3464 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3465 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3466 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3467 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 3468 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3469 | } |
| 3470 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3471 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3472 | * 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] | 3473 | * @shost: pointer to SCSI host data structure. |
| 3474 | * @time: elapsed time of the scan in jiffies. |
| 3475 | * |
| 3476 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3477 | * whether the scan host is finished. |
| 3478 | * |
| 3479 | * Note: there is no scan_start function as adapter initialization will have |
| 3480 | * asynchronously kicked off the link initialization. |
| 3481 | * |
| 3482 | * Return codes |
| 3483 | * 0 - SCSI host scan is not over yet. |
| 3484 | * 1 - SCSI host scan is over. |
| 3485 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3486 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3487 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3488 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3489 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3490 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3491 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3492 | spin_lock_irq(shost->host_lock); |
| 3493 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3494 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3495 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3496 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3497 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3498 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3499 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3500 | "0461 Scanning longer than 30 " |
| 3501 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3502 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3503 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3504 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3505 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 3506 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3507 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3508 | "0465 Link down longer than 15 " |
| 3509 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3510 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3512 | } |
| 3513 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3514 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3515 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3516 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3517 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3518 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3519 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3520 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3521 | goto finished; |
| 3522 | |
| 3523 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3524 | |
| 3525 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3526 | spin_unlock_irq(shost->host_lock); |
| 3527 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3528 | } |
| 3529 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3530 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3531 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3532 | * @shost: pointer to SCSI host data structure. |
| 3533 | * |
| 3534 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3535 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3536 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3537 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3538 | { |
| 3539 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3540 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3541 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3542 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3543 | */ |
| 3544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3545 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3546 | 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] | 3547 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3548 | |
| 3549 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3550 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3551 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3552 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3553 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3554 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3555 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3556 | |
| 3557 | fc_host_supported_speeds(shost) = 0; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 3558 | if (phba->lmt & LMT_32Gb) |
| 3559 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3560 | if (phba->lmt & LMT_16Gb) |
| 3561 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3562 | if (phba->lmt & LMT_10Gb) |
| 3563 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3564 | if (phba->lmt & LMT_8Gb) |
| 3565 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3566 | if (phba->lmt & LMT_4Gb) |
| 3567 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3568 | if (phba->lmt & LMT_2Gb) |
| 3569 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3570 | if (phba->lmt & LMT_1Gb) |
| 3571 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3572 | |
| 3573 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3574 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3575 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3576 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3577 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3578 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3579 | /* This value is also unchanging */ |
| 3580 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3581 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3582 | fc_host_active_fc4s(shost)[2] = 1; |
| 3583 | fc_host_active_fc4s(shost)[7] = 1; |
| 3584 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3585 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3586 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3587 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3588 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3589 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3591 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3592 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3593 | * @phba: pointer to lpfc hba data structure. |
| 3594 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3595 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3596 | * from generating interrupts and stops the device driver's timers for the |
| 3597 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3598 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3599 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3600 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3601 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3602 | /* Clear all interrupt enable conditions */ |
| 3603 | writel(0, phba->HCregaddr); |
| 3604 | readl(phba->HCregaddr); /* flush */ |
| 3605 | /* Clear all pending interrupts */ |
| 3606 | writel(0xffffffff, phba->HAregaddr); |
| 3607 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3608 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3609 | /* Reset some HBA SLI setup states */ |
| 3610 | lpfc_stop_hba_timers(phba); |
| 3611 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3612 | } |
| 3613 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3614 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3615 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3616 | * @phba: pointer to lpfc hba data structure. |
| 3617 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3618 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3619 | * from generating interrupts and stops the device driver's timers for the |
| 3620 | * device. |
| 3621 | **/ |
| 3622 | static void |
| 3623 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3624 | { |
| 3625 | /* Reset some HBA SLI4 setup states */ |
| 3626 | lpfc_stop_hba_timers(phba); |
| 3627 | phba->pport->work_port_events = 0; |
| 3628 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | /** |
| 3632 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3633 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3634 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3635 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3636 | * the API jump table function pointer from the lpfc_hba struct. |
| 3637 | **/ |
| 3638 | void |
| 3639 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3640 | { |
| 3641 | phba->lpfc_stop_port(phba); |
| 3642 | } |
| 3643 | |
| 3644 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3645 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3646 | * @phba: Pointer to hba for which this call is being executed. |
| 3647 | * |
| 3648 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3649 | **/ |
| 3650 | void |
| 3651 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3652 | { |
| 3653 | unsigned long fcf_redisc_wait_tmo = |
| 3654 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3655 | /* Start fcf rediscovery wait period timer */ |
| 3656 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3657 | spin_lock_irq(&phba->hbalock); |
| 3658 | /* Allow action to new fcf asynchronous event */ |
| 3659 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3660 | /* Mark the FCF rediscovery pending state */ |
| 3661 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3662 | spin_unlock_irq(&phba->hbalock); |
| 3663 | } |
| 3664 | |
| 3665 | /** |
| 3666 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3667 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3668 | * |
| 3669 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3670 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3671 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3672 | * list, and then worker thread shall be waked up for processing from the |
| 3673 | * worker thread context. |
| 3674 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 3675 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3676 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3677 | { |
| 3678 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3679 | |
| 3680 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3681 | spin_lock_irq(&phba->hbalock); |
| 3682 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3683 | spin_unlock_irq(&phba->hbalock); |
| 3684 | return; |
| 3685 | } |
| 3686 | /* Clear FCF rediscovery timer pending flag */ |
| 3687 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3688 | /* FCF rediscovery event to worker thread */ |
| 3689 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3690 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3691 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3692 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3693 | /* wake up worker thread */ |
| 3694 | lpfc_worker_wake_up(phba); |
| 3695 | } |
| 3696 | |
| 3697 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3698 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3699 | * @phba: pointer to lpfc hba data structure. |
| 3700 | * @acqe_link: pointer to the async link completion queue entry. |
| 3701 | * |
| 3702 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3703 | * translate it into the base driver's read link attention mailbox command |
| 3704 | * status. |
| 3705 | * |
| 3706 | * Return: Link-attention status in terms of base driver's coding. |
| 3707 | **/ |
| 3708 | static uint16_t |
| 3709 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3710 | struct lpfc_acqe_link *acqe_link) |
| 3711 | { |
| 3712 | uint16_t latt_fault; |
| 3713 | |
| 3714 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3715 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3716 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3717 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3718 | latt_fault = 0; |
| 3719 | break; |
| 3720 | default: |
| 3721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3722 | "0398 Invalid link fault code: x%x\n", |
| 3723 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3724 | latt_fault = MBXERR_ERROR; |
| 3725 | break; |
| 3726 | } |
| 3727 | return latt_fault; |
| 3728 | } |
| 3729 | |
| 3730 | /** |
| 3731 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3732 | * @phba: pointer to lpfc hba data structure. |
| 3733 | * @acqe_link: pointer to the async link completion queue entry. |
| 3734 | * |
| 3735 | * This routine is to parse the SLI4 link attention type and translate it |
| 3736 | * into the base driver's link attention type coding. |
| 3737 | * |
| 3738 | * Return: Link attention type in terms of base driver's coding. |
| 3739 | **/ |
| 3740 | static uint8_t |
| 3741 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3742 | struct lpfc_acqe_link *acqe_link) |
| 3743 | { |
| 3744 | uint8_t att_type; |
| 3745 | |
| 3746 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3747 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3748 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3749 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3750 | break; |
| 3751 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3752 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3753 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3754 | break; |
| 3755 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3756 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3757 | break; |
| 3758 | default: |
| 3759 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3760 | "0399 Invalid link attention type: x%x\n", |
| 3761 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3762 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3763 | break; |
| 3764 | } |
| 3765 | return att_type; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3769 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 3770 | * @phba: pointer to lpfc hba data structure. |
| 3771 | * |
| 3772 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 3773 | * |
| 3774 | * Return: link speed in terms of Mbps. |
| 3775 | **/ |
| 3776 | uint32_t |
| 3777 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 3778 | { |
| 3779 | uint32_t link_speed; |
| 3780 | |
| 3781 | if (!lpfc_is_link_up(phba)) |
| 3782 | return 0; |
| 3783 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 3784 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 3785 | switch (phba->fc_linkspeed) { |
| 3786 | case LPFC_LINK_SPEED_1GHZ: |
| 3787 | link_speed = 1000; |
| 3788 | break; |
| 3789 | case LPFC_LINK_SPEED_2GHZ: |
| 3790 | link_speed = 2000; |
| 3791 | break; |
| 3792 | case LPFC_LINK_SPEED_4GHZ: |
| 3793 | link_speed = 4000; |
| 3794 | break; |
| 3795 | case LPFC_LINK_SPEED_8GHZ: |
| 3796 | link_speed = 8000; |
| 3797 | break; |
| 3798 | case LPFC_LINK_SPEED_10GHZ: |
| 3799 | link_speed = 10000; |
| 3800 | break; |
| 3801 | case LPFC_LINK_SPEED_16GHZ: |
| 3802 | link_speed = 16000; |
| 3803 | break; |
| 3804 | default: |
| 3805 | link_speed = 0; |
| 3806 | } |
| 3807 | } else { |
| 3808 | if (phba->sli4_hba.link_state.logical_speed) |
| 3809 | link_speed = |
| 3810 | phba->sli4_hba.link_state.logical_speed; |
| 3811 | else |
| 3812 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3813 | } |
| 3814 | return link_speed; |
| 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 3819 | * @phba: pointer to lpfc hba data structure. |
| 3820 | * @evt_code: asynchronous event code. |
| 3821 | * @speed_code: asynchronous event link speed code. |
| 3822 | * |
| 3823 | * This routine is to parse the giving SLI4 async event link speed code into |
| 3824 | * value of Mbps for the link speed. |
| 3825 | * |
| 3826 | * Return: link speed in terms of Mbps. |
| 3827 | **/ |
| 3828 | static uint32_t |
| 3829 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 3830 | uint8_t speed_code) |
| 3831 | { |
| 3832 | uint32_t port_speed; |
| 3833 | |
| 3834 | switch (evt_code) { |
| 3835 | case LPFC_TRAILER_CODE_LINK: |
| 3836 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3837 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3838 | port_speed = 0; |
| 3839 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3840 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3841 | port_speed = 10; |
| 3842 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3843 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3844 | port_speed = 100; |
| 3845 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3846 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3847 | port_speed = 1000; |
| 3848 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3849 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3850 | port_speed = 10000; |
| 3851 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3852 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 3853 | port_speed = 20000; |
| 3854 | break; |
| 3855 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 3856 | port_speed = 25000; |
| 3857 | break; |
| 3858 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 3859 | port_speed = 40000; |
| 3860 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3861 | default: |
| 3862 | port_speed = 0; |
| 3863 | } |
| 3864 | break; |
| 3865 | case LPFC_TRAILER_CODE_FC: |
| 3866 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3867 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3868 | port_speed = 0; |
| 3869 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3870 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3871 | port_speed = 1000; |
| 3872 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3873 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3874 | port_speed = 2000; |
| 3875 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3876 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3877 | port_speed = 4000; |
| 3878 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3879 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3880 | port_speed = 8000; |
| 3881 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3882 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3883 | port_speed = 10000; |
| 3884 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3885 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3886 | port_speed = 16000; |
| 3887 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 3888 | case LPFC_FC_LA_SPEED_32G: |
| 3889 | port_speed = 32000; |
| 3890 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3891 | default: |
| 3892 | port_speed = 0; |
| 3893 | } |
| 3894 | break; |
| 3895 | default: |
| 3896 | port_speed = 0; |
| 3897 | } |
| 3898 | return port_speed; |
| 3899 | } |
| 3900 | |
| 3901 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3902 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3903 | * @phba: pointer to lpfc hba data structure. |
| 3904 | * @acqe_link: pointer to the async link completion queue entry. |
| 3905 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3906 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3907 | **/ |
| 3908 | static void |
| 3909 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3910 | struct lpfc_acqe_link *acqe_link) |
| 3911 | { |
| 3912 | struct lpfc_dmabuf *mp; |
| 3913 | LPFC_MBOXQ_t *pmb; |
| 3914 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3915 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3916 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3917 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3918 | |
| 3919 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3920 | 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] | 3921 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3922 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3923 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3924 | if (!pmb) { |
| 3925 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3926 | "0395 The mboxq allocation failed\n"); |
| 3927 | return; |
| 3928 | } |
| 3929 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3930 | if (!mp) { |
| 3931 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3932 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3933 | goto out_free_pmb; |
| 3934 | } |
| 3935 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3936 | if (!mp->virt) { |
| 3937 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3938 | "0397 The mbuf allocation failed\n"); |
| 3939 | goto out_free_dmabuf; |
| 3940 | } |
| 3941 | |
| 3942 | /* Cleanup any outstanding ELS commands */ |
| 3943 | lpfc_els_flush_all_cmd(phba); |
| 3944 | |
| 3945 | /* Block ELS IOCBs until we have done process link event */ |
| 3946 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3947 | |
| 3948 | /* Update link event statistics */ |
| 3949 | phba->sli.slistat.link_event++; |
| 3950 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3951 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3952 | lpfc_read_topology(phba, pmb, mp); |
| 3953 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3954 | pmb->vport = phba->pport; |
| 3955 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3956 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3957 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3958 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 3959 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3960 | phba->sli4_hba.link_state.duplex = |
| 3961 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3962 | phba->sli4_hba.link_state.status = |
| 3963 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3964 | phba->sli4_hba.link_state.type = |
| 3965 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3966 | phba->sli4_hba.link_state.number = |
| 3967 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3968 | phba->sli4_hba.link_state.fault = |
| 3969 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3970 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3971 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 3972 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3974 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3975 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3976 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3977 | phba->sli4_hba.link_state.speed, |
| 3978 | phba->sli4_hba.link_state.topology, |
| 3979 | phba->sli4_hba.link_state.status, |
| 3980 | phba->sli4_hba.link_state.type, |
| 3981 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3982 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3983 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3984 | /* |
| 3985 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3986 | * topology info. Note: Optional for non FC-AL ports. |
| 3987 | */ |
| 3988 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3989 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3990 | if (rc == MBX_NOT_FINISHED) |
| 3991 | goto out_free_dmabuf; |
| 3992 | return; |
| 3993 | } |
| 3994 | /* |
| 3995 | * For FCoE Mode: fill in all the topology information we need and call |
| 3996 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3997 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3998 | */ |
| 3999 | /* Parse and translate status field */ |
| 4000 | mb = &pmb->u.mb; |
| 4001 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 4002 | |
| 4003 | /* Parse and translate link attention fields */ |
| 4004 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4005 | la->eventTag = acqe_link->event_tag; |
| 4006 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4007 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4008 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4009 | |
| 4010 | /* Fake the the following irrelvant fields */ |
| 4011 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4012 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4013 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4014 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4015 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4016 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4017 | |
| 4018 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4019 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4020 | |
| 4021 | return; |
| 4022 | |
| 4023 | out_free_dmabuf: |
| 4024 | kfree(mp); |
| 4025 | out_free_pmb: |
| 4026 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4027 | } |
| 4028 | |
| 4029 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4030 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 4031 | * @phba: pointer to lpfc hba data structure. |
| 4032 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 4033 | * |
| 4034 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 4035 | * that the event was received and then issue a read_topology mailbox command so |
| 4036 | * that the rest of the driver will treat it the same as SLI3. |
| 4037 | **/ |
| 4038 | static void |
| 4039 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 4040 | { |
| 4041 | struct lpfc_dmabuf *mp; |
| 4042 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4043 | MAILBOX_t *mb; |
| 4044 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4045 | int rc; |
| 4046 | |
| 4047 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 4048 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 4049 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4050 | "2895 Non FC link Event detected.(%d)\n", |
| 4051 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 4052 | return; |
| 4053 | } |
| 4054 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4055 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4056 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 4057 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4058 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 4059 | phba->sli4_hba.link_state.topology = |
| 4060 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 4061 | phba->sli4_hba.link_state.status = |
| 4062 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 4063 | phba->sli4_hba.link_state.type = |
| 4064 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 4065 | phba->sli4_hba.link_state.number = |
| 4066 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 4067 | phba->sli4_hba.link_state.fault = |
| 4068 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 4069 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4070 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4071 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4072 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 4073 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 4074 | "%dMbps Fault:%d\n", |
| 4075 | phba->sli4_hba.link_state.speed, |
| 4076 | phba->sli4_hba.link_state.topology, |
| 4077 | phba->sli4_hba.link_state.status, |
| 4078 | phba->sli4_hba.link_state.type, |
| 4079 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4080 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4081 | phba->sli4_hba.link_state.fault); |
| 4082 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4083 | if (!pmb) { |
| 4084 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4085 | "2897 The mboxq allocation failed\n"); |
| 4086 | return; |
| 4087 | } |
| 4088 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4089 | if (!mp) { |
| 4090 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4091 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 4092 | goto out_free_pmb; |
| 4093 | } |
| 4094 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4095 | if (!mp->virt) { |
| 4096 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4097 | "2899 The mbuf allocation failed\n"); |
| 4098 | goto out_free_dmabuf; |
| 4099 | } |
| 4100 | |
| 4101 | /* Cleanup any outstanding ELS commands */ |
| 4102 | lpfc_els_flush_all_cmd(phba); |
| 4103 | |
| 4104 | /* Block ELS IOCBs until we have done process link event */ |
| 4105 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 4106 | |
| 4107 | /* Update link event statistics */ |
| 4108 | phba->sli.slistat.link_event++; |
| 4109 | |
| 4110 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4111 | lpfc_read_topology(phba, pmb, mp); |
| 4112 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 4113 | pmb->vport = phba->pport; |
| 4114 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4115 | if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) { |
| 4116 | /* Parse and translate status field */ |
| 4117 | mb = &pmb->u.mb; |
| 4118 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, |
| 4119 | (void *)acqe_fc); |
| 4120 | |
| 4121 | /* Parse and translate link attention fields */ |
| 4122 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 4123 | la->eventTag = acqe_fc->event_tag; |
| 4124 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 4125 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 4126 | |
| 4127 | /* Invoke the mailbox command callback function */ |
| 4128 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 4129 | |
| 4130 | return; |
| 4131 | } |
| 4132 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4133 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4134 | if (rc == MBX_NOT_FINISHED) |
| 4135 | goto out_free_dmabuf; |
| 4136 | return; |
| 4137 | |
| 4138 | out_free_dmabuf: |
| 4139 | kfree(mp); |
| 4140 | out_free_pmb: |
| 4141 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4142 | } |
| 4143 | |
| 4144 | /** |
| 4145 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 4146 | * @phba: pointer to lpfc hba data structure. |
| 4147 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 4148 | * |
| 4149 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 4150 | **/ |
| 4151 | static void |
| 4152 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 4153 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4154 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 4155 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4156 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4157 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4158 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4159 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4160 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4161 | struct Scsi_Host *shost; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4162 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4163 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 4164 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4165 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4166 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4167 | "x%08x SLI Event Type:%d\n", |
| 4168 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4169 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4170 | |
| 4171 | port_name = phba->Port[0]; |
| 4172 | if (port_name == 0x00) |
| 4173 | port_name = '?'; /* get port name is empty */ |
| 4174 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4175 | switch (evt_type) { |
| 4176 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 4177 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4178 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 4179 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4180 | |
| 4181 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4182 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 4183 | acqe_sli->event_data1, port_name); |
| 4184 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4185 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4186 | shost = lpfc_shost_from_vport(phba->pport); |
| 4187 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4188 | sizeof(temp_event_data), |
| 4189 | (char *)&temp_event_data, |
| 4190 | SCSI_NL_VID_TYPE_PCI |
| 4191 | | PCI_VENDOR_ID_EMULEX); |
| 4192 | break; |
| 4193 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 4194 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4195 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 4196 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4197 | |
| 4198 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4199 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 4200 | acqe_sli->event_data1, port_name); |
| 4201 | |
| 4202 | shost = lpfc_shost_from_vport(phba->pport); |
| 4203 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4204 | sizeof(temp_event_data), |
| 4205 | (char *)&temp_event_data, |
| 4206 | SCSI_NL_VID_TYPE_PCI |
| 4207 | | PCI_VENDOR_ID_EMULEX); |
| 4208 | break; |
| 4209 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 4210 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4211 | &acqe_sli->event_data1; |
| 4212 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4213 | /* fetch the status for this port */ |
| 4214 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4215 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4216 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 4217 | &misconfigured->theEvent); |
| 4218 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4219 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4220 | break; |
| 4221 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4222 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 4223 | &misconfigured->theEvent); |
| 4224 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4225 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4226 | break; |
| 4227 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4228 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 4229 | &misconfigured->theEvent); |
| 4230 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4231 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4232 | break; |
| 4233 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4234 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 4235 | &misconfigured->theEvent); |
| 4236 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4237 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4238 | break; |
| 4239 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4240 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4241 | "3296 " |
| 4242 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 4243 | "event: Invalid link %d", |
| 4244 | phba->sli4_hba.lnk_info.lnk_no); |
| 4245 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4246 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4247 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4248 | /* Skip if optic state unchanged */ |
| 4249 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 4250 | return; |
| 4251 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4252 | switch (status) { |
| 4253 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4254 | sprintf(message, "Physical Link is functional"); |
| 4255 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4256 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 4257 | sprintf(message, "Optics faulted/incorrectly " |
| 4258 | "installed/not installed - Reseat optics, " |
| 4259 | "if issue not resolved, replace."); |
| 4260 | break; |
| 4261 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 4262 | sprintf(message, |
| 4263 | "Optics of two types installed - Remove one " |
| 4264 | "optic or install matching pair of optics."); |
| 4265 | break; |
| 4266 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 4267 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4268 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4269 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4270 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 4271 | sprintf(message, "Unqualified optics - Replace with " |
| 4272 | "Avago optics for Warranty and Technical " |
| 4273 | "Support - Link is%s operational", |
| 4274 | (operational) ? "" : " not"); |
| 4275 | break; |
| 4276 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 4277 | sprintf(message, "Uncertified optics - Replace with " |
| 4278 | "Avago-certified optics to enable link " |
| 4279 | "operation - Link is%s operational", |
| 4280 | (operational) ? "" : " not"); |
| 4281 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4282 | default: |
| 4283 | /* firmware is reporting a status we don't know about */ |
| 4284 | sprintf(message, "Unknown event status x%02x", status); |
| 4285 | break; |
| 4286 | } |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4287 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4288 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4289 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4290 | break; |
| 4291 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 4292 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4293 | "3192 Remote DPort Test Initiated - " |
| 4294 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 4295 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4296 | break; |
| 4297 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4298 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4299 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4300 | "x%08x SLI Event Type:%d\n", |
| 4301 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4302 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4303 | break; |
| 4304 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4308 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 4309 | * @vport: pointer to vport data structure. |
| 4310 | * |
| 4311 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 4312 | * response to a CVL event. |
| 4313 | * |
| 4314 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 4315 | * return NULL. |
| 4316 | **/ |
| 4317 | static struct lpfc_nodelist * |
| 4318 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 4319 | { |
| 4320 | struct lpfc_nodelist *ndlp; |
| 4321 | struct Scsi_Host *shost; |
| 4322 | struct lpfc_hba *phba; |
| 4323 | |
| 4324 | if (!vport) |
| 4325 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4326 | phba = vport->phba; |
| 4327 | if (!phba) |
| 4328 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4329 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4330 | if (!ndlp) { |
| 4331 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 4332 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4333 | if (!ndlp) |
| 4334 | return 0; |
| 4335 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 4336 | /* Set the node type */ |
| 4337 | ndlp->nlp_type |= NLP_FABRIC; |
| 4338 | /* Put ndlp onto node list */ |
| 4339 | lpfc_enqueue_node(vport, ndlp); |
| 4340 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4341 | /* re-setup ndlp without removing from node list */ |
| 4342 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4343 | if (!ndlp) |
| 4344 | return 0; |
| 4345 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4346 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4347 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4348 | return NULL; |
| 4349 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4350 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4351 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4352 | return NULL; |
| 4353 | shost = lpfc_shost_from_vport(vport); |
| 4354 | if (!shost) |
| 4355 | return NULL; |
| 4356 | lpfc_linkdown_port(vport); |
| 4357 | lpfc_cleanup_pending_mbox(vport); |
| 4358 | spin_lock_irq(shost->host_lock); |
| 4359 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4360 | spin_unlock_irq(shost->host_lock); |
| 4361 | |
| 4362 | return ndlp; |
| 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4367 | * @vport: pointer to lpfc hba data structure. |
| 4368 | * |
| 4369 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4370 | * response to a FCF dead event. |
| 4371 | **/ |
| 4372 | static void |
| 4373 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4374 | { |
| 4375 | struct lpfc_vport **vports; |
| 4376 | int i; |
| 4377 | |
| 4378 | vports = lpfc_create_vport_work_array(phba); |
| 4379 | if (vports) |
| 4380 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4381 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4382 | lpfc_destroy_vport_work_array(phba, vports); |
| 4383 | } |
| 4384 | |
| 4385 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4386 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4387 | * @phba: pointer to lpfc hba data structure. |
| 4388 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4389 | * |
| 4390 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4391 | **/ |
| 4392 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4393 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4394 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4395 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4396 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4397 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4398 | struct lpfc_vport *vport; |
| 4399 | struct lpfc_nodelist *ndlp; |
| 4400 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4401 | int active_vlink_present; |
| 4402 | struct lpfc_vport **vports; |
| 4403 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4404 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4405 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4406 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4407 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4408 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4409 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4410 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4411 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4412 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4413 | "2546 New FCF event, evt_tag:x%x, " |
| 4414 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4415 | acqe_fip->event_tag, |
| 4416 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4417 | else |
| 4418 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4419 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4420 | "2788 FCF param modified event, " |
| 4421 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4422 | acqe_fip->event_tag, |
| 4423 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4424 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4425 | /* |
| 4426 | * During period of FCF discovery, read the FCF |
| 4427 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4428 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4429 | */ |
| 4430 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4431 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4432 | "2779 Read FCF (x%x) for updating " |
| 4433 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4434 | acqe_fip->index); |
| 4435 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4436 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4437 | |
| 4438 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4439 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4440 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4441 | spin_unlock_irq(&phba->hbalock); |
| 4442 | break; |
| 4443 | } |
| 4444 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 4445 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 4446 | spin_unlock_irq(&phba->hbalock); |
| 4447 | break; |
| 4448 | } |
| 4449 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4450 | /* If the FCF has been in discovered state, do nothing. */ |
| 4451 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4452 | spin_unlock_irq(&phba->hbalock); |
| 4453 | break; |
| 4454 | } |
| 4455 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4456 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4457 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 4458 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4459 | "2770 Start FCF table scan per async FCF " |
| 4460 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4461 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4462 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 4463 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4464 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4465 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4466 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4467 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4468 | break; |
| 4469 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4470 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4471 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4472 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4473 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 4474 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4475 | break; |
| 4476 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4477 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4478 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4479 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4480 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4481 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4482 | /* |
| 4483 | * If we are in the middle of FCF failover process, clear |
| 4484 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4485 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4486 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame^] | 4487 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 4488 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4489 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4490 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4491 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4492 | break; |
| 4493 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4494 | spin_unlock_irq(&phba->hbalock); |
| 4495 | |
| 4496 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4497 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4498 | break; |
| 4499 | |
| 4500 | /* |
| 4501 | * Otherwise, request the port to rediscover the entire FCF |
| 4502 | * table for a fast recovery from case that the current FCF |
| 4503 | * is no longer valid as we are not in the middle of FCF |
| 4504 | * failover process already. |
| 4505 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4506 | spin_lock_irq(&phba->hbalock); |
| 4507 | /* Mark the fast failover process in progress */ |
| 4508 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 4509 | spin_unlock_irq(&phba->hbalock); |
| 4510 | |
| 4511 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4512 | "2771 Start FCF fast failover process due to " |
| 4513 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 4514 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 4515 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4516 | if (rc) { |
| 4517 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4518 | LOG_DISCOVERY, |
| 4519 | "2772 Issue FCF rediscover mabilbox " |
| 4520 | "command failed, fail through to FCF " |
| 4521 | "dead event\n"); |
| 4522 | spin_lock_irq(&phba->hbalock); |
| 4523 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 4524 | spin_unlock_irq(&phba->hbalock); |
| 4525 | /* |
| 4526 | * Last resort will fail over by treating this |
| 4527 | * as a link down to FCF registration. |
| 4528 | */ |
| 4529 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 4530 | } else { |
| 4531 | /* Reset FCF roundrobin bmask for new discovery */ |
| 4532 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 4533 | /* |
| 4534 | * Handling fast FCF failover to a DEAD FCF event is |
| 4535 | * considered equalivant to receiving CVL to all vports. |
| 4536 | */ |
| 4537 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 4538 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4539 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4540 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4541 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4542 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4543 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4544 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4545 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4546 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4547 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4548 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4549 | if (!ndlp) |
| 4550 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4551 | active_vlink_present = 0; |
| 4552 | |
| 4553 | vports = lpfc_create_vport_work_array(phba); |
| 4554 | if (vports) { |
| 4555 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4556 | i++) { |
| 4557 | if ((!(vports[i]->fc_flag & |
| 4558 | FC_VPORT_CVL_RCVD)) && |
| 4559 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4560 | active_vlink_present = 1; |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | lpfc_destroy_vport_work_array(phba, vports); |
| 4565 | } |
| 4566 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 4567 | /* |
| 4568 | * Don't re-instantiate if vport is marked for deletion. |
| 4569 | * If we are here first then vport_delete is going to wait |
| 4570 | * for discovery to complete. |
| 4571 | */ |
| 4572 | if (!(vport->load_flag & FC_UNLOADING) && |
| 4573 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4574 | /* |
| 4575 | * If there are other active VLinks present, |
| 4576 | * re-instantiate the Vlink using FDISC. |
| 4577 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4578 | mod_timer(&ndlp->nlp_delayfunc, |
| 4579 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4580 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4581 | spin_lock_irq(shost->host_lock); |
| 4582 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4583 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4584 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4585 | vport->port_state = LPFC_FDISC; |
| 4586 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4587 | /* |
| 4588 | * Otherwise, we request port to rediscover |
| 4589 | * the entire FCF table for a fast recovery |
| 4590 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4591 | * is no longer valid if we are not already |
| 4592 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4593 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4594 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4595 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4596 | spin_unlock_irq(&phba->hbalock); |
| 4597 | break; |
| 4598 | } |
| 4599 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4600 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4601 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4602 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4603 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4604 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4605 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4606 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4607 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4608 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4609 | LOG_DISCOVERY, |
| 4610 | "2774 Issue FCF rediscover " |
| 4611 | "mabilbox command failed, " |
| 4612 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4613 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4614 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4615 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4616 | /* |
| 4617 | * Last resort will be re-try on the |
| 4618 | * the current registered FCF entry. |
| 4619 | */ |
| 4620 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4621 | } else |
| 4622 | /* |
| 4623 | * Reset FCF roundrobin bmask for new |
| 4624 | * discovery. |
| 4625 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4626 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4627 | } |
| 4628 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4629 | default: |
| 4630 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4631 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4632 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4633 | break; |
| 4634 | } |
| 4635 | } |
| 4636 | |
| 4637 | /** |
| 4638 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4639 | * @phba: pointer to lpfc hba data structure. |
| 4640 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4641 | * |
| 4642 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4643 | **/ |
| 4644 | static void |
| 4645 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4646 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4647 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4648 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4649 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4650 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4651 | "handled yet\n"); |
| 4652 | } |
| 4653 | |
| 4654 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4655 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4656 | * @phba: pointer to lpfc hba data structure. |
| 4657 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4658 | * |
| 4659 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4660 | * is an asynchronous notified of a logical link speed change. The Port |
| 4661 | * reports the logical link speed in units of 10Mbps. |
| 4662 | **/ |
| 4663 | static void |
| 4664 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4665 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4666 | { |
| 4667 | uint16_t prev_ll_spd; |
| 4668 | |
| 4669 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4670 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4671 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4672 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4673 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4674 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4675 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4676 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 4677 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4681 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4682 | * @phba: pointer to lpfc hba data structure. |
| 4683 | * |
| 4684 | * This routine is invoked by the worker thread to process all the pending |
| 4685 | * SLI4 asynchronous events. |
| 4686 | **/ |
| 4687 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4688 | { |
| 4689 | struct lpfc_cq_event *cq_event; |
| 4690 | |
| 4691 | /* First, declare the async event has been handled */ |
| 4692 | spin_lock_irq(&phba->hbalock); |
| 4693 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4694 | spin_unlock_irq(&phba->hbalock); |
| 4695 | /* Now, handle all the async events */ |
| 4696 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4697 | /* Get the first event from the head of the event queue */ |
| 4698 | spin_lock_irq(&phba->hbalock); |
| 4699 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4700 | cq_event, struct lpfc_cq_event, list); |
| 4701 | spin_unlock_irq(&phba->hbalock); |
| 4702 | /* Process the asynchronous event */ |
| 4703 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4704 | case LPFC_TRAILER_CODE_LINK: |
| 4705 | lpfc_sli4_async_link_evt(phba, |
| 4706 | &cq_event->cqe.acqe_link); |
| 4707 | break; |
| 4708 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4709 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4710 | break; |
| 4711 | case LPFC_TRAILER_CODE_DCBX: |
| 4712 | lpfc_sli4_async_dcbx_evt(phba, |
| 4713 | &cq_event->cqe.acqe_dcbx); |
| 4714 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4715 | case LPFC_TRAILER_CODE_GRP5: |
| 4716 | lpfc_sli4_async_grp5_evt(phba, |
| 4717 | &cq_event->cqe.acqe_grp5); |
| 4718 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4719 | case LPFC_TRAILER_CODE_FC: |
| 4720 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4721 | break; |
| 4722 | case LPFC_TRAILER_CODE_SLI: |
| 4723 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4724 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4725 | default: |
| 4726 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4727 | "1804 Invalid asynchrous event code: " |
| 4728 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4729 | &cq_event->cqe.mcqe_cmpl)); |
| 4730 | break; |
| 4731 | } |
| 4732 | /* Free the completion event processed to the free pool */ |
| 4733 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4738 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4739 | * @phba: pointer to lpfc hba data structure. |
| 4740 | * |
| 4741 | * This routine is invoked by the worker thread to process FCF table |
| 4742 | * rediscovery pending completion event. |
| 4743 | **/ |
| 4744 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4745 | { |
| 4746 | int rc; |
| 4747 | |
| 4748 | spin_lock_irq(&phba->hbalock); |
| 4749 | /* Clear FCF rediscovery timeout event */ |
| 4750 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4751 | /* Clear driver fast failover FCF record flag */ |
| 4752 | phba->fcf.failover_rec.flag = 0; |
| 4753 | /* Set state for FCF fast failover */ |
| 4754 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4755 | spin_unlock_irq(&phba->hbalock); |
| 4756 | |
| 4757 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4758 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4759 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4760 | 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] | 4761 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4762 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4763 | "2747 Issue FCF scan read FCF mailbox " |
| 4764 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4768 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4769 | * @phba: pointer to lpfc hba data structure. |
| 4770 | * @dev_grp: The HBA PCI-Device group number. |
| 4771 | * |
| 4772 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4773 | * API jump table entries. |
| 4774 | * |
| 4775 | * Return: 0 if success, otherwise -ENODEV |
| 4776 | **/ |
| 4777 | int |
| 4778 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4779 | { |
| 4780 | int rc; |
| 4781 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4782 | /* Set up lpfc PCI-device group */ |
| 4783 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4784 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4785 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4786 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4787 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4788 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4789 | /* Set up device INIT API function jump table */ |
| 4790 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4791 | if (rc) |
| 4792 | return -ENODEV; |
| 4793 | /* Set up SCSI API function jump table */ |
| 4794 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4795 | if (rc) |
| 4796 | return -ENODEV; |
| 4797 | /* Set up SLI API function jump table */ |
| 4798 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4799 | if (rc) |
| 4800 | return -ENODEV; |
| 4801 | /* Set up MBOX API function jump table */ |
| 4802 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4803 | if (rc) |
| 4804 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4805 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4806 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4810 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4811 | * @phba: pointer to lpfc hba data structure. |
| 4812 | * @intr_mode: active interrupt mode adopted. |
| 4813 | * |
| 4814 | * This routine it invoked to log the currently used active interrupt mode |
| 4815 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4816 | **/ |
| 4817 | 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] | 4818 | { |
| 4819 | switch (intr_mode) { |
| 4820 | case 0: |
| 4821 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4822 | "0470 Enable INTx interrupt mode.\n"); |
| 4823 | break; |
| 4824 | case 1: |
| 4825 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4826 | "0481 Enabled MSI interrupt mode.\n"); |
| 4827 | break; |
| 4828 | case 2: |
| 4829 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4830 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4831 | break; |
| 4832 | default: |
| 4833 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4834 | "0482 Illegal interrupt mode.\n"); |
| 4835 | break; |
| 4836 | } |
| 4837 | return; |
| 4838 | } |
| 4839 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4840 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4841 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4842 | * @phba: pointer to lpfc hba data structure. |
| 4843 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4844 | * This routine is invoked to enable the PCI device that is common to all |
| 4845 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4846 | * |
| 4847 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4848 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4849 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4850 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4851 | static int |
| 4852 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4853 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4854 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4855 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4856 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4857 | /* Obtain PCI device reference */ |
| 4858 | if (!phba->pcidev) |
| 4859 | goto out_error; |
| 4860 | else |
| 4861 | pdev = phba->pcidev; |
| 4862 | /* Select PCI BARs */ |
| 4863 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4864 | /* Enable PCI device */ |
| 4865 | if (pci_enable_device_mem(pdev)) |
| 4866 | goto out_error; |
| 4867 | /* Request PCI resource for the device */ |
| 4868 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4869 | goto out_disable_device; |
| 4870 | /* Set up device as PCI master and save state for EEH */ |
| 4871 | pci_set_master(pdev); |
| 4872 | pci_try_set_mwi(pdev); |
| 4873 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4874 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4875 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 4876 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4877 | pdev->needs_freset = 1; |
| 4878 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4879 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4880 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4881 | out_disable_device: |
| 4882 | pci_disable_device(pdev); |
| 4883 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4884 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4885 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4886 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4890 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4891 | * @phba: pointer to lpfc hba data structure. |
| 4892 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4893 | * This routine is invoked to disable the PCI device that is common to all |
| 4894 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4895 | **/ |
| 4896 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4897 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4898 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4899 | struct pci_dev *pdev; |
| 4900 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4901 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4902 | /* Obtain PCI device reference */ |
| 4903 | if (!phba->pcidev) |
| 4904 | return; |
| 4905 | else |
| 4906 | pdev = phba->pcidev; |
| 4907 | /* Select PCI BARs */ |
| 4908 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4909 | /* Release PCI resource and disable PCI device */ |
| 4910 | pci_release_selected_regions(pdev, bars); |
| 4911 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4912 | |
| 4913 | return; |
| 4914 | } |
| 4915 | |
| 4916 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4917 | * lpfc_reset_hba - Reset a hba |
| 4918 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4919 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4920 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4921 | * offline, performs a board restart, and then brings the board back |
| 4922 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4923 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4924 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4925 | void |
| 4926 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4928 | /* If resets are disabled then set error state and return. */ |
| 4929 | if (!phba->cfg_enable_hba_reset) { |
| 4930 | phba->link_state = LPFC_HBA_ERROR; |
| 4931 | return; |
| 4932 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4933 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 4934 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 4935 | else |
| 4936 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4937 | lpfc_offline(phba); |
| 4938 | lpfc_sli_brdrestart(phba); |
| 4939 | lpfc_online(phba); |
| 4940 | lpfc_unblock_mgmt_io(phba); |
| 4941 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4942 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4943 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4944 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4945 | * @phba: pointer to lpfc hba data structure. |
| 4946 | * |
| 4947 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4948 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4949 | * enable the number of virtual functions to the physical function. As |
| 4950 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4951 | * API call does not considered as an error condition for most of the device. |
| 4952 | **/ |
| 4953 | uint16_t |
| 4954 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4955 | { |
| 4956 | struct pci_dev *pdev = phba->pcidev; |
| 4957 | uint16_t nr_virtfn; |
| 4958 | int pos; |
| 4959 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4960 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4961 | if (pos == 0) |
| 4962 | return 0; |
| 4963 | |
| 4964 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4965 | return nr_virtfn; |
| 4966 | } |
| 4967 | |
| 4968 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4969 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4970 | * @phba: pointer to lpfc hba data structure. |
| 4971 | * @nr_vfn: number of virtual functions to be enabled. |
| 4972 | * |
| 4973 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4974 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4975 | * enable the number of virtual functions to the physical function. As |
| 4976 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4977 | * API call does not considered as an error condition for most of the device. |
| 4978 | **/ |
| 4979 | int |
| 4980 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4981 | { |
| 4982 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4983 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4984 | int rc; |
| 4985 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4986 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4987 | if (nr_vfn > max_nr_vfn) { |
| 4988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4989 | "3057 Requested vfs (%d) greater than " |
| 4990 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4991 | return -EINVAL; |
| 4992 | } |
| 4993 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4994 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4995 | if (rc) { |
| 4996 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4997 | "2806 Failed to enable sriov on this device " |
| 4998 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4999 | nr_vfn, rc); |
| 5000 | } else |
| 5001 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5002 | "2807 Successful enable sriov on this device " |
| 5003 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 5004 | return rc; |
| 5005 | } |
| 5006 | |
| 5007 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5008 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 5009 | * @phba: pointer to lpfc hba data structure. |
| 5010 | * |
| 5011 | * This routine is invoked to set up the driver internal resources specific to |
| 5012 | * support the SLI-3 HBA device it attached to. |
| 5013 | * |
| 5014 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5015 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5016 | * other values - error |
| 5017 | **/ |
| 5018 | static int |
| 5019 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 5020 | { |
| 5021 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5022 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5023 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5024 | /* |
| 5025 | * Initialize timers used by driver |
| 5026 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5027 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5028 | /* Heartbeat timer */ |
| 5029 | init_timer(&phba->hb_tmofunc); |
| 5030 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 5031 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 5032 | |
| 5033 | psli = &phba->sli; |
| 5034 | /* MBOX heartbeat timer */ |
| 5035 | init_timer(&psli->mbox_tmo); |
| 5036 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 5037 | psli->mbox_tmo.data = (unsigned long) phba; |
| 5038 | /* FCP polling mode timer */ |
| 5039 | init_timer(&phba->fcp_poll_timer); |
| 5040 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 5041 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 5042 | /* Fabric block timer */ |
| 5043 | init_timer(&phba->fabric_block_timer); |
| 5044 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 5045 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 5046 | /* EA polling mode timer */ |
| 5047 | init_timer(&phba->eratt_poll); |
| 5048 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 5049 | phba->eratt_poll.data = (unsigned long) phba; |
| 5050 | |
| 5051 | /* Host attention work mask setup */ |
| 5052 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 5053 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 5054 | |
| 5055 | /* Get all the module params for configuring this host */ |
| 5056 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5057 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 5058 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 5059 | /* check for menlo minimum sg count */ |
| 5060 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 5061 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 5062 | } |
| 5063 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5064 | if (!phba->sli.ring) |
Firo Yang | c6cb9b4 | 2015-08-31 16:48:09 -0400 | [diff] [blame] | 5065 | phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5066 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 5067 | if (!phba->sli.ring) |
| 5068 | return -ENOMEM; |
| 5069 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5070 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5071 | * 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] | 5072 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5073 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5074 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5075 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5076 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
Bodo Stroesser | 5f406fa | 2015-08-31 16:48:10 -0400 | [diff] [blame] | 5077 | lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5078 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5079 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 5080 | if (phba->cfg_enable_bg) { |
| 5081 | /* |
| 5082 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5083 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 5084 | * over how many protection data segments the SCSI Layer |
| 5085 | * will hand us (ie: there could be one for every block |
| 5086 | * in the IO), we just allocate enough BDEs to accomidate |
| 5087 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5088 | * minimize the risk of running out. |
| 5089 | */ |
| 5090 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5091 | sizeof(struct fcp_rsp) + |
| 5092 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 5093 | |
| 5094 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 5095 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 5096 | |
| 5097 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 5098 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 5099 | } else { |
| 5100 | /* |
| 5101 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5102 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 5103 | * cfg_sg_seg_cnt data segments. |
| 5104 | */ |
| 5105 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5106 | sizeof(struct fcp_rsp) + |
| 5107 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 5108 | |
| 5109 | /* Total BDEs in BPL for scsi_sg_list */ |
| 5110 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5111 | } |
| 5112 | |
| 5113 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5114 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 5115 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5116 | phba->cfg_total_seg_cnt); |
| 5117 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5118 | phba->max_vpi = LPFC_MAX_VPI; |
| 5119 | /* This will be set to correct value after config_port mbox */ |
| 5120 | phba->max_vports = 0; |
| 5121 | |
| 5122 | /* |
| 5123 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 5124 | */ |
| 5125 | lpfc_sli_setup(phba); |
| 5126 | lpfc_sli_queue_setup(phba); |
| 5127 | |
| 5128 | /* Allocate device driver memory */ |
| 5129 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 5130 | return -ENOMEM; |
| 5131 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5132 | /* |
| 5133 | * Enable sr-iov virtual functions if supported and configured |
| 5134 | * through the module parameter. |
| 5135 | */ |
| 5136 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5137 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5138 | phba->cfg_sriov_nr_virtfn); |
| 5139 | if (rc) { |
| 5140 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5141 | "2808 Requested number of SR-IOV " |
| 5142 | "virtual functions (%d) is not " |
| 5143 | "supported\n", |
| 5144 | phba->cfg_sriov_nr_virtfn); |
| 5145 | phba->cfg_sriov_nr_virtfn = 0; |
| 5146 | } |
| 5147 | } |
| 5148 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5149 | return 0; |
| 5150 | } |
| 5151 | |
| 5152 | /** |
| 5153 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 5154 | * @phba: pointer to lpfc hba data structure. |
| 5155 | * |
| 5156 | * This routine is invoked to unset the driver internal resources set up |
| 5157 | * specific for supporting the SLI-3 HBA device it attached to. |
| 5158 | **/ |
| 5159 | static void |
| 5160 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 5161 | { |
| 5162 | /* Free device driver memory allocated */ |
| 5163 | lpfc_mem_free_all(phba); |
| 5164 | |
| 5165 | return; |
| 5166 | } |
| 5167 | |
| 5168 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5169 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 5170 | * @phba: pointer to lpfc hba data structure. |
| 5171 | * |
| 5172 | * This routine is invoked to set up the driver internal resources specific to |
| 5173 | * support the SLI-4 HBA device it attached to. |
| 5174 | * |
| 5175 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5176 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5177 | * other values - error |
| 5178 | **/ |
| 5179 | static int |
| 5180 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 5181 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5182 | struct lpfc_vector_map_info *cpup; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5183 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5184 | LPFC_MBOXQ_t *mboxq; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5185 | int rc, i, hbq_count, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5186 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 5187 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5188 | int longs; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5189 | int fof_vectors = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5190 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 5191 | /* Get all the module params for configuring this host */ |
| 5192 | lpfc_get_cfgparam(phba); |
| 5193 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5194 | /* Before proceed, wait for POST done and device ready */ |
| 5195 | rc = lpfc_sli4_post_status_check(phba); |
| 5196 | if (rc) |
| 5197 | return -ENODEV; |
| 5198 | |
| 5199 | /* |
| 5200 | * Initialize timers used by driver |
| 5201 | */ |
| 5202 | |
| 5203 | /* Heartbeat timer */ |
| 5204 | init_timer(&phba->hb_tmofunc); |
| 5205 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 5206 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5207 | init_timer(&phba->rrq_tmr); |
| 5208 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 5209 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5210 | |
| 5211 | psli = &phba->sli; |
| 5212 | /* MBOX heartbeat timer */ |
| 5213 | init_timer(&psli->mbox_tmo); |
| 5214 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 5215 | psli->mbox_tmo.data = (unsigned long) phba; |
| 5216 | /* Fabric block timer */ |
| 5217 | init_timer(&phba->fabric_block_timer); |
| 5218 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 5219 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 5220 | /* EA polling mode timer */ |
| 5221 | init_timer(&phba->eratt_poll); |
| 5222 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 5223 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5224 | /* FCF rediscover timer */ |
| 5225 | init_timer(&phba->fcf.redisc_wait); |
| 5226 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 5227 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 5228 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5229 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5230 | * Control structure for handling external multi-buffer mailbox |
| 5231 | * command pass-through. |
| 5232 | */ |
| 5233 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 5234 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 5235 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 5236 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5237 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5238 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5239 | /* This will be set to correct value after the read_config mbox */ |
| 5240 | phba->max_vports = 0; |
| 5241 | |
| 5242 | /* Program the default value of vlan_id and fc_map */ |
| 5243 | phba->valid_vlan = 0; |
| 5244 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5245 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5246 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5247 | |
| 5248 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5249 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 5250 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 5251 | */ |
| 5252 | if (!phba->sli.ring) |
| 5253 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5254 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5255 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 5256 | if (!phba->sli.ring) |
| 5257 | return -ENOMEM; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5258 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5259 | /* |
| 5260 | * It doesn't matter what family our adapter is in, we are |
| 5261 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 5262 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 5263 | */ |
| 5264 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 5265 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) |
| 5266 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5267 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5268 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5269 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5270 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5271 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5272 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5273 | if (phba->cfg_enable_bg) { |
| 5274 | /* |
| 5275 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5276 | * the FCP rsp, and a SGE for each. Sice we have no control |
| 5277 | * over how many protection data segments the SCSI Layer |
| 5278 | * will hand us (ie: there could be one for every block |
| 5279 | * in the IO), we just allocate enough SGEs to accomidate |
| 5280 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5281 | * minimize the risk of running out. |
| 5282 | */ |
| 5283 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5284 | sizeof(struct fcp_rsp) + max_buf_size; |
| 5285 | |
| 5286 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 5287 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 5288 | |
| 5289 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
| 5290 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
| 5291 | } else { |
| 5292 | /* |
| 5293 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5294 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 5295 | * cfg_sg_seg_cnt data segments. |
| 5296 | */ |
| 5297 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5298 | sizeof(struct fcp_rsp) + |
| 5299 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); |
| 5300 | |
| 5301 | /* Total SGEs for scsi_sg_list */ |
| 5302 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5303 | /* |
| 5304 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need |
| 5305 | * to post 1 page for the SGL. |
| 5306 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5307 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5308 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5309 | /* Initialize the host templates with the updated values. */ |
| 5310 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5311 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5312 | |
| 5313 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5314 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5315 | else |
| 5316 | phba->cfg_sg_dma_buf_size = |
| 5317 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5318 | |
| 5319 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5320 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5321 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5322 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5323 | |
| 5324 | /* Initialize buffer queue management fields */ |
| 5325 | hbq_count = lpfc_sli_hbq_count(); |
| 5326 | for (i = 0; i < hbq_count; ++i) |
| 5327 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5328 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5329 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5330 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5331 | |
| 5332 | /* |
| 5333 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5334 | */ |
| 5335 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5336 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5337 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5338 | /* This abort list used by worker thread */ |
| 5339 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 5340 | |
| 5341 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5342 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5343 | */ |
| 5344 | |
| 5345 | /* Driver internel slow-path CQ Event pool */ |
| 5346 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5347 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5348 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5349 | /* Asynchronous event CQ Event work queue list */ |
| 5350 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5351 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5352 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5353 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5354 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5355 | /* Receive queue CQ Event work queue list */ |
| 5356 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5357 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5358 | /* Initialize extent block lists. */ |
| 5359 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 5360 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 5361 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 5362 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 5363 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5364 | /* initialize optic_state to 0xFF */ |
| 5365 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 5366 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5367 | /* Initialize the driver internal SLI layer lists. */ |
| 5368 | lpfc_sli_setup(phba); |
| 5369 | lpfc_sli_queue_setup(phba); |
| 5370 | |
| 5371 | /* Allocate device driver memory */ |
| 5372 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 5373 | if (rc) |
| 5374 | return -ENOMEM; |
| 5375 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5376 | /* IF Type 2 ports get initialized now. */ |
| 5377 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5378 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 5379 | rc = lpfc_pci_function_reset(phba); |
| 5380 | if (unlikely(rc)) |
| 5381 | return -ENODEV; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5382 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5383 | } |
| 5384 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5385 | /* Create the bootstrap mailbox command */ |
| 5386 | rc = lpfc_create_bootstrap_mbox(phba); |
| 5387 | if (unlikely(rc)) |
| 5388 | goto out_free_mem; |
| 5389 | |
| 5390 | /* Set up the host's endian order with the device. */ |
| 5391 | rc = lpfc_setup_endian_order(phba); |
| 5392 | if (unlikely(rc)) |
| 5393 | goto out_free_bsmbx; |
| 5394 | |
| 5395 | /* Set up the hba's configuration parameters. */ |
| 5396 | rc = lpfc_sli4_read_config(phba); |
| 5397 | if (unlikely(rc)) |
| 5398 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5399 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 5400 | if (unlikely(rc)) |
| 5401 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5402 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5403 | /* IF Type 0 ports get initialized now. */ |
| 5404 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5405 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 5406 | rc = lpfc_pci_function_reset(phba); |
| 5407 | if (unlikely(rc)) |
| 5408 | goto out_free_bsmbx; |
| 5409 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5410 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5411 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 5412 | GFP_KERNEL); |
| 5413 | if (!mboxq) { |
| 5414 | rc = -ENOMEM; |
| 5415 | goto out_free_bsmbx; |
| 5416 | } |
| 5417 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5418 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5419 | lpfc_supported_pages(mboxq); |
| 5420 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5421 | if (!rc) { |
| 5422 | mqe = &mboxq->u.mqe; |
| 5423 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 5424 | LPFC_MAX_SUPPORTED_PAGES); |
| 5425 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 5426 | switch (pn_page[i]) { |
| 5427 | case LPFC_SLI4_PARAMETERS: |
| 5428 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 5429 | break; |
| 5430 | default: |
| 5431 | break; |
| 5432 | } |
| 5433 | } |
| 5434 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 5435 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 5436 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 5437 | if (rc) { |
| 5438 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5439 | rc = -EIO; |
| 5440 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5441 | } |
| 5442 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5443 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5444 | /* |
| 5445 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5446 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 5447 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5448 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5449 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 5450 | if (rc) { |
| 5451 | if (phba->sli4_hba.extents_in_use && |
| 5452 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 5453 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5454 | "2999 Unsupported SLI4 Parameters " |
| 5455 | "Extents and RPI headers enabled.\n"); |
| 5456 | goto out_free_bsmbx; |
| 5457 | } |
| 5458 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5459 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5460 | |
| 5461 | /* Verify OAS is supported */ |
| 5462 | lpfc_sli4_oas_verify(phba); |
| 5463 | if (phba->cfg_fof) |
| 5464 | fof_vectors = 1; |
| 5465 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5466 | /* Verify all the SLI4 queues */ |
| 5467 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5468 | if (rc) |
| 5469 | goto out_free_bsmbx; |
| 5470 | |
| 5471 | /* Create driver internal CQE event pool */ |
| 5472 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 5473 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5474 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5475 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5476 | /* Initialize sgl lists per host */ |
| 5477 | lpfc_init_sgl_list(phba); |
| 5478 | |
| 5479 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5480 | rc = lpfc_init_active_sgl_array(phba); |
| 5481 | if (rc) { |
| 5482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5483 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5484 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5485 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5486 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 5487 | if (rc) { |
| 5488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5489 | "1432 Failed to initialize rpi headers.\n"); |
| 5490 | goto out_free_active_sgl; |
| 5491 | } |
| 5492 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5493 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5494 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 5495 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 5496 | GFP_KERNEL); |
| 5497 | if (!phba->fcf.fcf_rr_bmask) { |
| 5498 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5499 | "2759 Failed allocate memory for FCF round " |
| 5500 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5501 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5502 | goto out_remove_rpi_hdrs; |
| 5503 | } |
| 5504 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5505 | phba->sli4_hba.fcp_eq_hdl = |
| 5506 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5507 | (fof_vectors + phba->cfg_fcp_io_channel)), |
| 5508 | GFP_KERNEL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5509 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 5510 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5511 | "2572 Failed allocate memory for " |
| 5512 | "fast-path per-EQ handle array\n"); |
| 5513 | rc = -ENOMEM; |
| 5514 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5518 | (fof_vectors + |
| 5519 | phba->cfg_fcp_io_channel)), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5520 | if (!phba->sli4_hba.msix_entries) { |
| 5521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5522 | "2573 Failed allocate memory for msi-x " |
| 5523 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5524 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5525 | goto out_free_fcp_eq_hdl; |
| 5526 | } |
| 5527 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5528 | phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) * |
| 5529 | phba->sli4_hba.num_present_cpu), |
| 5530 | GFP_KERNEL); |
| 5531 | if (!phba->sli4_hba.cpu_map) { |
| 5532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5533 | "3327 Failed allocate memory for msi-x " |
| 5534 | "interrupt vector mapping\n"); |
| 5535 | rc = -ENOMEM; |
| 5536 | goto out_free_msix; |
| 5537 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 5538 | if (lpfc_used_cpu == NULL) { |
| 5539 | lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu), |
| 5540 | GFP_KERNEL); |
| 5541 | if (!lpfc_used_cpu) { |
| 5542 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5543 | "3335 Failed allocate memory for msi-x " |
| 5544 | "interrupt vector mapping\n"); |
| 5545 | kfree(phba->sli4_hba.cpu_map); |
| 5546 | rc = -ENOMEM; |
| 5547 | goto out_free_msix; |
| 5548 | } |
| 5549 | for (i = 0; i < lpfc_present_cpu; i++) |
| 5550 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 5551 | } |
| 5552 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5553 | /* Initialize io channels for round robin */ |
| 5554 | cpup = phba->sli4_hba.cpu_map; |
| 5555 | rc = 0; |
| 5556 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 5557 | cpup->channel_id = rc; |
| 5558 | rc++; |
| 5559 | if (rc >= phba->cfg_fcp_io_channel) |
| 5560 | rc = 0; |
| 5561 | } |
| 5562 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5563 | /* |
| 5564 | * Enable sr-iov virtual functions if supported and configured |
| 5565 | * through the module parameter. |
| 5566 | */ |
| 5567 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5568 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5569 | phba->cfg_sriov_nr_virtfn); |
| 5570 | if (rc) { |
| 5571 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5572 | "3020 Requested number of SR-IOV " |
| 5573 | "virtual functions (%d) is not " |
| 5574 | "supported\n", |
| 5575 | phba->cfg_sriov_nr_virtfn); |
| 5576 | phba->cfg_sriov_nr_virtfn = 0; |
| 5577 | } |
| 5578 | } |
| 5579 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5580 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5581 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5582 | out_free_msix: |
| 5583 | kfree(phba->sli4_hba.msix_entries); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5584 | out_free_fcp_eq_hdl: |
| 5585 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5586 | out_free_fcf_rr_bmask: |
| 5587 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5588 | out_remove_rpi_hdrs: |
| 5589 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 5590 | out_free_active_sgl: |
| 5591 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5592 | out_destroy_cq_event_pool: |
| 5593 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5594 | out_free_bsmbx: |
| 5595 | lpfc_destroy_bootstrap_mbox(phba); |
| 5596 | out_free_mem: |
| 5597 | lpfc_mem_free(phba); |
| 5598 | return rc; |
| 5599 | } |
| 5600 | |
| 5601 | /** |
| 5602 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5603 | * @phba: pointer to lpfc hba data structure. |
| 5604 | * |
| 5605 | * This routine is invoked to unset the driver internal resources set up |
| 5606 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5607 | **/ |
| 5608 | static void |
| 5609 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5610 | { |
| 5611 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5612 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5613 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 5614 | kfree(phba->sli4_hba.cpu_map); |
| 5615 | phba->sli4_hba.num_present_cpu = 0; |
| 5616 | phba->sli4_hba.num_online_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 5617 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5618 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5619 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5620 | kfree(phba->sli4_hba.msix_entries); |
| 5621 | |
| 5622 | /* Free memory allocated for fast-path work queue handles */ |
| 5623 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5624 | |
| 5625 | /* Free the allocated rpi headers. */ |
| 5626 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5627 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5628 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5629 | /* Free eligible FCF index bmask */ |
| 5630 | kfree(phba->fcf.fcf_rr_bmask); |
| 5631 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5632 | /* Free the ELS sgl list */ |
| 5633 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5634 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5635 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5636 | /* Free the completion queue EQ event pool */ |
| 5637 | lpfc_sli4_cq_event_release_all(phba); |
| 5638 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5639 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5640 | /* Release resource identifiers. */ |
| 5641 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5642 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5643 | /* Free the bsmbx region. */ |
| 5644 | lpfc_destroy_bootstrap_mbox(phba); |
| 5645 | |
| 5646 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5647 | lpfc_mem_free_all(phba); |
| 5648 | |
| 5649 | /* Free the current connect table */ |
| 5650 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5651 | &phba->fcf_conn_rec_list, list) { |
| 5652 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5653 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5654 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5655 | |
| 5656 | return; |
| 5657 | } |
| 5658 | |
| 5659 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5660 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5661 | * @phba: The hba struct for which this call is being executed. |
| 5662 | * @dev_grp: The HBA PCI-Device group number. |
| 5663 | * |
| 5664 | * This routine sets up the device INIT interface API function jump table |
| 5665 | * in @phba struct. |
| 5666 | * |
| 5667 | * Returns: 0 - success, -ENODEV - failure. |
| 5668 | **/ |
| 5669 | int |
| 5670 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5671 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5672 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5673 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5674 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5675 | switch (dev_grp) { |
| 5676 | case LPFC_PCI_DEV_LP: |
| 5677 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5678 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5679 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5680 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5681 | case LPFC_PCI_DEV_OC: |
| 5682 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5683 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5684 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5685 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5686 | default: |
| 5687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5688 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5689 | dev_grp); |
| 5690 | return -ENODEV; |
| 5691 | break; |
| 5692 | } |
| 5693 | return 0; |
| 5694 | } |
| 5695 | |
| 5696 | /** |
| 5697 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5698 | * @phba: pointer to lpfc hba data structure. |
| 5699 | * |
| 5700 | * This routine is invoked to set up the driver internal resources before the |
| 5701 | * device specific resource setup to support the HBA device it attached to. |
| 5702 | * |
| 5703 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5704 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5705 | * other values - error |
| 5706 | **/ |
| 5707 | static int |
| 5708 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5709 | { |
| 5710 | /* |
| 5711 | * Driver resources common to all SLI revisions |
| 5712 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5713 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5714 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5715 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5716 | /* Initialize ndlp management spinlock */ |
| 5717 | spin_lock_init(&phba->ndlp_lock); |
| 5718 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5719 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5720 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5721 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5722 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5723 | /* Initialize the wait queue head for the kernel thread */ |
| 5724 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5725 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5726 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 5727 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5728 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5729 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5730 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5731 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5732 | /* Initialize the fabric iocb list */ |
| 5733 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5734 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5735 | /* Initialize list to save ELS buffers */ |
| 5736 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5737 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5738 | /* Initialize FCF connection rec list */ |
| 5739 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5740 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5741 | /* Initialize OAS configuration list */ |
| 5742 | spin_lock_init(&phba->devicelock); |
| 5743 | INIT_LIST_HEAD(&phba->luns); |
| 5744 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5745 | return 0; |
| 5746 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5747 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5748 | /** |
| 5749 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5750 | * @phba: pointer to lpfc hba data structure. |
| 5751 | * |
| 5752 | * This routine is invoked to set up the driver internal resources after the |
| 5753 | * device specific resource setup to support the HBA device it attached to. |
| 5754 | * |
| 5755 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5756 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5757 | * other values - error |
| 5758 | **/ |
| 5759 | static int |
| 5760 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5761 | { |
| 5762 | int error; |
| 5763 | |
| 5764 | /* Startup the kernel thread for this host adapter. */ |
| 5765 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5766 | "lpfc_worker_%d", phba->brd_no); |
| 5767 | if (IS_ERR(phba->worker_thread)) { |
| 5768 | error = PTR_ERR(phba->worker_thread); |
| 5769 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5770 | } |
| 5771 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5772 | return 0; |
| 5773 | } |
| 5774 | |
| 5775 | /** |
| 5776 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5777 | * @phba: pointer to lpfc hba data structure. |
| 5778 | * |
| 5779 | * This routine is invoked to unset the driver internal resources set up after |
| 5780 | * the device specific resource setup for supporting the HBA device it |
| 5781 | * attached to. |
| 5782 | **/ |
| 5783 | static void |
| 5784 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5785 | { |
| 5786 | /* Stop kernel worker thread */ |
| 5787 | kthread_stop(phba->worker_thread); |
| 5788 | } |
| 5789 | |
| 5790 | /** |
| 5791 | * lpfc_free_iocb_list - Free iocb list. |
| 5792 | * @phba: pointer to lpfc hba data structure. |
| 5793 | * |
| 5794 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5795 | **/ |
| 5796 | static void |
| 5797 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5798 | { |
| 5799 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5800 | |
| 5801 | spin_lock_irq(&phba->hbalock); |
| 5802 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5803 | &phba->lpfc_iocb_list, list) { |
| 5804 | list_del(&iocbq_entry->list); |
| 5805 | kfree(iocbq_entry); |
| 5806 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5807 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5808 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5809 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5810 | return; |
| 5811 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5812 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5813 | /** |
| 5814 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5815 | * @phba: pointer to lpfc hba data structure. |
| 5816 | * |
| 5817 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5818 | * list and set up the IOCB tag array accordingly. |
| 5819 | * |
| 5820 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5821 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5822 | * other values - error |
| 5823 | **/ |
| 5824 | static int |
| 5825 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5826 | { |
| 5827 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5828 | uint16_t iotag; |
| 5829 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5830 | |
| 5831 | /* Initialize and populate the iocb list per host. */ |
| 5832 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5833 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5834 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5835 | if (iocbq_entry == NULL) { |
| 5836 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5837 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5838 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5839 | goto out_free_iocbq; |
| 5840 | } |
| 5841 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5842 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5843 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5844 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5845 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5846 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5847 | goto out_free_iocbq; |
| 5848 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5849 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5850 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5851 | |
| 5852 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5853 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5854 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5855 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5856 | } |
| 5857 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5858 | return 0; |
| 5859 | |
| 5860 | out_free_iocbq: |
| 5861 | lpfc_free_iocb_list(phba); |
| 5862 | |
| 5863 | return -ENOMEM; |
| 5864 | } |
| 5865 | |
| 5866 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5867 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5868 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5869 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5870 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5871 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5872 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5873 | void |
| 5874 | 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] | 5875 | { |
| 5876 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5877 | |
| 5878 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5879 | list_del(&sglq_entry->list); |
| 5880 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5881 | kfree(sglq_entry); |
| 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | /** |
| 5886 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5887 | * @phba: pointer to lpfc hba data structure. |
| 5888 | * |
| 5889 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5890 | **/ |
| 5891 | static void |
| 5892 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5893 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5894 | LIST_HEAD(sglq_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5895 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5896 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5897 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5898 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5899 | spin_lock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5900 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5901 | spin_unlock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5902 | spin_unlock_irq(&phba->hbalock); |
| 5903 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5904 | /* Now free the sgl list */ |
| 5905 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | /** |
| 5909 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5910 | * @phba: pointer to lpfc hba data structure. |
| 5911 | * |
| 5912 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5913 | * This array will hold the sglq_entry's for active IOs. |
| 5914 | **/ |
| 5915 | static int |
| 5916 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5917 | { |
| 5918 | int size; |
| 5919 | size = sizeof(struct lpfc_sglq *); |
| 5920 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5921 | |
| 5922 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5923 | kzalloc(size, GFP_KERNEL); |
| 5924 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5925 | return -ENOMEM; |
| 5926 | return 0; |
| 5927 | } |
| 5928 | |
| 5929 | /** |
| 5930 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5931 | * @phba: pointer to lpfc hba data structure. |
| 5932 | * |
| 5933 | * This routine is invoked to walk through the array of active sglq entries |
| 5934 | * and free all of the resources. |
| 5935 | * This is just a place holder for now. |
| 5936 | **/ |
| 5937 | static void |
| 5938 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5939 | { |
| 5940 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5941 | } |
| 5942 | |
| 5943 | /** |
| 5944 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5945 | * @phba: pointer to lpfc hba data structure. |
| 5946 | * |
| 5947 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5948 | * list and set up the sgl xritag tag array accordingly. |
| 5949 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5950 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5951 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5952 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5953 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5954 | /* Initialize and populate the sglq list per host/VF. */ |
| 5955 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5956 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5957 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5958 | /* els xri-sgl book keeping */ |
| 5959 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5960 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5961 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5962 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | /** |
| 5966 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5967 | * @phba: pointer to lpfc hba data structure. |
| 5968 | * |
| 5969 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5970 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5971 | * 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] | 5972 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5973 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5974 | * |
| 5975 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5976 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5977 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5978 | **/ |
| 5979 | int |
| 5980 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5981 | { |
| 5982 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5983 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5984 | |
| 5985 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5986 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5987 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5988 | if (phba->sli4_hba.extents_in_use) |
| 5989 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5990 | |
| 5991 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5992 | if (!rpi_hdr) { |
| 5993 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5994 | "0391 Error during rpi post operation\n"); |
| 5995 | lpfc_sli4_remove_rpis(phba); |
| 5996 | rc = -ENODEV; |
| 5997 | } |
| 5998 | |
| 5999 | return rc; |
| 6000 | } |
| 6001 | |
| 6002 | /** |
| 6003 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 6004 | * @phba: pointer to lpfc hba data structure. |
| 6005 | * |
| 6006 | * This routine is invoked to allocate a single 4KB memory region to |
| 6007 | * support rpis and stores them in the phba. This single region |
| 6008 | * provides support for up to 64 rpis. The region is used globally |
| 6009 | * by the device. |
| 6010 | * |
| 6011 | * Returns: |
| 6012 | * A valid rpi hdr on success. |
| 6013 | * A NULL pointer on any failure. |
| 6014 | **/ |
| 6015 | struct lpfc_rpi_hdr * |
| 6016 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 6017 | { |
| 6018 | uint16_t rpi_limit, curr_rpi_range; |
| 6019 | struct lpfc_dmabuf *dmabuf; |
| 6020 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6021 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6022 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6023 | /* |
| 6024 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 6025 | * required. Set the expected maximum count and let the actual value |
| 6026 | * get set when extents are fully allocated. |
| 6027 | */ |
| 6028 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6029 | return NULL; |
| 6030 | if (phba->sli4_hba.extents_in_use) |
| 6031 | return NULL; |
| 6032 | |
| 6033 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6034 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6035 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6036 | |
| 6037 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6038 | /* |
| 6039 | * Establish the starting RPI in this header block. The starting |
| 6040 | * rpi is normalized to a zero base because the physical rpi is |
| 6041 | * port based. |
| 6042 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6043 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6044 | spin_unlock_irq(&phba->hbalock); |
| 6045 | |
| 6046 | /* |
| 6047 | * The port has a limited number of rpis. The increment here |
| 6048 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 6049 | * and to allow the full max_rpi range per port. |
| 6050 | */ |
| 6051 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6052 | rpi_count = rpi_limit - curr_rpi_range; |
| 6053 | else |
| 6054 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6055 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6056 | if (!rpi_count) |
| 6057 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6058 | /* |
| 6059 | * First allocate the protocol header region for the port. The |
| 6060 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 6061 | */ |
| 6062 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6063 | if (!dmabuf) |
| 6064 | return NULL; |
| 6065 | |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6066 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 6067 | LPFC_HDR_TEMPLATE_SIZE, |
| 6068 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6069 | if (!dmabuf->virt) { |
| 6070 | rpi_hdr = NULL; |
| 6071 | goto err_free_dmabuf; |
| 6072 | } |
| 6073 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6074 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 6075 | rpi_hdr = NULL; |
| 6076 | goto err_free_coherent; |
| 6077 | } |
| 6078 | |
| 6079 | /* Save the rpi header data for cleanup later. */ |
| 6080 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 6081 | if (!rpi_hdr) |
| 6082 | goto err_free_coherent; |
| 6083 | |
| 6084 | rpi_hdr->dmabuf = dmabuf; |
| 6085 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 6086 | rpi_hdr->page_count = 1; |
| 6087 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6088 | |
| 6089 | /* The rpi_hdr stores the logical index only. */ |
| 6090 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6091 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 6092 | |
| 6093 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6094 | * The next_rpi stores the next logical module-64 rpi value used |
| 6095 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6096 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6097 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6098 | spin_unlock_irq(&phba->hbalock); |
| 6099 | return rpi_hdr; |
| 6100 | |
| 6101 | err_free_coherent: |
| 6102 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 6103 | dmabuf->virt, dmabuf->phys); |
| 6104 | err_free_dmabuf: |
| 6105 | kfree(dmabuf); |
| 6106 | return NULL; |
| 6107 | } |
| 6108 | |
| 6109 | /** |
| 6110 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 6111 | * @phba: pointer to lpfc hba data structure. |
| 6112 | * |
| 6113 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6114 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 6115 | * presumes the caller has released all rpis consumed by fabric or port |
| 6116 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6117 | **/ |
| 6118 | void |
| 6119 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 6120 | { |
| 6121 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 6122 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6123 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6124 | goto exit; |
| 6125 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6126 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 6127 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 6128 | list_del(&rpi_hdr->list); |
| 6129 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 6130 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 6131 | kfree(rpi_hdr->dmabuf); |
| 6132 | kfree(rpi_hdr); |
| 6133 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6134 | exit: |
| 6135 | /* There are no rpis available to the port now. */ |
| 6136 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6140 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 6141 | * @pdev: pointer to pci device data structure. |
| 6142 | * |
| 6143 | * This routine is invoked to allocate the driver hba data structure for an |
| 6144 | * HBA device. If the allocation is successful, the phba reference to the |
| 6145 | * PCI device data structure is set. |
| 6146 | * |
| 6147 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6148 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6149 | * NULL - error |
| 6150 | **/ |
| 6151 | static struct lpfc_hba * |
| 6152 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 6153 | { |
| 6154 | struct lpfc_hba *phba; |
| 6155 | |
| 6156 | /* Allocate memory for HBA structure */ |
| 6157 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 6158 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 6159 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6160 | return NULL; |
| 6161 | } |
| 6162 | |
| 6163 | /* Set reference to PCI device in HBA structure */ |
| 6164 | phba->pcidev = pdev; |
| 6165 | |
| 6166 | /* Assign an unused board number */ |
| 6167 | phba->brd_no = lpfc_get_instance(); |
| 6168 | if (phba->brd_no < 0) { |
| 6169 | kfree(phba); |
| 6170 | return NULL; |
| 6171 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6172 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6173 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 6174 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6175 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 6176 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6177 | return phba; |
| 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 6182 | * @phba: pointer to lpfc hba data structure. |
| 6183 | * |
| 6184 | * This routine is invoked to free the driver hba data structure with an |
| 6185 | * HBA device. |
| 6186 | **/ |
| 6187 | static void |
| 6188 | lpfc_hba_free(struct lpfc_hba *phba) |
| 6189 | { |
| 6190 | /* Release the driver assigned board number */ |
| 6191 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 6192 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6193 | /* Free memory allocated with sli rings */ |
| 6194 | kfree(phba->sli.ring); |
| 6195 | phba->sli.ring = NULL; |
| 6196 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6197 | kfree(phba); |
| 6198 | return; |
| 6199 | } |
| 6200 | |
| 6201 | /** |
| 6202 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 6203 | * @phba: pointer to lpfc hba data structure. |
| 6204 | * |
| 6205 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 6206 | * host with it. |
| 6207 | * |
| 6208 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6209 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6210 | * other values - error |
| 6211 | **/ |
| 6212 | static int |
| 6213 | lpfc_create_shost(struct lpfc_hba *phba) |
| 6214 | { |
| 6215 | struct lpfc_vport *vport; |
| 6216 | struct Scsi_Host *shost; |
| 6217 | |
| 6218 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | phba->fc_edtov = FF_DEF_EDTOV; |
| 6220 | phba->fc_ratov = FF_DEF_RATOV; |
| 6221 | phba->fc_altov = FF_DEF_ALTOV; |
| 6222 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 6223 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6224 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6225 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6226 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6227 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6228 | |
| 6229 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6230 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6231 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6232 | /* Put reference to SCSI host to driver's device private data */ |
| 6233 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6234 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6235 | /* |
| 6236 | * At this point we are fully registered with PSA. In addition, |
| 6237 | * any initial discovery should be completed. |
| 6238 | */ |
| 6239 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6240 | if (phba->cfg_enable_SmartSAN || |
| 6241 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6242 | |
| 6243 | /* Setup appropriate attribute masks */ |
| 6244 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6245 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6246 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 6247 | else |
| 6248 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 6249 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6250 | return 0; |
| 6251 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6252 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6253 | /** |
| 6254 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 6255 | * @phba: pointer to lpfc hba data structure. |
| 6256 | * |
| 6257 | * This routine is invoked to destroy HBA physical port and the associated |
| 6258 | * SCSI host. |
| 6259 | **/ |
| 6260 | static void |
| 6261 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 6262 | { |
| 6263 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6264 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6265 | /* Destroy physical port that associated with the SCSI host */ |
| 6266 | destroy_port(vport); |
| 6267 | |
| 6268 | return; |
| 6269 | } |
| 6270 | |
| 6271 | /** |
| 6272 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 6273 | * @phba: pointer to lpfc hba data structure. |
| 6274 | * @shost: the shost to be used to detect Block guard settings. |
| 6275 | * |
| 6276 | * This routine sets up the local Block guard protocol settings for @shost. |
| 6277 | * This routine also allocates memory for debugging bg buffers. |
| 6278 | **/ |
| 6279 | static void |
| 6280 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 6281 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6282 | uint32_t old_mask; |
| 6283 | uint32_t old_guard; |
| 6284 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6285 | int pagecnt = 10; |
| 6286 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 6287 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6288 | "1478 Registering BlockGuard with the " |
| 6289 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6290 | |
| 6291 | old_mask = lpfc_prot_mask; |
| 6292 | old_guard = lpfc_prot_guard; |
| 6293 | |
| 6294 | /* Only allow supported values */ |
| 6295 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 6296 | SHOST_DIX_TYPE0_PROTECTION | |
| 6297 | SHOST_DIX_TYPE1_PROTECTION); |
| 6298 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 6299 | |
| 6300 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 6301 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 6302 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 6303 | |
| 6304 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 6305 | if ((old_mask != lpfc_prot_mask) || |
| 6306 | (old_guard != lpfc_prot_guard)) |
| 6307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6308 | "1475 Registering BlockGuard with the " |
| 6309 | "SCSI layer: mask %d guard %d\n", |
| 6310 | lpfc_prot_mask, lpfc_prot_guard); |
| 6311 | |
| 6312 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 6313 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 6314 | } else |
| 6315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6316 | "1479 Not Registering BlockGuard with the SCSI " |
| 6317 | "layer, Bad protection parameters: %d %d\n", |
| 6318 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6319 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6320 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6321 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6322 | while (pagecnt) { |
| 6323 | spin_lock_init(&_dump_buf_lock); |
| 6324 | _dump_buf_data = |
| 6325 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6326 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6327 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6328 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6329 | "_dump_buf_data at 0x%p\n", |
| 6330 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6331 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6332 | memset(_dump_buf_data, 0, |
| 6333 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6334 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6335 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6336 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6337 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6338 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6339 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6340 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6341 | "memory for hexdump\n"); |
| 6342 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6343 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6344 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6345 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6346 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6347 | while (pagecnt) { |
| 6348 | _dump_buf_dif = |
| 6349 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6350 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6351 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6352 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6353 | "_dump_buf_dif at 0x%p\n", |
| 6354 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6355 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6356 | memset(_dump_buf_dif, 0, |
| 6357 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6358 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6359 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6360 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6361 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6362 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6363 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6364 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6365 | "memory for hexdump\n"); |
| 6366 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6367 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6368 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6369 | _dump_buf_dif); |
| 6370 | } |
| 6371 | |
| 6372 | /** |
| 6373 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 6374 | * @phba: pointer to lpfc hba data structure. |
| 6375 | * |
| 6376 | * This routine is invoked to perform all the necessary post initialization |
| 6377 | * setup for the device. |
| 6378 | **/ |
| 6379 | static void |
| 6380 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 6381 | { |
| 6382 | struct Scsi_Host *shost; |
| 6383 | struct lpfc_adapter_event_header adapter_event; |
| 6384 | |
| 6385 | /* Get the default values for Model Name and Description */ |
| 6386 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 6387 | |
| 6388 | /* |
| 6389 | * hba setup may have changed the hba_queue_depth so we need to |
| 6390 | * adjust the value of can_queue. |
| 6391 | */ |
| 6392 | shost = pci_get_drvdata(phba->pcidev); |
| 6393 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 6394 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 6395 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6396 | |
| 6397 | lpfc_host_attrib_init(shost); |
| 6398 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6399 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6400 | spin_lock_irq(shost->host_lock); |
| 6401 | lpfc_poll_start_timer(phba); |
| 6402 | spin_unlock_irq(shost->host_lock); |
| 6403 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 6404 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6405 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6406 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6407 | /* Send board arrival event to upper layer */ |
| 6408 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 6409 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 6410 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6411 | sizeof(adapter_event), |
| 6412 | (char *) &adapter_event, |
| 6413 | LPFC_NL_VENDOR_ID); |
| 6414 | return; |
| 6415 | } |
| 6416 | |
| 6417 | /** |
| 6418 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 6419 | * @phba: pointer to lpfc hba data structure. |
| 6420 | * |
| 6421 | * This routine is invoked to set up the PCI device memory space for device |
| 6422 | * with SLI-3 interface spec. |
| 6423 | * |
| 6424 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6425 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6426 | * other values - error |
| 6427 | **/ |
| 6428 | static int |
| 6429 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 6430 | { |
| 6431 | struct pci_dev *pdev; |
| 6432 | unsigned long bar0map_len, bar2map_len; |
| 6433 | int i, hbq_count; |
| 6434 | void *ptr; |
| 6435 | int error = -ENODEV; |
| 6436 | |
| 6437 | /* Obtain PCI device reference */ |
| 6438 | if (!phba->pcidev) |
| 6439 | return error; |
| 6440 | else |
| 6441 | pdev = phba->pcidev; |
| 6442 | |
| 6443 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6444 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 6445 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 6446 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 6447 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6448 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6449 | } |
| 6450 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6451 | |
| 6452 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 6453 | * required by each mapping. |
| 6454 | */ |
| 6455 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 6456 | bar0map_len = pci_resource_len(pdev, 0); |
| 6457 | |
| 6458 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 6459 | bar2map_len = pci_resource_len(pdev, 2); |
| 6460 | |
| 6461 | /* Map HBA SLIM to a kernel virtual address. */ |
| 6462 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 6463 | if (!phba->slim_memmap_p) { |
| 6464 | dev_printk(KERN_ERR, &pdev->dev, |
| 6465 | "ioremap failed for SLIM memory.\n"); |
| 6466 | goto out; |
| 6467 | } |
| 6468 | |
| 6469 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 6470 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 6471 | if (!phba->ctrl_regs_memmap_p) { |
| 6472 | dev_printk(KERN_ERR, &pdev->dev, |
| 6473 | "ioremap failed for HBA control registers.\n"); |
| 6474 | goto out_iounmap_slim; |
| 6475 | } |
| 6476 | |
| 6477 | /* Allocate memory for SLI-2 structures */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6478 | phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6479 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6480 | if (!phba->slim2p.virt) |
| 6481 | goto out_iounmap; |
| 6482 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6483 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6484 | phba->mbox_ext = (phba->slim2p.virt + |
| 6485 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6486 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 6487 | phba->IOCBs = (phba->slim2p.virt + |
| 6488 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 6489 | |
| 6490 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 6491 | lpfc_sli_hbq_size(), |
| 6492 | &phba->hbqslimp.phys, |
| 6493 | GFP_KERNEL); |
| 6494 | if (!phba->hbqslimp.virt) |
| 6495 | goto out_free_slim; |
| 6496 | |
| 6497 | hbq_count = lpfc_sli_hbq_count(); |
| 6498 | ptr = phba->hbqslimp.virt; |
| 6499 | for (i = 0; i < hbq_count; ++i) { |
| 6500 | phba->hbqs[i].hbq_virt = ptr; |
| 6501 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 6502 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 6503 | sizeof(struct lpfc_hbq_entry)); |
| 6504 | } |
| 6505 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 6506 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 6507 | |
| 6508 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 6509 | |
| 6510 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 6511 | |
| 6512 | phba->MBslimaddr = phba->slim_memmap_p; |
| 6513 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 6514 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 6515 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 6516 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6517 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6518 | return 0; |
| 6519 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6520 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6521 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6522 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6523 | out_iounmap: |
| 6524 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6525 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6526 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6527 | out: |
| 6528 | return error; |
| 6529 | } |
| 6530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6531 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6532 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 6533 | * @phba: pointer to lpfc hba data structure. |
| 6534 | * |
| 6535 | * This routine is invoked to unset the PCI device memory space for device |
| 6536 | * with SLI-3 interface spec. |
| 6537 | **/ |
| 6538 | static void |
| 6539 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 6540 | { |
| 6541 | struct pci_dev *pdev; |
| 6542 | |
| 6543 | /* Obtain PCI device reference */ |
| 6544 | if (!phba->pcidev) |
| 6545 | return; |
| 6546 | else |
| 6547 | pdev = phba->pcidev; |
| 6548 | |
| 6549 | /* Free coherent DMA memory allocated */ |
| 6550 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 6551 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 6552 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6553 | phba->slim2p.virt, phba->slim2p.phys); |
| 6554 | |
| 6555 | /* I/O memory unmap */ |
| 6556 | iounmap(phba->ctrl_regs_memmap_p); |
| 6557 | iounmap(phba->slim_memmap_p); |
| 6558 | |
| 6559 | return; |
| 6560 | } |
| 6561 | |
| 6562 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6563 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 6564 | * @phba: pointer to lpfc hba data structure. |
| 6565 | * |
| 6566 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 6567 | * done and check status. |
| 6568 | * |
| 6569 | * Return 0 if successful, otherwise -ENODEV. |
| 6570 | **/ |
| 6571 | int |
| 6572 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 6573 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6574 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 6575 | struct lpfc_register reg_data; |
| 6576 | int i, port_error = 0; |
| 6577 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6578 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6579 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 6580 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6581 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6582 | return -ENODEV; |
| 6583 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6584 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 6585 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6586 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 6587 | &portsmphr_reg.word0) || |
| 6588 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6589 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6590 | port_error = -ENODEV; |
| 6591 | break; |
| 6592 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6593 | if (LPFC_POST_STAGE_PORT_READY == |
| 6594 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6595 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6596 | msleep(10); |
| 6597 | } |
| 6598 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6599 | /* |
| 6600 | * If there was a port error during POST, then don't proceed with |
| 6601 | * other register reads as the data may not be valid. Just exit. |
| 6602 | */ |
| 6603 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6604 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6605 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 6606 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 6607 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 6608 | portsmphr_reg.word0, |
| 6609 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 6610 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 6611 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 6612 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 6613 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 6614 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 6615 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 6616 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 6617 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6618 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6619 | "2534 Device Info: SLIFamily=0x%x, " |
| 6620 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 6621 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6622 | bf_get(lpfc_sli_intf_sli_family, |
| 6623 | &phba->sli4_hba.sli_intf), |
| 6624 | bf_get(lpfc_sli_intf_slirev, |
| 6625 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6626 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6627 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6628 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6629 | &phba->sli4_hba.sli_intf), |
| 6630 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6631 | &phba->sli4_hba.sli_intf), |
| 6632 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6633 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6634 | /* |
| 6635 | * Check for other Port errors during the initialization |
| 6636 | * process. Fail the load if the port did not come up |
| 6637 | * correctly. |
| 6638 | */ |
| 6639 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6640 | &phba->sli4_hba.sli_intf); |
| 6641 | switch (if_type) { |
| 6642 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6643 | phba->sli4_hba.ue_mask_lo = |
| 6644 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6645 | phba->sli4_hba.ue_mask_hi = |
| 6646 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6647 | uerrlo_reg.word0 = |
| 6648 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6649 | uerrhi_reg.word0 = |
| 6650 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6651 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6652 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6653 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6654 | "1422 Unrecoverable Error " |
| 6655 | "Detected during POST " |
| 6656 | "uerr_lo_reg=0x%x, " |
| 6657 | "uerr_hi_reg=0x%x, " |
| 6658 | "ue_mask_lo_reg=0x%x, " |
| 6659 | "ue_mask_hi_reg=0x%x\n", |
| 6660 | uerrlo_reg.word0, |
| 6661 | uerrhi_reg.word0, |
| 6662 | phba->sli4_hba.ue_mask_lo, |
| 6663 | phba->sli4_hba.ue_mask_hi); |
| 6664 | port_error = -ENODEV; |
| 6665 | } |
| 6666 | break; |
| 6667 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6668 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6669 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6670 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6671 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6672 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6673 | phba->work_status[0] = |
| 6674 | readl(phba->sli4_hba.u.if_type2. |
| 6675 | ERR1regaddr); |
| 6676 | phba->work_status[1] = |
| 6677 | readl(phba->sli4_hba.u.if_type2. |
| 6678 | ERR2regaddr); |
| 6679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6680 | "2888 Unrecoverable port error " |
| 6681 | "following POST: port status reg " |
| 6682 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6683 | "error 1=0x%x, error 2=0x%x\n", |
| 6684 | reg_data.word0, |
| 6685 | portsmphr_reg.word0, |
| 6686 | phba->work_status[0], |
| 6687 | phba->work_status[1]); |
| 6688 | port_error = -ENODEV; |
| 6689 | } |
| 6690 | break; |
| 6691 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6692 | default: |
| 6693 | break; |
| 6694 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6695 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6696 | return port_error; |
| 6697 | } |
| 6698 | |
| 6699 | /** |
| 6700 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6701 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6702 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6703 | * |
| 6704 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6705 | * memory map. |
| 6706 | **/ |
| 6707 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6708 | 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] | 6709 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6710 | switch (if_type) { |
| 6711 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6712 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6713 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6714 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6715 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6716 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6717 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6718 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6719 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6720 | phba->sli4_hba.SLIINTFregaddr = |
| 6721 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6722 | break; |
| 6723 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6724 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6725 | phba->sli4_hba.conf_regs_memmap_p + |
| 6726 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6727 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6728 | phba->sli4_hba.conf_regs_memmap_p + |
| 6729 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6730 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6731 | phba->sli4_hba.conf_regs_memmap_p + |
| 6732 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6733 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6734 | phba->sli4_hba.conf_regs_memmap_p + |
| 6735 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6736 | phba->sli4_hba.SLIINTFregaddr = |
| 6737 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6738 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6739 | phba->sli4_hba.conf_regs_memmap_p + |
| 6740 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6741 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6742 | phba->sli4_hba.conf_regs_memmap_p + |
| 6743 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6744 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6745 | phba->sli4_hba.conf_regs_memmap_p + |
| 6746 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6747 | phba->sli4_hba.EQCQDBregaddr = |
| 6748 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6749 | phba->sli4_hba.MQDBregaddr = |
| 6750 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6751 | phba->sli4_hba.BMBXregaddr = |
| 6752 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6753 | break; |
| 6754 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6755 | default: |
| 6756 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6757 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6758 | if_type); |
| 6759 | break; |
| 6760 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | /** |
| 6764 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6765 | * @phba: pointer to lpfc hba data structure. |
| 6766 | * |
| 6767 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6768 | * memory map. |
| 6769 | **/ |
| 6770 | static void |
| 6771 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6772 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6773 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6774 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6775 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6776 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6777 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6778 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6779 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6780 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6781 | } |
| 6782 | |
| 6783 | /** |
| 6784 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6785 | * @phba: pointer to lpfc hba data structure. |
| 6786 | * @vf: virtual function number |
| 6787 | * |
| 6788 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6789 | * based on the given viftual function number, @vf. |
| 6790 | * |
| 6791 | * Return 0 if successful, otherwise -ENODEV. |
| 6792 | **/ |
| 6793 | static int |
| 6794 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6795 | { |
| 6796 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6797 | return -ENODEV; |
| 6798 | |
| 6799 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6800 | vf * LPFC_VFR_PAGE_SIZE + |
| 6801 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6802 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6803 | vf * LPFC_VFR_PAGE_SIZE + |
| 6804 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6805 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6806 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6807 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6808 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6809 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6810 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6811 | return 0; |
| 6812 | } |
| 6813 | |
| 6814 | /** |
| 6815 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6816 | * @phba: pointer to lpfc hba data structure. |
| 6817 | * |
| 6818 | * This routine is invoked to create the bootstrap mailbox |
| 6819 | * region consistent with the SLI-4 interface spec. This |
| 6820 | * routine allocates all memory necessary to communicate |
| 6821 | * mailbox commands to the port and sets up all alignment |
| 6822 | * needs. No locks are expected to be held when calling |
| 6823 | * this routine. |
| 6824 | * |
| 6825 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6826 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6827 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6828 | **/ |
| 6829 | static int |
| 6830 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6831 | { |
| 6832 | uint32_t bmbx_size; |
| 6833 | struct lpfc_dmabuf *dmabuf; |
| 6834 | struct dma_address *dma_address; |
| 6835 | uint32_t pa_addr; |
| 6836 | uint64_t phys_addr; |
| 6837 | |
| 6838 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6839 | if (!dmabuf) |
| 6840 | return -ENOMEM; |
| 6841 | |
| 6842 | /* |
| 6843 | * The bootstrap mailbox region is comprised of 2 parts |
| 6844 | * plus an alignment restriction of 16 bytes. |
| 6845 | */ |
| 6846 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6847 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 6848 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6849 | if (!dmabuf->virt) { |
| 6850 | kfree(dmabuf); |
| 6851 | return -ENOMEM; |
| 6852 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6853 | |
| 6854 | /* |
| 6855 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6856 | * operations are simple later. The mailbox dma address is required |
| 6857 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6858 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6859 | * command to the port. |
| 6860 | */ |
| 6861 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6862 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6863 | |
| 6864 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6865 | LPFC_ALIGN_16_BYTE); |
| 6866 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6867 | LPFC_ALIGN_16_BYTE); |
| 6868 | |
| 6869 | /* |
| 6870 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6871 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6872 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6873 | * the 30-bit address is the high or low address. |
| 6874 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6875 | * clean on 32 bit machines. |
| 6876 | */ |
| 6877 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6878 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6879 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6880 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6881 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6882 | |
| 6883 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6884 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6885 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6886 | return 0; |
| 6887 | } |
| 6888 | |
| 6889 | /** |
| 6890 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6891 | * @phba: pointer to lpfc hba data structure. |
| 6892 | * |
| 6893 | * This routine is invoked to teardown the bootstrap mailbox |
| 6894 | * region and release all host resources. This routine requires |
| 6895 | * the caller to ensure all mailbox commands recovered, no |
| 6896 | * additional mailbox comands are sent, and interrupts are disabled |
| 6897 | * before calling this routine. |
| 6898 | * |
| 6899 | **/ |
| 6900 | static void |
| 6901 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6902 | { |
| 6903 | dma_free_coherent(&phba->pcidev->dev, |
| 6904 | phba->sli4_hba.bmbx.bmbx_size, |
| 6905 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6906 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6907 | |
| 6908 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6909 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6910 | } |
| 6911 | |
| 6912 | /** |
| 6913 | * lpfc_sli4_read_config - Get the config parameters. |
| 6914 | * @phba: pointer to lpfc hba data structure. |
| 6915 | * |
| 6916 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6917 | * The configuration parameters are used to set the base and maximum values |
| 6918 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6919 | * allocation for the port. |
| 6920 | * |
| 6921 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6922 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6923 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6924 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6925 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6926 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6927 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6928 | { |
| 6929 | LPFC_MBOXQ_t *pmb; |
| 6930 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6931 | union lpfc_sli4_cfg_shdr *shdr; |
| 6932 | uint32_t shdr_status, shdr_add_status; |
| 6933 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6934 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6935 | char *pdesc_0; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6936 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6937 | |
| 6938 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6939 | if (!pmb) { |
| 6940 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6941 | "2011 Unable to allocate memory for issuing " |
| 6942 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6943 | return -ENOMEM; |
| 6944 | } |
| 6945 | |
| 6946 | lpfc_read_config(phba, pmb); |
| 6947 | |
| 6948 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6949 | if (rc != MBX_SUCCESS) { |
| 6950 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6951 | "2012 Mailbox failed , mbxCmd x%x " |
| 6952 | "READ_CONFIG, mbxStatus x%x\n", |
| 6953 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6954 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6955 | rc = -EIO; |
| 6956 | } else { |
| 6957 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6958 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6959 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6960 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6961 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6962 | phba->sli4_hba.lnk_info.lnk_no = |
| 6963 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6964 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6965 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6966 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6967 | phba->sli4_hba.lnk_info.lnk_no); |
| 6968 | } else |
| 6969 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6970 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6971 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6972 | phba->sli4_hba.extents_in_use = |
| 6973 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6974 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6975 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6976 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6977 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6978 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6979 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6980 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6981 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6982 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6983 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6984 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6985 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6986 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6987 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6988 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6989 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6990 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6991 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6992 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6993 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6994 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6995 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6996 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6997 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6998 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6999 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 7000 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 7001 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 7002 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 7003 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7004 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 7005 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7006 | phba->max_vports = phba->max_vpi; |
| 7007 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7008 | "2003 cfg params Extents? %d " |
| 7009 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7010 | "VPI(B:%d M:%d) " |
| 7011 | "VFI(B:%d M:%d) " |
| 7012 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7013 | "FCFI(Count:%d)\n", |
| 7014 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7015 | phba->sli4_hba.max_cfg_param.xri_base, |
| 7016 | phba->sli4_hba.max_cfg_param.max_xri, |
| 7017 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 7018 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 7019 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 7020 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 7021 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 7022 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7023 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 7024 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7025 | |
| 7026 | if (rc) |
| 7027 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7028 | |
| 7029 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7030 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 7031 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 7032 | if (phba->cfg_hba_queue_depth > length) { |
| 7033 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7034 | "3361 HBA queue depth changed from %d to %d\n", |
| 7035 | phba->cfg_hba_queue_depth, length); |
| 7036 | phba->cfg_hba_queue_depth = length; |
| 7037 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7038 | |
| 7039 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 7040 | LPFC_SLI_INTF_IF_TYPE_2) |
| 7041 | goto read_cfg_out; |
| 7042 | |
| 7043 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 7044 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 7045 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7046 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7047 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 7048 | length, LPFC_SLI4_MBX_EMBED); |
| 7049 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7050 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7051 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7052 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7053 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7054 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7055 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7056 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7057 | "3026 Mailbox failed , mbxCmd x%x " |
| 7058 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 7059 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 7060 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7061 | goto read_cfg_out; |
| 7062 | } |
| 7063 | |
| 7064 | /* search for fc_fcoe resrouce descriptor */ |
| 7065 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7066 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7067 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 7068 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 7069 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 7070 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 7071 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 7072 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 7073 | goto read_cfg_out; |
| 7074 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7075 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7076 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7077 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7078 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7079 | phba->sli4_hba.iov.pf_number = |
| 7080 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 7081 | phba->sli4_hba.iov.vf_number = |
| 7082 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 7083 | break; |
| 7084 | } |
| 7085 | } |
| 7086 | |
| 7087 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 7088 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 7089 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 7090 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 7091 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7092 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7093 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7094 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 7095 | "Resrouce Descriptor:x%x\n", |
| 7096 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7097 | |
| 7098 | read_cfg_out: |
| 7099 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7100 | return rc; |
| 7101 | } |
| 7102 | |
| 7103 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7104 | * 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] | 7105 | * @phba: pointer to lpfc hba data structure. |
| 7106 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7107 | * This routine is invoked to setup the port-side endian order when |
| 7108 | * the port if_type is 0. This routine has no function for other |
| 7109 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7110 | * |
| 7111 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7112 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7113 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7114 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7115 | **/ |
| 7116 | static int |
| 7117 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 7118 | { |
| 7119 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7120 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7121 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 7122 | HOST_ENDIAN_HIGH_WORD1}; |
| 7123 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7124 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7125 | switch (if_type) { |
| 7126 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7127 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7128 | GFP_KERNEL); |
| 7129 | if (!mboxq) { |
| 7130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7131 | "0492 Unable to allocate memory for " |
| 7132 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 7133 | "command\n"); |
| 7134 | return -ENOMEM; |
| 7135 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7136 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7137 | /* |
| 7138 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 7139 | * two words to contain special data values and no other data. |
| 7140 | */ |
| 7141 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 7142 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 7143 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7144 | if (rc != MBX_SUCCESS) { |
| 7145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7146 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 7147 | "failed with status x%x\n", |
| 7148 | rc); |
| 7149 | rc = -EIO; |
| 7150 | } |
| 7151 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7152 | break; |
| 7153 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7154 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7155 | default: |
| 7156 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7157 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7158 | return rc; |
| 7159 | } |
| 7160 | |
| 7161 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7162 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7163 | * @phba: pointer to lpfc hba data structure. |
| 7164 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7165 | * This routine is invoked to check the user settable queue counts for EQs and |
| 7166 | * CQs. after this routine is called the counts will be set to valid values that |
| 7167 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 7168 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7169 | * |
| 7170 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7171 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7172 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7173 | **/ |
| 7174 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7175 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7176 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7177 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7178 | uint32_t cpu; |
| 7179 | uint32_t i = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7180 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7181 | |
| 7182 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7183 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7184 | * device parameters |
| 7185 | */ |
| 7186 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7187 | /* Sanity check on HBA EQ parameters */ |
| 7188 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7189 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7190 | /* It doesn't make sense to have more io channels then online CPUs */ |
| 7191 | for_each_present_cpu(cpu) { |
| 7192 | if (cpu_online(cpu)) |
| 7193 | i++; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7194 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7195 | phba->sli4_hba.num_online_cpu = i; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 7196 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7197 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7198 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7199 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7200 | lpfc_printf_log(phba, |
| 7201 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7202 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7203 | "online CPUs: from %d to %d\n", |
| 7204 | cfg_fcp_io_channel, i); |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7205 | cfg_fcp_io_channel = i; |
| 7206 | } |
| 7207 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7208 | if (cfg_fcp_io_channel + fof_vectors > |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7209 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7210 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 7211 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7213 | "2574 Not enough EQs (%d) from the " |
| 7214 | "pci function for supporting FCP " |
| 7215 | "EQs (%d)\n", |
| 7216 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7217 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7218 | goto out_error; |
| 7219 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7220 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7221 | "2575 Reducing IO channels to match number of " |
| 7222 | "available EQs: from %d to %d\n", |
| 7223 | cfg_fcp_io_channel, |
| 7224 | phba->sli4_hba.max_cfg_param.max_eq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7225 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq - |
| 7226 | fof_vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7227 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7228 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7229 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7230 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7231 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7232 | /* Get EQ depth from module parameter, fake the default for now */ |
| 7233 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 7234 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 7235 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7236 | /* Get CQ depth from module parameter, fake the default for now */ |
| 7237 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 7238 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 7239 | |
| 7240 | return 0; |
| 7241 | out_error: |
| 7242 | return -ENOMEM; |
| 7243 | } |
| 7244 | |
| 7245 | /** |
| 7246 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 7247 | * @phba: pointer to lpfc hba data structure. |
| 7248 | * |
| 7249 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 7250 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 7251 | * count (queue depth) shall be taken from the module parameter. For now, |
| 7252 | * we just use some constant number as place holder. |
| 7253 | * |
| 7254 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 7255 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7256 | * -ENOMEM - No availble memory |
| 7257 | * -EIO - The mailbox failed to complete successfully. |
| 7258 | **/ |
| 7259 | int |
| 7260 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 7261 | { |
| 7262 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7263 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7264 | |
| 7265 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7266 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7267 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7268 | if (!phba->cfg_fcp_io_channel) |
| 7269 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7270 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7271 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 7272 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 7273 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 7274 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 7275 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 7276 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 7277 | |
| 7278 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7279 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7280 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7282 | "2576 Failed allocate memory for " |
| 7283 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7284 | goto out_error; |
| 7285 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7286 | |
| 7287 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7288 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7289 | if (!phba->sli4_hba.fcp_cq) { |
| 7290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7291 | "2577 Failed allocate memory for fast-path " |
| 7292 | "CQ record array\n"); |
| 7293 | goto out_error; |
| 7294 | } |
| 7295 | |
| 7296 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7297 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7298 | if (!phba->sli4_hba.fcp_wq) { |
| 7299 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7300 | "2578 Failed allocate memory for fast-path " |
| 7301 | "WQ record array\n"); |
| 7302 | goto out_error; |
| 7303 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7304 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7305 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7306 | * Since the first EQ can have multiple CQs associated with it, |
| 7307 | * this array is used to quickly see if we have a FCP fast-path |
| 7308 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7309 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7310 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 7311 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7312 | if (!phba->sli4_hba.fcp_cq_map) { |
| 7313 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7314 | "2545 Failed allocate memory for fast-path " |
| 7315 | "CQ map\n"); |
| 7316 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7317 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7318 | |
| 7319 | /* |
| 7320 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 7321 | * how many EQs to create. |
| 7322 | */ |
| 7323 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7324 | |
| 7325 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7326 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 7327 | phba->sli4_hba.eq_ecount); |
| 7328 | if (!qdesc) { |
| 7329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7330 | "0497 Failed allocate EQ (%d)\n", idx); |
| 7331 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7332 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7333 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 7334 | |
| 7335 | /* Create Fast Path FCP CQs */ |
| 7336 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7337 | phba->sli4_hba.cq_ecount); |
| 7338 | if (!qdesc) { |
| 7339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7340 | "0499 Failed allocate fast-path FCP " |
| 7341 | "CQ (%d)\n", idx); |
| 7342 | goto out_error; |
| 7343 | } |
| 7344 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 7345 | |
| 7346 | /* Create Fast Path FCP WQs */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7347 | if (phba->fcp_embed_io) { |
| 7348 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 7349 | LPFC_WQE128_SIZE, |
| 7350 | LPFC_WQE128_DEF_COUNT); |
| 7351 | } else { |
| 7352 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 7353 | phba->sli4_hba.wq_esize, |
| 7354 | phba->sli4_hba.wq_ecount); |
| 7355 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7356 | if (!qdesc) { |
| 7357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7358 | "0503 Failed allocate fast-path FCP " |
| 7359 | "WQ (%d)\n", idx); |
| 7360 | goto out_error; |
| 7361 | } |
| 7362 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7363 | } |
| 7364 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7365 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7366 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7367 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7368 | */ |
| 7369 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7370 | /* Create slow-path Mailbox Command Complete Queue */ |
| 7371 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7372 | phba->sli4_hba.cq_ecount); |
| 7373 | if (!qdesc) { |
| 7374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7375 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7376 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7377 | } |
| 7378 | phba->sli4_hba.mbx_cq = qdesc; |
| 7379 | |
| 7380 | /* Create slow-path ELS Complete Queue */ |
| 7381 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7382 | phba->sli4_hba.cq_ecount); |
| 7383 | if (!qdesc) { |
| 7384 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7385 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7386 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7387 | } |
| 7388 | phba->sli4_hba.els_cq = qdesc; |
| 7389 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7390 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7391 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7392 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7393 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7394 | |
| 7395 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7396 | |
| 7397 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 7398 | phba->sli4_hba.mq_ecount); |
| 7399 | if (!qdesc) { |
| 7400 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7401 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7402 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7403 | } |
| 7404 | phba->sli4_hba.mbx_wq = qdesc; |
| 7405 | |
| 7406 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7407 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7408 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7409 | |
| 7410 | /* Create slow-path ELS Work Queue */ |
| 7411 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7412 | phba->sli4_hba.wq_ecount); |
| 7413 | if (!qdesc) { |
| 7414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7415 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7416 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7417 | } |
| 7418 | phba->sli4_hba.els_wq = qdesc; |
| 7419 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7420 | /* |
| 7421 | * Create Receive Queue (RQ) |
| 7422 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7423 | |
| 7424 | /* Create Receive Queue for header */ |
| 7425 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7426 | phba->sli4_hba.rq_ecount); |
| 7427 | if (!qdesc) { |
| 7428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7429 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7430 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7431 | } |
| 7432 | phba->sli4_hba.hdr_rq = qdesc; |
| 7433 | |
| 7434 | /* Create Receive Queue for data */ |
| 7435 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7436 | phba->sli4_hba.rq_ecount); |
| 7437 | if (!qdesc) { |
| 7438 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7439 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7440 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7441 | } |
| 7442 | phba->sli4_hba.dat_rq = qdesc; |
| 7443 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7444 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
| 7445 | if (phba->cfg_fof) |
| 7446 | lpfc_fof_queue_create(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7447 | return 0; |
| 7448 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7449 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7450 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7451 | return -ENOMEM; |
| 7452 | } |
| 7453 | |
| 7454 | /** |
| 7455 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 7456 | * @phba: pointer to lpfc hba data structure. |
| 7457 | * |
| 7458 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 7459 | * operation. |
| 7460 | * |
| 7461 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7462 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7463 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7464 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7466 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7467 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 7468 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7469 | int idx; |
| 7470 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7471 | if (phba->cfg_fof) |
| 7472 | lpfc_fof_queue_destroy(phba); |
| 7473 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7474 | if (phba->sli4_hba.hba_eq != NULL) { |
| 7475 | /* Release HBA event queue */ |
| 7476 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7477 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 7478 | lpfc_sli4_queue_free( |
| 7479 | phba->sli4_hba.hba_eq[idx]); |
| 7480 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 7481 | } |
| 7482 | } |
| 7483 | kfree(phba->sli4_hba.hba_eq); |
| 7484 | phba->sli4_hba.hba_eq = NULL; |
| 7485 | } |
| 7486 | |
| 7487 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 7488 | /* Release FCP completion queue */ |
| 7489 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7490 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 7491 | lpfc_sli4_queue_free( |
| 7492 | phba->sli4_hba.fcp_cq[idx]); |
| 7493 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 7494 | } |
| 7495 | } |
| 7496 | kfree(phba->sli4_hba.fcp_cq); |
| 7497 | phba->sli4_hba.fcp_cq = NULL; |
| 7498 | } |
| 7499 | |
| 7500 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 7501 | /* Release FCP work queue */ |
| 7502 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7503 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 7504 | lpfc_sli4_queue_free( |
| 7505 | phba->sli4_hba.fcp_wq[idx]); |
| 7506 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 7507 | } |
| 7508 | } |
| 7509 | kfree(phba->sli4_hba.fcp_wq); |
| 7510 | phba->sli4_hba.fcp_wq = NULL; |
| 7511 | } |
| 7512 | |
| 7513 | /* Release FCP CQ mapping array */ |
| 7514 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 7515 | kfree(phba->sli4_hba.fcp_cq_map); |
| 7516 | phba->sli4_hba.fcp_cq_map = NULL; |
| 7517 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7518 | |
| 7519 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7520 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 7521 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 7522 | phba->sli4_hba.mbx_wq = NULL; |
| 7523 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7524 | |
| 7525 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7526 | if (phba->sli4_hba.els_wq != NULL) { |
| 7527 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 7528 | phba->sli4_hba.els_wq = NULL; |
| 7529 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7530 | |
| 7531 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7532 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 7533 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 7534 | phba->sli4_hba.hdr_rq = NULL; |
| 7535 | } |
| 7536 | if (phba->sli4_hba.dat_rq != NULL) { |
| 7537 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 7538 | phba->sli4_hba.dat_rq = NULL; |
| 7539 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7541 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7542 | if (phba->sli4_hba.els_cq != NULL) { |
| 7543 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 7544 | phba->sli4_hba.els_cq = NULL; |
| 7545 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7546 | |
| 7547 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7548 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 7549 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 7550 | phba->sli4_hba.mbx_cq = NULL; |
| 7551 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7552 | |
| 7553 | return; |
| 7554 | } |
| 7555 | |
| 7556 | /** |
| 7557 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 7558 | * @phba: pointer to lpfc hba data structure. |
| 7559 | * |
| 7560 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 7561 | * operation. |
| 7562 | * |
| 7563 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7564 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7565 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7566 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7567 | **/ |
| 7568 | int |
| 7569 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 7570 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7571 | struct lpfc_sli *psli = &phba->sli; |
| 7572 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7573 | int rc = -ENOMEM; |
| 7574 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 7575 | int fcp_cq_index = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7576 | uint32_t shdr_status, shdr_add_status; |
| 7577 | union lpfc_sli4_cfg_shdr *shdr; |
| 7578 | LPFC_MBOXQ_t *mboxq; |
| 7579 | uint32_t length; |
| 7580 | |
| 7581 | /* Check for dual-ULP support */ |
| 7582 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7583 | if (!mboxq) { |
| 7584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7585 | "3249 Unable to allocate memory for " |
| 7586 | "QUERY_FW_CFG mailbox command\n"); |
| 7587 | return -ENOMEM; |
| 7588 | } |
| 7589 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 7590 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7591 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7592 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 7593 | length, LPFC_SLI4_MBX_EMBED); |
| 7594 | |
| 7595 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7596 | |
| 7597 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7598 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7599 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7600 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7601 | if (shdr_status || shdr_add_status || rc) { |
| 7602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7603 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 7604 | "x%x add_status x%x, mbx status x%x\n", |
| 7605 | shdr_status, shdr_add_status, rc); |
| 7606 | if (rc != MBX_TIMEOUT) |
| 7607 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7608 | rc = -ENXIO; |
| 7609 | goto out_error; |
| 7610 | } |
| 7611 | |
| 7612 | phba->sli4_hba.fw_func_mode = |
| 7613 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 7614 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 7615 | 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] | 7616 | phba->sli4_hba.physical_port = |
| 7617 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7618 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7619 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 7620 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 7621 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 7622 | |
| 7623 | if (rc != MBX_TIMEOUT) |
| 7624 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7625 | |
| 7626 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7627 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7628 | */ |
| 7629 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7630 | /* Set up HBA event queue */ |
| 7631 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7632 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7633 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7634 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7635 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7636 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7637 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 7638 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7639 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7640 | "0522 Fast-path EQ (%d) not " |
| 7641 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7642 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7643 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7644 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7645 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 7646 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7647 | if (rc) { |
| 7648 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7649 | "0523 Failed setup of fast-path EQ " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7650 | "(%d), rc = 0x%x\n", fcp_eqidx, |
| 7651 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7652 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7653 | } |
| 7654 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7655 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7656 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7657 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7658 | } |
| 7659 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7660 | /* Set up fast-path FCP Response Complete Queue */ |
| 7661 | if (!phba->sli4_hba.fcp_cq) { |
| 7662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7663 | "3148 Fast-path FCP CQ array not " |
| 7664 | "allocated\n"); |
| 7665 | rc = -ENOMEM; |
| 7666 | goto out_destroy_hba_eq; |
| 7667 | } |
| 7668 | |
| 7669 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 7670 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 7671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7672 | "0526 Fast-path FCP CQ (%d) not " |
| 7673 | "allocated\n", fcp_cqidx); |
| 7674 | rc = -ENOMEM; |
| 7675 | goto out_destroy_fcp_cq; |
| 7676 | } |
| 7677 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 7678 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 7679 | if (rc) { |
| 7680 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7681 | "0527 Failed setup of fast-path FCP " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7682 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, |
| 7683 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7684 | goto out_destroy_fcp_cq; |
| 7685 | } |
| 7686 | |
| 7687 | /* Setup fcp_cq_map for fast lookup */ |
| 7688 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 7689 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7690 | |
| 7691 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7692 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7693 | "parent seq[%d]-id=%d\n", |
| 7694 | fcp_cqidx, |
| 7695 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7696 | fcp_cqidx, |
| 7697 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7698 | } |
| 7699 | |
| 7700 | /* Set up fast-path FCP Work Queue */ |
| 7701 | if (!phba->sli4_hba.fcp_wq) { |
| 7702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7703 | "3149 Fast-path FCP WQ array not " |
| 7704 | "allocated\n"); |
| 7705 | rc = -ENOMEM; |
| 7706 | goto out_destroy_fcp_cq; |
| 7707 | } |
| 7708 | |
| 7709 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7710 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7711 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7712 | "0534 Fast-path FCP WQ (%d) not " |
| 7713 | "allocated\n", fcp_wqidx); |
| 7714 | rc = -ENOMEM; |
| 7715 | goto out_destroy_fcp_wq; |
| 7716 | } |
| 7717 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7718 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7719 | LPFC_FCP); |
| 7720 | if (rc) { |
| 7721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7722 | "0535 Failed setup of fast-path FCP " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7723 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, |
| 7724 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7725 | goto out_destroy_fcp_wq; |
| 7726 | } |
| 7727 | |
| 7728 | /* Bind this WQ to the next FCP ring */ |
| 7729 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7730 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7731 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7732 | |
| 7733 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7734 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7735 | "parent cq[%d]-id=%d\n", |
| 7736 | fcp_wqidx, |
| 7737 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7738 | fcp_cq_index, |
| 7739 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7740 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7741 | /* |
| 7742 | * Set up Complete Queues (CQs) |
| 7743 | */ |
| 7744 | |
| 7745 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7746 | if (!phba->sli4_hba.mbx_cq) { |
| 7747 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7748 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7749 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7750 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7751 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7752 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7753 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7754 | if (rc) { |
| 7755 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7756 | "0529 Failed setup of slow-path mailbox CQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7757 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7758 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7759 | } |
| 7760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7761 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7762 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7763 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7764 | |
| 7765 | /* Set up slow-path ELS Complete Queue */ |
| 7766 | if (!phba->sli4_hba.els_cq) { |
| 7767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7768 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7769 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7770 | goto out_destroy_mbx_cq; |
| 7771 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7772 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7773 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7774 | if (rc) { |
| 7775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7776 | "0531 Failed setup of slow-path ELS CQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7777 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7778 | goto out_destroy_mbx_cq; |
| 7779 | } |
| 7780 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7781 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7782 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7783 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7784 | |
| 7785 | /* |
| 7786 | * Set up all the Work Queues (WQs) |
| 7787 | */ |
| 7788 | |
| 7789 | /* Set up Mailbox Command Queue */ |
| 7790 | if (!phba->sli4_hba.mbx_wq) { |
| 7791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7792 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7793 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7794 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7795 | } |
| 7796 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7797 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7798 | if (rc) { |
| 7799 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7800 | "0539 Failed setup of slow-path MQ: " |
| 7801 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7802 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7803 | } |
| 7804 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7805 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7806 | phba->sli4_hba.mbx_wq->queue_id, |
| 7807 | phba->sli4_hba.mbx_cq->queue_id); |
| 7808 | |
| 7809 | /* Set up slow-path ELS Work Queue */ |
| 7810 | if (!phba->sli4_hba.els_wq) { |
| 7811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7812 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7813 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7814 | goto out_destroy_mbx_wq; |
| 7815 | } |
| 7816 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7817 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7818 | if (rc) { |
| 7819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7820 | "0537 Failed setup of slow-path ELS WQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7821 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7822 | goto out_destroy_mbx_wq; |
| 7823 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7824 | |
| 7825 | /* Bind this WQ to the ELS ring */ |
| 7826 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7827 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7828 | phba->sli4_hba.els_cq->pring = pring; |
| 7829 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7830 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7831 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7832 | phba->sli4_hba.els_wq->queue_id, |
| 7833 | phba->sli4_hba.els_cq->queue_id); |
| 7834 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7835 | /* |
| 7836 | * Create Receive Queue (RQ) |
| 7837 | */ |
| 7838 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7840 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7841 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7842 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7843 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7844 | |
| 7845 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7846 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7847 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7848 | 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] | 7849 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7850 | if (rc) { |
| 7851 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7852 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7853 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7854 | goto out_destroy_fcp_wq; |
| 7855 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7856 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7857 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7858 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7859 | "parent cq-id=%d\n", |
| 7860 | phba->sli4_hba.hdr_rq->queue_id, |
| 7861 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7862 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7863 | |
| 7864 | if (phba->cfg_fof) { |
| 7865 | rc = lpfc_fof_queue_setup(phba); |
| 7866 | if (rc) { |
| 7867 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7868 | "0549 Failed setup of FOF Queues: " |
| 7869 | "rc = 0x%x\n", rc); |
| 7870 | goto out_destroy_els_rq; |
| 7871 | } |
| 7872 | } |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 7873 | |
| 7874 | /* |
| 7875 | * Configure EQ delay multipier for interrupt coalescing using |
| 7876 | * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time. |
| 7877 | */ |
| 7878 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
| 7879 | fcp_eqidx += LPFC_MAX_EQ_DELAY) |
| 7880 | lpfc_modify_fcp_eq_delay(phba, fcp_eqidx); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7881 | return 0; |
| 7882 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7883 | out_destroy_els_rq: |
| 7884 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7885 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7886 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7887 | out_destroy_mbx_wq: |
| 7888 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7889 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7890 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7891 | out_destroy_mbx_cq: |
| 7892 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7893 | out_destroy_fcp_wq: |
| 7894 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7895 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7896 | out_destroy_fcp_cq: |
| 7897 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7898 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7899 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7900 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7901 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7902 | out_error: |
| 7903 | return rc; |
| 7904 | } |
| 7905 | |
| 7906 | /** |
| 7907 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7908 | * @phba: pointer to lpfc hba data structure. |
| 7909 | * |
| 7910 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7911 | * operation. |
| 7912 | * |
| 7913 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7914 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7915 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7916 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7917 | **/ |
| 7918 | void |
| 7919 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7920 | { |
| 7921 | int fcp_qidx; |
| 7922 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7923 | /* Unset the queues created for Flash Optimized Fabric operations */ |
| 7924 | if (phba->cfg_fof) |
| 7925 | lpfc_fof_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7926 | /* Unset mailbox command work queue */ |
| 7927 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7928 | /* Unset ELS work queue */ |
| 7929 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7930 | /* Unset unsolicited receive queue */ |
| 7931 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7932 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7933 | if (phba->sli4_hba.fcp_wq) { |
| 7934 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7935 | fcp_qidx++) |
| 7936 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7937 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7938 | /* Unset mailbox command complete queue */ |
| 7939 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7940 | /* Unset ELS complete queue */ |
| 7941 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7942 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7943 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7944 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7945 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7946 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7947 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7948 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7949 | if (phba->sli4_hba.hba_eq) { |
| 7950 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7951 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7952 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7953 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7954 | } |
| 7955 | |
| 7956 | /** |
| 7957 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7958 | * @phba: pointer to lpfc hba data structure. |
| 7959 | * |
| 7960 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7961 | * events. The body of the completion queue event is a completion queue entry |
| 7962 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7963 | * the following HBA completion queue events for the worker thread to process: |
| 7964 | * - Mailbox asynchronous events |
| 7965 | * - Receive queue completion unsolicited events |
| 7966 | * Later, this can be used for all the slow-path events. |
| 7967 | * |
| 7968 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7969 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7970 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7971 | **/ |
| 7972 | static int |
| 7973 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7974 | { |
| 7975 | struct lpfc_cq_event *cq_event; |
| 7976 | int i; |
| 7977 | |
| 7978 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7979 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7980 | if (!cq_event) |
| 7981 | goto out_pool_create_fail; |
| 7982 | list_add_tail(&cq_event->list, |
| 7983 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7984 | } |
| 7985 | return 0; |
| 7986 | |
| 7987 | out_pool_create_fail: |
| 7988 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7989 | return -ENOMEM; |
| 7990 | } |
| 7991 | |
| 7992 | /** |
| 7993 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7994 | * @phba: pointer to lpfc hba data structure. |
| 7995 | * |
| 7996 | * This routine is invoked to free the pool of completion queue events at |
| 7997 | * driver unload time. Note that, it is the responsibility of the driver |
| 7998 | * cleanup routine to free all the outstanding completion-queue events |
| 7999 | * allocated from this pool back into the pool before invoking this routine |
| 8000 | * to destroy the pool. |
| 8001 | **/ |
| 8002 | static void |
| 8003 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 8004 | { |
| 8005 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 8006 | |
| 8007 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 8008 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 8009 | list_del(&cq_event->list); |
| 8010 | kfree(cq_event); |
| 8011 | } |
| 8012 | } |
| 8013 | |
| 8014 | /** |
| 8015 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 8016 | * @phba: pointer to lpfc hba data structure. |
| 8017 | * |
| 8018 | * This routine is the lock free version of the API invoked to allocate a |
| 8019 | * completion-queue event from the free pool. |
| 8020 | * |
| 8021 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 8022 | * NULL otherwise. |
| 8023 | **/ |
| 8024 | struct lpfc_cq_event * |
| 8025 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 8026 | { |
| 8027 | struct lpfc_cq_event *cq_event = NULL; |
| 8028 | |
| 8029 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 8030 | struct lpfc_cq_event, list); |
| 8031 | return cq_event; |
| 8032 | } |
| 8033 | |
| 8034 | /** |
| 8035 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 8036 | * @phba: pointer to lpfc hba data structure. |
| 8037 | * |
| 8038 | * This routine is the lock version of the API invoked to allocate a |
| 8039 | * completion-queue event from the free pool. |
| 8040 | * |
| 8041 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 8042 | * NULL otherwise. |
| 8043 | **/ |
| 8044 | struct lpfc_cq_event * |
| 8045 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 8046 | { |
| 8047 | struct lpfc_cq_event *cq_event; |
| 8048 | unsigned long iflags; |
| 8049 | |
| 8050 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8051 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 8052 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8053 | return cq_event; |
| 8054 | } |
| 8055 | |
| 8056 | /** |
| 8057 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 8058 | * @phba: pointer to lpfc hba data structure. |
| 8059 | * @cq_event: pointer to the completion queue event to be freed. |
| 8060 | * |
| 8061 | * This routine is the lock free version of the API invoked to release a |
| 8062 | * completion-queue event back into the free pool. |
| 8063 | **/ |
| 8064 | void |
| 8065 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 8066 | struct lpfc_cq_event *cq_event) |
| 8067 | { |
| 8068 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 8069 | } |
| 8070 | |
| 8071 | /** |
| 8072 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 8073 | * @phba: pointer to lpfc hba data structure. |
| 8074 | * @cq_event: pointer to the completion queue event to be freed. |
| 8075 | * |
| 8076 | * This routine is the lock version of the API invoked to release a |
| 8077 | * completion-queue event back into the free pool. |
| 8078 | **/ |
| 8079 | void |
| 8080 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 8081 | struct lpfc_cq_event *cq_event) |
| 8082 | { |
| 8083 | unsigned long iflags; |
| 8084 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8085 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 8086 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8087 | } |
| 8088 | |
| 8089 | /** |
| 8090 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 8091 | * @phba: pointer to lpfc hba data structure. |
| 8092 | * |
| 8093 | * This routine is to free all the pending completion-queue events to the |
| 8094 | * back into the free pool for device reset. |
| 8095 | **/ |
| 8096 | static void |
| 8097 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 8098 | { |
| 8099 | LIST_HEAD(cqelist); |
| 8100 | struct lpfc_cq_event *cqe; |
| 8101 | unsigned long iflags; |
| 8102 | |
| 8103 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 8104 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8105 | /* Pending FCP XRI abort events */ |
| 8106 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 8107 | &cqelist); |
| 8108 | /* Pending ELS XRI abort events */ |
| 8109 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 8110 | &cqelist); |
| 8111 | /* Pending asynnc events */ |
| 8112 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 8113 | &cqelist); |
| 8114 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8115 | |
| 8116 | while (!list_empty(&cqelist)) { |
| 8117 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 8118 | lpfc_sli4_cq_event_release(phba, cqe); |
| 8119 | } |
| 8120 | } |
| 8121 | |
| 8122 | /** |
| 8123 | * lpfc_pci_function_reset - Reset pci function. |
| 8124 | * @phba: pointer to lpfc hba data structure. |
| 8125 | * |
| 8126 | * This routine is invoked to request a PCI function reset. It will destroys |
| 8127 | * all resources assigned to the PCI function which originates this request. |
| 8128 | * |
| 8129 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8130 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8131 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8132 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | **/ |
| 8134 | int |
| 8135 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 8136 | { |
| 8137 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8138 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8139 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8140 | uint32_t rdy_chk; |
| 8141 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8142 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8143 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 8144 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8145 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8146 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8147 | switch (if_type) { |
| 8148 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8149 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8150 | GFP_KERNEL); |
| 8151 | if (!mboxq) { |
| 8152 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8153 | "0494 Unable to allocate memory for " |
| 8154 | "issuing SLI_FUNCTION_RESET mailbox " |
| 8155 | "command\n"); |
| 8156 | return -ENOMEM; |
| 8157 | } |
| 8158 | |
| 8159 | /* Setup PCI function reset mailbox-ioctl command */ |
| 8160 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8161 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 8162 | LPFC_SLI4_MBX_EMBED); |
| 8163 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8164 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8165 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8166 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8167 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 8168 | &shdr->response); |
| 8169 | if (rc != MBX_TIMEOUT) |
| 8170 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8171 | if (shdr_status || shdr_add_status || rc) { |
| 8172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8173 | "0495 SLI_FUNCTION_RESET mailbox " |
| 8174 | "failed with status x%x add_status x%x," |
| 8175 | " mbx status x%x\n", |
| 8176 | shdr_status, shdr_add_status, rc); |
| 8177 | rc = -ENXIO; |
| 8178 | } |
| 8179 | break; |
| 8180 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8181 | wait: |
| 8182 | /* |
| 8183 | * Poll the Port Status Register and wait for RDY for |
| 8184 | * up to 30 seconds. If the port doesn't respond, treat |
| 8185 | * it as an error. |
| 8186 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 8187 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8188 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 8189 | STATUSregaddr, ®_data.word0)) { |
| 8190 | rc = -ENODEV; |
| 8191 | goto out; |
| 8192 | } |
| 8193 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 8194 | break; |
| 8195 | msleep(20); |
| 8196 | } |
| 8197 | |
| 8198 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 8199 | phba->work_status[0] = readl( |
| 8200 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 8201 | phba->work_status[1] = readl( |
| 8202 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 8203 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8204 | "2890 Port not ready, port status reg " |
| 8205 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 8206 | reg_data.word0, |
| 8207 | phba->work_status[0], |
| 8208 | phba->work_status[1]); |
| 8209 | rc = -ENODEV; |
| 8210 | goto out; |
| 8211 | } |
| 8212 | |
| 8213 | if (!port_reset) { |
| 8214 | /* |
| 8215 | * Reset the port now |
| 8216 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8217 | reg_data.word0 = 0; |
| 8218 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 8219 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 8220 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 8221 | LPFC_SLIPORT_INIT_PORT); |
| 8222 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 8223 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 8224 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 8225 | pci_read_config_word(phba->pcidev, |
| 8226 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8227 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8228 | port_reset = 1; |
| 8229 | msleep(20); |
| 8230 | goto wait; |
| 8231 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 8232 | rc = -ENODEV; |
| 8233 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8234 | } |
| 8235 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8236 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8237 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8238 | default: |
| 8239 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8240 | } |
| 8241 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8242 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8243 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8244 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 8245 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8246 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8247 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8248 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 8249 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8250 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8251 | return rc; |
| 8252 | } |
| 8253 | |
| 8254 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8255 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 8256 | * @phba: pointer to lpfc hba data structure. |
| 8257 | * |
| 8258 | * This routine is invoked to set up the PCI device memory space for device |
| 8259 | * with SLI-4 interface spec. |
| 8260 | * |
| 8261 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8262 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8263 | * other values - error |
| 8264 | **/ |
| 8265 | static int |
| 8266 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 8267 | { |
| 8268 | struct pci_dev *pdev; |
| 8269 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 8270 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8271 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8272 | |
| 8273 | /* Obtain PCI device reference */ |
| 8274 | if (!phba->pcidev) |
| 8275 | return error; |
| 8276 | else |
| 8277 | pdev = phba->pcidev; |
| 8278 | |
| 8279 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 8280 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 8281 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 8282 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 8283 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8284 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 8285 | } |
| 8286 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8287 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8288 | /* |
| 8289 | * The BARs and register set definitions and offset locations are |
| 8290 | * dependent on the if_type. |
| 8291 | */ |
| 8292 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 8293 | &phba->sli4_hba.sli_intf.word0)) { |
| 8294 | return error; |
| 8295 | } |
| 8296 | |
| 8297 | /* There is no SLI3 failback for SLI4 devices. */ |
| 8298 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 8299 | LPFC_SLI_INTF_VALID) { |
| 8300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8301 | "2894 SLI_INTF reg contents invalid " |
| 8302 | "sli_intf reg 0x%x\n", |
| 8303 | phba->sli4_hba.sli_intf.word0); |
| 8304 | return error; |
| 8305 | } |
| 8306 | |
| 8307 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8308 | /* |
| 8309 | * Get the bus address of SLI4 device Bar regions and the |
| 8310 | * number of bytes required by each mapping. The mapping of the |
| 8311 | * particular PCI BARs regions is dependent on the type of |
| 8312 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8313 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8314 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 8315 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 8316 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8317 | |
| 8318 | /* |
| 8319 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 8320 | * addr |
| 8321 | */ |
| 8322 | phba->sli4_hba.conf_regs_memmap_p = |
| 8323 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 8324 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8325 | dev_printk(KERN_ERR, &pdev->dev, |
| 8326 | "ioremap failed for SLI4 PCI config " |
| 8327 | "registers.\n"); |
| 8328 | goto out; |
| 8329 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8330 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8331 | /* Set up BAR0 PCI config space register memory map */ |
| 8332 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 8333 | } else { |
| 8334 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 8335 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8336 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8337 | dev_printk(KERN_ERR, &pdev->dev, |
| 8338 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 8339 | goto out; |
| 8340 | } |
| 8341 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8342 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8343 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8344 | dev_printk(KERN_ERR, &pdev->dev, |
| 8345 | "ioremap failed for SLI4 PCI config " |
| 8346 | "registers.\n"); |
| 8347 | goto out; |
| 8348 | } |
| 8349 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8350 | } |
| 8351 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8352 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8353 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8354 | /* |
| 8355 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 8356 | * virtual address and setup the registers. |
| 8357 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8358 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 8359 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8360 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8361 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8362 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 8363 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8364 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8365 | goto out_iounmap_conf; |
| 8366 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8367 | phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8368 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8369 | } |
| 8370 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8371 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8372 | (pci_resource_start(pdev, PCI_64BIT_BAR4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8373 | /* |
| 8374 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 8375 | * virtual address and setup the registers. |
| 8376 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8377 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 8378 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8379 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8380 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8381 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 8382 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8383 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8384 | goto out_iounmap_ctrl; |
| 8385 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8386 | phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8387 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 8388 | if (error) |
| 8389 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8390 | } |
| 8391 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8392 | return 0; |
| 8393 | |
| 8394 | out_iounmap_all: |
| 8395 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8396 | out_iounmap_ctrl: |
| 8397 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8398 | out_iounmap_conf: |
| 8399 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8400 | out: |
| 8401 | return error; |
| 8402 | } |
| 8403 | |
| 8404 | /** |
| 8405 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 8406 | * @phba: pointer to lpfc hba data structure. |
| 8407 | * |
| 8408 | * This routine is invoked to unset the PCI device memory space for device |
| 8409 | * with SLI-4 interface spec. |
| 8410 | **/ |
| 8411 | static void |
| 8412 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 8413 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8414 | uint32_t if_type; |
| 8415 | 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] | 8416 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8417 | switch (if_type) { |
| 8418 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8419 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8420 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8421 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8422 | break; |
| 8423 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8424 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8425 | break; |
| 8426 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8427 | default: |
| 8428 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8429 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8430 | if_type); |
| 8431 | break; |
| 8432 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8433 | } |
| 8434 | |
| 8435 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8436 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 8437 | * @phba: pointer to lpfc hba data structure. |
| 8438 | * |
| 8439 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 8440 | * with SLI-3 interface specs. The kernel function pci_enable_msix_exact() |
| 8441 | * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(), |
| 8442 | * once invoked, enables either all or nothing, depending on the current |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8443 | * availability of PCI vector resources. The device driver is responsible |
| 8444 | * for calling the individual request_irq() to register each MSI-X vector |
| 8445 | * with a interrupt handler, which is done in this function. Note that |
| 8446 | * later when device is unloading, the driver should always call free_irq() |
| 8447 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8448 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8449 | * will be left with MSI-X enabled and leaks its vectors. |
| 8450 | * |
| 8451 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8452 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8453 | * other values - error |
| 8454 | **/ |
| 8455 | static int |
| 8456 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 8457 | { |
| 8458 | int rc, i; |
| 8459 | LPFC_MBOXQ_t *pmb; |
| 8460 | |
| 8461 | /* Set up MSI-X multi-message vectors */ |
| 8462 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8463 | phba->msix_entries[i].entry = i; |
| 8464 | |
| 8465 | /* Configure MSI-X capability structure */ |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 8466 | rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries, |
| 8467 | LPFC_MSIX_VECTORS); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8468 | if (rc) { |
| 8469 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8470 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8471 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8472 | } |
| 8473 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8474 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8475 | "0477 MSI-X entry[%d]: vector=x%x " |
| 8476 | "message=%d\n", i, |
| 8477 | phba->msix_entries[i].vector, |
| 8478 | phba->msix_entries[i].entry); |
| 8479 | /* |
| 8480 | * Assign MSI-X vectors to interrupt handlers |
| 8481 | */ |
| 8482 | |
| 8483 | /* vector-0 is associated to slow-path handler */ |
| 8484 | rc = request_irq(phba->msix_entries[0].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8485 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8486 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 8487 | if (rc) { |
| 8488 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8489 | "0421 MSI-X slow-path request_irq failed " |
| 8490 | "(%d)\n", rc); |
| 8491 | goto msi_fail_out; |
| 8492 | } |
| 8493 | |
| 8494 | /* vector-1 is associated to fast-path handler */ |
| 8495 | rc = request_irq(phba->msix_entries[1].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8496 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8497 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 8498 | |
| 8499 | if (rc) { |
| 8500 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8501 | "0429 MSI-X fast-path request_irq failed " |
| 8502 | "(%d)\n", rc); |
| 8503 | goto irq_fail_out; |
| 8504 | } |
| 8505 | |
| 8506 | /* |
| 8507 | * Configure HBA MSI-X attention conditions to messages |
| 8508 | */ |
| 8509 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8510 | |
| 8511 | if (!pmb) { |
| 8512 | rc = -ENOMEM; |
| 8513 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8514 | "0474 Unable to allocate memory for issuing " |
| 8515 | "MBOX_CONFIG_MSI command\n"); |
| 8516 | goto mem_fail_out; |
| 8517 | } |
| 8518 | rc = lpfc_config_msi(phba, pmb); |
| 8519 | if (rc) |
| 8520 | goto mbx_fail_out; |
| 8521 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8522 | if (rc != MBX_SUCCESS) { |
| 8523 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 8524 | "0351 Config MSI mailbox command failed, " |
| 8525 | "mbxCmd x%x, mbxStatus x%x\n", |
| 8526 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 8527 | goto mbx_fail_out; |
| 8528 | } |
| 8529 | |
| 8530 | /* Free memory allocated for mailbox command */ |
| 8531 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8532 | return rc; |
| 8533 | |
| 8534 | mbx_fail_out: |
| 8535 | /* Free memory allocated for mailbox command */ |
| 8536 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8537 | |
| 8538 | mem_fail_out: |
| 8539 | /* free the irq already requested */ |
| 8540 | free_irq(phba->msix_entries[1].vector, phba); |
| 8541 | |
| 8542 | irq_fail_out: |
| 8543 | /* free the irq already requested */ |
| 8544 | free_irq(phba->msix_entries[0].vector, phba); |
| 8545 | |
| 8546 | msi_fail_out: |
| 8547 | /* Unconfigure MSI-X capability structure */ |
| 8548 | pci_disable_msix(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8549 | |
| 8550 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8551 | return rc; |
| 8552 | } |
| 8553 | |
| 8554 | /** |
| 8555 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 8556 | * @phba: pointer to lpfc hba data structure. |
| 8557 | * |
| 8558 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8559 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 8560 | **/ |
| 8561 | static void |
| 8562 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 8563 | { |
| 8564 | int i; |
| 8565 | |
| 8566 | /* Free up MSI-X multi-message vectors */ |
| 8567 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8568 | free_irq(phba->msix_entries[i].vector, phba); |
| 8569 | /* Disable MSI-X */ |
| 8570 | pci_disable_msix(phba->pcidev); |
| 8571 | |
| 8572 | return; |
| 8573 | } |
| 8574 | |
| 8575 | /** |
| 8576 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 8577 | * @phba: pointer to lpfc hba data structure. |
| 8578 | * |
| 8579 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8580 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 8581 | * enable the MSI vector. The device driver is responsible for calling the |
| 8582 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 8583 | * is done in this function. |
| 8584 | * |
| 8585 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8586 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8587 | * other values - error |
| 8588 | */ |
| 8589 | static int |
| 8590 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 8591 | { |
| 8592 | int rc; |
| 8593 | |
| 8594 | rc = pci_enable_msi(phba->pcidev); |
| 8595 | if (!rc) |
| 8596 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8597 | "0462 PCI enable MSI mode success.\n"); |
| 8598 | else { |
| 8599 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8600 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 8601 | return rc; |
| 8602 | } |
| 8603 | |
| 8604 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8605 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8606 | if (rc) { |
| 8607 | pci_disable_msi(phba->pcidev); |
| 8608 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8609 | "0478 MSI request_irq failed (%d)\n", rc); |
| 8610 | } |
| 8611 | return rc; |
| 8612 | } |
| 8613 | |
| 8614 | /** |
| 8615 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 8616 | * @phba: pointer to lpfc hba data structure. |
| 8617 | * |
| 8618 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8619 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 8620 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8621 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8622 | * its vector. |
| 8623 | */ |
| 8624 | static void |
| 8625 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 8626 | { |
| 8627 | free_irq(phba->pcidev->irq, phba); |
| 8628 | pci_disable_msi(phba->pcidev); |
| 8629 | return; |
| 8630 | } |
| 8631 | |
| 8632 | /** |
| 8633 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 8634 | * @phba: pointer to lpfc hba data structure. |
| 8635 | * |
| 8636 | * This routine is invoked to enable device interrupt and associate driver's |
| 8637 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8638 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8639 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8640 | * mode which is supported by the platform, kernel, and device in the order |
| 8641 | * of: |
| 8642 | * MSI-X -> MSI -> IRQ. |
| 8643 | * |
| 8644 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8645 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8646 | * other values - error |
| 8647 | **/ |
| 8648 | static uint32_t |
| 8649 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8650 | { |
| 8651 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8652 | int retval; |
| 8653 | |
| 8654 | if (cfg_mode == 2) { |
| 8655 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8656 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8657 | if (!retval) { |
| 8658 | /* Now, try to enable MSI-X interrupt mode */ |
| 8659 | retval = lpfc_sli_enable_msix(phba); |
| 8660 | if (!retval) { |
| 8661 | /* Indicate initialization to MSI-X mode */ |
| 8662 | phba->intr_type = MSIX; |
| 8663 | intr_mode = 2; |
| 8664 | } |
| 8665 | } |
| 8666 | } |
| 8667 | |
| 8668 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8669 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8670 | retval = lpfc_sli_enable_msi(phba); |
| 8671 | if (!retval) { |
| 8672 | /* Indicate initialization to MSI mode */ |
| 8673 | phba->intr_type = MSI; |
| 8674 | intr_mode = 1; |
| 8675 | } |
| 8676 | } |
| 8677 | |
| 8678 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8679 | if (phba->intr_type == NONE) { |
| 8680 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8681 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8682 | if (!retval) { |
| 8683 | /* Indicate initialization to INTx mode */ |
| 8684 | phba->intr_type = INTx; |
| 8685 | intr_mode = 0; |
| 8686 | } |
| 8687 | } |
| 8688 | return intr_mode; |
| 8689 | } |
| 8690 | |
| 8691 | /** |
| 8692 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8693 | * @phba: pointer to lpfc hba data structure. |
| 8694 | * |
| 8695 | * This routine is invoked to disable device interrupt and disassociate the |
| 8696 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8697 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8698 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8699 | **/ |
| 8700 | static void |
| 8701 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8702 | { |
| 8703 | /* Disable the currently initialized interrupt mode */ |
| 8704 | if (phba->intr_type == MSIX) |
| 8705 | lpfc_sli_disable_msix(phba); |
| 8706 | else if (phba->intr_type == MSI) |
| 8707 | lpfc_sli_disable_msi(phba); |
| 8708 | else if (phba->intr_type == INTx) |
| 8709 | free_irq(phba->pcidev->irq, phba); |
| 8710 | |
| 8711 | /* Reset interrupt management states */ |
| 8712 | phba->intr_type = NONE; |
| 8713 | phba->sli.slistat.sli_intr = 0; |
| 8714 | |
| 8715 | return; |
| 8716 | } |
| 8717 | |
| 8718 | /** |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8719 | * lpfc_find_next_cpu - Find next available CPU that matches the phys_id |
| 8720 | * @phba: pointer to lpfc hba data structure. |
| 8721 | * |
| 8722 | * Find next available CPU to use for IRQ to CPU affinity. |
| 8723 | */ |
| 8724 | static int |
| 8725 | lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id) |
| 8726 | { |
| 8727 | struct lpfc_vector_map_info *cpup; |
| 8728 | int cpu; |
| 8729 | |
| 8730 | cpup = phba->sli4_hba.cpu_map; |
| 8731 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8732 | /* CPU must be online */ |
| 8733 | if (cpu_online(cpu)) { |
| 8734 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8735 | (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) && |
| 8736 | (cpup->phys_id == phys_id)) { |
| 8737 | return cpu; |
| 8738 | } |
| 8739 | } |
| 8740 | cpup++; |
| 8741 | } |
| 8742 | |
| 8743 | /* |
| 8744 | * If we get here, we have used ALL CPUs for the specific |
| 8745 | * phys_id. Now we need to clear out lpfc_used_cpu and start |
| 8746 | * reusing CPUs. |
| 8747 | */ |
| 8748 | |
| 8749 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8750 | if (lpfc_used_cpu[cpu] == phys_id) |
| 8751 | lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY; |
| 8752 | } |
| 8753 | |
| 8754 | cpup = phba->sli4_hba.cpu_map; |
| 8755 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8756 | /* CPU must be online */ |
| 8757 | if (cpu_online(cpu)) { |
| 8758 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8759 | (cpup->phys_id == phys_id)) { |
| 8760 | return cpu; |
| 8761 | } |
| 8762 | } |
| 8763 | cpup++; |
| 8764 | } |
| 8765 | return LPFC_VECTOR_MAP_EMPTY; |
| 8766 | } |
| 8767 | |
| 8768 | /** |
| 8769 | * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors |
| 8770 | * @phba: pointer to lpfc hba data structure. |
| 8771 | * @vectors: number of HBA vectors |
| 8772 | * |
| 8773 | * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector |
| 8774 | * affinization across multple physical CPUs (numa nodes). |
| 8775 | * In addition, this routine will assign an IO channel for each CPU |
| 8776 | * to use when issuing I/Os. |
| 8777 | */ |
| 8778 | static int |
| 8779 | lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors) |
| 8780 | { |
| 8781 | int i, idx, saved_chann, used_chann, cpu, phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8782 | int max_phys_id, min_phys_id; |
| 8783 | int num_io_channel, first_cpu, chan; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8784 | struct lpfc_vector_map_info *cpup; |
| 8785 | #ifdef CONFIG_X86 |
| 8786 | struct cpuinfo_x86 *cpuinfo; |
| 8787 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8788 | uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1]; |
| 8789 | |
| 8790 | /* If there is no mapping, just return */ |
| 8791 | if (!phba->cfg_fcp_cpu_map) |
| 8792 | return 1; |
| 8793 | |
| 8794 | /* Init cpu_map array */ |
| 8795 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 8796 | (sizeof(struct lpfc_vector_map_info) * |
| 8797 | phba->sli4_hba.num_present_cpu)); |
| 8798 | |
| 8799 | max_phys_id = 0; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8800 | min_phys_id = 0xff; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8801 | phys_id = 0; |
| 8802 | num_io_channel = 0; |
| 8803 | first_cpu = LPFC_VECTOR_MAP_EMPTY; |
| 8804 | |
| 8805 | /* Update CPU map with physical id and core id of each CPU */ |
| 8806 | cpup = phba->sli4_hba.cpu_map; |
| 8807 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8808 | #ifdef CONFIG_X86 |
| 8809 | cpuinfo = &cpu_data(cpu); |
| 8810 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 8811 | cpup->core_id = cpuinfo->cpu_core_id; |
| 8812 | #else |
| 8813 | /* No distinction between CPUs for other platforms */ |
| 8814 | cpup->phys_id = 0; |
| 8815 | cpup->core_id = 0; |
| 8816 | #endif |
| 8817 | |
| 8818 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8819 | "3328 CPU physid %d coreid %d\n", |
| 8820 | cpup->phys_id, cpup->core_id); |
| 8821 | |
| 8822 | if (cpup->phys_id > max_phys_id) |
| 8823 | max_phys_id = cpup->phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8824 | if (cpup->phys_id < min_phys_id) |
| 8825 | min_phys_id = cpup->phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8826 | cpup++; |
| 8827 | } |
| 8828 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8829 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8830 | /* Now associate the HBA vectors with specific CPUs */ |
| 8831 | for (idx = 0; idx < vectors; idx++) { |
| 8832 | cpup = phba->sli4_hba.cpu_map; |
| 8833 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8834 | if (cpu == LPFC_VECTOR_MAP_EMPTY) { |
| 8835 | |
| 8836 | /* Try for all phys_id's */ |
| 8837 | for (i = 1; i < max_phys_id; i++) { |
| 8838 | phys_id++; |
| 8839 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8840 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8841 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8842 | if (cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8843 | continue; |
| 8844 | goto found; |
| 8845 | } |
| 8846 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8847 | /* Use round robin for scheduling */ |
| 8848 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN; |
| 8849 | chan = 0; |
| 8850 | cpup = phba->sli4_hba.cpu_map; |
| 8851 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 8852 | cpup->channel_id = chan; |
| 8853 | cpup++; |
| 8854 | chan++; |
| 8855 | if (chan >= phba->cfg_fcp_io_channel) |
| 8856 | chan = 0; |
| 8857 | } |
| 8858 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8859 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8860 | "3329 Cannot set affinity:" |
| 8861 | "Error mapping vector %d (%d)\n", |
| 8862 | idx, vectors); |
| 8863 | return 0; |
| 8864 | } |
| 8865 | found: |
| 8866 | cpup += cpu; |
| 8867 | if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP) |
| 8868 | lpfc_used_cpu[cpu] = phys_id; |
| 8869 | |
| 8870 | /* Associate vector with selected CPU */ |
| 8871 | cpup->irq = phba->sli4_hba.msix_entries[idx].vector; |
| 8872 | |
| 8873 | /* Associate IO channel with selected CPU */ |
| 8874 | cpup->channel_id = idx; |
| 8875 | num_io_channel++; |
| 8876 | |
| 8877 | if (first_cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8878 | first_cpu = cpu; |
| 8879 | |
| 8880 | /* Now affinitize to the selected CPU */ |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8881 | i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx]. |
Ian Mitchell | c0365c0 | 2015-08-31 16:48:12 -0400 | [diff] [blame] | 8882 | vector, get_cpu_mask(cpu)); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8883 | |
| 8884 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8885 | "3330 Set Affinity: CPU %d channel %d " |
| 8886 | "irq %d (%x)\n", |
| 8887 | cpu, cpup->channel_id, |
| 8888 | phba->sli4_hba.msix_entries[idx].vector, i); |
| 8889 | |
| 8890 | /* Spread vector mapping across multple physical CPU nodes */ |
| 8891 | phys_id++; |
| 8892 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8893 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8894 | } |
| 8895 | |
| 8896 | /* |
| 8897 | * Finally fill in the IO channel for any remaining CPUs. |
| 8898 | * At this point, all IO channels have been assigned to a specific |
| 8899 | * MSIx vector, mapped to a specific CPU. |
| 8900 | * Base the remaining IO channel assigned, to IO channels already |
| 8901 | * assigned to other CPUs on the same phys_id. |
| 8902 | */ |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8903 | for (i = min_phys_id; i <= max_phys_id; i++) { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8904 | /* |
| 8905 | * If there are no io channels already mapped to |
| 8906 | * this phys_id, just round robin thru the io_channels. |
| 8907 | * Setup chann[] for round robin. |
| 8908 | */ |
| 8909 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8910 | chann[idx] = idx; |
| 8911 | |
| 8912 | saved_chann = 0; |
| 8913 | used_chann = 0; |
| 8914 | |
| 8915 | /* |
| 8916 | * First build a list of IO channels already assigned |
| 8917 | * to this phys_id before reassigning the same IO |
| 8918 | * channels to the remaining CPUs. |
| 8919 | */ |
| 8920 | cpup = phba->sli4_hba.cpu_map; |
| 8921 | cpu = first_cpu; |
| 8922 | cpup += cpu; |
| 8923 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; |
| 8924 | idx++) { |
| 8925 | if (cpup->phys_id == i) { |
| 8926 | /* |
| 8927 | * Save any IO channels that are |
| 8928 | * already mapped to this phys_id. |
| 8929 | */ |
| 8930 | if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) { |
James Smart | 6690e0d | 2015-12-16 18:11:56 -0500 | [diff] [blame] | 8931 | if (saved_chann <= |
| 8932 | LPFC_FCP_IO_CHAN_MAX) { |
| 8933 | chann[saved_chann] = |
| 8934 | cpup->channel_id; |
| 8935 | saved_chann++; |
| 8936 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8937 | goto out; |
| 8938 | } |
| 8939 | |
| 8940 | /* See if we are using round-robin */ |
| 8941 | if (saved_chann == 0) |
| 8942 | saved_chann = |
| 8943 | phba->cfg_fcp_io_channel; |
| 8944 | |
| 8945 | /* Associate next IO channel with CPU */ |
| 8946 | cpup->channel_id = chann[used_chann]; |
| 8947 | num_io_channel++; |
| 8948 | used_chann++; |
| 8949 | if (used_chann == saved_chann) |
| 8950 | used_chann = 0; |
| 8951 | |
| 8952 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8953 | "3331 Set IO_CHANN " |
| 8954 | "CPU %d channel %d\n", |
| 8955 | idx, cpup->channel_id); |
| 8956 | } |
| 8957 | out: |
| 8958 | cpu++; |
| 8959 | if (cpu >= phba->sli4_hba.num_present_cpu) { |
| 8960 | cpup = phba->sli4_hba.cpu_map; |
| 8961 | cpu = 0; |
| 8962 | } else { |
| 8963 | cpup++; |
| 8964 | } |
| 8965 | } |
| 8966 | } |
| 8967 | |
| 8968 | if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) { |
| 8969 | cpup = phba->sli4_hba.cpu_map; |
| 8970 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) { |
| 8971 | if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) { |
| 8972 | cpup->channel_id = 0; |
| 8973 | num_io_channel++; |
| 8974 | |
| 8975 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8976 | "3332 Assign IO_CHANN " |
| 8977 | "CPU %d channel %d\n", |
| 8978 | idx, cpup->channel_id); |
| 8979 | } |
| 8980 | cpup++; |
| 8981 | } |
| 8982 | } |
| 8983 | |
| 8984 | /* Sanity check */ |
| 8985 | if (num_io_channel != phba->sli4_hba.num_present_cpu) |
| 8986 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8987 | "3333 Set affinity mismatch:" |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8988 | "%d chann != %d cpus: %d vectors\n", |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8989 | num_io_channel, phba->sli4_hba.num_present_cpu, |
| 8990 | vectors); |
| 8991 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8992 | /* Enable using cpu affinity for scheduling */ |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8993 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU; |
| 8994 | return 1; |
| 8995 | } |
| 8996 | |
| 8997 | |
| 8998 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8999 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 9000 | * @phba: pointer to lpfc hba data structure. |
| 9001 | * |
| 9002 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 9003 | * with SLI-4 interface spec. The kernel function pci_enable_msix_range() |
| 9004 | * is called to enable the MSI-X vectors. The device driver is responsible |
| 9005 | * for calling the individual request_irq() to register each MSI-X vector |
| 9006 | * with a interrupt handler, which is done in this function. Note that |
| 9007 | * later when device is unloading, the driver should always call free_irq() |
| 9008 | * on all MSI-X vectors it has done request_irq() on before calling |
| 9009 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 9010 | * will be left with MSI-X enabled and leaks its vectors. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9011 | * |
| 9012 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9013 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9014 | * other values - error |
| 9015 | **/ |
| 9016 | static int |
| 9017 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 9018 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9019 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9020 | |
| 9021 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 9022 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9023 | phba->sli4_hba.msix_entries[index].entry = index; |
| 9024 | |
| 9025 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 9026 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9027 | if (phba->cfg_fof) { |
| 9028 | phba->sli4_hba.msix_entries[index].entry = index; |
| 9029 | vectors++; |
| 9030 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 9031 | rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries, |
| 9032 | 2, vectors); |
| 9033 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9034 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9035 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9036 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9037 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 9038 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9039 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9040 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9041 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9042 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9043 | "0489 MSI-X entry[%d]: vector=x%x " |
| 9044 | "message=%d\n", index, |
| 9045 | phba->sli4_hba.msix_entries[index].vector, |
| 9046 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9047 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9048 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9049 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 9050 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9051 | snprintf((char *)&phba->sli4_hba.handler_name[index], |
| 9052 | LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 9053 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9054 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9055 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9056 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9057 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9058 | if (phba->cfg_fof && (index == (vectors - 1))) |
| 9059 | rc = request_irq( |
| 9060 | phba->sli4_hba.msix_entries[index].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9061 | &lpfc_sli4_fof_intr_handler, 0, |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9062 | (char *)&phba->sli4_hba.handler_name[index], |
| 9063 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 9064 | else |
| 9065 | rc = request_irq( |
| 9066 | phba->sli4_hba.msix_entries[index].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9067 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 9068 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9069 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9070 | if (rc) { |
| 9071 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9072 | "0486 MSI-X fast-path (%d) " |
| 9073 | "request_irq failed (%d)\n", index, rc); |
| 9074 | goto cfg_fail_out; |
| 9075 | } |
| 9076 | } |
| 9077 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9078 | if (phba->cfg_fof) |
| 9079 | vectors--; |
| 9080 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 9081 | if (vectors != phba->cfg_fcp_io_channel) { |
| 9082 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9083 | "3238 Reducing IO channels to match number of " |
| 9084 | "MSI-X vectors, requested %d got %d\n", |
| 9085 | phba->cfg_fcp_io_channel, vectors); |
| 9086 | phba->cfg_fcp_io_channel = vectors; |
| 9087 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9088 | |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9089 | if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport))) |
| 9090 | lpfc_sli4_set_affinity(phba, vectors); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9091 | return rc; |
| 9092 | |
| 9093 | cfg_fail_out: |
| 9094 | /* free the irq already requested */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9095 | for (--index; index >= 0; index--) { |
| 9096 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 9097 | vector, NULL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9098 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 9099 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9100 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9101 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9102 | /* Unconfigure MSI-X capability structure */ |
| 9103 | pci_disable_msix(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9104 | |
| 9105 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9106 | return rc; |
| 9107 | } |
| 9108 | |
| 9109 | /** |
| 9110 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 9111 | * @phba: pointer to lpfc hba data structure. |
| 9112 | * |
| 9113 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 9114 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 9115 | **/ |
| 9116 | static void |
| 9117 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 9118 | { |
| 9119 | int index; |
| 9120 | |
| 9121 | /* Free up MSI-X multi-message vectors */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9122 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
| 9123 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 9124 | vector, NULL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9125 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9126 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9127 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9128 | if (phba->cfg_fof) { |
| 9129 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 9130 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 9131 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9132 | /* Disable MSI-X */ |
| 9133 | pci_disable_msix(phba->pcidev); |
| 9134 | |
| 9135 | return; |
| 9136 | } |
| 9137 | |
| 9138 | /** |
| 9139 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 9140 | * @phba: pointer to lpfc hba data structure. |
| 9141 | * |
| 9142 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 9143 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 9144 | * to enable the MSI vector. The device driver is responsible for calling |
| 9145 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 9146 | * which is done in this function. |
| 9147 | * |
| 9148 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9149 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9150 | * other values - error |
| 9151 | **/ |
| 9152 | static int |
| 9153 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 9154 | { |
| 9155 | int rc, index; |
| 9156 | |
| 9157 | rc = pci_enable_msi(phba->pcidev); |
| 9158 | if (!rc) |
| 9159 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9160 | "0487 PCI enable MSI mode success.\n"); |
| 9161 | else { |
| 9162 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9163 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 9164 | return rc; |
| 9165 | } |
| 9166 | |
| 9167 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9168 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9169 | if (rc) { |
| 9170 | pci_disable_msi(phba->pcidev); |
| 9171 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9172 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9173 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9174 | } |
| 9175 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9176 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9177 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9178 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9179 | } |
| 9180 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9181 | if (phba->cfg_fof) { |
| 9182 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9183 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9184 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9185 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9186 | } |
| 9187 | |
| 9188 | /** |
| 9189 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 9190 | * @phba: pointer to lpfc hba data structure. |
| 9191 | * |
| 9192 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 9193 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 9194 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 9195 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 9196 | * its vector. |
| 9197 | **/ |
| 9198 | static void |
| 9199 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 9200 | { |
| 9201 | free_irq(phba->pcidev->irq, phba); |
| 9202 | pci_disable_msi(phba->pcidev); |
| 9203 | return; |
| 9204 | } |
| 9205 | |
| 9206 | /** |
| 9207 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 9208 | * @phba: pointer to lpfc hba data structure. |
| 9209 | * |
| 9210 | * This routine is invoked to enable device interrupt and associate driver's |
| 9211 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 9212 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 9213 | * the driver will try to fallback from the configured interrupt mode to an |
| 9214 | * interrupt mode which is supported by the platform, kernel, and device in |
| 9215 | * the order of: |
| 9216 | * MSI-X -> MSI -> IRQ. |
| 9217 | * |
| 9218 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9219 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9220 | * other values - error |
| 9221 | **/ |
| 9222 | static uint32_t |
| 9223 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 9224 | { |
| 9225 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 9226 | int retval, index; |
| 9227 | |
| 9228 | if (cfg_mode == 2) { |
| 9229 | /* Preparation before conf_msi mbox cmd */ |
| 9230 | retval = 0; |
| 9231 | if (!retval) { |
| 9232 | /* Now, try to enable MSI-X interrupt mode */ |
| 9233 | retval = lpfc_sli4_enable_msix(phba); |
| 9234 | if (!retval) { |
| 9235 | /* Indicate initialization to MSI-X mode */ |
| 9236 | phba->intr_type = MSIX; |
| 9237 | intr_mode = 2; |
| 9238 | } |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | /* Fallback to MSI if MSI-X initialization failed */ |
| 9243 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 9244 | retval = lpfc_sli4_enable_msi(phba); |
| 9245 | if (!retval) { |
| 9246 | /* Indicate initialization to MSI mode */ |
| 9247 | phba->intr_type = MSI; |
| 9248 | intr_mode = 1; |
| 9249 | } |
| 9250 | } |
| 9251 | |
| 9252 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 9253 | if (phba->intr_type == NONE) { |
| 9254 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 9255 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 9256 | if (!retval) { |
| 9257 | /* Indicate initialization to INTx mode */ |
| 9258 | phba->intr_type = INTx; |
| 9259 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9260 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9261 | index++) { |
| 9262 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9263 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9264 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 9265 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9266 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9267 | if (phba->cfg_fof) { |
| 9268 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9269 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9270 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 9271 | fcp_eq_in_use, 1); |
| 9272 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9273 | } |
| 9274 | } |
| 9275 | return intr_mode; |
| 9276 | } |
| 9277 | |
| 9278 | /** |
| 9279 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 9280 | * @phba: pointer to lpfc hba data structure. |
| 9281 | * |
| 9282 | * This routine is invoked to disable device interrupt and disassociate |
| 9283 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 9284 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 9285 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 9286 | **/ |
| 9287 | static void |
| 9288 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 9289 | { |
| 9290 | /* Disable the currently initialized interrupt mode */ |
| 9291 | if (phba->intr_type == MSIX) |
| 9292 | lpfc_sli4_disable_msix(phba); |
| 9293 | else if (phba->intr_type == MSI) |
| 9294 | lpfc_sli4_disable_msi(phba); |
| 9295 | else if (phba->intr_type == INTx) |
| 9296 | free_irq(phba->pcidev->irq, phba); |
| 9297 | |
| 9298 | /* Reset interrupt management states */ |
| 9299 | phba->intr_type = NONE; |
| 9300 | phba->sli.slistat.sli_intr = 0; |
| 9301 | |
| 9302 | return; |
| 9303 | } |
| 9304 | |
| 9305 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9306 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 9307 | * @phba: pointer to lpfc hba data structure. |
| 9308 | * |
| 9309 | * This routine is invoked to unset the HBA device initialization steps to |
| 9310 | * a device with SLI-3 interface spec. |
| 9311 | **/ |
| 9312 | static void |
| 9313 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 9314 | { |
| 9315 | struct lpfc_vport *vport = phba->pport; |
| 9316 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9317 | |
| 9318 | spin_lock_irq(shost->host_lock); |
| 9319 | vport->load_flag |= FC_UNLOADING; |
| 9320 | spin_unlock_irq(shost->host_lock); |
| 9321 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9322 | kfree(phba->vpi_bmask); |
| 9323 | kfree(phba->vpi_ids); |
| 9324 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9325 | lpfc_stop_hba_timers(phba); |
| 9326 | |
| 9327 | phba->pport->work_port_events = 0; |
| 9328 | |
| 9329 | lpfc_sli_hba_down(phba); |
| 9330 | |
| 9331 | lpfc_sli_brdrestart(phba); |
| 9332 | |
| 9333 | lpfc_sli_disable_intr(phba); |
| 9334 | |
| 9335 | return; |
| 9336 | } |
| 9337 | |
| 9338 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9339 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 9340 | * @phba: Pointer to HBA context object. |
| 9341 | * |
| 9342 | * This function is called in the SLI4 code path to wait for completion |
| 9343 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 9344 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 9345 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 9346 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 9347 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 9348 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 9349 | * the rest of the driver unload resource release. |
| 9350 | **/ |
| 9351 | static void |
| 9352 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 9353 | { |
| 9354 | int wait_time = 0; |
| 9355 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9356 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9357 | |
| 9358 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 9359 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 9360 | if (!fcp_xri_cmpl) |
| 9361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9362 | "2877 FCP XRI exchange busy " |
| 9363 | "wait time: %d seconds.\n", |
| 9364 | wait_time/1000); |
| 9365 | if (!els_xri_cmpl) |
| 9366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9367 | "2878 ELS XRI exchange busy " |
| 9368 | "wait time: %d seconds.\n", |
| 9369 | wait_time/1000); |
| 9370 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 9371 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 9372 | } else { |
| 9373 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 9374 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 9375 | } |
| 9376 | fcp_xri_cmpl = |
| 9377 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9378 | els_xri_cmpl = |
| 9379 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9380 | } |
| 9381 | } |
| 9382 | |
| 9383 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9384 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 9385 | * @phba: Pointer to HBA context object. |
| 9386 | * |
| 9387 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 9388 | * function. The caller is not required to hold any lock. This routine |
| 9389 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 9390 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 9391 | * free any pending commands. |
| 9392 | **/ |
| 9393 | static void |
| 9394 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 9395 | { |
| 9396 | int wait_cnt = 0; |
| 9397 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9398 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9399 | |
| 9400 | lpfc_stop_hba_timers(phba); |
| 9401 | phba->sli4_hba.intr_enable = 0; |
| 9402 | |
| 9403 | /* |
| 9404 | * Gracefully wait out the potential current outstanding asynchronous |
| 9405 | * mailbox command. |
| 9406 | */ |
| 9407 | |
| 9408 | /* First, block any pending async mailbox command from posted */ |
| 9409 | spin_lock_irq(&phba->hbalock); |
| 9410 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 9411 | spin_unlock_irq(&phba->hbalock); |
| 9412 | /* Now, trying to wait it out if we can */ |
| 9413 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9414 | msleep(10); |
| 9415 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 9416 | break; |
| 9417 | } |
| 9418 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 9419 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9420 | spin_lock_irq(&phba->hbalock); |
| 9421 | mboxq = phba->sli.mbox_active; |
| 9422 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9423 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9424 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9425 | phba->sli.mbox_active = NULL; |
| 9426 | spin_unlock_irq(&phba->hbalock); |
| 9427 | } |
| 9428 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9429 | /* Abort all iocbs associated with the hba */ |
| 9430 | lpfc_sli_hba_iocb_abort(phba); |
| 9431 | |
| 9432 | /* Wait for completion of device XRI exchange busy */ |
| 9433 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 9434 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9435 | /* Disable PCI subsystem interrupt */ |
| 9436 | lpfc_sli4_disable_intr(phba); |
| 9437 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9438 | /* Disable SR-IOV if enabled */ |
| 9439 | if (phba->cfg_sriov_nr_virtfn) |
| 9440 | pci_disable_sriov(pdev); |
| 9441 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9442 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9443 | kthread_stop(phba->worker_thread); |
| 9444 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9445 | /* Reset SLI4 HBA FCoE function */ |
| 9446 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9447 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9448 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9449 | /* Stop the SLI4 device port */ |
| 9450 | phba->pport->work_port_events = 0; |
| 9451 | } |
| 9452 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9453 | /** |
| 9454 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 9455 | * @phba: Pointer to HBA context object. |
| 9456 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9457 | * |
| 9458 | * This function is called in the SLI4 code path to read the port's |
| 9459 | * sli4 capabilities. |
| 9460 | * |
| 9461 | * This function may be be called from any context that can block-wait |
| 9462 | * for the completion. The expectation is that this routine is called |
| 9463 | * typically from probe_one or from the online routine. |
| 9464 | **/ |
| 9465 | int |
| 9466 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9467 | { |
| 9468 | int rc; |
| 9469 | struct lpfc_mqe *mqe; |
| 9470 | struct lpfc_pc_sli4_params *sli4_params; |
| 9471 | uint32_t mbox_tmo; |
| 9472 | |
| 9473 | rc = 0; |
| 9474 | mqe = &mboxq->u.mqe; |
| 9475 | |
| 9476 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9477 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9478 | if (!phba->sli4_hba.intr_enable) |
| 9479 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9480 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9481 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9482 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9483 | } |
| 9484 | |
| 9485 | if (unlikely(rc)) |
| 9486 | return 1; |
| 9487 | |
| 9488 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9489 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 9490 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 9491 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 9492 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 9493 | &mqe->un.sli4_params); |
| 9494 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 9495 | &mqe->un.sli4_params); |
| 9496 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 9497 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 9498 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 9499 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 9500 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 9501 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 9502 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 9503 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 9504 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 9505 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 9506 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 9507 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 9508 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 9509 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 9510 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 9511 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 9512 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 9513 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 9514 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 9515 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 9516 | 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] | 9517 | |
| 9518 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9519 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9520 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9521 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9522 | return rc; |
| 9523 | } |
| 9524 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9525 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9526 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 9527 | * @phba: Pointer to HBA context object. |
| 9528 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9529 | * |
| 9530 | * This function is called in the SLI4 code path to read the port's |
| 9531 | * sli4 capabilities. |
| 9532 | * |
| 9533 | * This function may be be called from any context that can block-wait |
| 9534 | * for the completion. The expectation is that this routine is called |
| 9535 | * typically from probe_one or from the online routine. |
| 9536 | **/ |
| 9537 | int |
| 9538 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9539 | { |
| 9540 | int rc; |
| 9541 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 9542 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9543 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9544 | int length; |
| 9545 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 9546 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9547 | /* |
| 9548 | * By default, the driver assumes the SLI4 port requires RPI |
| 9549 | * header postings. The SLI4_PARAM response will correct this |
| 9550 | * assumption. |
| 9551 | */ |
| 9552 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 9553 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9554 | /* Read the port's SLI4 Config Parameters */ |
| 9555 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 9556 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9557 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9558 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 9559 | length, LPFC_SLI4_MBX_EMBED); |
| 9560 | if (!phba->sli4_hba.intr_enable) |
| 9561 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9562 | else { |
| 9563 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 9564 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9565 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9566 | if (unlikely(rc)) |
| 9567 | return rc; |
| 9568 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9569 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 9570 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 9571 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 9572 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 9573 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 9574 | mbx_sli4_parameters); |
| 9575 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 9576 | mbx_sli4_parameters); |
| 9577 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 9578 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 9579 | else |
| 9580 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 9581 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 9582 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9583 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9584 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 9585 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 9586 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 9587 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 9588 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9589 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 9590 | mbx_sli4_parameters); |
| 9591 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 9592 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9593 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 9594 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9595 | |
| 9596 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9597 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9598 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9599 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9600 | /* |
| 9601 | * Issue IOs with CDB embedded in WQE to minimized the number |
| 9602 | * of DMAs the firmware has to do. Setting this to 1 also forces |
| 9603 | * the driver to use 128 bytes WQEs for FCP IOs. |
| 9604 | */ |
| 9605 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 9606 | phba->fcp_embed_io = 1; |
| 9607 | else |
| 9608 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 9609 | |
| 9610 | /* |
| 9611 | * Check if the SLI port supports MDS Diagnostics |
| 9612 | */ |
| 9613 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 9614 | phba->mds_diags_support = 1; |
| 9615 | else |
| 9616 | phba->mds_diags_support = 0; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9617 | return 0; |
| 9618 | } |
| 9619 | |
| 9620 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9621 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 9622 | * @pdev: pointer to PCI device |
| 9623 | * @pid: pointer to PCI device identifier |
| 9624 | * |
| 9625 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 9626 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9627 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9628 | * information of the device and driver to see if the driver state that it can |
| 9629 | * support this kind of device. If the match is successful, the driver core |
| 9630 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 9631 | * does all the initialization that it needs to do to handle the HBA properly. |
| 9632 | * |
| 9633 | * Return code |
| 9634 | * 0 - driver can claim the device |
| 9635 | * negative value - driver can not claim the device |
| 9636 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9637 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9638 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9639 | { |
| 9640 | struct lpfc_hba *phba; |
| 9641 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9642 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9643 | int error; |
| 9644 | uint32_t cfg_mode, intr_mode; |
| 9645 | |
| 9646 | /* Allocate memory for HBA structure */ |
| 9647 | phba = lpfc_hba_alloc(pdev); |
| 9648 | if (!phba) |
| 9649 | return -ENOMEM; |
| 9650 | |
| 9651 | /* Perform generic PCI device enabling operation */ |
| 9652 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9653 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9654 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9655 | |
| 9656 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 9657 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 9658 | if (error) |
| 9659 | goto out_disable_pci_dev; |
| 9660 | |
| 9661 | /* Set up SLI-3 specific device PCI memory space */ |
| 9662 | error = lpfc_sli_pci_mem_setup(phba); |
| 9663 | if (error) { |
| 9664 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9665 | "1402 Failed to set up pci memory space.\n"); |
| 9666 | goto out_disable_pci_dev; |
| 9667 | } |
| 9668 | |
| 9669 | /* Set up phase-1 common device driver resources */ |
| 9670 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9671 | if (error) { |
| 9672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9673 | "1403 Failed to set up driver resource.\n"); |
| 9674 | goto out_unset_pci_mem_s3; |
| 9675 | } |
| 9676 | |
| 9677 | /* Set up SLI-3 specific device driver resources */ |
| 9678 | error = lpfc_sli_driver_resource_setup(phba); |
| 9679 | if (error) { |
| 9680 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9681 | "1404 Failed to set up driver resource.\n"); |
| 9682 | goto out_unset_pci_mem_s3; |
| 9683 | } |
| 9684 | |
| 9685 | /* Initialize and populate the iocb list per host */ |
| 9686 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 9687 | if (error) { |
| 9688 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9689 | "1405 Failed to initialize iocb list.\n"); |
| 9690 | goto out_unset_driver_resource_s3; |
| 9691 | } |
| 9692 | |
| 9693 | /* Set up common device driver resources */ |
| 9694 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9695 | if (error) { |
| 9696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9697 | "1406 Failed to set up driver resource.\n"); |
| 9698 | goto out_free_iocb_list; |
| 9699 | } |
| 9700 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9701 | /* Get the default values for Model Name and Description */ |
| 9702 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9703 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9704 | /* Create SCSI host to the physical port */ |
| 9705 | error = lpfc_create_shost(phba); |
| 9706 | if (error) { |
| 9707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9708 | "1407 Failed to create scsi host.\n"); |
| 9709 | goto out_unset_driver_resource; |
| 9710 | } |
| 9711 | |
| 9712 | /* Configure sysfs attributes */ |
| 9713 | vport = phba->pport; |
| 9714 | error = lpfc_alloc_sysfs_attr(vport); |
| 9715 | if (error) { |
| 9716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9717 | "1476 Failed to allocate sysfs attr\n"); |
| 9718 | goto out_destroy_shost; |
| 9719 | } |
| 9720 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9721 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9722 | /* Now, trying to enable interrupt and bring up the device */ |
| 9723 | cfg_mode = phba->cfg_use_msi; |
| 9724 | while (true) { |
| 9725 | /* Put device to a known state before enabling interrupt */ |
| 9726 | lpfc_stop_port(phba); |
| 9727 | /* Configure and enable interrupt */ |
| 9728 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 9729 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9731 | "0431 Failed to enable interrupt.\n"); |
| 9732 | error = -ENODEV; |
| 9733 | goto out_free_sysfs_attr; |
| 9734 | } |
| 9735 | /* SLI-3 HBA setup */ |
| 9736 | if (lpfc_sli_hba_setup(phba)) { |
| 9737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9738 | "1477 Failed to set up hba\n"); |
| 9739 | error = -ENODEV; |
| 9740 | goto out_remove_device; |
| 9741 | } |
| 9742 | |
| 9743 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 9744 | msleep(50); |
| 9745 | /* Check active interrupts on message signaled interrupts */ |
| 9746 | if (intr_mode == 0 || |
| 9747 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 9748 | /* Log the current active interrupt mode */ |
| 9749 | phba->intr_mode = intr_mode; |
| 9750 | lpfc_log_intr_mode(phba, intr_mode); |
| 9751 | break; |
| 9752 | } else { |
| 9753 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9754 | "0447 Configure interrupt mode (%d) " |
| 9755 | "failed active interrupt test.\n", |
| 9756 | intr_mode); |
| 9757 | /* Disable the current interrupt mode */ |
| 9758 | lpfc_sli_disable_intr(phba); |
| 9759 | /* Try next level of interrupt mode */ |
| 9760 | cfg_mode = --intr_mode; |
| 9761 | } |
| 9762 | } |
| 9763 | |
| 9764 | /* Perform post initialization setup */ |
| 9765 | lpfc_post_init_setup(phba); |
| 9766 | |
| 9767 | /* Check if there are static vports to be created. */ |
| 9768 | lpfc_create_static_vport(phba); |
| 9769 | |
| 9770 | return 0; |
| 9771 | |
| 9772 | out_remove_device: |
| 9773 | lpfc_unset_hba(phba); |
| 9774 | out_free_sysfs_attr: |
| 9775 | lpfc_free_sysfs_attr(vport); |
| 9776 | out_destroy_shost: |
| 9777 | lpfc_destroy_shost(phba); |
| 9778 | out_unset_driver_resource: |
| 9779 | lpfc_unset_driver_resource_phase2(phba); |
| 9780 | out_free_iocb_list: |
| 9781 | lpfc_free_iocb_list(phba); |
| 9782 | out_unset_driver_resource_s3: |
| 9783 | lpfc_sli_driver_resource_unset(phba); |
| 9784 | out_unset_pci_mem_s3: |
| 9785 | lpfc_sli_pci_mem_unset(phba); |
| 9786 | out_disable_pci_dev: |
| 9787 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9788 | if (shost) |
| 9789 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9790 | out_free_phba: |
| 9791 | lpfc_hba_free(phba); |
| 9792 | return error; |
| 9793 | } |
| 9794 | |
| 9795 | /** |
| 9796 | * 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] | 9797 | * @pdev: pointer to PCI device |
| 9798 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9799 | * This routine is to be called to disattach a device with SLI-3 interface |
| 9800 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9801 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9802 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9803 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9804 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9805 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9806 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9807 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9808 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9809 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9810 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9811 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9812 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 9813 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9814 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9815 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9816 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9817 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9818 | lpfc_free_sysfs_attr(vport); |
| 9819 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9820 | /* Release all the vports against this physical port */ |
| 9821 | vports = lpfc_create_vport_work_array(phba); |
| 9822 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9823 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9824 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9825 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9826 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9827 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9828 | lpfc_destroy_vport_work_array(phba, vports); |
| 9829 | |
| 9830 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9831 | fc_remove_host(shost); |
| 9832 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 9833 | lpfc_cleanup(vport); |
| 9834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9835 | /* |
| 9836 | * Bring down the SLI Layer. This step disable all interrupts, |
| 9837 | * clears the rings, discards all mailbox commands, and resets |
| 9838 | * the HBA. |
| 9839 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9840 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 9841 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9842 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9843 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9844 | kthread_stop(phba->worker_thread); |
| 9845 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9846 | lpfc_sli_brdrestart(phba); |
| 9847 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9848 | kfree(phba->vpi_bmask); |
| 9849 | kfree(phba->vpi_ids); |
| 9850 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9851 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9852 | spin_lock_irq(&phba->hbalock); |
| 9853 | list_del_init(&vport->listentry); |
| 9854 | spin_unlock_irq(&phba->hbalock); |
| 9855 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9856 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9857 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9858 | /* Disable SR-IOV if enabled */ |
| 9859 | if (phba->cfg_sriov_nr_virtfn) |
| 9860 | pci_disable_sriov(pdev); |
| 9861 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9862 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9863 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9864 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9865 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9866 | |
| 9867 | /* |
| 9868 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 9869 | * corresponding pools here. |
| 9870 | */ |
| 9871 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9872 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9873 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9874 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9875 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9876 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9877 | /* Free resources associated with SLI2 interface */ |
| 9878 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9879 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9880 | |
| 9881 | /* unmap adapter SLIM and Control Registers */ |
| 9882 | iounmap(phba->ctrl_regs_memmap_p); |
| 9883 | iounmap(phba->slim_memmap_p); |
| 9884 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9885 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9886 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9887 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9888 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9889 | } |
| 9890 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9891 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9892 | * 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] | 9893 | * @pdev: pointer to PCI device |
| 9894 | * @msg: power management message |
| 9895 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9896 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9897 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 9898 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 9899 | * worker thread for the device, turning off device's interrupt and DMA, |
| 9900 | * and bring the device offline. Note that as the driver implements the |
| 9901 | * minimum PM requirements to a power-aware driver's PM support for the |
| 9902 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9903 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 9904 | * fully reinitialize its device during resume() method call, the driver will |
| 9905 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 9906 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9907 | * |
| 9908 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9909 | * 0 - driver suspended the device |
| 9910 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9911 | **/ |
| 9912 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9913 | 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] | 9914 | { |
| 9915 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9916 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9917 | |
| 9918 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9919 | "0473 PCI device Power Management suspend.\n"); |
| 9920 | |
| 9921 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9922 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9923 | lpfc_offline(phba); |
| 9924 | kthread_stop(phba->worker_thread); |
| 9925 | |
| 9926 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9927 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9928 | |
| 9929 | /* Save device state to PCI config space */ |
| 9930 | pci_save_state(pdev); |
| 9931 | pci_set_power_state(pdev, PCI_D3hot); |
| 9932 | |
| 9933 | return 0; |
| 9934 | } |
| 9935 | |
| 9936 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9937 | * 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] | 9938 | * @pdev: pointer to PCI device |
| 9939 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9940 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9941 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9942 | * invokes this method, it restores the device's PCI config space state and |
| 9943 | * fully reinitializes the device and brings it online. Note that as the |
| 9944 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9945 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9946 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9947 | * driver will fully reinitialize its device during resume() method call, |
| 9948 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9949 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9950 | * |
| 9951 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9952 | * 0 - driver suspended the device |
| 9953 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9954 | **/ |
| 9955 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9956 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9957 | { |
| 9958 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9959 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9960 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9961 | int error; |
| 9962 | |
| 9963 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9964 | "0452 PCI device Power Management resume.\n"); |
| 9965 | |
| 9966 | /* Restore device state from PCI config space */ |
| 9967 | pci_set_power_state(pdev, PCI_D0); |
| 9968 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9969 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9970 | /* |
| 9971 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9972 | * device saved_state flag, need to save the restored state again. |
| 9973 | */ |
| 9974 | pci_save_state(pdev); |
| 9975 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9976 | if (pdev->is_busmaster) |
| 9977 | pci_set_master(pdev); |
| 9978 | |
| 9979 | /* Startup the kernel thread for this host adapter. */ |
| 9980 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9981 | "lpfc_worker_%d", phba->brd_no); |
| 9982 | if (IS_ERR(phba->worker_thread)) { |
| 9983 | error = PTR_ERR(phba->worker_thread); |
| 9984 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9985 | "0434 PM resume failed to start worker " |
| 9986 | "thread: error=x%x.\n", error); |
| 9987 | return error; |
| 9988 | } |
| 9989 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9990 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9991 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9992 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9993 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9994 | "0430 PM resume Failed to enable interrupt\n"); |
| 9995 | return -EIO; |
| 9996 | } else |
| 9997 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9998 | |
| 9999 | /* Restart HBA and bring it online */ |
| 10000 | lpfc_sli_brdrestart(phba); |
| 10001 | lpfc_online(phba); |
| 10002 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10003 | /* Log the current active interrupt mode */ |
| 10004 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10005 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10006 | return 0; |
| 10007 | } |
| 10008 | |
| 10009 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10010 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 10011 | * @phba: pointer to lpfc hba data structure. |
| 10012 | * |
| 10013 | * 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] | 10014 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10015 | **/ |
| 10016 | static void |
| 10017 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10018 | { |
| 10019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10020 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10021 | |
| 10022 | /* |
| 10023 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10024 | * and let the SCSI mid-layer to retry them to recover. |
| 10025 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10026 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10027 | } |
| 10028 | |
| 10029 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10030 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 10031 | * @phba: pointer to lpfc hba data structure. |
| 10032 | * |
| 10033 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 10034 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10035 | * pending I/Os. |
| 10036 | **/ |
| 10037 | static void |
| 10038 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10039 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10040 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10041 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10042 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10043 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10044 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10045 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10046 | /* Block all SCSI devices' I/Os on the host */ |
| 10047 | lpfc_scsi_dev_block(phba); |
| 10048 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10049 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10050 | lpfc_sli_flush_fcp_rings(phba); |
| 10051 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10052 | /* stop all timers */ |
| 10053 | lpfc_stop_hba_timers(phba); |
| 10054 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10055 | /* Disable interrupt and pci device */ |
| 10056 | lpfc_sli_disable_intr(phba); |
| 10057 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10058 | } |
| 10059 | |
| 10060 | /** |
| 10061 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 10062 | * @phba: pointer to lpfc hba data structure. |
| 10063 | * |
| 10064 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 10065 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10066 | * pending I/Os. |
| 10067 | **/ |
| 10068 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10069 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10070 | { |
| 10071 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10072 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10073 | /* Block all SCSI devices' I/Os on the host */ |
| 10074 | lpfc_scsi_dev_block(phba); |
| 10075 | |
| 10076 | /* stop all timers */ |
| 10077 | lpfc_stop_hba_timers(phba); |
| 10078 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10079 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10080 | lpfc_sli_flush_fcp_rings(phba); |
| 10081 | } |
| 10082 | |
| 10083 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10084 | * 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] | 10085 | * @pdev: pointer to PCI device. |
| 10086 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10087 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10088 | * This routine is called from the PCI subsystem for I/O error handling to |
| 10089 | * device with SLI-3 interface spec. This function is called by the PCI |
| 10090 | * subsystem after a PCI bus error affecting this device has been detected. |
| 10091 | * When this function is invoked, it will need to stop all the I/Os and |
| 10092 | * interrupt(s) to the device. Once that is done, it will return |
| 10093 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 10094 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10095 | * |
| 10096 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10097 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10098 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10099 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10100 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10101 | static pci_ers_result_t |
| 10102 | 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] | 10103 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10104 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10105 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10106 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10107 | switch (state) { |
| 10108 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10109 | /* Non-fatal error, prepare for recovery */ |
| 10110 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10111 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10112 | case pci_channel_io_frozen: |
| 10113 | /* Fatal error, prepare for slot reset */ |
| 10114 | lpfc_sli_prep_dev_for_reset(phba); |
| 10115 | return PCI_ERS_RESULT_NEED_RESET; |
| 10116 | case pci_channel_io_perm_failure: |
| 10117 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10118 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10119 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10120 | default: |
| 10121 | /* Unknown state, prepare and request slot reset */ |
| 10122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10123 | "0472 Unknown PCI error state: x%x\n", state); |
| 10124 | lpfc_sli_prep_dev_for_reset(phba); |
| 10125 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 10126 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10127 | } |
| 10128 | |
| 10129 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10130 | * 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] | 10131 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10132 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10133 | * This routine is called from the PCI subsystem for error handling to |
| 10134 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 10135 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 10136 | * During the PCI subsystem error recovery, after driver returns |
| 10137 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10138 | * recovery and then call this routine before calling the .resume method |
| 10139 | * to recover the device. This function will initialize the HBA device, |
| 10140 | * enable the interrupt, but it will just put the HBA to offline state |
| 10141 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10142 | * |
| 10143 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10144 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10145 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10146 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10147 | static pci_ers_result_t |
| 10148 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10149 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10150 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10151 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10152 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10153 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10154 | |
| 10155 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 10156 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10157 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10158 | "PCI device after reset.\n"); |
| 10159 | return PCI_ERS_RESULT_DISCONNECT; |
| 10160 | } |
| 10161 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 10162 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10163 | |
| 10164 | /* |
| 10165 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10166 | * device saved_state flag, need to save the restored state again. |
| 10167 | */ |
| 10168 | pci_save_state(pdev); |
| 10169 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 10170 | if (pdev->is_busmaster) |
| 10171 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10172 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10173 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10174 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10175 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10176 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10177 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10178 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10179 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10181 | "0427 Cannot re-enable interrupt after " |
| 10182 | "slot reset.\n"); |
| 10183 | return PCI_ERS_RESULT_DISCONNECT; |
| 10184 | } else |
| 10185 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10186 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10187 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10188 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10189 | lpfc_offline(phba); |
| 10190 | lpfc_sli_brdrestart(phba); |
| 10191 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10192 | /* Log the current active interrupt mode */ |
| 10193 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10194 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10195 | return PCI_ERS_RESULT_RECOVERED; |
| 10196 | } |
| 10197 | |
| 10198 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10199 | * 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] | 10200 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10201 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10202 | * This routine is called from the PCI subsystem for error handling to device |
| 10203 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 10204 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10205 | * error recovery. After this call, traffic can start to flow from this device |
| 10206 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10207 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10208 | static void |
| 10209 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10210 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10211 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10212 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10213 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10214 | /* 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] | 10215 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10216 | |
| 10217 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10218 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10219 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10220 | } |
| 10221 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10222 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10223 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 10224 | * @phba: pointer to lpfc hba data structure. |
| 10225 | * |
| 10226 | * returns the number of ELS/CT IOCBs to reserve |
| 10227 | **/ |
| 10228 | int |
| 10229 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 10230 | { |
| 10231 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 10232 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10233 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 10234 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10235 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10236 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10237 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10238 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10239 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10240 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10241 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 10242 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10243 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 10244 | else if (max_xri <= 2048) |
| 10245 | return 200; |
| 10246 | else |
| 10247 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10248 | } else |
| 10249 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10250 | } |
| 10251 | |
| 10252 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10253 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10254 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10255 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10256 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10257 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10258 | static void |
| 10259 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10260 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10261 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10262 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10263 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10264 | struct list_head dma_buffer_list; |
| 10265 | int i, rc = 0; |
| 10266 | struct lpfc_dmabuf *dmabuf, *next; |
| 10267 | uint32_t offset = 0, temp_offset = 0; |
| 10268 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10269 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10270 | if (!fw) { |
| 10271 | rc = -ENXIO; |
| 10272 | goto out; |
| 10273 | } |
| 10274 | image = (struct lpfc_grp_hdr *)fw->data; |
| 10275 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10276 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10277 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 10278 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 10279 | LPFC_FILE_TYPE_GROUP) || |
| 10280 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 10281 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10283 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10284 | "Magic:%x Type:%x ID:%x\n", |
| 10285 | be32_to_cpu(image->magic_number), |
| 10286 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 10287 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10288 | rc = -EINVAL; |
| 10289 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10290 | } |
| 10291 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10292 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10294 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10295 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10296 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10297 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 10298 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 10299 | GFP_KERNEL); |
| 10300 | if (!dmabuf) { |
| 10301 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10302 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10303 | } |
| 10304 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 10305 | SLI4_PAGE_SIZE, |
| 10306 | &dmabuf->phys, |
| 10307 | GFP_KERNEL); |
| 10308 | if (!dmabuf->virt) { |
| 10309 | kfree(dmabuf); |
| 10310 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10311 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10312 | } |
| 10313 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 10314 | } |
| 10315 | while (offset < fw->size) { |
| 10316 | temp_offset = offset; |
| 10317 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10318 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10319 | memcpy(dmabuf->virt, |
| 10320 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10321 | fw->size - temp_offset); |
| 10322 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10323 | break; |
| 10324 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10325 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 10326 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10327 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10328 | } |
| 10329 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 10330 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10331 | if (rc) |
| 10332 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10333 | } |
| 10334 | rc = offset; |
| 10335 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10336 | |
| 10337 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10338 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 10339 | list_del(&dmabuf->list); |
| 10340 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 10341 | dmabuf->virt, dmabuf->phys); |
| 10342 | kfree(dmabuf); |
| 10343 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10344 | release_firmware(fw); |
| 10345 | out: |
| 10346 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10347 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10348 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10349 | } |
| 10350 | |
| 10351 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10352 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 10353 | * @phba: pointer to lpfc hba data structure. |
| 10354 | * |
| 10355 | * This routine is called to perform Linux generic firmware upgrade on device |
| 10356 | * that supports such feature. |
| 10357 | **/ |
| 10358 | int |
| 10359 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 10360 | { |
| 10361 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 10362 | int ret; |
| 10363 | const struct firmware *fw; |
| 10364 | |
| 10365 | /* Only supported on SLI4 interface type 2 for now */ |
| 10366 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 10367 | LPFC_SLI_INTF_IF_TYPE_2) |
| 10368 | return -EPERM; |
| 10369 | |
| 10370 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 10371 | |
| 10372 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 10373 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 10374 | file_name, &phba->pcidev->dev, |
| 10375 | GFP_KERNEL, (void *)phba, |
| 10376 | lpfc_write_firmware); |
| 10377 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 10378 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 10379 | if (!ret) |
| 10380 | lpfc_write_firmware(fw, (void *)phba); |
| 10381 | } else { |
| 10382 | ret = -EINVAL; |
| 10383 | } |
| 10384 | |
| 10385 | return ret; |
| 10386 | } |
| 10387 | |
| 10388 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10389 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 10390 | * @pdev: pointer to PCI device |
| 10391 | * @pid: pointer to PCI device identifier |
| 10392 | * |
| 10393 | * This routine is called from the kernel's PCI subsystem to device with |
| 10394 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10395 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 10396 | * information of the device and driver to see if the driver state that it |
| 10397 | * can support this kind of device. If the match is successful, the driver |
| 10398 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 10399 | * it does all the initialization that it needs to do to handle the HBA |
| 10400 | * properly. |
| 10401 | * |
| 10402 | * Return code |
| 10403 | * 0 - driver can claim the device |
| 10404 | * negative value - driver can not claim the device |
| 10405 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10406 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10407 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10408 | { |
| 10409 | struct lpfc_hba *phba; |
| 10410 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10411 | struct Scsi_Host *shost = NULL; |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 10412 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10413 | uint32_t cfg_mode, intr_mode; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10414 | int adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10415 | |
| 10416 | /* Allocate memory for HBA structure */ |
| 10417 | phba = lpfc_hba_alloc(pdev); |
| 10418 | if (!phba) |
| 10419 | return -ENOMEM; |
| 10420 | |
| 10421 | /* Perform generic PCI device enabling operation */ |
| 10422 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10423 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10424 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10425 | |
| 10426 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 10427 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 10428 | if (error) |
| 10429 | goto out_disable_pci_dev; |
| 10430 | |
| 10431 | /* Set up SLI-4 specific device PCI memory space */ |
| 10432 | error = lpfc_sli4_pci_mem_setup(phba); |
| 10433 | if (error) { |
| 10434 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10435 | "1410 Failed to set up pci memory space.\n"); |
| 10436 | goto out_disable_pci_dev; |
| 10437 | } |
| 10438 | |
| 10439 | /* Set up phase-1 common device driver resources */ |
| 10440 | error = lpfc_setup_driver_resource_phase1(phba); |
| 10441 | if (error) { |
| 10442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10443 | "1411 Failed to set up driver resource.\n"); |
| 10444 | goto out_unset_pci_mem_s4; |
| 10445 | } |
| 10446 | |
| 10447 | /* Set up SLI-4 Specific device driver resources */ |
| 10448 | error = lpfc_sli4_driver_resource_setup(phba); |
| 10449 | if (error) { |
| 10450 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10451 | "1412 Failed to set up driver resource.\n"); |
| 10452 | goto out_unset_pci_mem_s4; |
| 10453 | } |
| 10454 | |
| 10455 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10456 | |
| 10457 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10458 | "2821 initialize iocb list %d.\n", |
| 10459 | phba->cfg_iocb_cnt*1024); |
| 10460 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 10461 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10462 | if (error) { |
| 10463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10464 | "1413 Failed to initialize iocb list.\n"); |
| 10465 | goto out_unset_driver_resource_s4; |
| 10466 | } |
| 10467 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10468 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 10469 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10470 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10471 | /* Set up common device driver resources */ |
| 10472 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10473 | if (error) { |
| 10474 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10475 | "1414 Failed to set up driver resource.\n"); |
| 10476 | goto out_free_iocb_list; |
| 10477 | } |
| 10478 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10479 | /* Get the default values for Model Name and Description */ |
| 10480 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10481 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10482 | /* Create SCSI host to the physical port */ |
| 10483 | error = lpfc_create_shost(phba); |
| 10484 | if (error) { |
| 10485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10486 | "1415 Failed to create scsi host.\n"); |
| 10487 | goto out_unset_driver_resource; |
| 10488 | } |
| 10489 | |
| 10490 | /* Configure sysfs attributes */ |
| 10491 | vport = phba->pport; |
| 10492 | error = lpfc_alloc_sysfs_attr(vport); |
| 10493 | if (error) { |
| 10494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10495 | "1416 Failed to allocate sysfs attr\n"); |
| 10496 | goto out_destroy_shost; |
| 10497 | } |
| 10498 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10499 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10500 | /* Now, trying to enable interrupt and bring up the device */ |
| 10501 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10502 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10503 | /* Put device to a known state before enabling interrupt */ |
| 10504 | lpfc_stop_port(phba); |
| 10505 | /* Configure and enable interrupt */ |
| 10506 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 10507 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10509 | "0426 Failed to enable interrupt.\n"); |
| 10510 | error = -ENODEV; |
| 10511 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10512 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10513 | /* Default to single EQ for non-MSI-X */ |
| 10514 | if (phba->intr_type != MSIX) |
| 10515 | adjusted_fcp_io_channel = 1; |
| 10516 | else |
| 10517 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 10518 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
| 10519 | /* Set up SLI-4 HBA */ |
| 10520 | if (lpfc_sli4_hba_setup(phba)) { |
| 10521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10522 | "1421 Failed to set up hba\n"); |
| 10523 | error = -ENODEV; |
| 10524 | goto out_disable_intr; |
| 10525 | } |
| 10526 | |
| 10527 | /* Log the current active interrupt mode */ |
| 10528 | phba->intr_mode = intr_mode; |
| 10529 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10530 | |
| 10531 | /* Perform post initialization setup */ |
| 10532 | lpfc_post_init_setup(phba); |
| 10533 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10534 | /* check for firmware upgrade or downgrade */ |
| 10535 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 10536 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10537 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 10538 | /* Check if there are static vports to be created. */ |
| 10539 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10540 | return 0; |
| 10541 | |
| 10542 | out_disable_intr: |
| 10543 | lpfc_sli4_disable_intr(phba); |
| 10544 | out_free_sysfs_attr: |
| 10545 | lpfc_free_sysfs_attr(vport); |
| 10546 | out_destroy_shost: |
| 10547 | lpfc_destroy_shost(phba); |
| 10548 | out_unset_driver_resource: |
| 10549 | lpfc_unset_driver_resource_phase2(phba); |
| 10550 | out_free_iocb_list: |
| 10551 | lpfc_free_iocb_list(phba); |
| 10552 | out_unset_driver_resource_s4: |
| 10553 | lpfc_sli4_driver_resource_unset(phba); |
| 10554 | out_unset_pci_mem_s4: |
| 10555 | lpfc_sli4_pci_mem_unset(phba); |
| 10556 | out_disable_pci_dev: |
| 10557 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10558 | if (shost) |
| 10559 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10560 | out_free_phba: |
| 10561 | lpfc_hba_free(phba); |
| 10562 | return error; |
| 10563 | } |
| 10564 | |
| 10565 | /** |
| 10566 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 10567 | * @pdev: pointer to PCI device |
| 10568 | * |
| 10569 | * This routine is called from the kernel's PCI subsystem to device with |
| 10570 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10571 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10572 | * device to be removed from the PCI subsystem properly. |
| 10573 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10574 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10575 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 10576 | { |
| 10577 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10578 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 10579 | struct lpfc_vport **vports; |
| 10580 | struct lpfc_hba *phba = vport->phba; |
| 10581 | int i; |
| 10582 | |
| 10583 | /* Mark the device unloading flag */ |
| 10584 | spin_lock_irq(&phba->hbalock); |
| 10585 | vport->load_flag |= FC_UNLOADING; |
| 10586 | spin_unlock_irq(&phba->hbalock); |
| 10587 | |
| 10588 | /* Free the HBA sysfs attributes */ |
| 10589 | lpfc_free_sysfs_attr(vport); |
| 10590 | |
| 10591 | /* Release all the vports against this physical port */ |
| 10592 | vports = lpfc_create_vport_work_array(phba); |
| 10593 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10594 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10595 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10596 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10597 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10598 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10599 | lpfc_destroy_vport_work_array(phba, vports); |
| 10600 | |
| 10601 | /* Remove FC host and then SCSI host with the physical port */ |
| 10602 | fc_remove_host(shost); |
| 10603 | scsi_remove_host(shost); |
| 10604 | |
| 10605 | /* Perform cleanup on the physical port */ |
| 10606 | lpfc_cleanup(vport); |
| 10607 | |
| 10608 | /* |
| 10609 | * Bring down the SLI Layer. This step disables all interrupts, |
| 10610 | * clears the rings, discards all mailbox commands, and resets |
| 10611 | * the HBA FCoE function. |
| 10612 | */ |
| 10613 | lpfc_debugfs_terminate(vport); |
| 10614 | lpfc_sli4_hba_unset(phba); |
| 10615 | |
| 10616 | spin_lock_irq(&phba->hbalock); |
| 10617 | list_del_init(&vport->listentry); |
| 10618 | spin_unlock_irq(&phba->hbalock); |
| 10619 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10620 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10621 | * buffers are released to their corresponding pools here. |
| 10622 | */ |
| 10623 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10624 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10625 | lpfc_sli4_driver_resource_unset(phba); |
| 10626 | |
| 10627 | /* Unmap adapter Control and Doorbell registers */ |
| 10628 | lpfc_sli4_pci_mem_unset(phba); |
| 10629 | |
| 10630 | /* Release PCI resources and disable device's PCI function */ |
| 10631 | scsi_host_put(shost); |
| 10632 | lpfc_disable_pci_dev(phba); |
| 10633 | |
| 10634 | /* Finally, free the driver's device data structure */ |
| 10635 | lpfc_hba_free(phba); |
| 10636 | |
| 10637 | return; |
| 10638 | } |
| 10639 | |
| 10640 | /** |
| 10641 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 10642 | * @pdev: pointer to PCI device |
| 10643 | * @msg: power management message |
| 10644 | * |
| 10645 | * This routine is called from the kernel's PCI subsystem to support system |
| 10646 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 10647 | * this method, it quiesces the device by stopping the driver's worker |
| 10648 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 10649 | * the device offline. Note that as the driver implements the minimum PM |
| 10650 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 10651 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 10652 | * method call will be treated as SUSPEND and the driver will fully |
| 10653 | * reinitialize its device during resume() method call, the driver will set |
| 10654 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 10655 | * according to the @msg provided by the PM. |
| 10656 | * |
| 10657 | * Return code |
| 10658 | * 0 - driver suspended the device |
| 10659 | * Error otherwise |
| 10660 | **/ |
| 10661 | static int |
| 10662 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 10663 | { |
| 10664 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10665 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10666 | |
| 10667 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10668 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10669 | |
| 10670 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10671 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10672 | lpfc_offline(phba); |
| 10673 | kthread_stop(phba->worker_thread); |
| 10674 | |
| 10675 | /* Disable interrupt from device */ |
| 10676 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10677 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10678 | |
| 10679 | /* Save device state to PCI config space */ |
| 10680 | pci_save_state(pdev); |
| 10681 | pci_set_power_state(pdev, PCI_D3hot); |
| 10682 | |
| 10683 | return 0; |
| 10684 | } |
| 10685 | |
| 10686 | /** |
| 10687 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 10688 | * @pdev: pointer to PCI device |
| 10689 | * |
| 10690 | * This routine is called from the kernel's PCI subsystem to support system |
| 10691 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 10692 | * this method, it restores the device's PCI config space state and fully |
| 10693 | * reinitializes the device and brings it online. Note that as the driver |
| 10694 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 10695 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 10696 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 10697 | * will fully reinitialize its device during resume() method call, the device |
| 10698 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 10699 | * state. |
| 10700 | * |
| 10701 | * Return code |
| 10702 | * 0 - driver suspended the device |
| 10703 | * Error otherwise |
| 10704 | **/ |
| 10705 | static int |
| 10706 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 10707 | { |
| 10708 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10709 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10710 | uint32_t intr_mode; |
| 10711 | int error; |
| 10712 | |
| 10713 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10714 | "0292 PCI device Power Management resume.\n"); |
| 10715 | |
| 10716 | /* Restore device state from PCI config space */ |
| 10717 | pci_set_power_state(pdev, PCI_D0); |
| 10718 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10719 | |
| 10720 | /* |
| 10721 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10722 | * device saved_state flag, need to save the restored state again. |
| 10723 | */ |
| 10724 | pci_save_state(pdev); |
| 10725 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10726 | if (pdev->is_busmaster) |
| 10727 | pci_set_master(pdev); |
| 10728 | |
| 10729 | /* Startup the kernel thread for this host adapter. */ |
| 10730 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 10731 | "lpfc_worker_%d", phba->brd_no); |
| 10732 | if (IS_ERR(phba->worker_thread)) { |
| 10733 | error = PTR_ERR(phba->worker_thread); |
| 10734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10735 | "0293 PM resume failed to start worker " |
| 10736 | "thread: error=x%x.\n", error); |
| 10737 | return error; |
| 10738 | } |
| 10739 | |
| 10740 | /* Configure and enable interrupt */ |
| 10741 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10742 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10744 | "0294 PM resume Failed to enable interrupt\n"); |
| 10745 | return -EIO; |
| 10746 | } else |
| 10747 | phba->intr_mode = intr_mode; |
| 10748 | |
| 10749 | /* Restart HBA and bring it online */ |
| 10750 | lpfc_sli_brdrestart(phba); |
| 10751 | lpfc_online(phba); |
| 10752 | |
| 10753 | /* Log the current active interrupt mode */ |
| 10754 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10755 | |
| 10756 | return 0; |
| 10757 | } |
| 10758 | |
| 10759 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10760 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 10761 | * @phba: pointer to lpfc hba data structure. |
| 10762 | * |
| 10763 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 10764 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 10765 | **/ |
| 10766 | static void |
| 10767 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10768 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10769 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10770 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 10771 | /* |
| 10772 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10773 | * and let the SCSI mid-layer to retry them to recover. |
| 10774 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10775 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10776 | } |
| 10777 | |
| 10778 | /** |
| 10779 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 10780 | * @phba: pointer to lpfc hba data structure. |
| 10781 | * |
| 10782 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 10783 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10784 | * pending I/Os. |
| 10785 | **/ |
| 10786 | static void |
| 10787 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10788 | { |
| 10789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10790 | "2826 PCI channel disable preparing for reset\n"); |
| 10791 | |
| 10792 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10793 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10794 | |
| 10795 | /* Block all SCSI devices' I/Os on the host */ |
| 10796 | lpfc_scsi_dev_block(phba); |
| 10797 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10798 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10799 | lpfc_sli_flush_fcp_rings(phba); |
| 10800 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10801 | /* stop all timers */ |
| 10802 | lpfc_stop_hba_timers(phba); |
| 10803 | |
| 10804 | /* Disable interrupt and pci device */ |
| 10805 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10806 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10807 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10808 | } |
| 10809 | |
| 10810 | /** |
| 10811 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 10812 | * @phba: pointer to lpfc hba data structure. |
| 10813 | * |
| 10814 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 10815 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10816 | * pending I/Os. |
| 10817 | **/ |
| 10818 | static void |
| 10819 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 10820 | { |
| 10821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10822 | "2827 PCI channel permanent disable for failure\n"); |
| 10823 | |
| 10824 | /* Block all SCSI devices' I/Os on the host */ |
| 10825 | lpfc_scsi_dev_block(phba); |
| 10826 | |
| 10827 | /* stop all timers */ |
| 10828 | lpfc_stop_hba_timers(phba); |
| 10829 | |
| 10830 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10831 | lpfc_sli_flush_fcp_rings(phba); |
| 10832 | } |
| 10833 | |
| 10834 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10835 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 10836 | * @pdev: pointer to PCI device. |
| 10837 | * @state: the current PCI connection state. |
| 10838 | * |
| 10839 | * This routine is called from the PCI subsystem for error handling to device |
| 10840 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 10841 | * after a PCI bus error affecting this device has been detected. When this |
| 10842 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 10843 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 10844 | * for the PCI subsystem to perform proper recovery as desired. |
| 10845 | * |
| 10846 | * Return codes |
| 10847 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10848 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10849 | **/ |
| 10850 | static pci_ers_result_t |
| 10851 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 10852 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10853 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10854 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10855 | |
| 10856 | switch (state) { |
| 10857 | case pci_channel_io_normal: |
| 10858 | /* Non-fatal error, prepare for recovery */ |
| 10859 | lpfc_sli4_prep_dev_for_recover(phba); |
| 10860 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10861 | case pci_channel_io_frozen: |
| 10862 | /* Fatal error, prepare for slot reset */ |
| 10863 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10864 | return PCI_ERS_RESULT_NEED_RESET; |
| 10865 | case pci_channel_io_perm_failure: |
| 10866 | /* Permanent failure, prepare for device down */ |
| 10867 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 10868 | return PCI_ERS_RESULT_DISCONNECT; |
| 10869 | default: |
| 10870 | /* Unknown state, prepare and request slot reset */ |
| 10871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10872 | "2825 Unknown PCI error state: x%x\n", state); |
| 10873 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10874 | return PCI_ERS_RESULT_NEED_RESET; |
| 10875 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10876 | } |
| 10877 | |
| 10878 | /** |
| 10879 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 10880 | * @pdev: pointer to PCI device. |
| 10881 | * |
| 10882 | * This routine is called from the PCI subsystem for error handling to device |
| 10883 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 10884 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 10885 | * PCI subsystem error recovery, after the driver returns |
| 10886 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10887 | * recovery and then call this routine before calling the .resume method to |
| 10888 | * recover the device. This function will initialize the HBA device, enable |
| 10889 | * the interrupt, but it will just put the HBA to offline state without |
| 10890 | * passing any I/O traffic. |
| 10891 | * |
| 10892 | * Return codes |
| 10893 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10894 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10895 | */ |
| 10896 | static pci_ers_result_t |
| 10897 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 10898 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10899 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10900 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10901 | struct lpfc_sli *psli = &phba->sli; |
| 10902 | uint32_t intr_mode; |
| 10903 | |
| 10904 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 10905 | if (pci_enable_device_mem(pdev)) { |
| 10906 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10907 | "PCI device after reset.\n"); |
| 10908 | return PCI_ERS_RESULT_DISCONNECT; |
| 10909 | } |
| 10910 | |
| 10911 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 10912 | |
| 10913 | /* |
| 10914 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10915 | * device saved_state flag, need to save the restored state again. |
| 10916 | */ |
| 10917 | pci_save_state(pdev); |
| 10918 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10919 | if (pdev->is_busmaster) |
| 10920 | pci_set_master(pdev); |
| 10921 | |
| 10922 | spin_lock_irq(&phba->hbalock); |
| 10923 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 10924 | spin_unlock_irq(&phba->hbalock); |
| 10925 | |
| 10926 | /* Configure and enable interrupt */ |
| 10927 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10928 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10930 | "2824 Cannot re-enable interrupt after " |
| 10931 | "slot reset.\n"); |
| 10932 | return PCI_ERS_RESULT_DISCONNECT; |
| 10933 | } else |
| 10934 | phba->intr_mode = intr_mode; |
| 10935 | |
| 10936 | /* Log the current active interrupt mode */ |
| 10937 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10938 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10939 | return PCI_ERS_RESULT_RECOVERED; |
| 10940 | } |
| 10941 | |
| 10942 | /** |
| 10943 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10944 | * @pdev: pointer to PCI device |
| 10945 | * |
| 10946 | * This routine is called from the PCI subsystem for error handling to device |
| 10947 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10948 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10949 | * error recovery. After this call, traffic can start to flow from this device |
| 10950 | * again. |
| 10951 | **/ |
| 10952 | static void |
| 10953 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10954 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10955 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10956 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10957 | |
| 10958 | /* |
| 10959 | * In case of slot reset, as function reset is performed through |
| 10960 | * mailbox command which needs DMA to be enabled, this operation |
| 10961 | * has to be moved to the io resume phase. Taking device offline |
| 10962 | * will perform the necessary cleanup. |
| 10963 | */ |
| 10964 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10965 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10966 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10967 | lpfc_offline(phba); |
| 10968 | lpfc_sli_brdrestart(phba); |
| 10969 | /* Bring the device back online */ |
| 10970 | lpfc_online(phba); |
| 10971 | } |
| 10972 | |
| 10973 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10974 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10975 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10976 | } |
| 10977 | |
| 10978 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10979 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10980 | * @pdev: pointer to PCI device |
| 10981 | * @pid: pointer to PCI device identifier |
| 10982 | * |
| 10983 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10984 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10985 | * at PCI device-specific information of the device and driver to see if the |
| 10986 | * driver state that it can support this kind of device. If the match is |
| 10987 | * successful, the driver core invokes this routine. This routine dispatches |
| 10988 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10989 | * do all the initialization that it needs to do to handle the HBA device |
| 10990 | * properly. |
| 10991 | * |
| 10992 | * Return code |
| 10993 | * 0 - driver can claim the device |
| 10994 | * negative value - driver can not claim the device |
| 10995 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10996 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10997 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10998 | { |
| 10999 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11000 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11001 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11002 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11003 | return -ENODEV; |
| 11004 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11005 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11006 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11007 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11008 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11009 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11010 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11011 | return rc; |
| 11012 | } |
| 11013 | |
| 11014 | /** |
| 11015 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 11016 | * @pdev: pointer to PCI device |
| 11017 | * |
| 11018 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 11019 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 11020 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 11021 | * remove routine, which will perform all the necessary cleanup for the |
| 11022 | * device to be removed from the PCI subsystem properly. |
| 11023 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11024 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11025 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 11026 | { |
| 11027 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11028 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11029 | |
| 11030 | switch (phba->pci_dev_grp) { |
| 11031 | case LPFC_PCI_DEV_LP: |
| 11032 | lpfc_pci_remove_one_s3(pdev); |
| 11033 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11034 | case LPFC_PCI_DEV_OC: |
| 11035 | lpfc_pci_remove_one_s4(pdev); |
| 11036 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11037 | default: |
| 11038 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11039 | "1424 Invalid PCI device group: 0x%x\n", |
| 11040 | phba->pci_dev_grp); |
| 11041 | break; |
| 11042 | } |
| 11043 | return; |
| 11044 | } |
| 11045 | |
| 11046 | /** |
| 11047 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 11048 | * @pdev: pointer to PCI device |
| 11049 | * @msg: power management message |
| 11050 | * |
| 11051 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 11052 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 11053 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 11054 | * suspend the device. |
| 11055 | * |
| 11056 | * Return code |
| 11057 | * 0 - driver suspended the device |
| 11058 | * Error otherwise |
| 11059 | **/ |
| 11060 | static int |
| 11061 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 11062 | { |
| 11063 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11064 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11065 | int rc = -ENODEV; |
| 11066 | |
| 11067 | switch (phba->pci_dev_grp) { |
| 11068 | case LPFC_PCI_DEV_LP: |
| 11069 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 11070 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11071 | case LPFC_PCI_DEV_OC: |
| 11072 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 11073 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11074 | default: |
| 11075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11076 | "1425 Invalid PCI device group: 0x%x\n", |
| 11077 | phba->pci_dev_grp); |
| 11078 | break; |
| 11079 | } |
| 11080 | return rc; |
| 11081 | } |
| 11082 | |
| 11083 | /** |
| 11084 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 11085 | * @pdev: pointer to PCI device |
| 11086 | * |
| 11087 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 11088 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 11089 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 11090 | * resume the device. |
| 11091 | * |
| 11092 | * Return code |
| 11093 | * 0 - driver suspended the device |
| 11094 | * Error otherwise |
| 11095 | **/ |
| 11096 | static int |
| 11097 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 11098 | { |
| 11099 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11100 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11101 | int rc = -ENODEV; |
| 11102 | |
| 11103 | switch (phba->pci_dev_grp) { |
| 11104 | case LPFC_PCI_DEV_LP: |
| 11105 | rc = lpfc_pci_resume_one_s3(pdev); |
| 11106 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11107 | case LPFC_PCI_DEV_OC: |
| 11108 | rc = lpfc_pci_resume_one_s4(pdev); |
| 11109 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11110 | default: |
| 11111 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11112 | "1426 Invalid PCI device group: 0x%x\n", |
| 11113 | phba->pci_dev_grp); |
| 11114 | break; |
| 11115 | } |
| 11116 | return rc; |
| 11117 | } |
| 11118 | |
| 11119 | /** |
| 11120 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 11121 | * @pdev: pointer to PCI device. |
| 11122 | * @state: the current PCI connection state. |
| 11123 | * |
| 11124 | * This routine is registered to the PCI subsystem for error handling. This |
| 11125 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 11126 | * this device has been detected. When this routine is invoked, it dispatches |
| 11127 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 11128 | * routine, which will perform the proper error detected operation. |
| 11129 | * |
| 11130 | * Return codes |
| 11131 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 11132 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11133 | **/ |
| 11134 | static pci_ers_result_t |
| 11135 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 11136 | { |
| 11137 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11138 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11139 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 11140 | |
| 11141 | switch (phba->pci_dev_grp) { |
| 11142 | case LPFC_PCI_DEV_LP: |
| 11143 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 11144 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11145 | case LPFC_PCI_DEV_OC: |
| 11146 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 11147 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11148 | default: |
| 11149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11150 | "1427 Invalid PCI device group: 0x%x\n", |
| 11151 | phba->pci_dev_grp); |
| 11152 | break; |
| 11153 | } |
| 11154 | return rc; |
| 11155 | } |
| 11156 | |
| 11157 | /** |
| 11158 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 11159 | * @pdev: pointer to PCI device. |
| 11160 | * |
| 11161 | * This routine is registered to the PCI subsystem for error handling. This |
| 11162 | * function is called after PCI bus has been reset to restart the PCI card |
| 11163 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 11164 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 11165 | * routine, which will perform the proper device reset. |
| 11166 | * |
| 11167 | * Return codes |
| 11168 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 11169 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11170 | **/ |
| 11171 | static pci_ers_result_t |
| 11172 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 11173 | { |
| 11174 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11175 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11176 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 11177 | |
| 11178 | switch (phba->pci_dev_grp) { |
| 11179 | case LPFC_PCI_DEV_LP: |
| 11180 | rc = lpfc_io_slot_reset_s3(pdev); |
| 11181 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11182 | case LPFC_PCI_DEV_OC: |
| 11183 | rc = lpfc_io_slot_reset_s4(pdev); |
| 11184 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11185 | default: |
| 11186 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11187 | "1428 Invalid PCI device group: 0x%x\n", |
| 11188 | phba->pci_dev_grp); |
| 11189 | break; |
| 11190 | } |
| 11191 | return rc; |
| 11192 | } |
| 11193 | |
| 11194 | /** |
| 11195 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 11196 | * @pdev: pointer to PCI device |
| 11197 | * |
| 11198 | * This routine is registered to the PCI subsystem for error handling. It |
| 11199 | * is called when kernel error recovery tells the lpfc driver that it is |
| 11200 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 11201 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 11202 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 11203 | **/ |
| 11204 | static void |
| 11205 | lpfc_io_resume(struct pci_dev *pdev) |
| 11206 | { |
| 11207 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11208 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11209 | |
| 11210 | switch (phba->pci_dev_grp) { |
| 11211 | case LPFC_PCI_DEV_LP: |
| 11212 | lpfc_io_resume_s3(pdev); |
| 11213 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11214 | case LPFC_PCI_DEV_OC: |
| 11215 | lpfc_io_resume_s4(pdev); |
| 11216 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11217 | default: |
| 11218 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11219 | "1429 Invalid PCI device group: 0x%x\n", |
| 11220 | phba->pci_dev_grp); |
| 11221 | break; |
| 11222 | } |
| 11223 | return; |
| 11224 | } |
| 11225 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11226 | /** |
| 11227 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 11228 | * @phba: pointer to lpfc hba data structure. |
| 11229 | * |
| 11230 | * This routine checks to see if OAS is supported for this adapter. If |
| 11231 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 11232 | * the enable oas flag is cleared and the pool created for OAS device data |
| 11233 | * is destroyed. |
| 11234 | * |
| 11235 | **/ |
| 11236 | void |
| 11237 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 11238 | { |
| 11239 | |
| 11240 | if (!phba->cfg_EnableXLane) |
| 11241 | return; |
| 11242 | |
| 11243 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 11244 | phba->cfg_fof = 1; |
| 11245 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11246 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11247 | if (phba->device_data_mem_pool) |
| 11248 | mempool_destroy(phba->device_data_mem_pool); |
| 11249 | phba->device_data_mem_pool = NULL; |
| 11250 | } |
| 11251 | |
| 11252 | return; |
| 11253 | } |
| 11254 | |
| 11255 | /** |
| 11256 | * lpfc_fof_queue_setup - Set up all the fof queues |
| 11257 | * @phba: pointer to lpfc hba data structure. |
| 11258 | * |
| 11259 | * This routine is invoked to set up all the fof queues for the FC HBA |
| 11260 | * operation. |
| 11261 | * |
| 11262 | * Return codes |
| 11263 | * 0 - successful |
| 11264 | * -ENOMEM - No available memory |
| 11265 | **/ |
| 11266 | int |
| 11267 | lpfc_fof_queue_setup(struct lpfc_hba *phba) |
| 11268 | { |
| 11269 | struct lpfc_sli *psli = &phba->sli; |
| 11270 | int rc; |
| 11271 | |
| 11272 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); |
| 11273 | if (rc) |
| 11274 | return -ENOMEM; |
| 11275 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11276 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11277 | |
| 11278 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, |
| 11279 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); |
| 11280 | if (rc) |
| 11281 | goto out_oas_cq; |
| 11282 | |
| 11283 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, |
| 11284 | phba->sli4_hba.oas_cq, LPFC_FCP); |
| 11285 | if (rc) |
| 11286 | goto out_oas_wq; |
| 11287 | |
| 11288 | phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 11289 | phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 11290 | } |
| 11291 | |
| 11292 | return 0; |
| 11293 | |
| 11294 | out_oas_wq: |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11295 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11296 | out_oas_cq: |
| 11297 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); |
| 11298 | return rc; |
| 11299 | |
| 11300 | } |
| 11301 | |
| 11302 | /** |
| 11303 | * lpfc_fof_queue_create - Create all the fof queues |
| 11304 | * @phba: pointer to lpfc hba data structure. |
| 11305 | * |
| 11306 | * This routine is invoked to allocate all the fof queues for the FC HBA |
| 11307 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 11308 | * count (queue depth) shall be taken from the module parameter. For now, |
| 11309 | * we just use some constant number as place holder. |
| 11310 | * |
| 11311 | * Return codes |
| 11312 | * 0 - successful |
| 11313 | * -ENOMEM - No availble memory |
| 11314 | * -EIO - The mailbox failed to complete successfully. |
| 11315 | **/ |
| 11316 | int |
| 11317 | lpfc_fof_queue_create(struct lpfc_hba *phba) |
| 11318 | { |
| 11319 | struct lpfc_queue *qdesc; |
| 11320 | |
| 11321 | /* Create FOF EQ */ |
| 11322 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 11323 | phba->sli4_hba.eq_ecount); |
| 11324 | if (!qdesc) |
| 11325 | goto out_error; |
| 11326 | |
| 11327 | phba->sli4_hba.fof_eq = qdesc; |
| 11328 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11329 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11330 | |
| 11331 | /* Create OAS CQ */ |
| 11332 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 11333 | phba->sli4_hba.cq_ecount); |
| 11334 | if (!qdesc) |
| 11335 | goto out_error; |
| 11336 | |
| 11337 | phba->sli4_hba.oas_cq = qdesc; |
| 11338 | |
| 11339 | /* Create OAS WQ */ |
| 11340 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 11341 | phba->sli4_hba.wq_ecount); |
| 11342 | if (!qdesc) |
| 11343 | goto out_error; |
| 11344 | |
| 11345 | phba->sli4_hba.oas_wq = qdesc; |
| 11346 | |
| 11347 | } |
| 11348 | return 0; |
| 11349 | |
| 11350 | out_error: |
| 11351 | lpfc_fof_queue_destroy(phba); |
| 11352 | return -ENOMEM; |
| 11353 | } |
| 11354 | |
| 11355 | /** |
| 11356 | * lpfc_fof_queue_destroy - Destroy all the fof queues |
| 11357 | * @phba: pointer to lpfc hba data structure. |
| 11358 | * |
| 11359 | * This routine is invoked to release all the SLI4 queues with the FC HBA |
| 11360 | * operation. |
| 11361 | * |
| 11362 | * Return codes |
| 11363 | * 0 - successful |
| 11364 | **/ |
| 11365 | int |
| 11366 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) |
| 11367 | { |
| 11368 | /* Release FOF Event queue */ |
| 11369 | if (phba->sli4_hba.fof_eq != NULL) { |
| 11370 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); |
| 11371 | phba->sli4_hba.fof_eq = NULL; |
| 11372 | } |
| 11373 | |
| 11374 | /* Release OAS Completion queue */ |
| 11375 | if (phba->sli4_hba.oas_cq != NULL) { |
| 11376 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); |
| 11377 | phba->sli4_hba.oas_cq = NULL; |
| 11378 | } |
| 11379 | |
| 11380 | /* Release OAS Work queue */ |
| 11381 | if (phba->sli4_hba.oas_wq != NULL) { |
| 11382 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); |
| 11383 | phba->sli4_hba.oas_wq = NULL; |
| 11384 | } |
| 11385 | return 0; |
| 11386 | } |
| 11387 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11388 | static struct pci_device_id lpfc_id_table[] = { |
| 11389 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 11390 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 11391 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 11392 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11393 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 11394 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11395 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 11396 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11397 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 11398 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11399 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 11400 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11401 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 11402 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11403 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 11404 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11405 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 11406 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11407 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 11408 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11409 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 11410 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11411 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 11412 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11413 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 11414 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11415 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 11416 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11417 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 11418 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11419 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 11420 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11421 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 11422 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11423 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 11424 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11425 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 11426 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11427 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 11428 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11429 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 11430 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11431 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 11432 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11433 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 11434 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11435 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 11436 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11437 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 11438 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11439 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 11440 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11441 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 11442 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11443 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 11444 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 11445 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 11446 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11447 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 11448 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11449 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 11450 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11451 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 11452 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11453 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 11454 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11455 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 11456 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11457 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 11458 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11459 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 11460 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11461 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 11462 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11463 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 11464 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11465 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 11466 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11467 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11468 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11469 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 11470 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 11471 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 11472 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11473 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 11474 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 11475 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 11476 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11477 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 11478 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 11479 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_G6_FC, |
| 11480 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 11481 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 11482 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11483 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 11484 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11485 | { 0 } |
| 11486 | }; |
| 11487 | |
| 11488 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 11489 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 11490 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11491 | .error_detected = lpfc_io_error_detected, |
| 11492 | .slot_reset = lpfc_io_slot_reset, |
| 11493 | .resume = lpfc_io_resume, |
| 11494 | }; |
| 11495 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11496 | static struct pci_driver lpfc_driver = { |
| 11497 | .name = LPFC_DRIVER_NAME, |
| 11498 | .id_table = lpfc_id_table, |
| 11499 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11500 | .remove = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11501 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11502 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11503 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11504 | }; |
| 11505 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11506 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 11507 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11508 | }; |
| 11509 | |
| 11510 | static struct miscdevice lpfc_mgmt_dev = { |
| 11511 | .minor = MISC_DYNAMIC_MINOR, |
| 11512 | .name = "lpfcmgmt", |
| 11513 | .fops = &lpfc_mgmt_fop, |
| 11514 | }; |
| 11515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11516 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11517 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11518 | * |
| 11519 | * This routine is to be invoked when the lpfc module is loaded into the |
| 11520 | * kernel. The special kernel macro module_init() is used to indicate the |
| 11521 | * role of this routine to the kernel as lpfc module entry point. |
| 11522 | * |
| 11523 | * Return codes |
| 11524 | * 0 - successful |
| 11525 | * -ENOMEM - FC attach transport failed |
| 11526 | * all others - failed |
| 11527 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11528 | static int __init |
| 11529 | lpfc_init(void) |
| 11530 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11531 | int cpu; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11532 | int error = 0; |
| 11533 | |
| 11534 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 11535 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11536 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11537 | error = misc_register(&lpfc_mgmt_dev); |
| 11538 | if (error) |
| 11539 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 11540 | "misc_register returned with status %d", error); |
| 11541 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11542 | if (lpfc_enable_npiv) { |
| 11543 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 11544 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 11545 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11546 | lpfc_transport_template = |
| 11547 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11548 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11549 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11550 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11551 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11552 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 11553 | if (lpfc_vport_transport_template == NULL) { |
| 11554 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11555 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11556 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11557 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11558 | |
| 11559 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11560 | lpfc_used_cpu = NULL; |
| 11561 | lpfc_present_cpu = 0; |
| 11562 | for_each_present_cpu(cpu) |
| 11563 | lpfc_present_cpu++; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11564 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11565 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11566 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11567 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11568 | if (lpfc_enable_npiv) |
| 11569 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11570 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11571 | |
| 11572 | return error; |
| 11573 | } |
| 11574 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11575 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11576 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11577 | * |
| 11578 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 11579 | * The special kernel macro module_exit() is used to indicate the role of |
| 11580 | * this routine to the kernel as lpfc module exit point. |
| 11581 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11582 | static void __exit |
| 11583 | lpfc_exit(void) |
| 11584 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11585 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11586 | pci_unregister_driver(&lpfc_driver); |
| 11587 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11588 | if (lpfc_enable_npiv) |
| 11589 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11590 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11591 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 11592 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11593 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 11594 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 11595 | } |
| 11596 | |
| 11597 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11598 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 11599 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11600 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 11601 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 11602 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11603 | kfree(lpfc_used_cpu); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 11604 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11605 | } |
| 11606 | |
| 11607 | module_init(lpfc_init); |
| 11608 | module_exit(lpfc_exit); |
| 11609 | MODULE_LICENSE("GPL"); |
| 11610 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 11611 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 11612 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |