| 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 | f25e8e7 | 2015-04-07 15:07:28 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2015 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, |
| 571 | jiffies + msecs_to_jiffies(1000 * LPFC_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) && |
| 702 | !(phba->lmt & LMT_16Gb))) { |
| 703 | /* Reset link speed to auto */ |
| 704 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 705 | "1302 Invalid speed for this board:%d " |
| 706 | "Reset link speed to auto.\n", |
| 707 | phba->cfg_link_speed); |
| 708 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 709 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 710 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 711 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 712 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 713 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 714 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 715 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 717 | "0498 Adapter failed to init, mbxCmd x%x " |
| 718 | "INIT_LINK, mbxStatus x%x\n", |
| 719 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 720 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 721 | /* Clear all interrupt enable conditions */ |
| 722 | writel(0, phba->HCregaddr); |
| 723 | readl(phba->HCregaddr); /* flush */ |
| 724 | /* Clear all pending interrupts */ |
| 725 | writel(0xffffffff, phba->HAregaddr); |
| 726 | readl(phba->HAregaddr); /* flush */ |
| 727 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 728 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 729 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 730 | mempool_free(pmb, phba->mbox_mem_pool); |
| 731 | return -EIO; |
| 732 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 733 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 734 | if (flag == MBX_POLL) |
| 735 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 742 | * @phba: pointer to lpfc hba data structure. |
| 743 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 744 | * |
| 745 | * This routine will issue the DOWN_LINK mailbox command call. |
| 746 | * It is available to other drivers through the lpfc_hba data |
| 747 | * structure for use to stop the link. |
| 748 | * |
| 749 | * Return code |
| 750 | * 0 - success |
| 751 | * Any other value - error |
| 752 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 753 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 754 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 755 | { |
| 756 | LPFC_MBOXQ_t *pmb; |
| 757 | int rc; |
| 758 | |
| 759 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 760 | if (!pmb) { |
| 761 | phba->link_state = LPFC_HBA_ERROR; |
| 762 | return -ENOMEM; |
| 763 | } |
| 764 | |
| 765 | lpfc_printf_log(phba, |
| 766 | KERN_ERR, LOG_INIT, |
| 767 | "0491 Adapter Link is disabled.\n"); |
| 768 | lpfc_down_link(phba, pmb); |
| 769 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 770 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 771 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 772 | lpfc_printf_log(phba, |
| 773 | KERN_ERR, LOG_INIT, |
| 774 | "2522 Adapter failed to issue DOWN_LINK" |
| 775 | " mbox command rc 0x%x\n", rc); |
| 776 | |
| 777 | mempool_free(pmb, phba->mbox_mem_pool); |
| 778 | return -EIO; |
| 779 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 780 | if (flag == MBX_POLL) |
| 781 | mempool_free(pmb, phba->mbox_mem_pool); |
| 782 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 787 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 788 | * @phba: pointer to lpfc HBA data structure. |
| 789 | * |
| 790 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 791 | * bringing down the SLI Layer. |
| 792 | * |
| 793 | * Return codes |
| 794 | * 0 - success. |
| 795 | * Any other value - error. |
| 796 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 798 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 800 | struct lpfc_vport **vports; |
| 801 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 802 | |
| 803 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 804 | /* Disable interrupts */ |
| 805 | writel(0, phba->HCregaddr); |
| 806 | readl(phba->HCregaddr); /* flush */ |
| 807 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 808 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 809 | if (phba->pport->load_flag & FC_UNLOADING) |
| 810 | lpfc_cleanup_discovery_resources(phba->pport); |
| 811 | else { |
| 812 | vports = lpfc_create_vport_work_array(phba); |
| 813 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 814 | for (i = 0; i <= phba->max_vports && |
| 815 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 816 | lpfc_cleanup_discovery_resources(vports[i]); |
| 817 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 818 | } |
| 819 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | } |
| 821 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 822 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 823 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 824 | * rspiocb which got deferred |
| 825 | * |
| 826 | * @phba: pointer to lpfc HBA data structure. |
| 827 | * |
| 828 | * This routine will cleanup completed slow path events after HBA is reset |
| 829 | * when bringing down the SLI Layer. |
| 830 | * |
| 831 | * |
| 832 | * Return codes |
| 833 | * void. |
| 834 | **/ |
| 835 | static void |
| 836 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 837 | { |
| 838 | struct lpfc_iocbq *rspiocbq; |
| 839 | struct hbq_dmabuf *dmabuf; |
| 840 | struct lpfc_cq_event *cq_event; |
| 841 | |
| 842 | spin_lock_irq(&phba->hbalock); |
| 843 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 844 | spin_unlock_irq(&phba->hbalock); |
| 845 | |
| 846 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 847 | /* Get the response iocb from the head of work queue */ |
| 848 | spin_lock_irq(&phba->hbalock); |
| 849 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 850 | cq_event, struct lpfc_cq_event, list); |
| 851 | spin_unlock_irq(&phba->hbalock); |
| 852 | |
| 853 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 854 | case CQE_CODE_COMPL_WQE: |
| 855 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 856 | cq_event); |
| 857 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 858 | break; |
| 859 | case CQE_CODE_RECEIVE: |
| 860 | case CQE_CODE_RECEIVE_V1: |
| 861 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 862 | cq_event); |
| 863 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 869 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 870 | * @phba: pointer to lpfc HBA data structure. |
| 871 | * |
| 872 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 873 | * when bringing down the SLI Layer. |
| 874 | * |
| 875 | * |
| 876 | * Return codes |
| 877 | * void. |
| 878 | **/ |
| 879 | static void |
| 880 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 881 | { |
| 882 | struct lpfc_sli *psli = &phba->sli; |
| 883 | struct lpfc_sli_ring *pring; |
| 884 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 885 | LIST_HEAD(buflist); |
| 886 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 887 | |
| 888 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 889 | lpfc_sli_hbqbuf_free_all(phba); |
| 890 | else { |
| 891 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 892 | pring = &psli->ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 893 | spin_lock_irq(&phba->hbalock); |
| 894 | list_splice_init(&pring->postbufq, &buflist); |
| 895 | spin_unlock_irq(&phba->hbalock); |
| 896 | |
| 897 | count = 0; |
| 898 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 899 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 900 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 901 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 902 | kfree(mp); |
| 903 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 904 | |
| 905 | spin_lock_irq(&phba->hbalock); |
| 906 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 907 | spin_unlock_irq(&phba->hbalock); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
| 912 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 913 | * @phba: pointer to lpfc HBA data structure. |
| 914 | * |
| 915 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 916 | * down the SLI Layer. |
| 917 | * |
| 918 | * Return codes |
| 919 | * void |
| 920 | **/ |
| 921 | static void |
| 922 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 923 | { |
| 924 | struct lpfc_sli *psli = &phba->sli; |
| 925 | struct lpfc_sli_ring *pring; |
| 926 | LIST_HEAD(completions); |
| 927 | int i; |
| 928 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 929 | for (i = 0; i < psli->num_rings; i++) { |
| 930 | pring = &psli->ring[i]; |
| 931 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 932 | spin_lock_irq(&pring->ring_lock); |
| 933 | else |
| 934 | spin_lock_irq(&phba->hbalock); |
| 935 | /* At this point in time the HBA is either reset or DOA. Either |
| 936 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 937 | */ |
| 938 | list_splice_init(&pring->txcmplq, &completions); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 939 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 940 | |
| 941 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 942 | spin_unlock_irq(&pring->ring_lock); |
| 943 | else |
| 944 | spin_unlock_irq(&phba->hbalock); |
| 945 | |
| 946 | /* Cancel all the IOCBs from the completions list */ |
| 947 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 948 | IOERR_SLI_ABORTED); |
| 949 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 954 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 955 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 956 | * @phba: pointer to lpfc HBA data structure. |
| 957 | * |
| 958 | * This routine will do uninitialization after the HBA is reset when bring |
| 959 | * down the SLI Layer. |
| 960 | * |
| 961 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 962 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 963 | * Any other value - error. |
| 964 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 965 | static int |
| 966 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 967 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 968 | lpfc_hba_free_post_buf(phba); |
| 969 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 970 | return 0; |
| 971 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 972 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 973 | /** |
| 974 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 975 | * @phba: pointer to lpfc HBA data structure. |
| 976 | * |
| 977 | * This routine will do uninitialization after the HBA is reset when bring |
| 978 | * down the SLI Layer. |
| 979 | * |
| 980 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 981 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 982 | * Any other value - error. |
| 983 | **/ |
| 984 | static int |
| 985 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 986 | { |
| 987 | struct lpfc_scsi_buf *psb, *psb_next; |
| 988 | LIST_HEAD(aborts); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 989 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 990 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 991 | struct lpfc_sli *psli = &phba->sli; |
| 992 | struct lpfc_sli_ring *pring; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 993 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 994 | lpfc_hba_free_post_buf(phba); |
| 995 | lpfc_hba_clean_txcmplq(phba); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 996 | pring = &psli->ring[LPFC_ELS_RING]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 997 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 998 | /* At this point in time the HBA is either reset or DOA. Either |
| 999 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 1000 | * on the lpfc_sgl_list so that it can either be freed if the |
| 1001 | * driver is unloading or reposted if the driver is restarting |
| 1002 | * the port. |
| 1003 | */ |
| 1004 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 1005 | /* scsl_buf_list */ |
| 1006 | /* abts_sgl_list_lock required because worker thread uses this |
| 1007 | * list. |
| 1008 | */ |
| 1009 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1010 | list_for_each_entry(sglq_entry, |
| 1011 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1012 | sglq_entry->state = SGL_FREED; |
| 1013 | |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1014 | spin_lock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1015 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 1016 | &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1017 | spin_unlock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1018 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 1019 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 1020 | * list. |
| 1021 | */ |
| 1022 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1023 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 1024 | &aborts); |
| 1025 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1026 | spin_unlock_irq(&phba->hbalock); |
| 1027 | |
| 1028 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 1029 | psb->pCmd = NULL; |
| 1030 | psb->status = IOSTAT_SUCCESS; |
| 1031 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1032 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1033 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 1034 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1035 | |
| 1036 | lpfc_sli4_free_sp_events(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1042 | * @phba: pointer to lpfc HBA data structure. |
| 1043 | * |
| 1044 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1045 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1046 | * |
| 1047 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1048 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1049 | * Any other value - error. |
| 1050 | **/ |
| 1051 | int |
| 1052 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1053 | { |
| 1054 | return (*phba->lpfc_hba_down_post)(phba); |
| 1055 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1056 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1057 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1058 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1059 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1060 | * |
| 1061 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1062 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1063 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1064 | * event will be used by the worker thread to invoke the actual timeout |
| 1065 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1066 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1067 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1068 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1069 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1070 | lpfc_hb_timeout(unsigned long ptr) |
| 1071 | { |
| 1072 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1073 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1074 | unsigned long iflag; |
| 1075 | |
| 1076 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1077 | |
| 1078 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1079 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1080 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1081 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1082 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1083 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1084 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1085 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1086 | if (!tmo_posted) |
| 1087 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1091 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1092 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1093 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1094 | * |
| 1095 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1096 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1097 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1098 | * event will be used by the worker thread to invoke the actual timeout |
| 1099 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1100 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1101 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1102 | **/ |
| 1103 | static void |
| 1104 | lpfc_rrq_timeout(unsigned long ptr) |
| 1105 | { |
| 1106 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1107 | unsigned long iflag; |
| 1108 | |
| 1109 | phba = (struct lpfc_hba *)ptr; |
| 1110 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1111 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1112 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1113 | else |
| 1114 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1115 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1116 | |
| 1117 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1118 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1122 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1123 | * @phba: pointer to lpfc hba data structure. |
| 1124 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1125 | * |
| 1126 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1127 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1128 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1129 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1130 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1131 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1132 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1133 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1134 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1135 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1136 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1137 | static void |
| 1138 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1139 | { |
| 1140 | unsigned long drvr_flag; |
| 1141 | |
| 1142 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1143 | phba->hb_outstanding = 0; |
| 1144 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1145 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1146 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1147 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1148 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1149 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1150 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1151 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1152 | jiffies + |
| 1153 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1154 | return; |
| 1155 | } |
| 1156 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1158 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1159 | * @phba: pointer to lpfc hba data structure. |
| 1160 | * |
| 1161 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1162 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1163 | * handler performs any periodic operations needed for the device. If such |
| 1164 | * periodic event has already been attended to either in the interrupt handler |
| 1165 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1166 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1167 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1168 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1169 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1170 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1171 | * to offline. |
| 1172 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1173 | void |
| 1174 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1175 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1176 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1177 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1178 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1179 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1180 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1181 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1182 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1183 | vports = lpfc_create_vport_work_array(phba); |
| 1184 | if (vports != NULL) |
| 1185 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1186 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1187 | lpfc_destroy_vport_work_array(phba, vports); |
| 1188 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1189 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1190 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1191 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1192 | return; |
| 1193 | |
| 1194 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1195 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1196 | if (time_after(phba->last_completion_time + |
| 1197 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1198 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1199 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1200 | if (!phba->hb_outstanding) |
| 1201 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1202 | jiffies + |
| 1203 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1204 | else |
| 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_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1211 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1212 | if (phba->elsbuf_cnt && |
| 1213 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1214 | spin_lock_irq(&phba->hbalock); |
| 1215 | list_splice_init(&phba->elsbuf, &completions); |
| 1216 | phba->elsbuf_cnt = 0; |
| 1217 | phba->elsbuf_prev_cnt = 0; |
| 1218 | spin_unlock_irq(&phba->hbalock); |
| 1219 | |
| 1220 | while (!list_empty(&completions)) { |
| 1221 | list_remove_head(&completions, buf_ptr, |
| 1222 | struct lpfc_dmabuf, list); |
| 1223 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1224 | kfree(buf_ptr); |
| 1225 | } |
| 1226 | } |
| 1227 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1228 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1229 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1230 | if (phba->cfg_enable_hba_heartbeat) { |
| 1231 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1232 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1233 | (list_empty(&psli->mboxq))) { |
| 1234 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1235 | GFP_KERNEL); |
| 1236 | if (!pmboxq) { |
| 1237 | mod_timer(&phba->hb_tmofunc, |
| 1238 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1239 | msecs_to_jiffies(1000 * |
| 1240 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1241 | return; |
| 1242 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1243 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1244 | lpfc_heart_beat(phba, pmboxq); |
| 1245 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1246 | pmboxq->vport = phba->pport; |
| 1247 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1248 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1249 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1250 | if (retval != MBX_BUSY && |
| 1251 | retval != MBX_SUCCESS) { |
| 1252 | mempool_free(pmboxq, |
| 1253 | phba->mbox_mem_pool); |
| 1254 | mod_timer(&phba->hb_tmofunc, |
| 1255 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1256 | msecs_to_jiffies(1000 * |
| 1257 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1258 | return; |
| 1259 | } |
| 1260 | phba->skipped_hb = 0; |
| 1261 | phba->hb_outstanding = 1; |
| 1262 | } else if (time_before_eq(phba->last_completion_time, |
| 1263 | phba->skipped_hb)) { |
| 1264 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1265 | "2857 Last completion time not " |
| 1266 | " updated in %d ms\n", |
| 1267 | jiffies_to_msecs(jiffies |
| 1268 | - phba->last_completion_time)); |
| 1269 | } else |
| 1270 | phba->skipped_hb = jiffies; |
| 1271 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1272 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1273 | jiffies + |
| 1274 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1275 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1276 | } else { |
| 1277 | /* |
| 1278 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1279 | * we need to give the hb mailbox cmd a chance to |
| 1280 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1281 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1282 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1283 | "0459 Adapter heartbeat still out" |
| 1284 | "standing:last compl time was %d ms.\n", |
| 1285 | jiffies_to_msecs(jiffies |
| 1286 | - phba->last_completion_time)); |
| 1287 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1288 | jiffies + |
| 1289 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1290 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1295 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1296 | * @phba: pointer to lpfc hba data structure. |
| 1297 | * |
| 1298 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1299 | * other than Port Error 6 has been detected. |
| 1300 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1301 | static void |
| 1302 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1303 | { |
| 1304 | struct lpfc_sli *psli = &phba->sli; |
| 1305 | |
| 1306 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1307 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1308 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1309 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1310 | |
| 1311 | lpfc_offline(phba); |
| 1312 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1313 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1314 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1315 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1316 | lpfc_hba_down_post(phba); |
| 1317 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1318 | lpfc_unblock_mgmt_io(phba); |
| 1319 | phba->link_state = LPFC_HBA_ERROR; |
| 1320 | return; |
| 1321 | } |
| 1322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1323 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1324 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1325 | * @phba: pointer to lpfc hba data structure. |
| 1326 | * |
| 1327 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1328 | * other than Port Error 6 has been detected. |
| 1329 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1330 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1331 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1332 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1333 | spin_lock_irq(&phba->hbalock); |
| 1334 | phba->link_state = LPFC_HBA_ERROR; |
| 1335 | spin_unlock_irq(&phba->hbalock); |
| 1336 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1337 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1338 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1339 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1340 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1344 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1345 | * @phba: pointer to lpfc hba data structure. |
| 1346 | * |
| 1347 | * This routine is invoked to handle the deferred HBA hardware error |
| 1348 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1349 | * and another ER bit in the host status register. The driver will |
| 1350 | * wait until the ER1 bit clears before handling the error condition. |
| 1351 | **/ |
| 1352 | static void |
| 1353 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1354 | { |
| 1355 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1356 | struct lpfc_sli *psli = &phba->sli; |
| 1357 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1358 | /* If the pci channel is offline, ignore possible errors, |
| 1359 | * since we cannot communicate with the pci card anyway. |
| 1360 | */ |
| 1361 | if (pci_channel_offline(phba->pcidev)) { |
| 1362 | spin_lock_irq(&phba->hbalock); |
| 1363 | phba->hba_flag &= ~DEFER_ERATT; |
| 1364 | spin_unlock_irq(&phba->hbalock); |
| 1365 | return; |
| 1366 | } |
| 1367 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1369 | "0479 Deferred Adapter Hardware Error " |
| 1370 | "Data: x%x x%x x%x\n", |
| 1371 | phba->work_hs, |
| 1372 | phba->work_status[0], phba->work_status[1]); |
| 1373 | |
| 1374 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1375 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1376 | spin_unlock_irq(&phba->hbalock); |
| 1377 | |
| 1378 | |
| 1379 | /* |
| 1380 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1381 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1382 | * SCSI layer retry it after re-establishing link. |
| 1383 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1384 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1385 | |
| 1386 | /* |
| 1387 | * There was a firmware error. Take the hba offline and then |
| 1388 | * attempt to restart it. |
| 1389 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1390 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1391 | lpfc_offline(phba); |
| 1392 | |
| 1393 | /* Wait for the ER1 bit to clear.*/ |
| 1394 | while (phba->work_hs & HS_FFER1) { |
| 1395 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1396 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1397 | phba->work_hs = UNPLUG_ERR ; |
| 1398 | break; |
| 1399 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1400 | /* If driver is unloading let the worker thread continue */ |
| 1401 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1402 | phba->work_hs = 0; |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * This is to ptrotect against a race condition in which |
| 1409 | * first write to the host attention register clear the |
| 1410 | * host status register. |
| 1411 | */ |
| 1412 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1413 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1414 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1415 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1416 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1417 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1418 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1419 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1420 | } |
| 1421 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1422 | static void |
| 1423 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1424 | { |
| 1425 | struct lpfc_board_event_header board_event; |
| 1426 | struct Scsi_Host *shost; |
| 1427 | |
| 1428 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1429 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1430 | shost = lpfc_shost_from_vport(phba->pport); |
| 1431 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1432 | sizeof(board_event), |
| 1433 | (char *) &board_event, |
| 1434 | LPFC_NL_VENDOR_ID); |
| 1435 | } |
| 1436 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1437 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1438 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1439 | * @phba: pointer to lpfc hba data structure. |
| 1440 | * |
| 1441 | * This routine is invoked to handle the following HBA hardware error |
| 1442 | * conditions: |
| 1443 | * 1 - HBA error attention interrupt |
| 1444 | * 2 - DMA ring index out of range |
| 1445 | * 3 - Mailbox command came back as unknown |
| 1446 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1447 | static void |
| 1448 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1451 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1452 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1453 | unsigned long temperature; |
| 1454 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1455 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1456 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1457 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1458 | * since we cannot communicate with the pci card anyway. |
| 1459 | */ |
| 1460 | if (pci_channel_offline(phba->pcidev)) { |
| 1461 | spin_lock_irq(&phba->hbalock); |
| 1462 | phba->hba_flag &= ~DEFER_ERATT; |
| 1463 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1464 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1467 | /* If resets are disabled then leave the HBA alone and return */ |
| 1468 | if (!phba->cfg_enable_hba_reset) |
| 1469 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1471 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1472 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1473 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1474 | if (phba->hba_flag & DEFER_ERATT) |
| 1475 | lpfc_handle_deferred_eratt(phba); |
| 1476 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1477 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1478 | if (phba->work_hs & HS_FFER6) |
| 1479 | /* Re-establishing Link */ |
| 1480 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1481 | "1301 Re-establishing Link " |
| 1482 | "Data: x%x x%x x%x\n", |
| 1483 | phba->work_hs, phba->work_status[0], |
| 1484 | phba->work_status[1]); |
| 1485 | if (phba->work_hs & HS_FFER8) |
| 1486 | /* Device Zeroization */ |
| 1487 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1488 | "2861 Host Authentication device " |
| 1489 | "zeroization Data:x%x x%x x%x\n", |
| 1490 | phba->work_hs, phba->work_status[0], |
| 1491 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1492 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1493 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1494 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1495 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1496 | |
| 1497 | /* |
| 1498 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1499 | * That could cause the I/Os dropped by the firmware. |
| 1500 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1501 | * retry it after re-establishing link. |
| 1502 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1503 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1505 | /* |
| 1506 | * There was a firmware error. Take the hba offline and then |
| 1507 | * attempt to restart it. |
| 1508 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1509 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1511 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1513 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1514 | return; |
| 1515 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1516 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1517 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1518 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1519 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1520 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1521 | temp_event_data.data = (uint32_t)temperature; |
| 1522 | |
| 1523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1524 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1525 | "(%ld), taking this port offline " |
| 1526 | "Data: x%x x%x x%x\n", |
| 1527 | temperature, phba->work_hs, |
| 1528 | phba->work_status[0], phba->work_status[1]); |
| 1529 | |
| 1530 | shost = lpfc_shost_from_vport(phba->pport); |
| 1531 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1532 | sizeof(temp_event_data), |
| 1533 | (char *) &temp_event_data, |
| 1534 | SCSI_NL_VID_TYPE_PCI |
| 1535 | | PCI_VENDOR_ID_EMULEX); |
| 1536 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1537 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1538 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1539 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1540 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1541 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | } else { |
| 1543 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1544 | * failure is a value other than FFER6. Do not call the offline |
| 1545 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | */ |
| 1547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1548 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1550 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | phba->work_status[0], phba->work_status[1]); |
| 1552 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1553 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1554 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1555 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1556 | sizeof(event_data), (char *) &event_data, |
| 1557 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1558 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1559 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1561 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1564 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1565 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1566 | * @phba: pointer to lpfc hba data structure. |
| 1567 | * @mbx_action: flag for mailbox shutdown action. |
| 1568 | * |
| 1569 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1570 | * response to port status register polling attention. It waits for port |
| 1571 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1572 | * During this process, interrupt vectors are freed and later requested |
| 1573 | * for handling possible port resource change. |
| 1574 | **/ |
| 1575 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1576 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1577 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1578 | { |
| 1579 | int rc; |
| 1580 | uint32_t intr_mode; |
| 1581 | |
| 1582 | /* |
| 1583 | * On error status condition, driver need to wait for port |
| 1584 | * ready before performing reset. |
| 1585 | */ |
| 1586 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1587 | if (!rc) { |
| 1588 | /* need reset: attempt for port recovery */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1589 | if (en_rn_msg) |
| 1590 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1591 | "2887 Reset Needed: Attempting Port " |
| 1592 | "Recovery...\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1593 | lpfc_offline_prep(phba, mbx_action); |
| 1594 | lpfc_offline(phba); |
| 1595 | /* release interrupt for possible resource change */ |
| 1596 | lpfc_sli4_disable_intr(phba); |
| 1597 | lpfc_sli_brdrestart(phba); |
| 1598 | /* request and enable interrupt */ |
| 1599 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1600 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1602 | "3175 Failed to enable interrupt\n"); |
| 1603 | return -EIO; |
| 1604 | } else { |
| 1605 | phba->intr_mode = intr_mode; |
| 1606 | } |
| 1607 | rc = lpfc_online(phba); |
| 1608 | if (rc == 0) |
| 1609 | lpfc_unblock_mgmt_io(phba); |
| 1610 | } |
| 1611 | return rc; |
| 1612 | } |
| 1613 | |
| 1614 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1615 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1616 | * @phba: pointer to lpfc hba data structure. |
| 1617 | * |
| 1618 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1619 | * conditions. |
| 1620 | **/ |
| 1621 | static void |
| 1622 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1623 | { |
| 1624 | struct lpfc_vport *vport = phba->pport; |
| 1625 | uint32_t event_data; |
| 1626 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1627 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1628 | struct lpfc_register portstat_reg = {0}; |
| 1629 | uint32_t reg_err1, reg_err2; |
| 1630 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1631 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1632 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1633 | struct temp_event temp_event_data; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1634 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1635 | |
| 1636 | /* If the pci channel is offline, ignore possible errors, since |
| 1637 | * we cannot communicate with the pci card anyway. |
| 1638 | */ |
| 1639 | if (pci_channel_offline(phba->pcidev)) |
| 1640 | return; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1641 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1642 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1643 | switch (if_type) { |
| 1644 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1645 | pci_rd_rc1 = lpfc_readl( |
| 1646 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1647 | &uerrlo_reg); |
| 1648 | pci_rd_rc2 = lpfc_readl( |
| 1649 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1650 | &uemasklo_reg); |
| 1651 | /* consider PCI bus read error as pci_channel_offline */ |
| 1652 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1653 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1654 | lpfc_sli4_offline_eratt(phba); |
| 1655 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1656 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1657 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1658 | pci_rd_rc1 = lpfc_readl( |
| 1659 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1660 | &portstat_reg.word0); |
| 1661 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1662 | if (pci_rd_rc1 == -EIO) { |
| 1663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1664 | "3151 PCI bus read access failure: x%x\n", |
| 1665 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1666 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1667 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1668 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1669 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1670 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1672 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1673 | "taking port offline Data: x%x x%x\n", |
| 1674 | reg_err1, reg_err2); |
| 1675 | |
| 1676 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1677 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1678 | temp_event_data.data = 0xFFFFFFFF; |
| 1679 | |
| 1680 | shost = lpfc_shost_from_vport(phba->pport); |
| 1681 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1682 | sizeof(temp_event_data), |
| 1683 | (char *)&temp_event_data, |
| 1684 | SCSI_NL_VID_TYPE_PCI |
| 1685 | | PCI_VENDOR_ID_EMULEX); |
| 1686 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1687 | spin_lock_irq(&phba->hbalock); |
| 1688 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1689 | spin_unlock_irq(&phba->hbalock); |
| 1690 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1691 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1692 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1693 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1694 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1696 | "3143 Port Down: Firmware Update " |
| 1697 | "Detected\n"); |
| 1698 | en_rn_msg = false; |
| 1699 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1700 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1701 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1702 | "3144 Port Down: Debug Dump\n"); |
| 1703 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1704 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1705 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1706 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1707 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1708 | /* If resets are disabled then leave the HBA alone and return */ |
| 1709 | if (!phba->cfg_enable_hba_reset) |
| 1710 | return; |
| 1711 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1712 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1713 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1714 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1715 | if (rc == 0) { |
| 1716 | /* don't report event on forced debug dump */ |
| 1717 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1718 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1719 | return; |
| 1720 | else |
| 1721 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1722 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1723 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1725 | "3152 Unrecoverable error, bring the port " |
| 1726 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1727 | lpfc_sli4_offline_eratt(phba); |
| 1728 | break; |
| 1729 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1730 | default: |
| 1731 | break; |
| 1732 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1733 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1734 | "3123 Report dump event to upper layer\n"); |
| 1735 | /* Send an internal error event to mgmt application */ |
| 1736 | lpfc_board_errevt_to_mgmt(phba); |
| 1737 | |
| 1738 | event_data = FC_REG_DUMP_EVENT; |
| 1739 | shost = lpfc_shost_from_vport(vport); |
| 1740 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1741 | sizeof(event_data), (char *) &event_data, |
| 1742 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /** |
| 1746 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1747 | * @phba: pointer to lpfc HBA data structure. |
| 1748 | * |
| 1749 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1750 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1751 | * |
| 1752 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1753 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1754 | * Any other value - error. |
| 1755 | **/ |
| 1756 | void |
| 1757 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1758 | { |
| 1759 | (*phba->lpfc_handle_eratt)(phba); |
| 1760 | } |
| 1761 | |
| 1762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1763 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1764 | * @phba: pointer to lpfc hba data structure. |
| 1765 | * |
| 1766 | * This routine is invoked from the worker thread to handle a HBA host |
| 1767 | * attention link event. |
| 1768 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1770 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1772 | struct lpfc_vport *vport = phba->pport; |
| 1773 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1774 | LPFC_MBOXQ_t *pmb; |
| 1775 | volatile uint32_t control; |
| 1776 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1777 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | |
| 1779 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1780 | if (!pmb) { |
| 1781 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1783 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | |
| 1785 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1786 | if (!mp) { |
| 1787 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1789 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1790 | |
| 1791 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1792 | if (!mp->virt) { |
| 1793 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1794 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1795 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1797 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1798 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | |
| 1800 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1801 | lpfc_read_topology(phba, pmb, mp); |
| 1802 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1803 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1804 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1805 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1806 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1807 | if (rc == MBX_NOT_FINISHED) { |
| 1808 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1809 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1810 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | |
| 1812 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1813 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | writel(HA_LATT, phba->HAregaddr); |
| 1815 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1816 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | |
| 1818 | return; |
| 1819 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1820 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1821 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1822 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | lpfc_handle_latt_free_mp: |
| 1824 | kfree(mp); |
| 1825 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1826 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | lpfc_handle_latt_err_exit: |
| 1828 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1831 | control = readl(phba->HCregaddr); |
| 1832 | control |= HC_LAINT_ENA; |
| 1833 | writel(control, phba->HCregaddr); |
| 1834 | readl(phba->HCregaddr); /* flush */ |
| 1835 | |
| 1836 | /* Clear Link Attention in HA REG */ |
| 1837 | writel(HA_LATT, phba->HAregaddr); |
| 1838 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1839 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1843 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1844 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1845 | |
| 1846 | return; |
| 1847 | } |
| 1848 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1849 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1850 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1851 | * @phba: pointer to lpfc hba data structure. |
| 1852 | * @vpd: pointer to the vital product data. |
| 1853 | * @len: length of the vital product data in bytes. |
| 1854 | * |
| 1855 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1856 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1857 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1858 | * |
| 1859 | * Return codes |
| 1860 | * 0 - pointer to the VPD passed in is NULL |
| 1861 | * 1 - success |
| 1862 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1863 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | { |
| 1866 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1867 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | int i, j; |
| 1869 | int finished = 0; |
| 1870 | int index = 0; |
| 1871 | |
| 1872 | if (!vpd) |
| 1873 | return 0; |
| 1874 | |
| 1875 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1876 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1877 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1879 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1880 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | switch (vpd[index]) { |
| 1882 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1883 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | index += 1; |
| 1885 | lenlo = vpd[index]; |
| 1886 | index += 1; |
| 1887 | lenhi = vpd[index]; |
| 1888 | index += 1; |
| 1889 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1890 | index += i; |
| 1891 | break; |
| 1892 | case 0x90: |
| 1893 | index += 1; |
| 1894 | lenlo = vpd[index]; |
| 1895 | index += 1; |
| 1896 | lenhi = vpd[index]; |
| 1897 | index += 1; |
| 1898 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1899 | if (Length > len - index) |
| 1900 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | while (Length > 0) { |
| 1902 | /* Look for Serial Number */ |
| 1903 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1904 | index += 2; |
| 1905 | i = vpd[index]; |
| 1906 | index += 1; |
| 1907 | j = 0; |
| 1908 | Length -= (3+i); |
| 1909 | while(i--) { |
| 1910 | phba->SerialNumber[j++] = vpd[index++]; |
| 1911 | if (j == 31) |
| 1912 | break; |
| 1913 | } |
| 1914 | phba->SerialNumber[j] = 0; |
| 1915 | continue; |
| 1916 | } |
| 1917 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1918 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1919 | index += 2; |
| 1920 | i = vpd[index]; |
| 1921 | index += 1; |
| 1922 | j = 0; |
| 1923 | Length -= (3+i); |
| 1924 | while(i--) { |
| 1925 | phba->ModelDesc[j++] = vpd[index++]; |
| 1926 | if (j == 255) |
| 1927 | break; |
| 1928 | } |
| 1929 | phba->ModelDesc[j] = 0; |
| 1930 | continue; |
| 1931 | } |
| 1932 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1933 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1934 | index += 2; |
| 1935 | i = vpd[index]; |
| 1936 | index += 1; |
| 1937 | j = 0; |
| 1938 | Length -= (3+i); |
| 1939 | while(i--) { |
| 1940 | phba->ModelName[j++] = vpd[index++]; |
| 1941 | if (j == 79) |
| 1942 | break; |
| 1943 | } |
| 1944 | phba->ModelName[j] = 0; |
| 1945 | continue; |
| 1946 | } |
| 1947 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1948 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1949 | index += 2; |
| 1950 | i = vpd[index]; |
| 1951 | index += 1; |
| 1952 | j = 0; |
| 1953 | Length -= (3+i); |
| 1954 | while(i--) { |
| 1955 | phba->ProgramType[j++] = vpd[index++]; |
| 1956 | if (j == 255) |
| 1957 | break; |
| 1958 | } |
| 1959 | phba->ProgramType[j] = 0; |
| 1960 | continue; |
| 1961 | } |
| 1962 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1963 | phba->vpd_flag |= VPD_PORT; |
| 1964 | index += 2; |
| 1965 | i = vpd[index]; |
| 1966 | index += 1; |
| 1967 | j = 0; |
| 1968 | Length -= (3+i); |
| 1969 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1970 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1971 | (phba->sli4_hba.pport_name_sta == |
| 1972 | LPFC_SLI4_PPNAME_GET)) { |
| 1973 | j++; |
| 1974 | index++; |
| 1975 | } else |
| 1976 | phba->Port[j++] = vpd[index++]; |
| 1977 | if (j == 19) |
| 1978 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1980 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1981 | (phba->sli4_hba.pport_name_sta == |
| 1982 | LPFC_SLI4_PPNAME_NON)) |
| 1983 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1984 | continue; |
| 1985 | } |
| 1986 | else { |
| 1987 | index += 2; |
| 1988 | i = vpd[index]; |
| 1989 | index += 1; |
| 1990 | index += i; |
| 1991 | Length -= (3 + i); |
| 1992 | } |
| 1993 | } |
| 1994 | finished = 0; |
| 1995 | break; |
| 1996 | case 0x78: |
| 1997 | finished = 1; |
| 1998 | break; |
| 1999 | default: |
| 2000 | index ++; |
| 2001 | break; |
| 2002 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2003 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | |
| 2005 | return(1); |
| 2006 | } |
| 2007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2008 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2009 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2010 | * @phba: pointer to lpfc hba data structure. |
| 2011 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2012 | * @descp: pointer to the data structure to hold the derived description. |
| 2013 | * |
| 2014 | * This routine retrieves HBA's description based on its registered PCI device |
| 2015 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2016 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2017 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2018 | * function returns, the @mdp will be filled with the model name. |
| 2019 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | 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] | 2022 | { |
| 2023 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2024 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2025 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2026 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2027 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2028 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2029 | char *name; |
| 2030 | char *bus; |
| 2031 | char *function; |
| 2032 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2033 | |
| 2034 | if (mdp && mdp[0] != '\0' |
| 2035 | && descp && descp[0] != '\0') |
| 2036 | return; |
| 2037 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2038 | if (phba->lmt & LMT_16Gb) |
| 2039 | max_speed = 16; |
| 2040 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2041 | max_speed = 10; |
| 2042 | else if (phba->lmt & LMT_8Gb) |
| 2043 | max_speed = 8; |
| 2044 | else if (phba->lmt & LMT_4Gb) |
| 2045 | max_speed = 4; |
| 2046 | else if (phba->lmt & LMT_2Gb) |
| 2047 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2048 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2049 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2050 | else |
| 2051 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | |
| 2053 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2055 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2056 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2057 | m = (typeof(m)){"LP6000", "PCI", |
| 2058 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2059 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | case PCI_DEVICE_ID_SUPERFLY: |
| 2061 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2062 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2064 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2065 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | break; |
| 2067 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2068 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2069 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | break; |
| 2071 | case PCI_DEVICE_ID_CENTAUR: |
| 2072 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2073 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2075 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2076 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2077 | break; |
| 2078 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2079 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2080 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2081 | break; |
| 2082 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2083 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2084 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | break; |
| 2086 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2087 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2088 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | break; |
| 2090 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2091 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2092 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | break; |
| 2094 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2095 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2096 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | break; |
| 2098 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2099 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2100 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | break; |
| 2102 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2103 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2104 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2106 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2107 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2108 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2109 | break; |
| 2110 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2111 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2112 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2113 | break; |
| 2114 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2115 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2116 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2117 | break; |
| 2118 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2119 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2120 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2121 | break; |
| 2122 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2123 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2124 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2125 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2126 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2127 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | break; |
| 2129 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2130 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2131 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | break; |
| 2133 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2134 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2136 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2137 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2138 | break; |
| 2139 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2140 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2141 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2142 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2144 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | break; |
| 2146 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2147 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | break; |
| 2149 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2150 | m = (typeof(m)){"LP101", "PCI-X", |
| 2151 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2152 | break; |
| 2153 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2154 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2155 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2156 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2157 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2158 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2159 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2160 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2161 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2162 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2163 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2164 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2165 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2166 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2167 | break; |
| 2168 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2169 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2170 | break; |
| 2171 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2172 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2173 | break; |
| 2174 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2175 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2176 | break; |
| 2177 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2178 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2179 | break; |
| 2180 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2181 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2182 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2183 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2184 | m = (typeof(m)){"LP21000", "PCIe", |
| 2185 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2186 | GE = 1; |
| 2187 | break; |
| 2188 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2189 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2190 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2191 | break; |
| 2192 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2193 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2194 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2195 | break; |
| 2196 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2197 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2198 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2199 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2200 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2201 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2202 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2203 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2204 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2205 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2206 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2207 | break; |
| 2208 | case PCI_DEVICE_ID_FALCON: |
| 2209 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2210 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2211 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2212 | case PCI_DEVICE_ID_BALIUS: |
| 2213 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2214 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2215 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2216 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2217 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2218 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2219 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2220 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2221 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2222 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2223 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2224 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2225 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2226 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2227 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2228 | oneConnect = 1; |
| 2229 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2230 | "Obsolete, Unsupported FCoE"}; |
| 2231 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2232 | case PCI_DEVICE_ID_SKYHAWK: |
| 2233 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2234 | oneConnect = 1; |
| 2235 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2236 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2237 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2238 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2239 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2241 | |
| 2242 | if (mdp && mdp[0] == '\0') |
| 2243 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2244 | /* |
| 2245 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2246 | * and we put the port number on the end |
| 2247 | */ |
| 2248 | if (descp && descp[0] == '\0') { |
| 2249 | if (oneConnect) |
| 2250 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2251 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2252 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2253 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2254 | else if (max_speed == 0) |
| 2255 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2256 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2257 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2258 | else |
| 2259 | snprintf(descp, 255, |
| 2260 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2261 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2262 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | } |
| 2265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2267 | * 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] | 2268 | * @phba: pointer to lpfc hba data structure. |
| 2269 | * @pring: pointer to a IOCB ring. |
| 2270 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2271 | * |
| 2272 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2273 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2274 | * |
| 2275 | * Return codes |
| 2276 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2277 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2279 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2280 | { |
| 2281 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2282 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2283 | struct lpfc_dmabuf *mp1, *mp2; |
| 2284 | |
| 2285 | cnt += pring->missbufcnt; |
| 2286 | |
| 2287 | /* While there are buffers to post */ |
| 2288 | while (cnt > 0) { |
| 2289 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2290 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2291 | if (iocb == NULL) { |
| 2292 | pring->missbufcnt = cnt; |
| 2293 | return cnt; |
| 2294 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | icmd = &iocb->iocb; |
| 2296 | |
| 2297 | /* 2 buffers can be posted per command */ |
| 2298 | /* Allocate buffer to post */ |
| 2299 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2300 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2301 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2302 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2303 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2304 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2305 | pring->missbufcnt = cnt; |
| 2306 | return cnt; |
| 2307 | } |
| 2308 | |
| 2309 | INIT_LIST_HEAD(&mp1->list); |
| 2310 | /* Allocate buffer to post */ |
| 2311 | if (cnt > 1) { |
| 2312 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2313 | if (mp2) |
| 2314 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2315 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2316 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2317 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2318 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2319 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2320 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | pring->missbufcnt = cnt; |
| 2322 | return cnt; |
| 2323 | } |
| 2324 | |
| 2325 | INIT_LIST_HEAD(&mp2->list); |
| 2326 | } else { |
| 2327 | mp2 = NULL; |
| 2328 | } |
| 2329 | |
| 2330 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2331 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2332 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2333 | icmd->ulpBdeCount = 1; |
| 2334 | cnt--; |
| 2335 | if (mp2) { |
| 2336 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2337 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2338 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2339 | cnt--; |
| 2340 | icmd->ulpBdeCount = 2; |
| 2341 | } |
| 2342 | |
| 2343 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2344 | icmd->ulpLe = 1; |
| 2345 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2346 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2347 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2349 | kfree(mp1); |
| 2350 | cnt++; |
| 2351 | if (mp2) { |
| 2352 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2353 | kfree(mp2); |
| 2354 | cnt++; |
| 2355 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2356 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | return cnt; |
| 2359 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2361 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | } |
| 2364 | pring->missbufcnt = 0; |
| 2365 | return 0; |
| 2366 | } |
| 2367 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2368 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2369 | * 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] | 2370 | * @phba: pointer to lpfc hba data structure. |
| 2371 | * |
| 2372 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2373 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2374 | * set to 64 IOCBs. |
| 2375 | * |
| 2376 | * Return codes |
| 2377 | * 0 - success (currently always success) |
| 2378 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | { |
| 2382 | struct lpfc_sli *psli = &phba->sli; |
| 2383 | |
| 2384 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2385 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | /* Ring 2 - FCP no buffers needed */ |
| 2387 | |
| 2388 | return 0; |
| 2389 | } |
| 2390 | |
| 2391 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2392 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2393 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2394 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2395 | * @HashResultPointer: pointer to an array as hash table. |
| 2396 | * |
| 2397 | * This routine sets up the initial values to the array of hash table entries |
| 2398 | * for the LC HBAs. |
| 2399 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | static void |
| 2401 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2402 | { |
| 2403 | HashResultPointer[0] = 0x67452301; |
| 2404 | HashResultPointer[1] = 0xEFCDAB89; |
| 2405 | HashResultPointer[2] = 0x98BADCFE; |
| 2406 | HashResultPointer[3] = 0x10325476; |
| 2407 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2408 | } |
| 2409 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2410 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2411 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2412 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2413 | * @HashWorkingPointer: pointer to an working hash table. |
| 2414 | * |
| 2415 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2416 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2417 | * The results are putting back to the initial hash table, returned through |
| 2418 | * the @HashResultPointer as the result hash table. |
| 2419 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | static void |
| 2421 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2422 | { |
| 2423 | int t; |
| 2424 | uint32_t TEMP; |
| 2425 | uint32_t A, B, C, D, E; |
| 2426 | t = 16; |
| 2427 | do { |
| 2428 | HashWorkingPointer[t] = |
| 2429 | S(1, |
| 2430 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2431 | 8] ^ |
| 2432 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2433 | } while (++t <= 79); |
| 2434 | t = 0; |
| 2435 | A = HashResultPointer[0]; |
| 2436 | B = HashResultPointer[1]; |
| 2437 | C = HashResultPointer[2]; |
| 2438 | D = HashResultPointer[3]; |
| 2439 | E = HashResultPointer[4]; |
| 2440 | |
| 2441 | do { |
| 2442 | if (t < 20) { |
| 2443 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2444 | } else if (t < 40) { |
| 2445 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2446 | } else if (t < 60) { |
| 2447 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2448 | } else { |
| 2449 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2450 | } |
| 2451 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2452 | E = D; |
| 2453 | D = C; |
| 2454 | C = S(30, B); |
| 2455 | B = A; |
| 2456 | A = TEMP; |
| 2457 | } while (++t <= 79); |
| 2458 | |
| 2459 | HashResultPointer[0] += A; |
| 2460 | HashResultPointer[1] += B; |
| 2461 | HashResultPointer[2] += C; |
| 2462 | HashResultPointer[3] += D; |
| 2463 | HashResultPointer[4] += E; |
| 2464 | |
| 2465 | } |
| 2466 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2468 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2469 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2470 | * @HashWorking: pointer to the entry of the working hash array. |
| 2471 | * |
| 2472 | * This routine calculates the working hash array referred by @HashWorking |
| 2473 | * from the challenge random numbers associated with the host, referred by |
| 2474 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2475 | * array and returned by reference through @HashWorking. |
| 2476 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2477 | static void |
| 2478 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2479 | { |
| 2480 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2481 | } |
| 2482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2484 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2485 | * @phba: pointer to lpfc hba data structure. |
| 2486 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2487 | * |
| 2488 | * This routine performs the special handling for LC HBA initialization. |
| 2489 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | void |
| 2491 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2492 | { |
| 2493 | int t; |
| 2494 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2495 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2497 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | if (!HashWorking) |
| 2499 | return; |
| 2500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2501 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2502 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2503 | |
| 2504 | for (t = 0; t < 7; t++) |
| 2505 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2506 | |
| 2507 | lpfc_sha_init(hbainit); |
| 2508 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2509 | kfree(HashWorking); |
| 2510 | } |
| 2511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2513 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2514 | * @vport: pointer to a virtual N_Port data structure. |
| 2515 | * |
| 2516 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2517 | * It invokes the discovery state machine to perform necessary state |
| 2518 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2519 | * the physical port is treated as @vport 0. |
| 2520 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2521 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2522 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2523 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2524 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2526 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2528 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2529 | lpfc_port_link_failure(vport); |
| 2530 | |
| 2531 | 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] | 2532 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2533 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2534 | NLP_STE_UNUSED_NODE); |
| 2535 | if (!ndlp) |
| 2536 | continue; |
| 2537 | spin_lock_irq(&phba->ndlp_lock); |
| 2538 | NLP_SET_FREE_REQ(ndlp); |
| 2539 | spin_unlock_irq(&phba->ndlp_lock); |
| 2540 | /* Trigger the release of the ndlp memory */ |
| 2541 | lpfc_nlp_put(ndlp); |
| 2542 | continue; |
| 2543 | } |
| 2544 | spin_lock_irq(&phba->ndlp_lock); |
| 2545 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2546 | /* The ndlp should not be in memory free mode already */ |
| 2547 | spin_unlock_irq(&phba->ndlp_lock); |
| 2548 | continue; |
| 2549 | } else |
| 2550 | /* Indicate request for freeing ndlp memory */ |
| 2551 | NLP_SET_FREE_REQ(ndlp); |
| 2552 | spin_unlock_irq(&phba->ndlp_lock); |
| 2553 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2554 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2555 | ndlp->nlp_DID == Fabric_DID) { |
| 2556 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2557 | lpfc_nlp_put(ndlp); |
| 2558 | continue; |
| 2559 | } |
| 2560 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2561 | /* take care of nodes in unused state before the state |
| 2562 | * machine taking action. |
| 2563 | */ |
| 2564 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2565 | lpfc_nlp_put(ndlp); |
| 2566 | continue; |
| 2567 | } |
| 2568 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2569 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2570 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2571 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2572 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2573 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2574 | NLP_EVT_DEVICE_RM); |
| 2575 | } |
| 2576 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2577 | /* At this point, ALL ndlp's should be gone |
| 2578 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2579 | * Lets wait for this to happen, if needed. |
| 2580 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2581 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2582 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2583 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2584 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2585 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2586 | &vport->fc_nodes, nlp_listp) { |
| 2587 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2588 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2589 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2590 | "usgmap:x%x refcnt:%d\n", |
| 2591 | ndlp->nlp_DID, (void *)ndlp, |
| 2592 | ndlp->nlp_usg_map, |
| 2593 | atomic_read( |
| 2594 | &ndlp->kref.refcount)); |
| 2595 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2596 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2597 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2598 | |
| 2599 | /* Wait for any activity on ndlps to settle */ |
| 2600 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2601 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2602 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | } |
| 2604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2605 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2606 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2607 | * @vport: pointer to a virtual N_Port data structure. |
| 2608 | * |
| 2609 | * This routine stops all the timers associated with a @vport. This function |
| 2610 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2611 | * port is treated as @vport 0. |
| 2612 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2613 | void |
| 2614 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2616 | del_timer_sync(&vport->els_tmofunc); |
| 2617 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2618 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2619 | lpfc_can_disctmo(vport); |
| 2620 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2621 | } |
| 2622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2623 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2624 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2625 | * @phba: pointer to lpfc hba data structure. |
| 2626 | * |
| 2627 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2628 | * caller of this routine should already hold the host lock. |
| 2629 | **/ |
| 2630 | void |
| 2631 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2632 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2633 | /* Clear pending FCF rediscovery wait flag */ |
| 2634 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2635 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2636 | /* Now, try to stop the timer */ |
| 2637 | del_timer(&phba->fcf.redisc_wait); |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2642 | * @phba: pointer to lpfc hba data structure. |
| 2643 | * |
| 2644 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2645 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2646 | * lock held before proceeding with disabling the timer and clearing the |
| 2647 | * wait timer pendig flag. |
| 2648 | **/ |
| 2649 | void |
| 2650 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2651 | { |
| 2652 | spin_lock_irq(&phba->hbalock); |
| 2653 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2654 | /* FCF rediscovery timer already fired or stopped */ |
| 2655 | spin_unlock_irq(&phba->hbalock); |
| 2656 | return; |
| 2657 | } |
| 2658 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2659 | /* Clear failover in progress flags */ |
| 2660 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2661 | spin_unlock_irq(&phba->hbalock); |
| 2662 | } |
| 2663 | |
| 2664 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2665 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2666 | * @phba: pointer to lpfc hba data structure. |
| 2667 | * |
| 2668 | * This routine stops all the timers associated with a HBA. This function is |
| 2669 | * invoked before either putting a HBA offline or unloading the driver. |
| 2670 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2671 | void |
| 2672 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2674 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2675 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2677 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2678 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2679 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2680 | del_timer_sync(&phba->rrq_tmr); |
| 2681 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2682 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2683 | phba->hb_outstanding = 0; |
| 2684 | |
| 2685 | switch (phba->pci_dev_grp) { |
| 2686 | case LPFC_PCI_DEV_LP: |
| 2687 | /* Stop any LightPulse device specific driver timers */ |
| 2688 | del_timer_sync(&phba->fcp_poll_timer); |
| 2689 | break; |
| 2690 | case LPFC_PCI_DEV_OC: |
| 2691 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2692 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2693 | break; |
| 2694 | default: |
| 2695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2696 | "0297 Invalid device group (x%x)\n", |
| 2697 | phba->pci_dev_grp); |
| 2698 | break; |
| 2699 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2700 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | } |
| 2702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2704 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2705 | * @phba: pointer to lpfc hba data structure. |
| 2706 | * |
| 2707 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2708 | * management interface is marked as blocked, all the user space access to |
| 2709 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2710 | * all be blocked. The HBA is set to block the management interface when the |
| 2711 | * driver prepares the HBA interface for online or offline. |
| 2712 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2713 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2714 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2715 | { |
| 2716 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2717 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2718 | unsigned long timeout; |
| 2719 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2720 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2721 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2722 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2723 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2724 | return; |
| 2725 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2726 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2727 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2728 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2729 | /* Determine how long we might wait for the active mailbox |
| 2730 | * command to be gracefully completed by firmware. |
| 2731 | */ |
| 2732 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2733 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2734 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2735 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2736 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2737 | /* Wait for the outstnading mailbox command to complete */ |
| 2738 | while (phba->sli.mbox_active) { |
| 2739 | /* Check active mailbox complete status every 2ms */ |
| 2740 | msleep(2); |
| 2741 | if (time_after(jiffies, timeout)) { |
| 2742 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2743 | "2813 Mgmt IO is Blocked %x " |
| 2744 | "- mbox cmd %x still active\n", |
| 2745 | phba->sli.sli_flag, actcmd); |
| 2746 | break; |
| 2747 | } |
| 2748 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2749 | } |
| 2750 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2751 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2752 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2753 | * @phba: pointer to lpfc hba data structure. |
| 2754 | * |
| 2755 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2756 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2757 | * is to fixup the temporary rpi assignments. |
| 2758 | **/ |
| 2759 | void |
| 2760 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2761 | { |
| 2762 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2763 | struct lpfc_vport **vports; |
| 2764 | int i; |
| 2765 | |
| 2766 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2767 | return; |
| 2768 | |
| 2769 | vports = lpfc_create_vport_work_array(phba); |
| 2770 | if (vports != NULL) { |
| 2771 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2772 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2773 | continue; |
| 2774 | |
| 2775 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2776 | &vports[i]->fc_nodes, |
| 2777 | nlp_listp) { |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2778 | if (NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2779 | ndlp->nlp_rpi = |
| 2780 | lpfc_sli4_alloc_rpi(phba); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2781 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 2782 | LOG_NODE, |
| 2783 | "0009 rpi:%x DID:%x " |
| 2784 | "flg:%x map:%x %p\n", |
| 2785 | ndlp->nlp_rpi, |
| 2786 | ndlp->nlp_DID, |
| 2787 | ndlp->nlp_flag, |
| 2788 | ndlp->nlp_usg_map, |
| 2789 | ndlp); |
| 2790 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | lpfc_destroy_vport_work_array(phba, vports); |
| 2795 | } |
| 2796 | |
| 2797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2798 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | * @phba: pointer to lpfc hba data structure. |
| 2800 | * |
| 2801 | * This routine initializes the HBA and brings a HBA online. During this |
| 2802 | * process, the management interface is blocked to prevent user space access |
| 2803 | * to the HBA interfering with the driver initialization. |
| 2804 | * |
| 2805 | * Return codes |
| 2806 | * 0 - successful |
| 2807 | * 1 - failed |
| 2808 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2809 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2812 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2813 | struct lpfc_vport **vports; |
| 2814 | int i; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2815 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | if (!phba) |
| 2818 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2819 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2821 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | return 0; |
| 2823 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2824 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2825 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2827 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2829 | if (!lpfc_sli_queue_setup(phba)) { |
| 2830 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2834 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2835 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2836 | lpfc_unblock_mgmt_io(phba); |
| 2837 | return 1; |
| 2838 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2839 | spin_lock_irq(&phba->hbalock); |
| 2840 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 2841 | vpis_cleared = true; |
| 2842 | spin_unlock_irq(&phba->hbalock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2843 | } else { |
| 2844 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2845 | lpfc_unblock_mgmt_io(phba); |
| 2846 | return 1; |
| 2847 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2848 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2850 | vports = lpfc_create_vport_work_array(phba); |
| 2851 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2852 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2853 | struct Scsi_Host *shost; |
| 2854 | shost = lpfc_shost_from_vport(vports[i]); |
| 2855 | spin_lock_irq(shost->host_lock); |
| 2856 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2857 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2858 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2859 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2860 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2861 | if ((vpis_cleared) && |
| 2862 | (vports[i]->port_type != |
| 2863 | LPFC_PHYSICAL_PORT)) |
| 2864 | vports[i]->vpi = 0; |
| 2865 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2866 | spin_unlock_irq(shost->host_lock); |
| 2867 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2868 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2870 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2871 | return 0; |
| 2872 | } |
| 2873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2875 | * 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] | 2876 | * @phba: pointer to lpfc hba data structure. |
| 2877 | * |
| 2878 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2879 | * HBA's management interface is marked as not blocked, all the user space |
| 2880 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2881 | * interface will be allowed. The HBA is set to block the management interface |
| 2882 | * when the driver prepares the HBA interface for online or offline and then |
| 2883 | * set to unblock the management interface afterwards. |
| 2884 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2885 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2886 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2887 | { |
| 2888 | unsigned long iflag; |
| 2889 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2891 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2892 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2893 | } |
| 2894 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2896 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2897 | * @phba: pointer to lpfc hba data structure. |
| 2898 | * |
| 2899 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2900 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2901 | * queue to make it ready to be brought offline. |
| 2902 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2903 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2904 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2905 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2906 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2907 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2908 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2909 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2910 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2912 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2913 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2915 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2916 | |
| 2917 | lpfc_linkdown(phba); |
| 2918 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2919 | /* Issue an unreg_login to all nodes on all vports */ |
| 2920 | vports = lpfc_create_vport_work_array(phba); |
| 2921 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2922 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2923 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2924 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2925 | shost = lpfc_shost_from_vport(vports[i]); |
| 2926 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2927 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2928 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2929 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2930 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2931 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2932 | shost = lpfc_shost_from_vport(vports[i]); |
| 2933 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2934 | &vports[i]->fc_nodes, |
| 2935 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2936 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2937 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2938 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2939 | continue; |
| 2940 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2941 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2942 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2943 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2944 | NULL, NLP_EVT_DEVICE_RM); |
| 2945 | } |
| 2946 | spin_lock_irq(shost->host_lock); |
| 2947 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2948 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2949 | /* |
| 2950 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2951 | * RPI. Get a new RPI when the adapter port |
| 2952 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2953 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2954 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2955 | lpfc_printf_vlog(ndlp->vport, |
| 2956 | KERN_INFO, LOG_NODE, |
| 2957 | "0011 lpfc_offline: " |
| 2958 | "ndlp:x%p did %x " |
| 2959 | "usgmap:x%x rpi:%x\n", |
| 2960 | ndlp, ndlp->nlp_DID, |
| 2961 | ndlp->nlp_usg_map, |
| 2962 | ndlp->nlp_rpi); |
| 2963 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2964 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2965 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2966 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2967 | } |
| 2968 | } |
| 2969 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2970 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2971 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2972 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2973 | } |
| 2974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2975 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2976 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2977 | * @phba: pointer to lpfc hba data structure. |
| 2978 | * |
| 2979 | * This routine actually brings a HBA offline. It stops all the timers |
| 2980 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2981 | * marks the HBA as in offline state for the upper layer protocol. |
| 2982 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2983 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2984 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2985 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2986 | struct Scsi_Host *shost; |
| 2987 | struct lpfc_vport **vports; |
| 2988 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2989 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2990 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2991 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2992 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2993 | /* stop port and all timers associated with this hba */ |
| 2994 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2995 | vports = lpfc_create_vport_work_array(phba); |
| 2996 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2997 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2998 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2999 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3000 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3001 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3003 | now. */ |
| 3004 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3005 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3006 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3007 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3008 | vports = lpfc_create_vport_work_array(phba); |
| 3009 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3010 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3011 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3012 | spin_lock_irq(shost->host_lock); |
| 3013 | vports[i]->work_port_events = 0; |
| 3014 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3015 | spin_unlock_irq(shost->host_lock); |
| 3016 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3017 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3018 | } |
| 3019 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3021 | * 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] | 3022 | * @phba: pointer to lpfc hba data structure. |
| 3023 | * |
| 3024 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3025 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3026 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3027 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3028 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3029 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | { |
| 3031 | struct lpfc_scsi_buf *sb, *sb_next; |
| 3032 | struct lpfc_iocbq *io, *io_next; |
| 3033 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3034 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3035 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3036 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3037 | |
| 3038 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3039 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3040 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | list_del(&sb->list); |
| 3042 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3044 | kfree(sb); |
| 3045 | phba->total_scsi_bufs--; |
| 3046 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3047 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3048 | |
| 3049 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3050 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3051 | list) { |
| 3052 | list_del(&sb->list); |
| 3053 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
| 3054 | sb->dma_handle); |
| 3055 | kfree(sb); |
| 3056 | phba->total_scsi_bufs--; |
| 3057 | } |
| 3058 | spin_unlock(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3059 | |
| 3060 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 3061 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 3062 | list_del(&io->list); |
| 3063 | kfree(io); |
| 3064 | phba->total_iocbq_bufs--; |
| 3065 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3066 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3067 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | /** |
| 3071 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 3072 | * @phba: pointer to lpfc hba data structure. |
| 3073 | * |
| 3074 | * This routine first calculates the sizes of the current els and allocated |
| 3075 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3076 | * XRIs assigned due to port function reset. During port initialization, the |
| 3077 | * current els and allocated scsi sgl lists are 0s. |
| 3078 | * |
| 3079 | * Return codes |
| 3080 | * 0 - successful (for now, it always returns 0) |
| 3081 | **/ |
| 3082 | int |
| 3083 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 3084 | { |
| 3085 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3086 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 3087 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 3088 | LIST_HEAD(els_sgl_list); |
| 3089 | LIST_HEAD(scsi_sgl_list); |
| 3090 | int rc; |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3091 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3092 | |
| 3093 | /* |
| 3094 | * update on pci function's els xri-sgl list |
| 3095 | */ |
| 3096 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3097 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3098 | /* els xri-sgl expanded */ |
| 3099 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3100 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3101 | "3157 ELS xri-sgl count increased from " |
| 3102 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3103 | els_xri_cnt); |
| 3104 | /* allocate the additional els sgls */ |
| 3105 | for (i = 0; i < xri_cnt; i++) { |
| 3106 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3107 | GFP_KERNEL); |
| 3108 | if (sglq_entry == NULL) { |
| 3109 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3110 | "2562 Failure to allocate an " |
| 3111 | "ELS sgl entry:%d\n", i); |
| 3112 | rc = -ENOMEM; |
| 3113 | goto out_free_mem; |
| 3114 | } |
| 3115 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3116 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3117 | &sglq_entry->phys); |
| 3118 | if (sglq_entry->virt == NULL) { |
| 3119 | kfree(sglq_entry); |
| 3120 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3121 | "2563 Failure to allocate an " |
| 3122 | "ELS mbuf:%d\n", i); |
| 3123 | rc = -ENOMEM; |
| 3124 | goto out_free_mem; |
| 3125 | } |
| 3126 | sglq_entry->sgl = sglq_entry->virt; |
| 3127 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3128 | sglq_entry->state = SGL_FREED; |
| 3129 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3130 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3131 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3132 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3133 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3134 | spin_unlock(&pring->ring_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3135 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3136 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3137 | /* els xri-sgl shrinked */ |
| 3138 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3139 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3140 | "3158 ELS xri-sgl count decreased from " |
| 3141 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3142 | els_xri_cnt); |
| 3143 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3144 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3145 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3146 | spin_unlock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3147 | spin_unlock_irq(&phba->hbalock); |
| 3148 | /* release extra els sgls from list */ |
| 3149 | for (i = 0; i < xri_cnt; i++) { |
| 3150 | list_remove_head(&els_sgl_list, |
| 3151 | sglq_entry, struct lpfc_sglq, list); |
| 3152 | if (sglq_entry) { |
| 3153 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3154 | sglq_entry->phys); |
| 3155 | kfree(sglq_entry); |
| 3156 | } |
| 3157 | } |
| 3158 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3159 | spin_lock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3160 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 3161 | spin_unlock(&pring->ring_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3162 | spin_unlock_irq(&phba->hbalock); |
| 3163 | } else |
| 3164 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3165 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3166 | els_xri_cnt); |
| 3167 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3168 | |
| 3169 | /* update xris to els sgls on the list */ |
| 3170 | sglq_entry = NULL; |
| 3171 | sglq_entry_next = NULL; |
| 3172 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3173 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 3174 | lxri = lpfc_sli4_next_xritag(phba); |
| 3175 | if (lxri == NO_XRI) { |
| 3176 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3177 | "2400 Failed to allocate xri for " |
| 3178 | "ELS sgl\n"); |
| 3179 | rc = -ENOMEM; |
| 3180 | goto out_free_mem; |
| 3181 | } |
| 3182 | sglq_entry->sli4_lxritag = lxri; |
| 3183 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3184 | } |
| 3185 | |
| 3186 | /* |
| 3187 | * update on pci function's allocated scsi xri-sgl list |
| 3188 | */ |
| 3189 | phba->total_scsi_bufs = 0; |
| 3190 | |
| 3191 | /* maximum number of xris available for scsi buffers */ |
| 3192 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3193 | els_xri_cnt; |
| 3194 | |
| 3195 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3196 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 3197 | "maximum SCSI xri count:%d\n", |
| 3198 | phba->sli4_hba.scsi_xri_cnt, |
| 3199 | phba->sli4_hba.scsi_xri_max); |
| 3200 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3201 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3202 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3203 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3204 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3205 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3206 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3207 | |
| 3208 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3209 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3210 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3211 | phba->sli4_hba.scsi_xri_max; |
| 3212 | /* release the extra allocated scsi buffers */ |
| 3213 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3214 | list_remove_head(&scsi_sgl_list, psb, |
| 3215 | struct lpfc_scsi_buf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3216 | if (psb) { |
| 3217 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
| 3218 | psb->data, psb->dma_handle); |
| 3219 | kfree(psb); |
| 3220 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3221 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3222 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3223 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3224 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | /* update xris associated to remaining allocated scsi buffers */ |
| 3228 | psb = NULL; |
| 3229 | psb_next = NULL; |
| 3230 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3231 | lxri = lpfc_sli4_next_xritag(phba); |
| 3232 | if (lxri == NO_XRI) { |
| 3233 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3234 | "2560 Failed to allocate xri for " |
| 3235 | "scsi buffer\n"); |
| 3236 | rc = -ENOMEM; |
| 3237 | goto out_free_mem; |
| 3238 | } |
| 3239 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3240 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3241 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3242 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3243 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3244 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3245 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3246 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3247 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3248 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3250 | |
| 3251 | out_free_mem: |
| 3252 | lpfc_free_els_sgl_list(phba); |
| 3253 | lpfc_scsi_free(phba); |
| 3254 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | } |
| 3256 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3257 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3258 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3259 | * @phba: pointer to lpfc hba data structure. |
| 3260 | * @instance: a unique integer ID to this FC port. |
| 3261 | * @dev: pointer to the device data structure. |
| 3262 | * |
| 3263 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3264 | * can be created on top of either a physical port or a virtual port provided |
| 3265 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3266 | * and associates the FC port created before adding the shost into the SCSI |
| 3267 | * layer. |
| 3268 | * |
| 3269 | * Return codes |
| 3270 | * @vport - pointer to the virtual N_Port data structure. |
| 3271 | * NULL - port create failed. |
| 3272 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3273 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3274 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3275 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3276 | struct lpfc_vport *vport; |
| 3277 | struct Scsi_Host *shost; |
| 3278 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3279 | |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3280 | if (dev != &phba->pcidev->dev) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3281 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3282 | sizeof(struct lpfc_vport)); |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3283 | } else { |
| 3284 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3285 | shost = scsi_host_alloc(&lpfc_template, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3286 | sizeof(struct lpfc_vport)); |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3287 | else |
| 3288 | shost = scsi_host_alloc(&lpfc_template_s3, |
| 3289 | sizeof(struct lpfc_vport)); |
| 3290 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3291 | if (!shost) |
| 3292 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3293 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3294 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3295 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3296 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3297 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3298 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3299 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3300 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3301 | shost->unique_id = instance; |
| 3302 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3303 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3304 | shost->this_id = -1; |
| 3305 | shost->max_cmd_len = 16; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3306 | shost->nr_hw_queues = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3307 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3308 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3309 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3310 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3311 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3312 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3313 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3314 | * Set initial can_queue value since 0 is no longer supported and |
| 3315 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3316 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3317 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3318 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3319 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3320 | shost->transportt = lpfc_vport_transport_template; |
| 3321 | vport->port_type = LPFC_NPIV_PORT; |
| 3322 | } else { |
| 3323 | shost->transportt = lpfc_transport_template; |
| 3324 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3325 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3326 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3327 | /* Initialize all internally managed lists. */ |
| 3328 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3329 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3330 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3331 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3332 | init_timer(&vport->fc_disctmo); |
| 3333 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3334 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3335 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3336 | init_timer(&vport->fc_fdmitmo); |
| 3337 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3338 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3339 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3340 | init_timer(&vport->els_tmofunc); |
| 3341 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3342 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3343 | |
| 3344 | init_timer(&vport->delayed_disc_tmo); |
| 3345 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3346 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3347 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3348 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3349 | if (error) |
| 3350 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3351 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3352 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3353 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3354 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3355 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3356 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3357 | out_put_shost: |
| 3358 | scsi_host_put(shost); |
| 3359 | out: |
| 3360 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3361 | } |
| 3362 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3363 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3364 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3365 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3366 | * |
| 3367 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3368 | * resources associated with the port are released. |
| 3369 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | void |
| 3371 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3372 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3373 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3374 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3375 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3376 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3377 | fc_remove_host(shost); |
| 3378 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3379 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3380 | spin_lock_irq(&phba->hbalock); |
| 3381 | list_del_init(&vport->listentry); |
| 3382 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3383 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3384 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3385 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3386 | } |
| 3387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3388 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3389 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3390 | * |
| 3391 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3392 | * uses the kernel idr facility to perform the task. |
| 3393 | * |
| 3394 | * Return codes: |
| 3395 | * instance - a unique integer ID allocated as the new instance. |
| 3396 | * -1 - lpfc get instance failed. |
| 3397 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3398 | int |
| 3399 | lpfc_get_instance(void) |
| 3400 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3401 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3402 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3403 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 3404 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3405 | } |
| 3406 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3408 | * 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] | 3409 | * @shost: pointer to SCSI host data structure. |
| 3410 | * @time: elapsed time of the scan in jiffies. |
| 3411 | * |
| 3412 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3413 | * whether the scan host is finished. |
| 3414 | * |
| 3415 | * Note: there is no scan_start function as adapter initialization will have |
| 3416 | * asynchronously kicked off the link initialization. |
| 3417 | * |
| 3418 | * Return codes |
| 3419 | * 0 - SCSI host scan is not over yet. |
| 3420 | * 1 - SCSI host scan is over. |
| 3421 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3422 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3423 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3424 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3425 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3426 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3427 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3428 | spin_lock_irq(shost->host_lock); |
| 3429 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3430 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3431 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3432 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3433 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3434 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3435 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3436 | "0461 Scanning longer than 30 " |
| 3437 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3438 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3439 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3440 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3441 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 3442 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3444 | "0465 Link down longer than 15 " |
| 3445 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3446 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3447 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3448 | } |
| 3449 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3450 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3451 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3452 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3453 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3454 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3455 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3456 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3457 | goto finished; |
| 3458 | |
| 3459 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3460 | |
| 3461 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3462 | spin_unlock_irq(shost->host_lock); |
| 3463 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3464 | } |
| 3465 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3466 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3467 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3468 | * @shost: pointer to SCSI host data structure. |
| 3469 | * |
| 3470 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3471 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3472 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3473 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3474 | { |
| 3475 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3476 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3477 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3478 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3479 | */ |
| 3480 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3481 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3482 | 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] | 3483 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3484 | |
| 3485 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3486 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3487 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3488 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3489 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3490 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3491 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3492 | |
| 3493 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3494 | if (phba->lmt & LMT_16Gb) |
| 3495 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3496 | if (phba->lmt & LMT_10Gb) |
| 3497 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3498 | if (phba->lmt & LMT_8Gb) |
| 3499 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3500 | if (phba->lmt & LMT_4Gb) |
| 3501 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3502 | if (phba->lmt & LMT_2Gb) |
| 3503 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3504 | if (phba->lmt & LMT_1Gb) |
| 3505 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3506 | |
| 3507 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3508 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3509 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3510 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3511 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3512 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3513 | /* This value is also unchanging */ |
| 3514 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3515 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3516 | fc_host_active_fc4s(shost)[2] = 1; |
| 3517 | fc_host_active_fc4s(shost)[7] = 1; |
| 3518 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3519 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3520 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3521 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3522 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3523 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3525 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3526 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3527 | * @phba: pointer to lpfc hba data structure. |
| 3528 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3529 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3530 | * from generating interrupts and stops the device driver's timers for the |
| 3531 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3532 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3533 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3534 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3535 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3536 | /* Clear all interrupt enable conditions */ |
| 3537 | writel(0, phba->HCregaddr); |
| 3538 | readl(phba->HCregaddr); /* flush */ |
| 3539 | /* Clear all pending interrupts */ |
| 3540 | writel(0xffffffff, phba->HAregaddr); |
| 3541 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3542 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3543 | /* Reset some HBA SLI setup states */ |
| 3544 | lpfc_stop_hba_timers(phba); |
| 3545 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3546 | } |
| 3547 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3548 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3549 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3550 | * @phba: pointer to lpfc hba data structure. |
| 3551 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3552 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3553 | * from generating interrupts and stops the device driver's timers for the |
| 3554 | * device. |
| 3555 | **/ |
| 3556 | static void |
| 3557 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3558 | { |
| 3559 | /* Reset some HBA SLI4 setup states */ |
| 3560 | lpfc_stop_hba_timers(phba); |
| 3561 | phba->pport->work_port_events = 0; |
| 3562 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
| 3566 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3567 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3568 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3569 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3570 | * the API jump table function pointer from the lpfc_hba struct. |
| 3571 | **/ |
| 3572 | void |
| 3573 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3574 | { |
| 3575 | phba->lpfc_stop_port(phba); |
| 3576 | } |
| 3577 | |
| 3578 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3579 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3580 | * @phba: Pointer to hba for which this call is being executed. |
| 3581 | * |
| 3582 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3583 | **/ |
| 3584 | void |
| 3585 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3586 | { |
| 3587 | unsigned long fcf_redisc_wait_tmo = |
| 3588 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3589 | /* Start fcf rediscovery wait period timer */ |
| 3590 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3591 | spin_lock_irq(&phba->hbalock); |
| 3592 | /* Allow action to new fcf asynchronous event */ |
| 3593 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3594 | /* Mark the FCF rediscovery pending state */ |
| 3595 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3596 | spin_unlock_irq(&phba->hbalock); |
| 3597 | } |
| 3598 | |
| 3599 | /** |
| 3600 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3601 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3602 | * |
| 3603 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3604 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3605 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3606 | * list, and then worker thread shall be waked up for processing from the |
| 3607 | * worker thread context. |
| 3608 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 3609 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3610 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3611 | { |
| 3612 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3613 | |
| 3614 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3615 | spin_lock_irq(&phba->hbalock); |
| 3616 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3617 | spin_unlock_irq(&phba->hbalock); |
| 3618 | return; |
| 3619 | } |
| 3620 | /* Clear FCF rediscovery timer pending flag */ |
| 3621 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3622 | /* FCF rediscovery event to worker thread */ |
| 3623 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3624 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3625 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3626 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3627 | /* wake up worker thread */ |
| 3628 | lpfc_worker_wake_up(phba); |
| 3629 | } |
| 3630 | |
| 3631 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3632 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3633 | * @phba: pointer to lpfc hba data structure. |
| 3634 | * @acqe_link: pointer to the async link completion queue entry. |
| 3635 | * |
| 3636 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3637 | * translate it into the base driver's read link attention mailbox command |
| 3638 | * status. |
| 3639 | * |
| 3640 | * Return: Link-attention status in terms of base driver's coding. |
| 3641 | **/ |
| 3642 | static uint16_t |
| 3643 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3644 | struct lpfc_acqe_link *acqe_link) |
| 3645 | { |
| 3646 | uint16_t latt_fault; |
| 3647 | |
| 3648 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3649 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3650 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3651 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3652 | latt_fault = 0; |
| 3653 | break; |
| 3654 | default: |
| 3655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3656 | "0398 Invalid link fault code: x%x\n", |
| 3657 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3658 | latt_fault = MBXERR_ERROR; |
| 3659 | break; |
| 3660 | } |
| 3661 | return latt_fault; |
| 3662 | } |
| 3663 | |
| 3664 | /** |
| 3665 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3666 | * @phba: pointer to lpfc hba data structure. |
| 3667 | * @acqe_link: pointer to the async link completion queue entry. |
| 3668 | * |
| 3669 | * This routine is to parse the SLI4 link attention type and translate it |
| 3670 | * into the base driver's link attention type coding. |
| 3671 | * |
| 3672 | * Return: Link attention type in terms of base driver's coding. |
| 3673 | **/ |
| 3674 | static uint8_t |
| 3675 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3676 | struct lpfc_acqe_link *acqe_link) |
| 3677 | { |
| 3678 | uint8_t att_type; |
| 3679 | |
| 3680 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3681 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3682 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3683 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3684 | break; |
| 3685 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3686 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3687 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3688 | break; |
| 3689 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3690 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3691 | break; |
| 3692 | default: |
| 3693 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3694 | "0399 Invalid link attention type: x%x\n", |
| 3695 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3696 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3697 | break; |
| 3698 | } |
| 3699 | return att_type; |
| 3700 | } |
| 3701 | |
| 3702 | /** |
| 3703 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3704 | * @phba: pointer to lpfc hba data structure. |
| 3705 | * @acqe_link: pointer to the async link completion queue entry. |
| 3706 | * |
| 3707 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3708 | * it into the base driver's link-attention link speed coding. |
| 3709 | * |
| 3710 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3711 | **/ |
| 3712 | static uint8_t |
| 3713 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3714 | struct lpfc_acqe_link *acqe_link) |
| 3715 | { |
| 3716 | uint8_t link_speed; |
| 3717 | |
| 3718 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3719 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3720 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3721 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3722 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3723 | break; |
| 3724 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3725 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3726 | break; |
| 3727 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3728 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3729 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3730 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 3731 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 3732 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 3733 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
| 3734 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3735 | default: |
| 3736 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3737 | "0483 Invalid link-attention link speed: x%x\n", |
| 3738 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3739 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3740 | break; |
| 3741 | } |
| 3742 | return link_speed; |
| 3743 | } |
| 3744 | |
| 3745 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3746 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 3747 | * @phba: pointer to lpfc hba data structure. |
| 3748 | * |
| 3749 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 3750 | * |
| 3751 | * Return: link speed in terms of Mbps. |
| 3752 | **/ |
| 3753 | uint32_t |
| 3754 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 3755 | { |
| 3756 | uint32_t link_speed; |
| 3757 | |
| 3758 | if (!lpfc_is_link_up(phba)) |
| 3759 | return 0; |
| 3760 | |
| 3761 | switch (phba->fc_linkspeed) { |
| 3762 | case LPFC_LINK_SPEED_1GHZ: |
| 3763 | link_speed = 1000; |
| 3764 | break; |
| 3765 | case LPFC_LINK_SPEED_2GHZ: |
| 3766 | link_speed = 2000; |
| 3767 | break; |
| 3768 | case LPFC_LINK_SPEED_4GHZ: |
| 3769 | link_speed = 4000; |
| 3770 | break; |
| 3771 | case LPFC_LINK_SPEED_8GHZ: |
| 3772 | link_speed = 8000; |
| 3773 | break; |
| 3774 | case LPFC_LINK_SPEED_10GHZ: |
| 3775 | link_speed = 10000; |
| 3776 | break; |
| 3777 | case LPFC_LINK_SPEED_16GHZ: |
| 3778 | link_speed = 16000; |
| 3779 | break; |
| 3780 | default: |
| 3781 | link_speed = 0; |
| 3782 | } |
| 3783 | return link_speed; |
| 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 3788 | * @phba: pointer to lpfc hba data structure. |
| 3789 | * @evt_code: asynchronous event code. |
| 3790 | * @speed_code: asynchronous event link speed code. |
| 3791 | * |
| 3792 | * This routine is to parse the giving SLI4 async event link speed code into |
| 3793 | * value of Mbps for the link speed. |
| 3794 | * |
| 3795 | * Return: link speed in terms of Mbps. |
| 3796 | **/ |
| 3797 | static uint32_t |
| 3798 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 3799 | uint8_t speed_code) |
| 3800 | { |
| 3801 | uint32_t port_speed; |
| 3802 | |
| 3803 | switch (evt_code) { |
| 3804 | case LPFC_TRAILER_CODE_LINK: |
| 3805 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3806 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3807 | port_speed = 0; |
| 3808 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3809 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3810 | port_speed = 10; |
| 3811 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3812 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3813 | port_speed = 100; |
| 3814 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3815 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3816 | port_speed = 1000; |
| 3817 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3818 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3819 | port_speed = 10000; |
| 3820 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3821 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 3822 | port_speed = 20000; |
| 3823 | break; |
| 3824 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 3825 | port_speed = 25000; |
| 3826 | break; |
| 3827 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 3828 | port_speed = 40000; |
| 3829 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3830 | default: |
| 3831 | port_speed = 0; |
| 3832 | } |
| 3833 | break; |
| 3834 | case LPFC_TRAILER_CODE_FC: |
| 3835 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3836 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3837 | port_speed = 0; |
| 3838 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3839 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3840 | port_speed = 1000; |
| 3841 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3842 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3843 | port_speed = 2000; |
| 3844 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3845 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3846 | port_speed = 4000; |
| 3847 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3848 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3849 | port_speed = 8000; |
| 3850 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3851 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3852 | port_speed = 10000; |
| 3853 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 3854 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3855 | port_speed = 16000; |
| 3856 | break; |
| 3857 | default: |
| 3858 | port_speed = 0; |
| 3859 | } |
| 3860 | break; |
| 3861 | default: |
| 3862 | port_speed = 0; |
| 3863 | } |
| 3864 | return port_speed; |
| 3865 | } |
| 3866 | |
| 3867 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3868 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3869 | * @phba: pointer to lpfc hba data structure. |
| 3870 | * @acqe_link: pointer to the async link completion queue entry. |
| 3871 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3872 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3873 | **/ |
| 3874 | static void |
| 3875 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3876 | struct lpfc_acqe_link *acqe_link) |
| 3877 | { |
| 3878 | struct lpfc_dmabuf *mp; |
| 3879 | LPFC_MBOXQ_t *pmb; |
| 3880 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3881 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3882 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3883 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3884 | |
| 3885 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3886 | 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] | 3887 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3888 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3889 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3890 | if (!pmb) { |
| 3891 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3892 | "0395 The mboxq allocation failed\n"); |
| 3893 | return; |
| 3894 | } |
| 3895 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3896 | if (!mp) { |
| 3897 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3898 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3899 | goto out_free_pmb; |
| 3900 | } |
| 3901 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3902 | if (!mp->virt) { |
| 3903 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3904 | "0397 The mbuf allocation failed\n"); |
| 3905 | goto out_free_dmabuf; |
| 3906 | } |
| 3907 | |
| 3908 | /* Cleanup any outstanding ELS commands */ |
| 3909 | lpfc_els_flush_all_cmd(phba); |
| 3910 | |
| 3911 | /* Block ELS IOCBs until we have done process link event */ |
| 3912 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3913 | |
| 3914 | /* Update link event statistics */ |
| 3915 | phba->sli.slistat.link_event++; |
| 3916 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3917 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3918 | lpfc_read_topology(phba, pmb, mp); |
| 3919 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3920 | pmb->vport = phba->pport; |
| 3921 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3922 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3923 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3924 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 3925 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3926 | phba->sli4_hba.link_state.duplex = |
| 3927 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3928 | phba->sli4_hba.link_state.status = |
| 3929 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3930 | phba->sli4_hba.link_state.type = |
| 3931 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3932 | phba->sli4_hba.link_state.number = |
| 3933 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3934 | phba->sli4_hba.link_state.fault = |
| 3935 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3936 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3937 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 3938 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3939 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3940 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3941 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3942 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3943 | phba->sli4_hba.link_state.speed, |
| 3944 | phba->sli4_hba.link_state.topology, |
| 3945 | phba->sli4_hba.link_state.status, |
| 3946 | phba->sli4_hba.link_state.type, |
| 3947 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3948 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3949 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3950 | /* |
| 3951 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3952 | * topology info. Note: Optional for non FC-AL ports. |
| 3953 | */ |
| 3954 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3955 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3956 | if (rc == MBX_NOT_FINISHED) |
| 3957 | goto out_free_dmabuf; |
| 3958 | return; |
| 3959 | } |
| 3960 | /* |
| 3961 | * For FCoE Mode: fill in all the topology information we need and call |
| 3962 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3963 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3964 | */ |
| 3965 | /* Parse and translate status field */ |
| 3966 | mb = &pmb->u.mb; |
| 3967 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3968 | |
| 3969 | /* Parse and translate link attention fields */ |
| 3970 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3971 | la->eventTag = acqe_link->event_tag; |
| 3972 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3973 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3974 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3975 | |
| 3976 | /* Fake the the following irrelvant fields */ |
| 3977 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3978 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3979 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3980 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3981 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3982 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3983 | |
| 3984 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3985 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3986 | |
| 3987 | return; |
| 3988 | |
| 3989 | out_free_dmabuf: |
| 3990 | kfree(mp); |
| 3991 | out_free_pmb: |
| 3992 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3993 | } |
| 3994 | |
| 3995 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3996 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3997 | * @phba: pointer to lpfc hba data structure. |
| 3998 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3999 | * |
| 4000 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 4001 | * that the event was received and then issue a read_topology mailbox command so |
| 4002 | * that the rest of the driver will treat it the same as SLI3. |
| 4003 | **/ |
| 4004 | static void |
| 4005 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 4006 | { |
| 4007 | struct lpfc_dmabuf *mp; |
| 4008 | LPFC_MBOXQ_t *pmb; |
| 4009 | int rc; |
| 4010 | |
| 4011 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 4012 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 4013 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4014 | "2895 Non FC link Event detected.(%d)\n", |
| 4015 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 4016 | return; |
| 4017 | } |
| 4018 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4019 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4020 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 4021 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4022 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 4023 | phba->sli4_hba.link_state.topology = |
| 4024 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 4025 | phba->sli4_hba.link_state.status = |
| 4026 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 4027 | phba->sli4_hba.link_state.type = |
| 4028 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 4029 | phba->sli4_hba.link_state.number = |
| 4030 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 4031 | phba->sli4_hba.link_state.fault = |
| 4032 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 4033 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4034 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4035 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4036 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 4037 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 4038 | "%dMbps Fault:%d\n", |
| 4039 | phba->sli4_hba.link_state.speed, |
| 4040 | phba->sli4_hba.link_state.topology, |
| 4041 | phba->sli4_hba.link_state.status, |
| 4042 | phba->sli4_hba.link_state.type, |
| 4043 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4044 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4045 | phba->sli4_hba.link_state.fault); |
| 4046 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4047 | if (!pmb) { |
| 4048 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4049 | "2897 The mboxq allocation failed\n"); |
| 4050 | return; |
| 4051 | } |
| 4052 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4053 | if (!mp) { |
| 4054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4055 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 4056 | goto out_free_pmb; |
| 4057 | } |
| 4058 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4059 | if (!mp->virt) { |
| 4060 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4061 | "2899 The mbuf allocation failed\n"); |
| 4062 | goto out_free_dmabuf; |
| 4063 | } |
| 4064 | |
| 4065 | /* Cleanup any outstanding ELS commands */ |
| 4066 | lpfc_els_flush_all_cmd(phba); |
| 4067 | |
| 4068 | /* Block ELS IOCBs until we have done process link event */ |
| 4069 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 4070 | |
| 4071 | /* Update link event statistics */ |
| 4072 | phba->sli.slistat.link_event++; |
| 4073 | |
| 4074 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4075 | lpfc_read_topology(phba, pmb, mp); |
| 4076 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 4077 | pmb->vport = phba->pport; |
| 4078 | |
| 4079 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4080 | if (rc == MBX_NOT_FINISHED) |
| 4081 | goto out_free_dmabuf; |
| 4082 | return; |
| 4083 | |
| 4084 | out_free_dmabuf: |
| 4085 | kfree(mp); |
| 4086 | out_free_pmb: |
| 4087 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 4092 | * @phba: pointer to lpfc hba data structure. |
| 4093 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 4094 | * |
| 4095 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 4096 | **/ |
| 4097 | static void |
| 4098 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 4099 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4100 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 4101 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4102 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4103 | uint8_t evt_type; |
| 4104 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4105 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4106 | struct Scsi_Host *shost; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4107 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4108 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 4109 | |
| 4110 | /* Special case Lancer */ |
| 4111 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 4112 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4113 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4114 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4115 | "x%08x SLI Event Type:%d\n", |
| 4116 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4117 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4118 | return; |
| 4119 | } |
| 4120 | |
| 4121 | port_name = phba->Port[0]; |
| 4122 | if (port_name == 0x00) |
| 4123 | port_name = '?'; /* get port name is empty */ |
| 4124 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4125 | switch (evt_type) { |
| 4126 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 4127 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4128 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 4129 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4130 | |
| 4131 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4132 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 4133 | acqe_sli->event_data1, port_name); |
| 4134 | |
| 4135 | shost = lpfc_shost_from_vport(phba->pport); |
| 4136 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4137 | sizeof(temp_event_data), |
| 4138 | (char *)&temp_event_data, |
| 4139 | SCSI_NL_VID_TYPE_PCI |
| 4140 | | PCI_VENDOR_ID_EMULEX); |
| 4141 | break; |
| 4142 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 4143 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4144 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 4145 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4146 | |
| 4147 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4148 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 4149 | acqe_sli->event_data1, port_name); |
| 4150 | |
| 4151 | shost = lpfc_shost_from_vport(phba->pport); |
| 4152 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4153 | sizeof(temp_event_data), |
| 4154 | (char *)&temp_event_data, |
| 4155 | SCSI_NL_VID_TYPE_PCI |
| 4156 | | PCI_VENDOR_ID_EMULEX); |
| 4157 | break; |
| 4158 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 4159 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4160 | &acqe_sli->event_data1; |
| 4161 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4162 | /* fetch the status for this port */ |
| 4163 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4164 | case LPFC_LINK_NUMBER_0: |
| 4165 | status = bf_get(lpfc_sli_misconfigured_port0, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4166 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4167 | break; |
| 4168 | case LPFC_LINK_NUMBER_1: |
| 4169 | status = bf_get(lpfc_sli_misconfigured_port1, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4170 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4171 | break; |
| 4172 | case LPFC_LINK_NUMBER_2: |
| 4173 | status = bf_get(lpfc_sli_misconfigured_port2, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4174 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4175 | break; |
| 4176 | case LPFC_LINK_NUMBER_3: |
| 4177 | status = bf_get(lpfc_sli_misconfigured_port3, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4178 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4179 | break; |
| 4180 | default: |
| 4181 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 4182 | break; |
| 4183 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4184 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4185 | switch (status) { |
| 4186 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 4187 | return; /* no message if the sfp is okay */ |
| 4188 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 4189 | sprintf(message, "Optics faulted/incorrectly " |
| 4190 | "installed/not installed - Reseat optics, " |
| 4191 | "if issue not resolved, replace."); |
| 4192 | break; |
| 4193 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 4194 | sprintf(message, |
| 4195 | "Optics of two types installed - Remove one " |
| 4196 | "optic or install matching pair of optics."); |
| 4197 | break; |
| 4198 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 4199 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4200 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4201 | break; |
| 4202 | default: |
| 4203 | /* firmware is reporting a status we don't know about */ |
| 4204 | sprintf(message, "Unknown event status x%02x", status); |
| 4205 | break; |
| 4206 | } |
| 4207 | |
| 4208 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4209 | "3176 Misconfigured Physical Port - " |
| 4210 | "Port Name %c %s\n", port_name, message); |
| 4211 | break; |
| 4212 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 4213 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4214 | "3192 Remote DPort Test Initiated - " |
| 4215 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 4216 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4217 | break; |
| 4218 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4219 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4220 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4221 | "x%08x SLI Event Type:%d\n", |
| 4222 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4223 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4224 | break; |
| 4225 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4229 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 4230 | * @vport: pointer to vport data structure. |
| 4231 | * |
| 4232 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 4233 | * response to a CVL event. |
| 4234 | * |
| 4235 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 4236 | * return NULL. |
| 4237 | **/ |
| 4238 | static struct lpfc_nodelist * |
| 4239 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 4240 | { |
| 4241 | struct lpfc_nodelist *ndlp; |
| 4242 | struct Scsi_Host *shost; |
| 4243 | struct lpfc_hba *phba; |
| 4244 | |
| 4245 | if (!vport) |
| 4246 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4247 | phba = vport->phba; |
| 4248 | if (!phba) |
| 4249 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4250 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4251 | if (!ndlp) { |
| 4252 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 4253 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4254 | if (!ndlp) |
| 4255 | return 0; |
| 4256 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 4257 | /* Set the node type */ |
| 4258 | ndlp->nlp_type |= NLP_FABRIC; |
| 4259 | /* Put ndlp onto node list */ |
| 4260 | lpfc_enqueue_node(vport, ndlp); |
| 4261 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4262 | /* re-setup ndlp without removing from node list */ |
| 4263 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4264 | if (!ndlp) |
| 4265 | return 0; |
| 4266 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4267 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4268 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4269 | return NULL; |
| 4270 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4271 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4272 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4273 | return NULL; |
| 4274 | shost = lpfc_shost_from_vport(vport); |
| 4275 | if (!shost) |
| 4276 | return NULL; |
| 4277 | lpfc_linkdown_port(vport); |
| 4278 | lpfc_cleanup_pending_mbox(vport); |
| 4279 | spin_lock_irq(shost->host_lock); |
| 4280 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4281 | spin_unlock_irq(shost->host_lock); |
| 4282 | |
| 4283 | return ndlp; |
| 4284 | } |
| 4285 | |
| 4286 | /** |
| 4287 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4288 | * @vport: pointer to lpfc hba data structure. |
| 4289 | * |
| 4290 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4291 | * response to a FCF dead event. |
| 4292 | **/ |
| 4293 | static void |
| 4294 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4295 | { |
| 4296 | struct lpfc_vport **vports; |
| 4297 | int i; |
| 4298 | |
| 4299 | vports = lpfc_create_vport_work_array(phba); |
| 4300 | if (vports) |
| 4301 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4302 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4303 | lpfc_destroy_vport_work_array(phba, vports); |
| 4304 | } |
| 4305 | |
| 4306 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4307 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4308 | * @phba: pointer to lpfc hba data structure. |
| 4309 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4310 | * |
| 4311 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4312 | **/ |
| 4313 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4314 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4315 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4316 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4317 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4318 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4319 | struct lpfc_vport *vport; |
| 4320 | struct lpfc_nodelist *ndlp; |
| 4321 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4322 | int active_vlink_present; |
| 4323 | struct lpfc_vport **vports; |
| 4324 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4325 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4326 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4327 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4328 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4329 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4330 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4331 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4332 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4333 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4334 | "2546 New FCF event, evt_tag:x%x, " |
| 4335 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4336 | acqe_fip->event_tag, |
| 4337 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4338 | else |
| 4339 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4340 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4341 | "2788 FCF param modified event, " |
| 4342 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4343 | acqe_fip->event_tag, |
| 4344 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4345 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4346 | /* |
| 4347 | * During period of FCF discovery, read the FCF |
| 4348 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4349 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4350 | */ |
| 4351 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4352 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4353 | "2779 Read FCF (x%x) for updating " |
| 4354 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4355 | acqe_fip->index); |
| 4356 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4357 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4358 | |
| 4359 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4360 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4361 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4362 | spin_unlock_irq(&phba->hbalock); |
| 4363 | break; |
| 4364 | } |
| 4365 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 4366 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 4367 | spin_unlock_irq(&phba->hbalock); |
| 4368 | break; |
| 4369 | } |
| 4370 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4371 | /* If the FCF has been in discovered state, do nothing. */ |
| 4372 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4373 | spin_unlock_irq(&phba->hbalock); |
| 4374 | break; |
| 4375 | } |
| 4376 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4377 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4378 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 4379 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4380 | "2770 Start FCF table scan per async FCF " |
| 4381 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4382 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4383 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 4384 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4385 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4386 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4387 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4388 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4389 | break; |
| 4390 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4391 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4392 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4393 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4394 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 4395 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4396 | break; |
| 4397 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4398 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4399 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4400 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4401 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4402 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4403 | /* |
| 4404 | * If we are in the middle of FCF failover process, clear |
| 4405 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4406 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4407 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4408 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4409 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4410 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4411 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4412 | break; |
| 4413 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4414 | spin_unlock_irq(&phba->hbalock); |
| 4415 | |
| 4416 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4417 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4418 | break; |
| 4419 | |
| 4420 | /* |
| 4421 | * Otherwise, request the port to rediscover the entire FCF |
| 4422 | * table for a fast recovery from case that the current FCF |
| 4423 | * is no longer valid as we are not in the middle of FCF |
| 4424 | * failover process already. |
| 4425 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4426 | spin_lock_irq(&phba->hbalock); |
| 4427 | /* Mark the fast failover process in progress */ |
| 4428 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 4429 | spin_unlock_irq(&phba->hbalock); |
| 4430 | |
| 4431 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4432 | "2771 Start FCF fast failover process due to " |
| 4433 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 4434 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 4435 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4436 | if (rc) { |
| 4437 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4438 | LOG_DISCOVERY, |
| 4439 | "2772 Issue FCF rediscover mabilbox " |
| 4440 | "command failed, fail through to FCF " |
| 4441 | "dead event\n"); |
| 4442 | spin_lock_irq(&phba->hbalock); |
| 4443 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 4444 | spin_unlock_irq(&phba->hbalock); |
| 4445 | /* |
| 4446 | * Last resort will fail over by treating this |
| 4447 | * as a link down to FCF registration. |
| 4448 | */ |
| 4449 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 4450 | } else { |
| 4451 | /* Reset FCF roundrobin bmask for new discovery */ |
| 4452 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 4453 | /* |
| 4454 | * Handling fast FCF failover to a DEAD FCF event is |
| 4455 | * considered equalivant to receiving CVL to all vports. |
| 4456 | */ |
| 4457 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 4458 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4459 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4460 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4461 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4462 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4463 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4464 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4465 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4466 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4467 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4468 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4469 | if (!ndlp) |
| 4470 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4471 | active_vlink_present = 0; |
| 4472 | |
| 4473 | vports = lpfc_create_vport_work_array(phba); |
| 4474 | if (vports) { |
| 4475 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4476 | i++) { |
| 4477 | if ((!(vports[i]->fc_flag & |
| 4478 | FC_VPORT_CVL_RCVD)) && |
| 4479 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4480 | active_vlink_present = 1; |
| 4481 | break; |
| 4482 | } |
| 4483 | } |
| 4484 | lpfc_destroy_vport_work_array(phba, vports); |
| 4485 | } |
| 4486 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 4487 | /* |
| 4488 | * Don't re-instantiate if vport is marked for deletion. |
| 4489 | * If we are here first then vport_delete is going to wait |
| 4490 | * for discovery to complete. |
| 4491 | */ |
| 4492 | if (!(vport->load_flag & FC_UNLOADING) && |
| 4493 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4494 | /* |
| 4495 | * If there are other active VLinks present, |
| 4496 | * re-instantiate the Vlink using FDISC. |
| 4497 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4498 | mod_timer(&ndlp->nlp_delayfunc, |
| 4499 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4500 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4501 | spin_lock_irq(shost->host_lock); |
| 4502 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4503 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4504 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4505 | vport->port_state = LPFC_FDISC; |
| 4506 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4507 | /* |
| 4508 | * Otherwise, we request port to rediscover |
| 4509 | * the entire FCF table for a fast recovery |
| 4510 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4511 | * is no longer valid if we are not already |
| 4512 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4513 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4514 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4515 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4516 | spin_unlock_irq(&phba->hbalock); |
| 4517 | break; |
| 4518 | } |
| 4519 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4520 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4521 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4522 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4523 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4524 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4525 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4526 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4527 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4528 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4529 | LOG_DISCOVERY, |
| 4530 | "2774 Issue FCF rediscover " |
| 4531 | "mabilbox command failed, " |
| 4532 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4533 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4534 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4535 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4536 | /* |
| 4537 | * Last resort will be re-try on the |
| 4538 | * the current registered FCF entry. |
| 4539 | */ |
| 4540 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4541 | } else |
| 4542 | /* |
| 4543 | * Reset FCF roundrobin bmask for new |
| 4544 | * discovery. |
| 4545 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4546 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4547 | } |
| 4548 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4549 | default: |
| 4550 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4551 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4552 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4553 | break; |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4559 | * @phba: pointer to lpfc hba data structure. |
| 4560 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4561 | * |
| 4562 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4563 | **/ |
| 4564 | static void |
| 4565 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4566 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4567 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4568 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4569 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4570 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4571 | "handled yet\n"); |
| 4572 | } |
| 4573 | |
| 4574 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4575 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4576 | * @phba: pointer to lpfc hba data structure. |
| 4577 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4578 | * |
| 4579 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4580 | * is an asynchronous notified of a logical link speed change. The Port |
| 4581 | * reports the logical link speed in units of 10Mbps. |
| 4582 | **/ |
| 4583 | static void |
| 4584 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4585 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4586 | { |
| 4587 | uint16_t prev_ll_spd; |
| 4588 | |
| 4589 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4590 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4591 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4592 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4593 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4594 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4595 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4596 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 4597 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4601 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4602 | * @phba: pointer to lpfc hba data structure. |
| 4603 | * |
| 4604 | * This routine is invoked by the worker thread to process all the pending |
| 4605 | * SLI4 asynchronous events. |
| 4606 | **/ |
| 4607 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4608 | { |
| 4609 | struct lpfc_cq_event *cq_event; |
| 4610 | |
| 4611 | /* First, declare the async event has been handled */ |
| 4612 | spin_lock_irq(&phba->hbalock); |
| 4613 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4614 | spin_unlock_irq(&phba->hbalock); |
| 4615 | /* Now, handle all the async events */ |
| 4616 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4617 | /* Get the first event from the head of the event queue */ |
| 4618 | spin_lock_irq(&phba->hbalock); |
| 4619 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4620 | cq_event, struct lpfc_cq_event, list); |
| 4621 | spin_unlock_irq(&phba->hbalock); |
| 4622 | /* Process the asynchronous event */ |
| 4623 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4624 | case LPFC_TRAILER_CODE_LINK: |
| 4625 | lpfc_sli4_async_link_evt(phba, |
| 4626 | &cq_event->cqe.acqe_link); |
| 4627 | break; |
| 4628 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4629 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4630 | break; |
| 4631 | case LPFC_TRAILER_CODE_DCBX: |
| 4632 | lpfc_sli4_async_dcbx_evt(phba, |
| 4633 | &cq_event->cqe.acqe_dcbx); |
| 4634 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4635 | case LPFC_TRAILER_CODE_GRP5: |
| 4636 | lpfc_sli4_async_grp5_evt(phba, |
| 4637 | &cq_event->cqe.acqe_grp5); |
| 4638 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4639 | case LPFC_TRAILER_CODE_FC: |
| 4640 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4641 | break; |
| 4642 | case LPFC_TRAILER_CODE_SLI: |
| 4643 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4644 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4645 | default: |
| 4646 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4647 | "1804 Invalid asynchrous event code: " |
| 4648 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4649 | &cq_event->cqe.mcqe_cmpl)); |
| 4650 | break; |
| 4651 | } |
| 4652 | /* Free the completion event processed to the free pool */ |
| 4653 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4658 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4659 | * @phba: pointer to lpfc hba data structure. |
| 4660 | * |
| 4661 | * This routine is invoked by the worker thread to process FCF table |
| 4662 | * rediscovery pending completion event. |
| 4663 | **/ |
| 4664 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4665 | { |
| 4666 | int rc; |
| 4667 | |
| 4668 | spin_lock_irq(&phba->hbalock); |
| 4669 | /* Clear FCF rediscovery timeout event */ |
| 4670 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4671 | /* Clear driver fast failover FCF record flag */ |
| 4672 | phba->fcf.failover_rec.flag = 0; |
| 4673 | /* Set state for FCF fast failover */ |
| 4674 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4675 | spin_unlock_irq(&phba->hbalock); |
| 4676 | |
| 4677 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4678 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4679 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4680 | 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] | 4681 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4682 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4683 | "2747 Issue FCF scan read FCF mailbox " |
| 4684 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4688 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4689 | * @phba: pointer to lpfc hba data structure. |
| 4690 | * @dev_grp: The HBA PCI-Device group number. |
| 4691 | * |
| 4692 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4693 | * API jump table entries. |
| 4694 | * |
| 4695 | * Return: 0 if success, otherwise -ENODEV |
| 4696 | **/ |
| 4697 | int |
| 4698 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4699 | { |
| 4700 | int rc; |
| 4701 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4702 | /* Set up lpfc PCI-device group */ |
| 4703 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4704 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4706 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4707 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4708 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4709 | /* Set up device INIT API function jump table */ |
| 4710 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4711 | if (rc) |
| 4712 | return -ENODEV; |
| 4713 | /* Set up SCSI API function jump table */ |
| 4714 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4715 | if (rc) |
| 4716 | return -ENODEV; |
| 4717 | /* Set up SLI API function jump table */ |
| 4718 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4719 | if (rc) |
| 4720 | return -ENODEV; |
| 4721 | /* Set up MBOX API function jump table */ |
| 4722 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4723 | if (rc) |
| 4724 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4725 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4726 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4730 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4731 | * @phba: pointer to lpfc hba data structure. |
| 4732 | * @intr_mode: active interrupt mode adopted. |
| 4733 | * |
| 4734 | * This routine it invoked to log the currently used active interrupt mode |
| 4735 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4736 | **/ |
| 4737 | 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] | 4738 | { |
| 4739 | switch (intr_mode) { |
| 4740 | case 0: |
| 4741 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4742 | "0470 Enable INTx interrupt mode.\n"); |
| 4743 | break; |
| 4744 | case 1: |
| 4745 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4746 | "0481 Enabled MSI interrupt mode.\n"); |
| 4747 | break; |
| 4748 | case 2: |
| 4749 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4750 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4751 | break; |
| 4752 | default: |
| 4753 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4754 | "0482 Illegal interrupt mode.\n"); |
| 4755 | break; |
| 4756 | } |
| 4757 | return; |
| 4758 | } |
| 4759 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4760 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4761 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4762 | * @phba: pointer to lpfc hba data structure. |
| 4763 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4764 | * This routine is invoked to enable the PCI device that is common to all |
| 4765 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4766 | * |
| 4767 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4768 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4769 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4770 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4771 | static int |
| 4772 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4773 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4774 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4775 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4776 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4777 | /* Obtain PCI device reference */ |
| 4778 | if (!phba->pcidev) |
| 4779 | goto out_error; |
| 4780 | else |
| 4781 | pdev = phba->pcidev; |
| 4782 | /* Select PCI BARs */ |
| 4783 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4784 | /* Enable PCI device */ |
| 4785 | if (pci_enable_device_mem(pdev)) |
| 4786 | goto out_error; |
| 4787 | /* Request PCI resource for the device */ |
| 4788 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4789 | goto out_disable_device; |
| 4790 | /* Set up device as PCI master and save state for EEH */ |
| 4791 | pci_set_master(pdev); |
| 4792 | pci_try_set_mwi(pdev); |
| 4793 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4794 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4795 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 4796 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4797 | pdev->needs_freset = 1; |
| 4798 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4799 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4800 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4801 | out_disable_device: |
| 4802 | pci_disable_device(pdev); |
| 4803 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4804 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4805 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4806 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4810 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4811 | * @phba: pointer to lpfc hba data structure. |
| 4812 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4813 | * This routine is invoked to disable the PCI device that is common to all |
| 4814 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4815 | **/ |
| 4816 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4817 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4818 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4819 | struct pci_dev *pdev; |
| 4820 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4821 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4822 | /* Obtain PCI device reference */ |
| 4823 | if (!phba->pcidev) |
| 4824 | return; |
| 4825 | else |
| 4826 | pdev = phba->pcidev; |
| 4827 | /* Select PCI BARs */ |
| 4828 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4829 | /* Release PCI resource and disable PCI device */ |
| 4830 | pci_release_selected_regions(pdev, bars); |
| 4831 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4832 | |
| 4833 | return; |
| 4834 | } |
| 4835 | |
| 4836 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4837 | * lpfc_reset_hba - Reset a hba |
| 4838 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4839 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4840 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4841 | * offline, performs a board restart, and then brings the board back |
| 4842 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4843 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4844 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4845 | void |
| 4846 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4848 | /* If resets are disabled then set error state and return. */ |
| 4849 | if (!phba->cfg_enable_hba_reset) { |
| 4850 | phba->link_state = LPFC_HBA_ERROR; |
| 4851 | return; |
| 4852 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4853 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 4854 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 4855 | else |
| 4856 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4857 | lpfc_offline(phba); |
| 4858 | lpfc_sli_brdrestart(phba); |
| 4859 | lpfc_online(phba); |
| 4860 | lpfc_unblock_mgmt_io(phba); |
| 4861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4862 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4863 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4864 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4865 | * @phba: pointer to lpfc hba data structure. |
| 4866 | * |
| 4867 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4868 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4869 | * enable the number of virtual functions to the physical function. As |
| 4870 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4871 | * API call does not considered as an error condition for most of the device. |
| 4872 | **/ |
| 4873 | uint16_t |
| 4874 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4875 | { |
| 4876 | struct pci_dev *pdev = phba->pcidev; |
| 4877 | uint16_t nr_virtfn; |
| 4878 | int pos; |
| 4879 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4880 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4881 | if (pos == 0) |
| 4882 | return 0; |
| 4883 | |
| 4884 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4885 | return nr_virtfn; |
| 4886 | } |
| 4887 | |
| 4888 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4889 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4890 | * @phba: pointer to lpfc hba data structure. |
| 4891 | * @nr_vfn: number of virtual functions to be enabled. |
| 4892 | * |
| 4893 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4894 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4895 | * enable the number of virtual functions to the physical function. As |
| 4896 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4897 | * API call does not considered as an error condition for most of the device. |
| 4898 | **/ |
| 4899 | int |
| 4900 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4901 | { |
| 4902 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4903 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4904 | int rc; |
| 4905 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4906 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4907 | if (nr_vfn > max_nr_vfn) { |
| 4908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4909 | "3057 Requested vfs (%d) greater than " |
| 4910 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4911 | return -EINVAL; |
| 4912 | } |
| 4913 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4914 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4915 | if (rc) { |
| 4916 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4917 | "2806 Failed to enable sriov on this device " |
| 4918 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4919 | nr_vfn, rc); |
| 4920 | } else |
| 4921 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4922 | "2807 Successful enable sriov on this device " |
| 4923 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4924 | return rc; |
| 4925 | } |
| 4926 | |
| 4927 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4928 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4929 | * @phba: pointer to lpfc hba data structure. |
| 4930 | * |
| 4931 | * This routine is invoked to set up the driver internal resources specific to |
| 4932 | * support the SLI-3 HBA device it attached to. |
| 4933 | * |
| 4934 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4935 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4936 | * other values - error |
| 4937 | **/ |
| 4938 | static int |
| 4939 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4940 | { |
| 4941 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4942 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4944 | /* |
| 4945 | * Initialize timers used by driver |
| 4946 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4947 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4948 | /* Heartbeat timer */ |
| 4949 | init_timer(&phba->hb_tmofunc); |
| 4950 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4951 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4952 | |
| 4953 | psli = &phba->sli; |
| 4954 | /* MBOX heartbeat timer */ |
| 4955 | init_timer(&psli->mbox_tmo); |
| 4956 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4957 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4958 | /* FCP polling mode timer */ |
| 4959 | init_timer(&phba->fcp_poll_timer); |
| 4960 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4961 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4962 | /* Fabric block timer */ |
| 4963 | init_timer(&phba->fabric_block_timer); |
| 4964 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4965 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4966 | /* EA polling mode timer */ |
| 4967 | init_timer(&phba->eratt_poll); |
| 4968 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4969 | phba->eratt_poll.data = (unsigned long) phba; |
| 4970 | |
| 4971 | /* Host attention work mask setup */ |
| 4972 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4973 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4974 | |
| 4975 | /* Get all the module params for configuring this host */ |
| 4976 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4977 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4978 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4979 | /* check for menlo minimum sg count */ |
| 4980 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4981 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4982 | } |
| 4983 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4984 | if (!phba->sli.ring) |
Firo Yang | c6cb9b4 | 2015-08-31 16:48:09 -0400 | [diff] [blame] | 4985 | phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4986 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4987 | if (!phba->sli.ring) |
| 4988 | return -ENOMEM; |
| 4989 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4990 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4991 | * 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] | 4992 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4993 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4994 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4995 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4996 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
Bodo Stroesser | 5f406fa | 2015-08-31 16:48:10 -0400 | [diff] [blame] | 4997 | lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4998 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4999 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 5000 | if (phba->cfg_enable_bg) { |
| 5001 | /* |
| 5002 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5003 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 5004 | * over how many protection data segments the SCSI Layer |
| 5005 | * will hand us (ie: there could be one for every block |
| 5006 | * in the IO), we just allocate enough BDEs to accomidate |
| 5007 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5008 | * minimize the risk of running out. |
| 5009 | */ |
| 5010 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5011 | sizeof(struct fcp_rsp) + |
| 5012 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 5013 | |
| 5014 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 5015 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 5016 | |
| 5017 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 5018 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 5019 | } else { |
| 5020 | /* |
| 5021 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5022 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 5023 | * cfg_sg_seg_cnt data segments. |
| 5024 | */ |
| 5025 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5026 | sizeof(struct fcp_rsp) + |
| 5027 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 5028 | |
| 5029 | /* Total BDEs in BPL for scsi_sg_list */ |
| 5030 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5031 | } |
| 5032 | |
| 5033 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5034 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 5035 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5036 | phba->cfg_total_seg_cnt); |
| 5037 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5038 | phba->max_vpi = LPFC_MAX_VPI; |
| 5039 | /* This will be set to correct value after config_port mbox */ |
| 5040 | phba->max_vports = 0; |
| 5041 | |
| 5042 | /* |
| 5043 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 5044 | */ |
| 5045 | lpfc_sli_setup(phba); |
| 5046 | lpfc_sli_queue_setup(phba); |
| 5047 | |
| 5048 | /* Allocate device driver memory */ |
| 5049 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 5050 | return -ENOMEM; |
| 5051 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5052 | /* |
| 5053 | * Enable sr-iov virtual functions if supported and configured |
| 5054 | * through the module parameter. |
| 5055 | */ |
| 5056 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5057 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5058 | phba->cfg_sriov_nr_virtfn); |
| 5059 | if (rc) { |
| 5060 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5061 | "2808 Requested number of SR-IOV " |
| 5062 | "virtual functions (%d) is not " |
| 5063 | "supported\n", |
| 5064 | phba->cfg_sriov_nr_virtfn); |
| 5065 | phba->cfg_sriov_nr_virtfn = 0; |
| 5066 | } |
| 5067 | } |
| 5068 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5069 | return 0; |
| 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 5074 | * @phba: pointer to lpfc hba data structure. |
| 5075 | * |
| 5076 | * This routine is invoked to unset the driver internal resources set up |
| 5077 | * specific for supporting the SLI-3 HBA device it attached to. |
| 5078 | **/ |
| 5079 | static void |
| 5080 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 5081 | { |
| 5082 | /* Free device driver memory allocated */ |
| 5083 | lpfc_mem_free_all(phba); |
| 5084 | |
| 5085 | return; |
| 5086 | } |
| 5087 | |
| 5088 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5089 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 5090 | * @phba: pointer to lpfc hba data structure. |
| 5091 | * |
| 5092 | * This routine is invoked to set up the driver internal resources specific to |
| 5093 | * support the SLI-4 HBA device it attached to. |
| 5094 | * |
| 5095 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5096 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5097 | * other values - error |
| 5098 | **/ |
| 5099 | static int |
| 5100 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 5101 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5102 | struct lpfc_vector_map_info *cpup; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5103 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5104 | LPFC_MBOXQ_t *mboxq; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5105 | int rc, i, hbq_count, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5106 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 5107 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5108 | int longs; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5109 | int fof_vectors = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5110 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 5111 | /* Get all the module params for configuring this host */ |
| 5112 | lpfc_get_cfgparam(phba); |
| 5113 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5114 | /* Before proceed, wait for POST done and device ready */ |
| 5115 | rc = lpfc_sli4_post_status_check(phba); |
| 5116 | if (rc) |
| 5117 | return -ENODEV; |
| 5118 | |
| 5119 | /* |
| 5120 | * Initialize timers used by driver |
| 5121 | */ |
| 5122 | |
| 5123 | /* Heartbeat timer */ |
| 5124 | init_timer(&phba->hb_tmofunc); |
| 5125 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 5126 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 5127 | init_timer(&phba->rrq_tmr); |
| 5128 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 5129 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5130 | |
| 5131 | psli = &phba->sli; |
| 5132 | /* MBOX heartbeat timer */ |
| 5133 | init_timer(&psli->mbox_tmo); |
| 5134 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 5135 | psli->mbox_tmo.data = (unsigned long) phba; |
| 5136 | /* Fabric block timer */ |
| 5137 | init_timer(&phba->fabric_block_timer); |
| 5138 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 5139 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 5140 | /* EA polling mode timer */ |
| 5141 | init_timer(&phba->eratt_poll); |
| 5142 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 5143 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5144 | /* FCF rediscover timer */ |
| 5145 | init_timer(&phba->fcf.redisc_wait); |
| 5146 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 5147 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 5148 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5149 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5150 | * Control structure for handling external multi-buffer mailbox |
| 5151 | * command pass-through. |
| 5152 | */ |
| 5153 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 5154 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 5155 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 5156 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5157 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5158 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5159 | /* This will be set to correct value after the read_config mbox */ |
| 5160 | phba->max_vports = 0; |
| 5161 | |
| 5162 | /* Program the default value of vlan_id and fc_map */ |
| 5163 | phba->valid_vlan = 0; |
| 5164 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5165 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5166 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5167 | |
| 5168 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5169 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 5170 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 5171 | */ |
| 5172 | if (!phba->sli.ring) |
| 5173 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5174 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5175 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 5176 | if (!phba->sli.ring) |
| 5177 | return -ENOMEM; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5178 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5179 | /* |
| 5180 | * It doesn't matter what family our adapter is in, we are |
| 5181 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 5182 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 5183 | */ |
| 5184 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 5185 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) |
| 5186 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5187 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5188 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5189 | * 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] | 5190 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5191 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5192 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5193 | if (phba->cfg_enable_bg) { |
| 5194 | /* |
| 5195 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5196 | * the FCP rsp, and a SGE for each. Sice we have no control |
| 5197 | * over how many protection data segments the SCSI Layer |
| 5198 | * will hand us (ie: there could be one for every block |
| 5199 | * in the IO), we just allocate enough SGEs to accomidate |
| 5200 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5201 | * minimize the risk of running out. |
| 5202 | */ |
| 5203 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5204 | sizeof(struct fcp_rsp) + max_buf_size; |
| 5205 | |
| 5206 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 5207 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 5208 | |
| 5209 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
| 5210 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
| 5211 | } else { |
| 5212 | /* |
| 5213 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5214 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 5215 | * cfg_sg_seg_cnt data segments. |
| 5216 | */ |
| 5217 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5218 | sizeof(struct fcp_rsp) + |
| 5219 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); |
| 5220 | |
| 5221 | /* Total SGEs for scsi_sg_list */ |
| 5222 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5223 | /* |
| 5224 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need |
| 5225 | * to post 1 page for the SGL. |
| 5226 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5227 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5228 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5229 | /* Initialize the host templates with the updated values. */ |
| 5230 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5231 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5232 | |
| 5233 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5234 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5235 | else |
| 5236 | phba->cfg_sg_dma_buf_size = |
| 5237 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5238 | |
| 5239 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5240 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5241 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5242 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5243 | |
| 5244 | /* Initialize buffer queue management fields */ |
| 5245 | hbq_count = lpfc_sli_hbq_count(); |
| 5246 | for (i = 0; i < hbq_count; ++i) |
| 5247 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5248 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5249 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5250 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5251 | |
| 5252 | /* |
| 5253 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5254 | */ |
| 5255 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5256 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5257 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5258 | /* This abort list used by worker thread */ |
| 5259 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 5260 | |
| 5261 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5262 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5263 | */ |
| 5264 | |
| 5265 | /* Driver internel slow-path CQ Event pool */ |
| 5266 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5267 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5268 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5269 | /* Asynchronous event CQ Event work queue list */ |
| 5270 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5271 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5272 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5273 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5274 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5275 | /* Receive queue CQ Event work queue list */ |
| 5276 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5277 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5278 | /* Initialize extent block lists. */ |
| 5279 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 5280 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 5281 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 5282 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 5283 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5284 | /* Initialize the driver internal SLI layer lists. */ |
| 5285 | lpfc_sli_setup(phba); |
| 5286 | lpfc_sli_queue_setup(phba); |
| 5287 | |
| 5288 | /* Allocate device driver memory */ |
| 5289 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 5290 | if (rc) |
| 5291 | return -ENOMEM; |
| 5292 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5293 | /* IF Type 2 ports get initialized now. */ |
| 5294 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5295 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 5296 | rc = lpfc_pci_function_reset(phba); |
| 5297 | if (unlikely(rc)) |
| 5298 | return -ENODEV; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5299 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5300 | } |
| 5301 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5302 | /* Create the bootstrap mailbox command */ |
| 5303 | rc = lpfc_create_bootstrap_mbox(phba); |
| 5304 | if (unlikely(rc)) |
| 5305 | goto out_free_mem; |
| 5306 | |
| 5307 | /* Set up the host's endian order with the device. */ |
| 5308 | rc = lpfc_setup_endian_order(phba); |
| 5309 | if (unlikely(rc)) |
| 5310 | goto out_free_bsmbx; |
| 5311 | |
| 5312 | /* Set up the hba's configuration parameters. */ |
| 5313 | rc = lpfc_sli4_read_config(phba); |
| 5314 | if (unlikely(rc)) |
| 5315 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5316 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 5317 | if (unlikely(rc)) |
| 5318 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5319 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5320 | /* IF Type 0 ports get initialized now. */ |
| 5321 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5322 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 5323 | rc = lpfc_pci_function_reset(phba); |
| 5324 | if (unlikely(rc)) |
| 5325 | goto out_free_bsmbx; |
| 5326 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5327 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5328 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 5329 | GFP_KERNEL); |
| 5330 | if (!mboxq) { |
| 5331 | rc = -ENOMEM; |
| 5332 | goto out_free_bsmbx; |
| 5333 | } |
| 5334 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5335 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5336 | lpfc_supported_pages(mboxq); |
| 5337 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5338 | if (!rc) { |
| 5339 | mqe = &mboxq->u.mqe; |
| 5340 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 5341 | LPFC_MAX_SUPPORTED_PAGES); |
| 5342 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 5343 | switch (pn_page[i]) { |
| 5344 | case LPFC_SLI4_PARAMETERS: |
| 5345 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 5346 | break; |
| 5347 | default: |
| 5348 | break; |
| 5349 | } |
| 5350 | } |
| 5351 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 5352 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 5353 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 5354 | if (rc) { |
| 5355 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5356 | rc = -EIO; |
| 5357 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5358 | } |
| 5359 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5360 | /* |
| 5361 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5362 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 5363 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5364 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5365 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 5366 | if (rc) { |
| 5367 | if (phba->sli4_hba.extents_in_use && |
| 5368 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 5369 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5370 | "2999 Unsupported SLI4 Parameters " |
| 5371 | "Extents and RPI headers enabled.\n"); |
| 5372 | goto out_free_bsmbx; |
| 5373 | } |
| 5374 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5375 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5376 | |
| 5377 | /* Verify OAS is supported */ |
| 5378 | lpfc_sli4_oas_verify(phba); |
| 5379 | if (phba->cfg_fof) |
| 5380 | fof_vectors = 1; |
| 5381 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5382 | /* Verify all the SLI4 queues */ |
| 5383 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5384 | if (rc) |
| 5385 | goto out_free_bsmbx; |
| 5386 | |
| 5387 | /* Create driver internal CQE event pool */ |
| 5388 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 5389 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5390 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5391 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5392 | /* Initialize sgl lists per host */ |
| 5393 | lpfc_init_sgl_list(phba); |
| 5394 | |
| 5395 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5396 | rc = lpfc_init_active_sgl_array(phba); |
| 5397 | if (rc) { |
| 5398 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5399 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5400 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5401 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5402 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 5403 | if (rc) { |
| 5404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5405 | "1432 Failed to initialize rpi headers.\n"); |
| 5406 | goto out_free_active_sgl; |
| 5407 | } |
| 5408 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5409 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5410 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 5411 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 5412 | GFP_KERNEL); |
| 5413 | if (!phba->fcf.fcf_rr_bmask) { |
| 5414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5415 | "2759 Failed allocate memory for FCF round " |
| 5416 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5417 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5418 | goto out_remove_rpi_hdrs; |
| 5419 | } |
| 5420 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5421 | phba->sli4_hba.fcp_eq_hdl = |
| 5422 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5423 | (fof_vectors + phba->cfg_fcp_io_channel)), |
| 5424 | GFP_KERNEL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5425 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 5426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5427 | "2572 Failed allocate memory for " |
| 5428 | "fast-path per-EQ handle array\n"); |
| 5429 | rc = -ENOMEM; |
| 5430 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5434 | (fof_vectors + |
| 5435 | phba->cfg_fcp_io_channel)), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5436 | if (!phba->sli4_hba.msix_entries) { |
| 5437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5438 | "2573 Failed allocate memory for msi-x " |
| 5439 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5440 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5441 | goto out_free_fcp_eq_hdl; |
| 5442 | } |
| 5443 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5444 | phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) * |
| 5445 | phba->sli4_hba.num_present_cpu), |
| 5446 | GFP_KERNEL); |
| 5447 | if (!phba->sli4_hba.cpu_map) { |
| 5448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5449 | "3327 Failed allocate memory for msi-x " |
| 5450 | "interrupt vector mapping\n"); |
| 5451 | rc = -ENOMEM; |
| 5452 | goto out_free_msix; |
| 5453 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 5454 | if (lpfc_used_cpu == NULL) { |
| 5455 | lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu), |
| 5456 | GFP_KERNEL); |
| 5457 | if (!lpfc_used_cpu) { |
| 5458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5459 | "3335 Failed allocate memory for msi-x " |
| 5460 | "interrupt vector mapping\n"); |
| 5461 | kfree(phba->sli4_hba.cpu_map); |
| 5462 | rc = -ENOMEM; |
| 5463 | goto out_free_msix; |
| 5464 | } |
| 5465 | for (i = 0; i < lpfc_present_cpu; i++) |
| 5466 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 5467 | } |
| 5468 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5469 | /* Initialize io channels for round robin */ |
| 5470 | cpup = phba->sli4_hba.cpu_map; |
| 5471 | rc = 0; |
| 5472 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 5473 | cpup->channel_id = rc; |
| 5474 | rc++; |
| 5475 | if (rc >= phba->cfg_fcp_io_channel) |
| 5476 | rc = 0; |
| 5477 | } |
| 5478 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5479 | /* |
| 5480 | * Enable sr-iov virtual functions if supported and configured |
| 5481 | * through the module parameter. |
| 5482 | */ |
| 5483 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5484 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5485 | phba->cfg_sriov_nr_virtfn); |
| 5486 | if (rc) { |
| 5487 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5488 | "3020 Requested number of SR-IOV " |
| 5489 | "virtual functions (%d) is not " |
| 5490 | "supported\n", |
| 5491 | phba->cfg_sriov_nr_virtfn); |
| 5492 | phba->cfg_sriov_nr_virtfn = 0; |
| 5493 | } |
| 5494 | } |
| 5495 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5496 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5497 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5498 | out_free_msix: |
| 5499 | kfree(phba->sli4_hba.msix_entries); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5500 | out_free_fcp_eq_hdl: |
| 5501 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5502 | out_free_fcf_rr_bmask: |
| 5503 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5504 | out_remove_rpi_hdrs: |
| 5505 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 5506 | out_free_active_sgl: |
| 5507 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5508 | out_destroy_cq_event_pool: |
| 5509 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5510 | out_free_bsmbx: |
| 5511 | lpfc_destroy_bootstrap_mbox(phba); |
| 5512 | out_free_mem: |
| 5513 | lpfc_mem_free(phba); |
| 5514 | return rc; |
| 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5519 | * @phba: pointer to lpfc hba data structure. |
| 5520 | * |
| 5521 | * This routine is invoked to unset the driver internal resources set up |
| 5522 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5523 | **/ |
| 5524 | static void |
| 5525 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5526 | { |
| 5527 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5528 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5529 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 5530 | kfree(phba->sli4_hba.cpu_map); |
| 5531 | phba->sli4_hba.num_present_cpu = 0; |
| 5532 | phba->sli4_hba.num_online_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 5533 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5534 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5535 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5536 | kfree(phba->sli4_hba.msix_entries); |
| 5537 | |
| 5538 | /* Free memory allocated for fast-path work queue handles */ |
| 5539 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5540 | |
| 5541 | /* Free the allocated rpi headers. */ |
| 5542 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5543 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5544 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5545 | /* Free eligible FCF index bmask */ |
| 5546 | kfree(phba->fcf.fcf_rr_bmask); |
| 5547 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5548 | /* Free the ELS sgl list */ |
| 5549 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5550 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5551 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5552 | /* Free the completion queue EQ event pool */ |
| 5553 | lpfc_sli4_cq_event_release_all(phba); |
| 5554 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5555 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5556 | /* Release resource identifiers. */ |
| 5557 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5558 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5559 | /* Free the bsmbx region. */ |
| 5560 | lpfc_destroy_bootstrap_mbox(phba); |
| 5561 | |
| 5562 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5563 | lpfc_mem_free_all(phba); |
| 5564 | |
| 5565 | /* Free the current connect table */ |
| 5566 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5567 | &phba->fcf_conn_rec_list, list) { |
| 5568 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5569 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5570 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5571 | |
| 5572 | return; |
| 5573 | } |
| 5574 | |
| 5575 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5576 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5577 | * @phba: The hba struct for which this call is being executed. |
| 5578 | * @dev_grp: The HBA PCI-Device group number. |
| 5579 | * |
| 5580 | * This routine sets up the device INIT interface API function jump table |
| 5581 | * in @phba struct. |
| 5582 | * |
| 5583 | * Returns: 0 - success, -ENODEV - failure. |
| 5584 | **/ |
| 5585 | int |
| 5586 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5587 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5588 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5589 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5590 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5591 | switch (dev_grp) { |
| 5592 | case LPFC_PCI_DEV_LP: |
| 5593 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5594 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5595 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5596 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5597 | case LPFC_PCI_DEV_OC: |
| 5598 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5599 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5600 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5601 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5602 | default: |
| 5603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5604 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5605 | dev_grp); |
| 5606 | return -ENODEV; |
| 5607 | break; |
| 5608 | } |
| 5609 | return 0; |
| 5610 | } |
| 5611 | |
| 5612 | /** |
| 5613 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5614 | * @phba: pointer to lpfc hba data structure. |
| 5615 | * |
| 5616 | * This routine is invoked to set up the driver internal resources before the |
| 5617 | * device specific resource setup to support the HBA device it attached to. |
| 5618 | * |
| 5619 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5620 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5621 | * other values - error |
| 5622 | **/ |
| 5623 | static int |
| 5624 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5625 | { |
| 5626 | /* |
| 5627 | * Driver resources common to all SLI revisions |
| 5628 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5629 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5630 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5631 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5632 | /* Initialize ndlp management spinlock */ |
| 5633 | spin_lock_init(&phba->ndlp_lock); |
| 5634 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5635 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5636 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5637 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5638 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5639 | /* Initialize the wait queue head for the kernel thread */ |
| 5640 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5641 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5642 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 5643 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5644 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5645 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5646 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5647 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5648 | /* Initialize the fabric iocb list */ |
| 5649 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5650 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5651 | /* Initialize list to save ELS buffers */ |
| 5652 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5653 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5654 | /* Initialize FCF connection rec list */ |
| 5655 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5656 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5657 | /* Initialize OAS configuration list */ |
| 5658 | spin_lock_init(&phba->devicelock); |
| 5659 | INIT_LIST_HEAD(&phba->luns); |
| 5660 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5661 | return 0; |
| 5662 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5663 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5664 | /** |
| 5665 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5666 | * @phba: pointer to lpfc hba data structure. |
| 5667 | * |
| 5668 | * This routine is invoked to set up the driver internal resources after the |
| 5669 | * device specific resource setup to support the HBA device it attached to. |
| 5670 | * |
| 5671 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5672 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5673 | * other values - error |
| 5674 | **/ |
| 5675 | static int |
| 5676 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5677 | { |
| 5678 | int error; |
| 5679 | |
| 5680 | /* Startup the kernel thread for this host adapter. */ |
| 5681 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5682 | "lpfc_worker_%d", phba->brd_no); |
| 5683 | if (IS_ERR(phba->worker_thread)) { |
| 5684 | error = PTR_ERR(phba->worker_thread); |
| 5685 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5686 | } |
| 5687 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5688 | return 0; |
| 5689 | } |
| 5690 | |
| 5691 | /** |
| 5692 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5693 | * @phba: pointer to lpfc hba data structure. |
| 5694 | * |
| 5695 | * This routine is invoked to unset the driver internal resources set up after |
| 5696 | * the device specific resource setup for supporting the HBA device it |
| 5697 | * attached to. |
| 5698 | **/ |
| 5699 | static void |
| 5700 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5701 | { |
| 5702 | /* Stop kernel worker thread */ |
| 5703 | kthread_stop(phba->worker_thread); |
| 5704 | } |
| 5705 | |
| 5706 | /** |
| 5707 | * lpfc_free_iocb_list - Free iocb list. |
| 5708 | * @phba: pointer to lpfc hba data structure. |
| 5709 | * |
| 5710 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5711 | **/ |
| 5712 | static void |
| 5713 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5714 | { |
| 5715 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5716 | |
| 5717 | spin_lock_irq(&phba->hbalock); |
| 5718 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5719 | &phba->lpfc_iocb_list, list) { |
| 5720 | list_del(&iocbq_entry->list); |
| 5721 | kfree(iocbq_entry); |
| 5722 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5723 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5724 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5725 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5726 | return; |
| 5727 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5728 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5729 | /** |
| 5730 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5731 | * @phba: pointer to lpfc hba data structure. |
| 5732 | * |
| 5733 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5734 | * list and set up the IOCB tag array accordingly. |
| 5735 | * |
| 5736 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5737 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5738 | * other values - error |
| 5739 | **/ |
| 5740 | static int |
| 5741 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5742 | { |
| 5743 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5744 | uint16_t iotag; |
| 5745 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5746 | |
| 5747 | /* Initialize and populate the iocb list per host. */ |
| 5748 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5749 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5750 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5751 | if (iocbq_entry == NULL) { |
| 5752 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5753 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5754 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5755 | goto out_free_iocbq; |
| 5756 | } |
| 5757 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5758 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5759 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5760 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5761 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5762 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5763 | goto out_free_iocbq; |
| 5764 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5765 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5766 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5767 | |
| 5768 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5769 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5770 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5771 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5772 | } |
| 5773 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5774 | return 0; |
| 5775 | |
| 5776 | out_free_iocbq: |
| 5777 | lpfc_free_iocb_list(phba); |
| 5778 | |
| 5779 | return -ENOMEM; |
| 5780 | } |
| 5781 | |
| 5782 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5783 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5784 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5785 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5786 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5787 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5788 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5789 | void |
| 5790 | 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] | 5791 | { |
| 5792 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5793 | |
| 5794 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5795 | list_del(&sglq_entry->list); |
| 5796 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5797 | kfree(sglq_entry); |
| 5798 | } |
| 5799 | } |
| 5800 | |
| 5801 | /** |
| 5802 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5803 | * @phba: pointer to lpfc hba data structure. |
| 5804 | * |
| 5805 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5806 | **/ |
| 5807 | static void |
| 5808 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5809 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5810 | LIST_HEAD(sglq_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5811 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5812 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5813 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5814 | spin_lock_irq(&phba->hbalock); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5815 | spin_lock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5816 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 5817 | spin_unlock(&pring->ring_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5818 | spin_unlock_irq(&phba->hbalock); |
| 5819 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5820 | /* Now free the sgl list */ |
| 5821 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | /** |
| 5825 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5826 | * @phba: pointer to lpfc hba data structure. |
| 5827 | * |
| 5828 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5829 | * This array will hold the sglq_entry's for active IOs. |
| 5830 | **/ |
| 5831 | static int |
| 5832 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5833 | { |
| 5834 | int size; |
| 5835 | size = sizeof(struct lpfc_sglq *); |
| 5836 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5837 | |
| 5838 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5839 | kzalloc(size, GFP_KERNEL); |
| 5840 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5841 | return -ENOMEM; |
| 5842 | return 0; |
| 5843 | } |
| 5844 | |
| 5845 | /** |
| 5846 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5847 | * @phba: pointer to lpfc hba data structure. |
| 5848 | * |
| 5849 | * This routine is invoked to walk through the array of active sglq entries |
| 5850 | * and free all of the resources. |
| 5851 | * This is just a place holder for now. |
| 5852 | **/ |
| 5853 | static void |
| 5854 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5855 | { |
| 5856 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5857 | } |
| 5858 | |
| 5859 | /** |
| 5860 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5861 | * @phba: pointer to lpfc hba data structure. |
| 5862 | * |
| 5863 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5864 | * list and set up the sgl xritag tag array accordingly. |
| 5865 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5866 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5867 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5868 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5869 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5870 | /* Initialize and populate the sglq list per host/VF. */ |
| 5871 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5872 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5873 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5874 | /* els xri-sgl book keeping */ |
| 5875 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5876 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5877 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5878 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5883 | * @phba: pointer to lpfc hba data structure. |
| 5884 | * |
| 5885 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5886 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5887 | * 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] | 5888 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5889 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5890 | * |
| 5891 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5892 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5893 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5894 | **/ |
| 5895 | int |
| 5896 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5897 | { |
| 5898 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5899 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5900 | |
| 5901 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5902 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5903 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5904 | if (phba->sli4_hba.extents_in_use) |
| 5905 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5906 | |
| 5907 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5908 | if (!rpi_hdr) { |
| 5909 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5910 | "0391 Error during rpi post operation\n"); |
| 5911 | lpfc_sli4_remove_rpis(phba); |
| 5912 | rc = -ENODEV; |
| 5913 | } |
| 5914 | |
| 5915 | return rc; |
| 5916 | } |
| 5917 | |
| 5918 | /** |
| 5919 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5920 | * @phba: pointer to lpfc hba data structure. |
| 5921 | * |
| 5922 | * This routine is invoked to allocate a single 4KB memory region to |
| 5923 | * support rpis and stores them in the phba. This single region |
| 5924 | * provides support for up to 64 rpis. The region is used globally |
| 5925 | * by the device. |
| 5926 | * |
| 5927 | * Returns: |
| 5928 | * A valid rpi hdr on success. |
| 5929 | * A NULL pointer on any failure. |
| 5930 | **/ |
| 5931 | struct lpfc_rpi_hdr * |
| 5932 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5933 | { |
| 5934 | uint16_t rpi_limit, curr_rpi_range; |
| 5935 | struct lpfc_dmabuf *dmabuf; |
| 5936 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5937 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5938 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5939 | /* |
| 5940 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5941 | * required. Set the expected maximum count and let the actual value |
| 5942 | * get set when extents are fully allocated. |
| 5943 | */ |
| 5944 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5945 | return NULL; |
| 5946 | if (phba->sli4_hba.extents_in_use) |
| 5947 | return NULL; |
| 5948 | |
| 5949 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5950 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5951 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5952 | |
| 5953 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5954 | /* |
| 5955 | * Establish the starting RPI in this header block. The starting |
| 5956 | * rpi is normalized to a zero base because the physical rpi is |
| 5957 | * port based. |
| 5958 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5959 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5960 | spin_unlock_irq(&phba->hbalock); |
| 5961 | |
| 5962 | /* |
| 5963 | * The port has a limited number of rpis. The increment here |
| 5964 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5965 | * and to allow the full max_rpi range per port. |
| 5966 | */ |
| 5967 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5968 | rpi_count = rpi_limit - curr_rpi_range; |
| 5969 | else |
| 5970 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5971 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5972 | if (!rpi_count) |
| 5973 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5974 | /* |
| 5975 | * First allocate the protocol header region for the port. The |
| 5976 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5977 | */ |
| 5978 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5979 | if (!dmabuf) |
| 5980 | return NULL; |
| 5981 | |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5982 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 5983 | LPFC_HDR_TEMPLATE_SIZE, |
| 5984 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5985 | if (!dmabuf->virt) { |
| 5986 | rpi_hdr = NULL; |
| 5987 | goto err_free_dmabuf; |
| 5988 | } |
| 5989 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5990 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5991 | rpi_hdr = NULL; |
| 5992 | goto err_free_coherent; |
| 5993 | } |
| 5994 | |
| 5995 | /* Save the rpi header data for cleanup later. */ |
| 5996 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5997 | if (!rpi_hdr) |
| 5998 | goto err_free_coherent; |
| 5999 | |
| 6000 | rpi_hdr->dmabuf = dmabuf; |
| 6001 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 6002 | rpi_hdr->page_count = 1; |
| 6003 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6004 | |
| 6005 | /* The rpi_hdr stores the logical index only. */ |
| 6006 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6007 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 6008 | |
| 6009 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6010 | * The next_rpi stores the next logical module-64 rpi value used |
| 6011 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6012 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 6013 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6014 | spin_unlock_irq(&phba->hbalock); |
| 6015 | return rpi_hdr; |
| 6016 | |
| 6017 | err_free_coherent: |
| 6018 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 6019 | dmabuf->virt, dmabuf->phys); |
| 6020 | err_free_dmabuf: |
| 6021 | kfree(dmabuf); |
| 6022 | return NULL; |
| 6023 | } |
| 6024 | |
| 6025 | /** |
| 6026 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 6027 | * @phba: pointer to lpfc hba data structure. |
| 6028 | * |
| 6029 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6030 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 6031 | * presumes the caller has released all rpis consumed by fabric or port |
| 6032 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6033 | **/ |
| 6034 | void |
| 6035 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 6036 | { |
| 6037 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 6038 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6039 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6040 | goto exit; |
| 6041 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6042 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 6043 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 6044 | list_del(&rpi_hdr->list); |
| 6045 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 6046 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 6047 | kfree(rpi_hdr->dmabuf); |
| 6048 | kfree(rpi_hdr); |
| 6049 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6050 | exit: |
| 6051 | /* There are no rpis available to the port now. */ |
| 6052 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6056 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 6057 | * @pdev: pointer to pci device data structure. |
| 6058 | * |
| 6059 | * This routine is invoked to allocate the driver hba data structure for an |
| 6060 | * HBA device. If the allocation is successful, the phba reference to the |
| 6061 | * PCI device data structure is set. |
| 6062 | * |
| 6063 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6064 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6065 | * NULL - error |
| 6066 | **/ |
| 6067 | static struct lpfc_hba * |
| 6068 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 6069 | { |
| 6070 | struct lpfc_hba *phba; |
| 6071 | |
| 6072 | /* Allocate memory for HBA structure */ |
| 6073 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 6074 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 6075 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6076 | return NULL; |
| 6077 | } |
| 6078 | |
| 6079 | /* Set reference to PCI device in HBA structure */ |
| 6080 | phba->pcidev = pdev; |
| 6081 | |
| 6082 | /* Assign an unused board number */ |
| 6083 | phba->brd_no = lpfc_get_instance(); |
| 6084 | if (phba->brd_no < 0) { |
| 6085 | kfree(phba); |
| 6086 | return NULL; |
| 6087 | } |
| 6088 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 6089 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6090 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 6091 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6092 | return phba; |
| 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 6097 | * @phba: pointer to lpfc hba data structure. |
| 6098 | * |
| 6099 | * This routine is invoked to free the driver hba data structure with an |
| 6100 | * HBA device. |
| 6101 | **/ |
| 6102 | static void |
| 6103 | lpfc_hba_free(struct lpfc_hba *phba) |
| 6104 | { |
| 6105 | /* Release the driver assigned board number */ |
| 6106 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 6107 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6108 | /* Free memory allocated with sli rings */ |
| 6109 | kfree(phba->sli.ring); |
| 6110 | phba->sli.ring = NULL; |
| 6111 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6112 | kfree(phba); |
| 6113 | return; |
| 6114 | } |
| 6115 | |
| 6116 | /** |
| 6117 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 6118 | * @phba: pointer to lpfc hba data structure. |
| 6119 | * |
| 6120 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 6121 | * host with it. |
| 6122 | * |
| 6123 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6124 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6125 | * other values - error |
| 6126 | **/ |
| 6127 | static int |
| 6128 | lpfc_create_shost(struct lpfc_hba *phba) |
| 6129 | { |
| 6130 | struct lpfc_vport *vport; |
| 6131 | struct Scsi_Host *shost; |
| 6132 | |
| 6133 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6134 | phba->fc_edtov = FF_DEF_EDTOV; |
| 6135 | phba->fc_ratov = FF_DEF_RATOV; |
| 6136 | phba->fc_altov = FF_DEF_ALTOV; |
| 6137 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 6138 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6139 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6140 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6141 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6142 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6143 | |
| 6144 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6145 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6146 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6147 | /* Put reference to SCSI host to driver's device private data */ |
| 6148 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6149 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6150 | return 0; |
| 6151 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6152 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6153 | /** |
| 6154 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 6155 | * @phba: pointer to lpfc hba data structure. |
| 6156 | * |
| 6157 | * This routine is invoked to destroy HBA physical port and the associated |
| 6158 | * SCSI host. |
| 6159 | **/ |
| 6160 | static void |
| 6161 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 6162 | { |
| 6163 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6164 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6165 | /* Destroy physical port that associated with the SCSI host */ |
| 6166 | destroy_port(vport); |
| 6167 | |
| 6168 | return; |
| 6169 | } |
| 6170 | |
| 6171 | /** |
| 6172 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 6173 | * @phba: pointer to lpfc hba data structure. |
| 6174 | * @shost: the shost to be used to detect Block guard settings. |
| 6175 | * |
| 6176 | * This routine sets up the local Block guard protocol settings for @shost. |
| 6177 | * This routine also allocates memory for debugging bg buffers. |
| 6178 | **/ |
| 6179 | static void |
| 6180 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 6181 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6182 | uint32_t old_mask; |
| 6183 | uint32_t old_guard; |
| 6184 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6185 | int pagecnt = 10; |
| 6186 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 6187 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6188 | "1478 Registering BlockGuard with the " |
| 6189 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6190 | |
| 6191 | old_mask = lpfc_prot_mask; |
| 6192 | old_guard = lpfc_prot_guard; |
| 6193 | |
| 6194 | /* Only allow supported values */ |
| 6195 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 6196 | SHOST_DIX_TYPE0_PROTECTION | |
| 6197 | SHOST_DIX_TYPE1_PROTECTION); |
| 6198 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 6199 | |
| 6200 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 6201 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 6202 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 6203 | |
| 6204 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 6205 | if ((old_mask != lpfc_prot_mask) || |
| 6206 | (old_guard != lpfc_prot_guard)) |
| 6207 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6208 | "1475 Registering BlockGuard with the " |
| 6209 | "SCSI layer: mask %d guard %d\n", |
| 6210 | lpfc_prot_mask, lpfc_prot_guard); |
| 6211 | |
| 6212 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 6213 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 6214 | } else |
| 6215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6216 | "1479 Not Registering BlockGuard with the SCSI " |
| 6217 | "layer, Bad protection parameters: %d %d\n", |
| 6218 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6219 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6220 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6221 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6222 | while (pagecnt) { |
| 6223 | spin_lock_init(&_dump_buf_lock); |
| 6224 | _dump_buf_data = |
| 6225 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6226 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6227 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6228 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6229 | "_dump_buf_data at 0x%p\n", |
| 6230 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6231 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6232 | memset(_dump_buf_data, 0, |
| 6233 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6234 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6235 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6236 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6237 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6238 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6239 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6240 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6241 | "memory for hexdump\n"); |
| 6242 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6243 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6244 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6245 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6246 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6247 | while (pagecnt) { |
| 6248 | _dump_buf_dif = |
| 6249 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6250 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6251 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6252 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6253 | "_dump_buf_dif at 0x%p\n", |
| 6254 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6255 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6256 | memset(_dump_buf_dif, 0, |
| 6257 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6258 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6259 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6260 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6261 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6262 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6263 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6264 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6265 | "memory for hexdump\n"); |
| 6266 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6267 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6268 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6269 | _dump_buf_dif); |
| 6270 | } |
| 6271 | |
| 6272 | /** |
| 6273 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 6274 | * @phba: pointer to lpfc hba data structure. |
| 6275 | * |
| 6276 | * This routine is invoked to perform all the necessary post initialization |
| 6277 | * setup for the device. |
| 6278 | **/ |
| 6279 | static void |
| 6280 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 6281 | { |
| 6282 | struct Scsi_Host *shost; |
| 6283 | struct lpfc_adapter_event_header adapter_event; |
| 6284 | |
| 6285 | /* Get the default values for Model Name and Description */ |
| 6286 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 6287 | |
| 6288 | /* |
| 6289 | * hba setup may have changed the hba_queue_depth so we need to |
| 6290 | * adjust the value of can_queue. |
| 6291 | */ |
| 6292 | shost = pci_get_drvdata(phba->pcidev); |
| 6293 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 6294 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 6295 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6296 | |
| 6297 | lpfc_host_attrib_init(shost); |
| 6298 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6299 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6300 | spin_lock_irq(shost->host_lock); |
| 6301 | lpfc_poll_start_timer(phba); |
| 6302 | spin_unlock_irq(shost->host_lock); |
| 6303 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 6304 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6305 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6306 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6307 | /* Send board arrival event to upper layer */ |
| 6308 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 6309 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 6310 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6311 | sizeof(adapter_event), |
| 6312 | (char *) &adapter_event, |
| 6313 | LPFC_NL_VENDOR_ID); |
| 6314 | return; |
| 6315 | } |
| 6316 | |
| 6317 | /** |
| 6318 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 6319 | * @phba: pointer to lpfc hba data structure. |
| 6320 | * |
| 6321 | * This routine is invoked to set up the PCI device memory space for device |
| 6322 | * with SLI-3 interface spec. |
| 6323 | * |
| 6324 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6325 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6326 | * other values - error |
| 6327 | **/ |
| 6328 | static int |
| 6329 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 6330 | { |
| 6331 | struct pci_dev *pdev; |
| 6332 | unsigned long bar0map_len, bar2map_len; |
| 6333 | int i, hbq_count; |
| 6334 | void *ptr; |
| 6335 | int error = -ENODEV; |
| 6336 | |
| 6337 | /* Obtain PCI device reference */ |
| 6338 | if (!phba->pcidev) |
| 6339 | return error; |
| 6340 | else |
| 6341 | pdev = phba->pcidev; |
| 6342 | |
| 6343 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6344 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 6345 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 6346 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 6347 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6348 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6349 | } |
| 6350 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6351 | |
| 6352 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 6353 | * required by each mapping. |
| 6354 | */ |
| 6355 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 6356 | bar0map_len = pci_resource_len(pdev, 0); |
| 6357 | |
| 6358 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 6359 | bar2map_len = pci_resource_len(pdev, 2); |
| 6360 | |
| 6361 | /* Map HBA SLIM to a kernel virtual address. */ |
| 6362 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 6363 | if (!phba->slim_memmap_p) { |
| 6364 | dev_printk(KERN_ERR, &pdev->dev, |
| 6365 | "ioremap failed for SLIM memory.\n"); |
| 6366 | goto out; |
| 6367 | } |
| 6368 | |
| 6369 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 6370 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 6371 | if (!phba->ctrl_regs_memmap_p) { |
| 6372 | dev_printk(KERN_ERR, &pdev->dev, |
| 6373 | "ioremap failed for HBA control registers.\n"); |
| 6374 | goto out_iounmap_slim; |
| 6375 | } |
| 6376 | |
| 6377 | /* Allocate memory for SLI-2 structures */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6378 | phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6379 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6380 | if (!phba->slim2p.virt) |
| 6381 | goto out_iounmap; |
| 6382 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6383 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6384 | phba->mbox_ext = (phba->slim2p.virt + |
| 6385 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6386 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 6387 | phba->IOCBs = (phba->slim2p.virt + |
| 6388 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 6389 | |
| 6390 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 6391 | lpfc_sli_hbq_size(), |
| 6392 | &phba->hbqslimp.phys, |
| 6393 | GFP_KERNEL); |
| 6394 | if (!phba->hbqslimp.virt) |
| 6395 | goto out_free_slim; |
| 6396 | |
| 6397 | hbq_count = lpfc_sli_hbq_count(); |
| 6398 | ptr = phba->hbqslimp.virt; |
| 6399 | for (i = 0; i < hbq_count; ++i) { |
| 6400 | phba->hbqs[i].hbq_virt = ptr; |
| 6401 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 6402 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 6403 | sizeof(struct lpfc_hbq_entry)); |
| 6404 | } |
| 6405 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 6406 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 6407 | |
| 6408 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 6409 | |
| 6410 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 6411 | |
| 6412 | phba->MBslimaddr = phba->slim_memmap_p; |
| 6413 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 6414 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 6415 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 6416 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6417 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6418 | return 0; |
| 6419 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6420 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6421 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6422 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6423 | out_iounmap: |
| 6424 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6425 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6426 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6427 | out: |
| 6428 | return error; |
| 6429 | } |
| 6430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6431 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6432 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 6433 | * @phba: pointer to lpfc hba data structure. |
| 6434 | * |
| 6435 | * This routine is invoked to unset the PCI device memory space for device |
| 6436 | * with SLI-3 interface spec. |
| 6437 | **/ |
| 6438 | static void |
| 6439 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 6440 | { |
| 6441 | struct pci_dev *pdev; |
| 6442 | |
| 6443 | /* Obtain PCI device reference */ |
| 6444 | if (!phba->pcidev) |
| 6445 | return; |
| 6446 | else |
| 6447 | pdev = phba->pcidev; |
| 6448 | |
| 6449 | /* Free coherent DMA memory allocated */ |
| 6450 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 6451 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 6452 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6453 | phba->slim2p.virt, phba->slim2p.phys); |
| 6454 | |
| 6455 | /* I/O memory unmap */ |
| 6456 | iounmap(phba->ctrl_regs_memmap_p); |
| 6457 | iounmap(phba->slim_memmap_p); |
| 6458 | |
| 6459 | return; |
| 6460 | } |
| 6461 | |
| 6462 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6463 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 6464 | * @phba: pointer to lpfc hba data structure. |
| 6465 | * |
| 6466 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 6467 | * done and check status. |
| 6468 | * |
| 6469 | * Return 0 if successful, otherwise -ENODEV. |
| 6470 | **/ |
| 6471 | int |
| 6472 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 6473 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6474 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 6475 | struct lpfc_register reg_data; |
| 6476 | int i, port_error = 0; |
| 6477 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6478 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6479 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 6480 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6481 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6482 | return -ENODEV; |
| 6483 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6484 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 6485 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6486 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 6487 | &portsmphr_reg.word0) || |
| 6488 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6489 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6490 | port_error = -ENODEV; |
| 6491 | break; |
| 6492 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6493 | if (LPFC_POST_STAGE_PORT_READY == |
| 6494 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6495 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6496 | msleep(10); |
| 6497 | } |
| 6498 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6499 | /* |
| 6500 | * If there was a port error during POST, then don't proceed with |
| 6501 | * other register reads as the data may not be valid. Just exit. |
| 6502 | */ |
| 6503 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6505 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 6506 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 6507 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 6508 | portsmphr_reg.word0, |
| 6509 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 6510 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 6511 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 6512 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 6513 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 6514 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 6515 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 6516 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 6517 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6518 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6519 | "2534 Device Info: SLIFamily=0x%x, " |
| 6520 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 6521 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6522 | bf_get(lpfc_sli_intf_sli_family, |
| 6523 | &phba->sli4_hba.sli_intf), |
| 6524 | bf_get(lpfc_sli_intf_slirev, |
| 6525 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6526 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6527 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6528 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6529 | &phba->sli4_hba.sli_intf), |
| 6530 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6531 | &phba->sli4_hba.sli_intf), |
| 6532 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6533 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6534 | /* |
| 6535 | * Check for other Port errors during the initialization |
| 6536 | * process. Fail the load if the port did not come up |
| 6537 | * correctly. |
| 6538 | */ |
| 6539 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6540 | &phba->sli4_hba.sli_intf); |
| 6541 | switch (if_type) { |
| 6542 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6543 | phba->sli4_hba.ue_mask_lo = |
| 6544 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6545 | phba->sli4_hba.ue_mask_hi = |
| 6546 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6547 | uerrlo_reg.word0 = |
| 6548 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6549 | uerrhi_reg.word0 = |
| 6550 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6551 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6552 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6554 | "1422 Unrecoverable Error " |
| 6555 | "Detected during POST " |
| 6556 | "uerr_lo_reg=0x%x, " |
| 6557 | "uerr_hi_reg=0x%x, " |
| 6558 | "ue_mask_lo_reg=0x%x, " |
| 6559 | "ue_mask_hi_reg=0x%x\n", |
| 6560 | uerrlo_reg.word0, |
| 6561 | uerrhi_reg.word0, |
| 6562 | phba->sli4_hba.ue_mask_lo, |
| 6563 | phba->sli4_hba.ue_mask_hi); |
| 6564 | port_error = -ENODEV; |
| 6565 | } |
| 6566 | break; |
| 6567 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6568 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6569 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6570 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6571 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6572 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6573 | phba->work_status[0] = |
| 6574 | readl(phba->sli4_hba.u.if_type2. |
| 6575 | ERR1regaddr); |
| 6576 | phba->work_status[1] = |
| 6577 | readl(phba->sli4_hba.u.if_type2. |
| 6578 | ERR2regaddr); |
| 6579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6580 | "2888 Unrecoverable port error " |
| 6581 | "following POST: port status reg " |
| 6582 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6583 | "error 1=0x%x, error 2=0x%x\n", |
| 6584 | reg_data.word0, |
| 6585 | portsmphr_reg.word0, |
| 6586 | phba->work_status[0], |
| 6587 | phba->work_status[1]); |
| 6588 | port_error = -ENODEV; |
| 6589 | } |
| 6590 | break; |
| 6591 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6592 | default: |
| 6593 | break; |
| 6594 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6595 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6596 | return port_error; |
| 6597 | } |
| 6598 | |
| 6599 | /** |
| 6600 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6601 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6602 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6603 | * |
| 6604 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6605 | * memory map. |
| 6606 | **/ |
| 6607 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6608 | 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] | 6609 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6610 | switch (if_type) { |
| 6611 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6612 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6613 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6614 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6615 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6616 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6617 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6618 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6619 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6620 | phba->sli4_hba.SLIINTFregaddr = |
| 6621 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6622 | break; |
| 6623 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6624 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6625 | phba->sli4_hba.conf_regs_memmap_p + |
| 6626 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6627 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6628 | phba->sli4_hba.conf_regs_memmap_p + |
| 6629 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6630 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6631 | phba->sli4_hba.conf_regs_memmap_p + |
| 6632 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6633 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6634 | phba->sli4_hba.conf_regs_memmap_p + |
| 6635 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6636 | phba->sli4_hba.SLIINTFregaddr = |
| 6637 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6638 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6639 | phba->sli4_hba.conf_regs_memmap_p + |
| 6640 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6641 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6642 | phba->sli4_hba.conf_regs_memmap_p + |
| 6643 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6644 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6645 | phba->sli4_hba.conf_regs_memmap_p + |
| 6646 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6647 | phba->sli4_hba.EQCQDBregaddr = |
| 6648 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6649 | phba->sli4_hba.MQDBregaddr = |
| 6650 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6651 | phba->sli4_hba.BMBXregaddr = |
| 6652 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6653 | break; |
| 6654 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6655 | default: |
| 6656 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6657 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6658 | if_type); |
| 6659 | break; |
| 6660 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6665 | * @phba: pointer to lpfc hba data structure. |
| 6666 | * |
| 6667 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6668 | * memory map. |
| 6669 | **/ |
| 6670 | static void |
| 6671 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6672 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6673 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6674 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6675 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6676 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6677 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6678 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6679 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6680 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6681 | } |
| 6682 | |
| 6683 | /** |
| 6684 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6685 | * @phba: pointer to lpfc hba data structure. |
| 6686 | * @vf: virtual function number |
| 6687 | * |
| 6688 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6689 | * based on the given viftual function number, @vf. |
| 6690 | * |
| 6691 | * Return 0 if successful, otherwise -ENODEV. |
| 6692 | **/ |
| 6693 | static int |
| 6694 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6695 | { |
| 6696 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6697 | return -ENODEV; |
| 6698 | |
| 6699 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6700 | vf * LPFC_VFR_PAGE_SIZE + |
| 6701 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6702 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6703 | vf * LPFC_VFR_PAGE_SIZE + |
| 6704 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6705 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6706 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6707 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6708 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6709 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6710 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6711 | return 0; |
| 6712 | } |
| 6713 | |
| 6714 | /** |
| 6715 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6716 | * @phba: pointer to lpfc hba data structure. |
| 6717 | * |
| 6718 | * This routine is invoked to create the bootstrap mailbox |
| 6719 | * region consistent with the SLI-4 interface spec. This |
| 6720 | * routine allocates all memory necessary to communicate |
| 6721 | * mailbox commands to the port and sets up all alignment |
| 6722 | * needs. No locks are expected to be held when calling |
| 6723 | * this routine. |
| 6724 | * |
| 6725 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6726 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6727 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6728 | **/ |
| 6729 | static int |
| 6730 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6731 | { |
| 6732 | uint32_t bmbx_size; |
| 6733 | struct lpfc_dmabuf *dmabuf; |
| 6734 | struct dma_address *dma_address; |
| 6735 | uint32_t pa_addr; |
| 6736 | uint64_t phys_addr; |
| 6737 | |
| 6738 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6739 | if (!dmabuf) |
| 6740 | return -ENOMEM; |
| 6741 | |
| 6742 | /* |
| 6743 | * The bootstrap mailbox region is comprised of 2 parts |
| 6744 | * plus an alignment restriction of 16 bytes. |
| 6745 | */ |
| 6746 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6747 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 6748 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6749 | if (!dmabuf->virt) { |
| 6750 | kfree(dmabuf); |
| 6751 | return -ENOMEM; |
| 6752 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6753 | |
| 6754 | /* |
| 6755 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6756 | * operations are simple later. The mailbox dma address is required |
| 6757 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6758 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6759 | * command to the port. |
| 6760 | */ |
| 6761 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6762 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6763 | |
| 6764 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6765 | LPFC_ALIGN_16_BYTE); |
| 6766 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6767 | LPFC_ALIGN_16_BYTE); |
| 6768 | |
| 6769 | /* |
| 6770 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6771 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6772 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6773 | * the 30-bit address is the high or low address. |
| 6774 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6775 | * clean on 32 bit machines. |
| 6776 | */ |
| 6777 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6778 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6779 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6780 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6781 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6782 | |
| 6783 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6784 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6785 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6786 | return 0; |
| 6787 | } |
| 6788 | |
| 6789 | /** |
| 6790 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6791 | * @phba: pointer to lpfc hba data structure. |
| 6792 | * |
| 6793 | * This routine is invoked to teardown the bootstrap mailbox |
| 6794 | * region and release all host resources. This routine requires |
| 6795 | * the caller to ensure all mailbox commands recovered, no |
| 6796 | * additional mailbox comands are sent, and interrupts are disabled |
| 6797 | * before calling this routine. |
| 6798 | * |
| 6799 | **/ |
| 6800 | static void |
| 6801 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6802 | { |
| 6803 | dma_free_coherent(&phba->pcidev->dev, |
| 6804 | phba->sli4_hba.bmbx.bmbx_size, |
| 6805 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6806 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6807 | |
| 6808 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6809 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6810 | } |
| 6811 | |
| 6812 | /** |
| 6813 | * lpfc_sli4_read_config - Get the config parameters. |
| 6814 | * @phba: pointer to lpfc hba data structure. |
| 6815 | * |
| 6816 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6817 | * The configuration parameters are used to set the base and maximum values |
| 6818 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6819 | * allocation for the port. |
| 6820 | * |
| 6821 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6822 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6823 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6824 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6825 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6826 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6827 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6828 | { |
| 6829 | LPFC_MBOXQ_t *pmb; |
| 6830 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6831 | union lpfc_sli4_cfg_shdr *shdr; |
| 6832 | uint32_t shdr_status, shdr_add_status; |
| 6833 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6834 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6835 | char *pdesc_0; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6836 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6837 | |
| 6838 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6839 | if (!pmb) { |
| 6840 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6841 | "2011 Unable to allocate memory for issuing " |
| 6842 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6843 | return -ENOMEM; |
| 6844 | } |
| 6845 | |
| 6846 | lpfc_read_config(phba, pmb); |
| 6847 | |
| 6848 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6849 | if (rc != MBX_SUCCESS) { |
| 6850 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6851 | "2012 Mailbox failed , mbxCmd x%x " |
| 6852 | "READ_CONFIG, mbxStatus x%x\n", |
| 6853 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6854 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6855 | rc = -EIO; |
| 6856 | } else { |
| 6857 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6858 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6859 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6860 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6861 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6862 | phba->sli4_hba.lnk_info.lnk_no = |
| 6863 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6864 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6865 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6866 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6867 | phba->sli4_hba.lnk_info.lnk_no); |
| 6868 | } else |
| 6869 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6870 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6871 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6872 | phba->sli4_hba.extents_in_use = |
| 6873 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6874 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6875 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6876 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6877 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6878 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6879 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6880 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6881 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6882 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6883 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6884 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6885 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6886 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6887 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6888 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6889 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6890 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6891 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6892 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6893 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6894 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6895 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6896 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6897 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6898 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6899 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6900 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6901 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6902 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6903 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6904 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6905 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6906 | phba->max_vports = phba->max_vpi; |
| 6907 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6908 | "2003 cfg params Extents? %d " |
| 6909 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6910 | "VPI(B:%d M:%d) " |
| 6911 | "VFI(B:%d M:%d) " |
| 6912 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6913 | "FCFI(Count:%d)\n", |
| 6914 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6915 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6916 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6917 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6918 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6919 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6920 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6921 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6922 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6923 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6924 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6925 | |
| 6926 | if (rc) |
| 6927 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6928 | |
| 6929 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6930 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 6931 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 6932 | if (phba->cfg_hba_queue_depth > length) { |
| 6933 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6934 | "3361 HBA queue depth changed from %d to %d\n", |
| 6935 | phba->cfg_hba_queue_depth, length); |
| 6936 | phba->cfg_hba_queue_depth = length; |
| 6937 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6938 | |
| 6939 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6940 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6941 | goto read_cfg_out; |
| 6942 | |
| 6943 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6944 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6945 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6946 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6947 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6948 | length, LPFC_SLI4_MBX_EMBED); |
| 6949 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6950 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6951 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6952 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6953 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6954 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6955 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6956 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6957 | "3026 Mailbox failed , mbxCmd x%x " |
| 6958 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6959 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6960 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6961 | goto read_cfg_out; |
| 6962 | } |
| 6963 | |
| 6964 | /* search for fc_fcoe resrouce descriptor */ |
| 6965 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6966 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6967 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6968 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6969 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6970 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6971 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6972 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6973 | goto read_cfg_out; |
| 6974 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6975 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6976 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6977 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6978 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6979 | phba->sli4_hba.iov.pf_number = |
| 6980 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6981 | phba->sli4_hba.iov.vf_number = |
| 6982 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6983 | break; |
| 6984 | } |
| 6985 | } |
| 6986 | |
| 6987 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6989 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6990 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6991 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6992 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6993 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6994 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6995 | "Resrouce Descriptor:x%x\n", |
| 6996 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6997 | |
| 6998 | read_cfg_out: |
| 6999 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7000 | return rc; |
| 7001 | } |
| 7002 | |
| 7003 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7004 | * 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] | 7005 | * @phba: pointer to lpfc hba data structure. |
| 7006 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7007 | * This routine is invoked to setup the port-side endian order when |
| 7008 | * the port if_type is 0. This routine has no function for other |
| 7009 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7010 | * |
| 7011 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7012 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7013 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7014 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7015 | **/ |
| 7016 | static int |
| 7017 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 7018 | { |
| 7019 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7020 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7021 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 7022 | HOST_ENDIAN_HIGH_WORD1}; |
| 7023 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7024 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7025 | switch (if_type) { |
| 7026 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7027 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7028 | GFP_KERNEL); |
| 7029 | if (!mboxq) { |
| 7030 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7031 | "0492 Unable to allocate memory for " |
| 7032 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 7033 | "command\n"); |
| 7034 | return -ENOMEM; |
| 7035 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7036 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7037 | /* |
| 7038 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 7039 | * two words to contain special data values and no other data. |
| 7040 | */ |
| 7041 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 7042 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 7043 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7044 | if (rc != MBX_SUCCESS) { |
| 7045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7046 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 7047 | "failed with status x%x\n", |
| 7048 | rc); |
| 7049 | rc = -EIO; |
| 7050 | } |
| 7051 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7052 | break; |
| 7053 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7054 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7055 | default: |
| 7056 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7057 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7058 | return rc; |
| 7059 | } |
| 7060 | |
| 7061 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7062 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | * @phba: pointer to lpfc hba data structure. |
| 7064 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7065 | * This routine is invoked to check the user settable queue counts for EQs and |
| 7066 | * CQs. after this routine is called the counts will be set to valid values that |
| 7067 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 7068 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7069 | * |
| 7070 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7071 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7072 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7073 | **/ |
| 7074 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7075 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7076 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7077 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7078 | uint32_t cpu; |
| 7079 | uint32_t i = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7080 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7081 | |
| 7082 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7083 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7084 | * device parameters |
| 7085 | */ |
| 7086 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7087 | /* Sanity check on HBA EQ parameters */ |
| 7088 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7089 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7090 | /* It doesn't make sense to have more io channels then online CPUs */ |
| 7091 | for_each_present_cpu(cpu) { |
| 7092 | if (cpu_online(cpu)) |
| 7093 | i++; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7094 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7095 | phba->sli4_hba.num_online_cpu = i; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 7096 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7097 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7098 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7099 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7100 | lpfc_printf_log(phba, |
| 7101 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7102 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7103 | "online CPUs: from %d to %d\n", |
| 7104 | cfg_fcp_io_channel, i); |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7105 | cfg_fcp_io_channel = i; |
| 7106 | } |
| 7107 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7108 | if (cfg_fcp_io_channel + fof_vectors > |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7109 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7110 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 7111 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7112 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7113 | "2574 Not enough EQs (%d) from the " |
| 7114 | "pci function for supporting FCP " |
| 7115 | "EQs (%d)\n", |
| 7116 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7117 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7118 | goto out_error; |
| 7119 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7120 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7121 | "2575 Reducing IO channels to match number of " |
| 7122 | "available EQs: from %d to %d\n", |
| 7123 | cfg_fcp_io_channel, |
| 7124 | phba->sli4_hba.max_cfg_param.max_eq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7125 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq - |
| 7126 | fof_vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7127 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7128 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7129 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7130 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7131 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7132 | /* Get EQ depth from module parameter, fake the default for now */ |
| 7133 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 7134 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 7135 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7136 | /* Get CQ depth from module parameter, fake the default for now */ |
| 7137 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 7138 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 7139 | |
| 7140 | return 0; |
| 7141 | out_error: |
| 7142 | return -ENOMEM; |
| 7143 | } |
| 7144 | |
| 7145 | /** |
| 7146 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 7147 | * @phba: pointer to lpfc hba data structure. |
| 7148 | * |
| 7149 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 7150 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 7151 | * count (queue depth) shall be taken from the module parameter. For now, |
| 7152 | * we just use some constant number as place holder. |
| 7153 | * |
| 7154 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 7155 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7156 | * -ENOMEM - No availble memory |
| 7157 | * -EIO - The mailbox failed to complete successfully. |
| 7158 | **/ |
| 7159 | int |
| 7160 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 7161 | { |
| 7162 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7163 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7164 | |
| 7165 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7166 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7167 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7168 | if (!phba->cfg_fcp_io_channel) |
| 7169 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7170 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7171 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 7172 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 7173 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 7174 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 7175 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 7176 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 7177 | |
| 7178 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7179 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7180 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7181 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7182 | "2576 Failed allocate memory for " |
| 7183 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7184 | goto out_error; |
| 7185 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7186 | |
| 7187 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7188 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7189 | if (!phba->sli4_hba.fcp_cq) { |
| 7190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7191 | "2577 Failed allocate memory for fast-path " |
| 7192 | "CQ record array\n"); |
| 7193 | goto out_error; |
| 7194 | } |
| 7195 | |
| 7196 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7197 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7198 | if (!phba->sli4_hba.fcp_wq) { |
| 7199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7200 | "2578 Failed allocate memory for fast-path " |
| 7201 | "WQ record array\n"); |
| 7202 | goto out_error; |
| 7203 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7204 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7205 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7206 | * Since the first EQ can have multiple CQs associated with it, |
| 7207 | * this array is used to quickly see if we have a FCP fast-path |
| 7208 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7209 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7210 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 7211 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7212 | if (!phba->sli4_hba.fcp_cq_map) { |
| 7213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7214 | "2545 Failed allocate memory for fast-path " |
| 7215 | "CQ map\n"); |
| 7216 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7217 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7218 | |
| 7219 | /* |
| 7220 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 7221 | * how many EQs to create. |
| 7222 | */ |
| 7223 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7224 | |
| 7225 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7226 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 7227 | phba->sli4_hba.eq_ecount); |
| 7228 | if (!qdesc) { |
| 7229 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7230 | "0497 Failed allocate EQ (%d)\n", idx); |
| 7231 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7232 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7233 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 7234 | |
| 7235 | /* Create Fast Path FCP CQs */ |
| 7236 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7237 | phba->sli4_hba.cq_ecount); |
| 7238 | if (!qdesc) { |
| 7239 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7240 | "0499 Failed allocate fast-path FCP " |
| 7241 | "CQ (%d)\n", idx); |
| 7242 | goto out_error; |
| 7243 | } |
| 7244 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 7245 | |
| 7246 | /* Create Fast Path FCP WQs */ |
| 7247 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7248 | phba->sli4_hba.wq_ecount); |
| 7249 | if (!qdesc) { |
| 7250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7251 | "0503 Failed allocate fast-path FCP " |
| 7252 | "WQ (%d)\n", idx); |
| 7253 | goto out_error; |
| 7254 | } |
| 7255 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7256 | } |
| 7257 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7258 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7259 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7260 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7261 | */ |
| 7262 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7263 | /* Create slow-path Mailbox Command Complete Queue */ |
| 7264 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7265 | phba->sli4_hba.cq_ecount); |
| 7266 | if (!qdesc) { |
| 7267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7268 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7269 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7270 | } |
| 7271 | phba->sli4_hba.mbx_cq = qdesc; |
| 7272 | |
| 7273 | /* Create slow-path ELS Complete Queue */ |
| 7274 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7275 | phba->sli4_hba.cq_ecount); |
| 7276 | if (!qdesc) { |
| 7277 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7278 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7279 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7280 | } |
| 7281 | phba->sli4_hba.els_cq = qdesc; |
| 7282 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7283 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7284 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7285 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7286 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7287 | |
| 7288 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7289 | |
| 7290 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 7291 | phba->sli4_hba.mq_ecount); |
| 7292 | if (!qdesc) { |
| 7293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7294 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7295 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7296 | } |
| 7297 | phba->sli4_hba.mbx_wq = qdesc; |
| 7298 | |
| 7299 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7300 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7301 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7302 | |
| 7303 | /* Create slow-path ELS Work Queue */ |
| 7304 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7305 | phba->sli4_hba.wq_ecount); |
| 7306 | if (!qdesc) { |
| 7307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7308 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7309 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7310 | } |
| 7311 | phba->sli4_hba.els_wq = qdesc; |
| 7312 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7313 | /* |
| 7314 | * Create Receive Queue (RQ) |
| 7315 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7316 | |
| 7317 | /* Create Receive Queue for header */ |
| 7318 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7319 | phba->sli4_hba.rq_ecount); |
| 7320 | if (!qdesc) { |
| 7321 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7322 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7323 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7324 | } |
| 7325 | phba->sli4_hba.hdr_rq = qdesc; |
| 7326 | |
| 7327 | /* Create Receive Queue for data */ |
| 7328 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7329 | phba->sli4_hba.rq_ecount); |
| 7330 | if (!qdesc) { |
| 7331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7332 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7333 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7334 | } |
| 7335 | phba->sli4_hba.dat_rq = qdesc; |
| 7336 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7337 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
| 7338 | if (phba->cfg_fof) |
| 7339 | lpfc_fof_queue_create(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7340 | return 0; |
| 7341 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7342 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7343 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7344 | return -ENOMEM; |
| 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 7349 | * @phba: pointer to lpfc hba data structure. |
| 7350 | * |
| 7351 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 7352 | * operation. |
| 7353 | * |
| 7354 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7355 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7356 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7357 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7358 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7359 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7360 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 7361 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7362 | int idx; |
| 7363 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7364 | if (phba->cfg_fof) |
| 7365 | lpfc_fof_queue_destroy(phba); |
| 7366 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7367 | if (phba->sli4_hba.hba_eq != NULL) { |
| 7368 | /* Release HBA event queue */ |
| 7369 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7370 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 7371 | lpfc_sli4_queue_free( |
| 7372 | phba->sli4_hba.hba_eq[idx]); |
| 7373 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 7374 | } |
| 7375 | } |
| 7376 | kfree(phba->sli4_hba.hba_eq); |
| 7377 | phba->sli4_hba.hba_eq = NULL; |
| 7378 | } |
| 7379 | |
| 7380 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 7381 | /* Release FCP completion queue */ |
| 7382 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7383 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 7384 | lpfc_sli4_queue_free( |
| 7385 | phba->sli4_hba.fcp_cq[idx]); |
| 7386 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 7387 | } |
| 7388 | } |
| 7389 | kfree(phba->sli4_hba.fcp_cq); |
| 7390 | phba->sli4_hba.fcp_cq = NULL; |
| 7391 | } |
| 7392 | |
| 7393 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 7394 | /* Release FCP work queue */ |
| 7395 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7396 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 7397 | lpfc_sli4_queue_free( |
| 7398 | phba->sli4_hba.fcp_wq[idx]); |
| 7399 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 7400 | } |
| 7401 | } |
| 7402 | kfree(phba->sli4_hba.fcp_wq); |
| 7403 | phba->sli4_hba.fcp_wq = NULL; |
| 7404 | } |
| 7405 | |
| 7406 | /* Release FCP CQ mapping array */ |
| 7407 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 7408 | kfree(phba->sli4_hba.fcp_cq_map); |
| 7409 | phba->sli4_hba.fcp_cq_map = NULL; |
| 7410 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7411 | |
| 7412 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7413 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 7414 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 7415 | phba->sli4_hba.mbx_wq = NULL; |
| 7416 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7417 | |
| 7418 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7419 | if (phba->sli4_hba.els_wq != NULL) { |
| 7420 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 7421 | phba->sli4_hba.els_wq = NULL; |
| 7422 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7423 | |
| 7424 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7425 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 7426 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 7427 | phba->sli4_hba.hdr_rq = NULL; |
| 7428 | } |
| 7429 | if (phba->sli4_hba.dat_rq != NULL) { |
| 7430 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 7431 | phba->sli4_hba.dat_rq = NULL; |
| 7432 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7433 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7434 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7435 | if (phba->sli4_hba.els_cq != NULL) { |
| 7436 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 7437 | phba->sli4_hba.els_cq = NULL; |
| 7438 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7439 | |
| 7440 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7441 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 7442 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 7443 | phba->sli4_hba.mbx_cq = NULL; |
| 7444 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7445 | |
| 7446 | return; |
| 7447 | } |
| 7448 | |
| 7449 | /** |
| 7450 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 7451 | * @phba: pointer to lpfc hba data structure. |
| 7452 | * |
| 7453 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 7454 | * operation. |
| 7455 | * |
| 7456 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7457 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7458 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7459 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7460 | **/ |
| 7461 | int |
| 7462 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 7463 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7464 | struct lpfc_sli *psli = &phba->sli; |
| 7465 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7466 | int rc = -ENOMEM; |
| 7467 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 7468 | int fcp_cq_index = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7469 | uint32_t shdr_status, shdr_add_status; |
| 7470 | union lpfc_sli4_cfg_shdr *shdr; |
| 7471 | LPFC_MBOXQ_t *mboxq; |
| 7472 | uint32_t length; |
| 7473 | |
| 7474 | /* Check for dual-ULP support */ |
| 7475 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7476 | if (!mboxq) { |
| 7477 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7478 | "3249 Unable to allocate memory for " |
| 7479 | "QUERY_FW_CFG mailbox command\n"); |
| 7480 | return -ENOMEM; |
| 7481 | } |
| 7482 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 7483 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7484 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7485 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 7486 | length, LPFC_SLI4_MBX_EMBED); |
| 7487 | |
| 7488 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7489 | |
| 7490 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7491 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7492 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7493 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7494 | if (shdr_status || shdr_add_status || rc) { |
| 7495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7496 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 7497 | "x%x add_status x%x, mbx status x%x\n", |
| 7498 | shdr_status, shdr_add_status, rc); |
| 7499 | if (rc != MBX_TIMEOUT) |
| 7500 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7501 | rc = -ENXIO; |
| 7502 | goto out_error; |
| 7503 | } |
| 7504 | |
| 7505 | phba->sli4_hba.fw_func_mode = |
| 7506 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 7507 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 7508 | 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] | 7509 | phba->sli4_hba.physical_port = |
| 7510 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7511 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7512 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 7513 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 7514 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 7515 | |
| 7516 | if (rc != MBX_TIMEOUT) |
| 7517 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7518 | |
| 7519 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7520 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7521 | */ |
| 7522 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7523 | /* Set up HBA event queue */ |
| 7524 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7525 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7526 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7527 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7528 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7529 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7530 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 7531 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7533 | "0522 Fast-path EQ (%d) not " |
| 7534 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7535 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7536 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7537 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7538 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 7539 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | if (rc) { |
| 7541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7542 | "0523 Failed setup of fast-path EQ " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7543 | "(%d), rc = 0x%x\n", fcp_eqidx, |
| 7544 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7545 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7546 | } |
| 7547 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7548 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7549 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7550 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7551 | } |
| 7552 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7553 | /* Set up fast-path FCP Response Complete Queue */ |
| 7554 | if (!phba->sli4_hba.fcp_cq) { |
| 7555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7556 | "3148 Fast-path FCP CQ array not " |
| 7557 | "allocated\n"); |
| 7558 | rc = -ENOMEM; |
| 7559 | goto out_destroy_hba_eq; |
| 7560 | } |
| 7561 | |
| 7562 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 7563 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 7564 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7565 | "0526 Fast-path FCP CQ (%d) not " |
| 7566 | "allocated\n", fcp_cqidx); |
| 7567 | rc = -ENOMEM; |
| 7568 | goto out_destroy_fcp_cq; |
| 7569 | } |
| 7570 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 7571 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 7572 | if (rc) { |
| 7573 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7574 | "0527 Failed setup of fast-path FCP " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7575 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, |
| 7576 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7577 | goto out_destroy_fcp_cq; |
| 7578 | } |
| 7579 | |
| 7580 | /* Setup fcp_cq_map for fast lookup */ |
| 7581 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 7582 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7583 | |
| 7584 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7585 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7586 | "parent seq[%d]-id=%d\n", |
| 7587 | fcp_cqidx, |
| 7588 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7589 | fcp_cqidx, |
| 7590 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7591 | } |
| 7592 | |
| 7593 | /* Set up fast-path FCP Work Queue */ |
| 7594 | if (!phba->sli4_hba.fcp_wq) { |
| 7595 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7596 | "3149 Fast-path FCP WQ array not " |
| 7597 | "allocated\n"); |
| 7598 | rc = -ENOMEM; |
| 7599 | goto out_destroy_fcp_cq; |
| 7600 | } |
| 7601 | |
| 7602 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7603 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7604 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7605 | "0534 Fast-path FCP WQ (%d) not " |
| 7606 | "allocated\n", fcp_wqidx); |
| 7607 | rc = -ENOMEM; |
| 7608 | goto out_destroy_fcp_wq; |
| 7609 | } |
| 7610 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7611 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7612 | LPFC_FCP); |
| 7613 | if (rc) { |
| 7614 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7615 | "0535 Failed setup of fast-path FCP " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7616 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, |
| 7617 | (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7618 | goto out_destroy_fcp_wq; |
| 7619 | } |
| 7620 | |
| 7621 | /* Bind this WQ to the next FCP ring */ |
| 7622 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7623 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7624 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7625 | |
| 7626 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7627 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7628 | "parent cq[%d]-id=%d\n", |
| 7629 | fcp_wqidx, |
| 7630 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7631 | fcp_cq_index, |
| 7632 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7633 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7634 | /* |
| 7635 | * Set up Complete Queues (CQs) |
| 7636 | */ |
| 7637 | |
| 7638 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7639 | if (!phba->sli4_hba.mbx_cq) { |
| 7640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7641 | "0528 Mailbox CQ not allocated\n"); |
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_fcp_wq; |
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_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7646 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
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 | "0529 Failed setup of slow-path mailbox CQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7650 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7651 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7652 | } |
| 7653 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7654 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7655 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7656 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7657 | |
| 7658 | /* Set up slow-path ELS Complete Queue */ |
| 7659 | if (!phba->sli4_hba.els_cq) { |
| 7660 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7661 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7662 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7663 | goto out_destroy_mbx_cq; |
| 7664 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7665 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7666 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7667 | if (rc) { |
| 7668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7669 | "0531 Failed setup of slow-path ELS CQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7670 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7671 | goto out_destroy_mbx_cq; |
| 7672 | } |
| 7673 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7674 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7675 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7676 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7677 | |
| 7678 | /* |
| 7679 | * Set up all the Work Queues (WQs) |
| 7680 | */ |
| 7681 | |
| 7682 | /* Set up Mailbox Command Queue */ |
| 7683 | if (!phba->sli4_hba.mbx_wq) { |
| 7684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7685 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7686 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7687 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7688 | } |
| 7689 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7690 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7691 | if (rc) { |
| 7692 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7693 | "0539 Failed setup of slow-path MQ: " |
| 7694 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7695 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7696 | } |
| 7697 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7698 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7699 | phba->sli4_hba.mbx_wq->queue_id, |
| 7700 | phba->sli4_hba.mbx_cq->queue_id); |
| 7701 | |
| 7702 | /* Set up slow-path ELS Work Queue */ |
| 7703 | if (!phba->sli4_hba.els_wq) { |
| 7704 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7705 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7706 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7707 | goto out_destroy_mbx_wq; |
| 7708 | } |
| 7709 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7710 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7711 | if (rc) { |
| 7712 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7713 | "0537 Failed setup of slow-path ELS WQ: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7714 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7715 | goto out_destroy_mbx_wq; |
| 7716 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7717 | |
| 7718 | /* Bind this WQ to the ELS ring */ |
| 7719 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7720 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7721 | phba->sli4_hba.els_cq->pring = pring; |
| 7722 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7723 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7724 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7725 | phba->sli4_hba.els_wq->queue_id, |
| 7726 | phba->sli4_hba.els_cq->queue_id); |
| 7727 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7728 | /* |
| 7729 | * Create Receive Queue (RQ) |
| 7730 | */ |
| 7731 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7733 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7734 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7735 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7736 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7737 | |
| 7738 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7739 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7740 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7741 | 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] | 7742 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7743 | if (rc) { |
| 7744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7745 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 7746 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7747 | goto out_destroy_fcp_wq; |
| 7748 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7749 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7750 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7751 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7752 | "parent cq-id=%d\n", |
| 7753 | phba->sli4_hba.hdr_rq->queue_id, |
| 7754 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7755 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7756 | |
| 7757 | if (phba->cfg_fof) { |
| 7758 | rc = lpfc_fof_queue_setup(phba); |
| 7759 | if (rc) { |
| 7760 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7761 | "0549 Failed setup of FOF Queues: " |
| 7762 | "rc = 0x%x\n", rc); |
| 7763 | goto out_destroy_els_rq; |
| 7764 | } |
| 7765 | } |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 7766 | |
| 7767 | /* |
| 7768 | * Configure EQ delay multipier for interrupt coalescing using |
| 7769 | * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time. |
| 7770 | */ |
| 7771 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; |
| 7772 | fcp_eqidx += LPFC_MAX_EQ_DELAY) |
| 7773 | lpfc_modify_fcp_eq_delay(phba, fcp_eqidx); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7774 | return 0; |
| 7775 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7776 | out_destroy_els_rq: |
| 7777 | 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] | 7778 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7779 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7780 | out_destroy_mbx_wq: |
| 7781 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7782 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7783 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7784 | out_destroy_mbx_cq: |
| 7785 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7786 | out_destroy_fcp_wq: |
| 7787 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7788 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7789 | out_destroy_fcp_cq: |
| 7790 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7791 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7792 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7793 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7794 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7795 | out_error: |
| 7796 | return rc; |
| 7797 | } |
| 7798 | |
| 7799 | /** |
| 7800 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7801 | * @phba: pointer to lpfc hba data structure. |
| 7802 | * |
| 7803 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7804 | * operation. |
| 7805 | * |
| 7806 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7807 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7808 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7809 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7810 | **/ |
| 7811 | void |
| 7812 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7813 | { |
| 7814 | int fcp_qidx; |
| 7815 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7816 | /* Unset the queues created for Flash Optimized Fabric operations */ |
| 7817 | if (phba->cfg_fof) |
| 7818 | lpfc_fof_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7819 | /* Unset mailbox command work queue */ |
| 7820 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7821 | /* Unset ELS work queue */ |
| 7822 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7823 | /* Unset unsolicited receive queue */ |
| 7824 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7825 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7826 | if (phba->sli4_hba.fcp_wq) { |
| 7827 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7828 | fcp_qidx++) |
| 7829 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7830 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7831 | /* Unset mailbox command complete queue */ |
| 7832 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7833 | /* Unset ELS complete queue */ |
| 7834 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7835 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7836 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7837 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7838 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7839 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7840 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7841 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7842 | if (phba->sli4_hba.hba_eq) { |
| 7843 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7844 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7845 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7846 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | /** |
| 7850 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7851 | * @phba: pointer to lpfc hba data structure. |
| 7852 | * |
| 7853 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7854 | * events. The body of the completion queue event is a completion queue entry |
| 7855 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7856 | * the following HBA completion queue events for the worker thread to process: |
| 7857 | * - Mailbox asynchronous events |
| 7858 | * - Receive queue completion unsolicited events |
| 7859 | * Later, this can be used for all the slow-path events. |
| 7860 | * |
| 7861 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7862 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7863 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7864 | **/ |
| 7865 | static int |
| 7866 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7867 | { |
| 7868 | struct lpfc_cq_event *cq_event; |
| 7869 | int i; |
| 7870 | |
| 7871 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7872 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7873 | if (!cq_event) |
| 7874 | goto out_pool_create_fail; |
| 7875 | list_add_tail(&cq_event->list, |
| 7876 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7877 | } |
| 7878 | return 0; |
| 7879 | |
| 7880 | out_pool_create_fail: |
| 7881 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7882 | return -ENOMEM; |
| 7883 | } |
| 7884 | |
| 7885 | /** |
| 7886 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7887 | * @phba: pointer to lpfc hba data structure. |
| 7888 | * |
| 7889 | * This routine is invoked to free the pool of completion queue events at |
| 7890 | * driver unload time. Note that, it is the responsibility of the driver |
| 7891 | * cleanup routine to free all the outstanding completion-queue events |
| 7892 | * allocated from this pool back into the pool before invoking this routine |
| 7893 | * to destroy the pool. |
| 7894 | **/ |
| 7895 | static void |
| 7896 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7897 | { |
| 7898 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7899 | |
| 7900 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7901 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7902 | list_del(&cq_event->list); |
| 7903 | kfree(cq_event); |
| 7904 | } |
| 7905 | } |
| 7906 | |
| 7907 | /** |
| 7908 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7909 | * @phba: pointer to lpfc hba data structure. |
| 7910 | * |
| 7911 | * This routine is the lock free version of the API invoked to allocate a |
| 7912 | * completion-queue event from the free pool. |
| 7913 | * |
| 7914 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7915 | * NULL otherwise. |
| 7916 | **/ |
| 7917 | struct lpfc_cq_event * |
| 7918 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7919 | { |
| 7920 | struct lpfc_cq_event *cq_event = NULL; |
| 7921 | |
| 7922 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7923 | struct lpfc_cq_event, list); |
| 7924 | return cq_event; |
| 7925 | } |
| 7926 | |
| 7927 | /** |
| 7928 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7929 | * @phba: pointer to lpfc hba data structure. |
| 7930 | * |
| 7931 | * This routine is the lock version of the API invoked to allocate a |
| 7932 | * completion-queue event from the free pool. |
| 7933 | * |
| 7934 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7935 | * NULL otherwise. |
| 7936 | **/ |
| 7937 | struct lpfc_cq_event * |
| 7938 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7939 | { |
| 7940 | struct lpfc_cq_event *cq_event; |
| 7941 | unsigned long iflags; |
| 7942 | |
| 7943 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7944 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7945 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7946 | return cq_event; |
| 7947 | } |
| 7948 | |
| 7949 | /** |
| 7950 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7951 | * @phba: pointer to lpfc hba data structure. |
| 7952 | * @cq_event: pointer to the completion queue event to be freed. |
| 7953 | * |
| 7954 | * This routine is the lock free version of the API invoked to release a |
| 7955 | * completion-queue event back into the free pool. |
| 7956 | **/ |
| 7957 | void |
| 7958 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7959 | struct lpfc_cq_event *cq_event) |
| 7960 | { |
| 7961 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7962 | } |
| 7963 | |
| 7964 | /** |
| 7965 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7966 | * @phba: pointer to lpfc hba data structure. |
| 7967 | * @cq_event: pointer to the completion queue event to be freed. |
| 7968 | * |
| 7969 | * This routine is the lock version of the API invoked to release a |
| 7970 | * completion-queue event back into the free pool. |
| 7971 | **/ |
| 7972 | void |
| 7973 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7974 | struct lpfc_cq_event *cq_event) |
| 7975 | { |
| 7976 | unsigned long iflags; |
| 7977 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7978 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7979 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7980 | } |
| 7981 | |
| 7982 | /** |
| 7983 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7984 | * @phba: pointer to lpfc hba data structure. |
| 7985 | * |
| 7986 | * This routine is to free all the pending completion-queue events to the |
| 7987 | * back into the free pool for device reset. |
| 7988 | **/ |
| 7989 | static void |
| 7990 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7991 | { |
| 7992 | LIST_HEAD(cqelist); |
| 7993 | struct lpfc_cq_event *cqe; |
| 7994 | unsigned long iflags; |
| 7995 | |
| 7996 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7997 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7998 | /* Pending FCP XRI abort events */ |
| 7999 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 8000 | &cqelist); |
| 8001 | /* Pending ELS XRI abort events */ |
| 8002 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 8003 | &cqelist); |
| 8004 | /* Pending asynnc events */ |
| 8005 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 8006 | &cqelist); |
| 8007 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8008 | |
| 8009 | while (!list_empty(&cqelist)) { |
| 8010 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 8011 | lpfc_sli4_cq_event_release(phba, cqe); |
| 8012 | } |
| 8013 | } |
| 8014 | |
| 8015 | /** |
| 8016 | * lpfc_pci_function_reset - Reset pci function. |
| 8017 | * @phba: pointer to lpfc hba data structure. |
| 8018 | * |
| 8019 | * This routine is invoked to request a PCI function reset. It will destroys |
| 8020 | * all resources assigned to the PCI function which originates this request. |
| 8021 | * |
| 8022 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8023 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8024 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8025 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8026 | **/ |
| 8027 | int |
| 8028 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 8029 | { |
| 8030 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8031 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8032 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8033 | uint32_t rdy_chk; |
| 8034 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8035 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8036 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 8037 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8038 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8039 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8040 | switch (if_type) { |
| 8041 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8042 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8043 | GFP_KERNEL); |
| 8044 | if (!mboxq) { |
| 8045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8046 | "0494 Unable to allocate memory for " |
| 8047 | "issuing SLI_FUNCTION_RESET mailbox " |
| 8048 | "command\n"); |
| 8049 | return -ENOMEM; |
| 8050 | } |
| 8051 | |
| 8052 | /* Setup PCI function reset mailbox-ioctl command */ |
| 8053 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8054 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 8055 | LPFC_SLI4_MBX_EMBED); |
| 8056 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8057 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8058 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8059 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8060 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 8061 | &shdr->response); |
| 8062 | if (rc != MBX_TIMEOUT) |
| 8063 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8064 | if (shdr_status || shdr_add_status || rc) { |
| 8065 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8066 | "0495 SLI_FUNCTION_RESET mailbox " |
| 8067 | "failed with status x%x add_status x%x," |
| 8068 | " mbx status x%x\n", |
| 8069 | shdr_status, shdr_add_status, rc); |
| 8070 | rc = -ENXIO; |
| 8071 | } |
| 8072 | break; |
| 8073 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8074 | wait: |
| 8075 | /* |
| 8076 | * Poll the Port Status Register and wait for RDY for |
| 8077 | * up to 30 seconds. If the port doesn't respond, treat |
| 8078 | * it as an error. |
| 8079 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 8080 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8081 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 8082 | STATUSregaddr, ®_data.word0)) { |
| 8083 | rc = -ENODEV; |
| 8084 | goto out; |
| 8085 | } |
| 8086 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 8087 | break; |
| 8088 | msleep(20); |
| 8089 | } |
| 8090 | |
| 8091 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 8092 | phba->work_status[0] = readl( |
| 8093 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 8094 | phba->work_status[1] = readl( |
| 8095 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 8096 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8097 | "2890 Port not ready, port status reg " |
| 8098 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 8099 | reg_data.word0, |
| 8100 | phba->work_status[0], |
| 8101 | phba->work_status[1]); |
| 8102 | rc = -ENODEV; |
| 8103 | goto out; |
| 8104 | } |
| 8105 | |
| 8106 | if (!port_reset) { |
| 8107 | /* |
| 8108 | * Reset the port now |
| 8109 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8110 | reg_data.word0 = 0; |
| 8111 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 8112 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 8113 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 8114 | LPFC_SLIPORT_INIT_PORT); |
| 8115 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 8116 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 8117 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 8118 | pci_read_config_word(phba->pcidev, |
| 8119 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8120 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8121 | port_reset = 1; |
| 8122 | msleep(20); |
| 8123 | goto wait; |
| 8124 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 8125 | rc = -ENODEV; |
| 8126 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8127 | } |
| 8128 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8129 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8130 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8131 | default: |
| 8132 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | } |
| 8134 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8135 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8136 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8137 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 8138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8139 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 8140 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8141 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 8142 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8143 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8144 | return rc; |
| 8145 | } |
| 8146 | |
| 8147 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8148 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 8149 | * @phba: pointer to lpfc hba data structure. |
| 8150 | * |
| 8151 | * This routine is invoked to set up the PCI device memory space for device |
| 8152 | * with SLI-4 interface spec. |
| 8153 | * |
| 8154 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8155 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8156 | * other values - error |
| 8157 | **/ |
| 8158 | static int |
| 8159 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 8160 | { |
| 8161 | struct pci_dev *pdev; |
| 8162 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 8163 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8164 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8165 | |
| 8166 | /* Obtain PCI device reference */ |
| 8167 | if (!phba->pcidev) |
| 8168 | return error; |
| 8169 | else |
| 8170 | pdev = phba->pcidev; |
| 8171 | |
| 8172 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 8173 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 8174 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 8175 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 8176 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8177 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 8178 | } |
| 8179 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8180 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8181 | /* |
| 8182 | * The BARs and register set definitions and offset locations are |
| 8183 | * dependent on the if_type. |
| 8184 | */ |
| 8185 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 8186 | &phba->sli4_hba.sli_intf.word0)) { |
| 8187 | return error; |
| 8188 | } |
| 8189 | |
| 8190 | /* There is no SLI3 failback for SLI4 devices. */ |
| 8191 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 8192 | LPFC_SLI_INTF_VALID) { |
| 8193 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8194 | "2894 SLI_INTF reg contents invalid " |
| 8195 | "sli_intf reg 0x%x\n", |
| 8196 | phba->sli4_hba.sli_intf.word0); |
| 8197 | return error; |
| 8198 | } |
| 8199 | |
| 8200 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8201 | /* |
| 8202 | * Get the bus address of SLI4 device Bar regions and the |
| 8203 | * number of bytes required by each mapping. The mapping of the |
| 8204 | * particular PCI BARs regions is dependent on the type of |
| 8205 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8206 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8207 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 8208 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 8209 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8210 | |
| 8211 | /* |
| 8212 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 8213 | * addr |
| 8214 | */ |
| 8215 | phba->sli4_hba.conf_regs_memmap_p = |
| 8216 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 8217 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8218 | dev_printk(KERN_ERR, &pdev->dev, |
| 8219 | "ioremap failed for SLI4 PCI config " |
| 8220 | "registers.\n"); |
| 8221 | goto out; |
| 8222 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8223 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8224 | /* Set up BAR0 PCI config space register memory map */ |
| 8225 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 8226 | } else { |
| 8227 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 8228 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8229 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8230 | dev_printk(KERN_ERR, &pdev->dev, |
| 8231 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 8232 | goto out; |
| 8233 | } |
| 8234 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8235 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8236 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8237 | dev_printk(KERN_ERR, &pdev->dev, |
| 8238 | "ioremap failed for SLI4 PCI config " |
| 8239 | "registers.\n"); |
| 8240 | goto out; |
| 8241 | } |
| 8242 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8243 | } |
| 8244 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8245 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8246 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8247 | /* |
| 8248 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 8249 | * virtual address and setup the registers. |
| 8250 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8251 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 8252 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8253 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8254 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8255 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 8256 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8257 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8258 | goto out_iounmap_conf; |
| 8259 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8260 | phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8261 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8262 | } |
| 8263 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8264 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8265 | (pci_resource_start(pdev, PCI_64BIT_BAR4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8266 | /* |
| 8267 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 8268 | * virtual address and setup the registers. |
| 8269 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8270 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 8271 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8272 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8273 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8274 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 8275 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8276 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8277 | goto out_iounmap_ctrl; |
| 8278 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8279 | phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8280 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 8281 | if (error) |
| 8282 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8283 | } |
| 8284 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8285 | return 0; |
| 8286 | |
| 8287 | out_iounmap_all: |
| 8288 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8289 | out_iounmap_ctrl: |
| 8290 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8291 | out_iounmap_conf: |
| 8292 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8293 | out: |
| 8294 | return error; |
| 8295 | } |
| 8296 | |
| 8297 | /** |
| 8298 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 8299 | * @phba: pointer to lpfc hba data structure. |
| 8300 | * |
| 8301 | * This routine is invoked to unset the PCI device memory space for device |
| 8302 | * with SLI-4 interface spec. |
| 8303 | **/ |
| 8304 | static void |
| 8305 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 8306 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8307 | uint32_t if_type; |
| 8308 | 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] | 8309 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8310 | switch (if_type) { |
| 8311 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8312 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8313 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8314 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8315 | break; |
| 8316 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8317 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8318 | break; |
| 8319 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8320 | default: |
| 8321 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8322 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8323 | if_type); |
| 8324 | break; |
| 8325 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8326 | } |
| 8327 | |
| 8328 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8329 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 8330 | * @phba: pointer to lpfc hba data structure. |
| 8331 | * |
| 8332 | * 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] | 8333 | * with SLI-3 interface specs. The kernel function pci_enable_msix_exact() |
| 8334 | * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(), |
| 8335 | * once invoked, enables either all or nothing, depending on the current |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8336 | * availability of PCI vector resources. The device driver is responsible |
| 8337 | * for calling the individual request_irq() to register each MSI-X vector |
| 8338 | * with a interrupt handler, which is done in this function. Note that |
| 8339 | * later when device is unloading, the driver should always call free_irq() |
| 8340 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8341 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8342 | * will be left with MSI-X enabled and leaks its vectors. |
| 8343 | * |
| 8344 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8345 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8346 | * other values - error |
| 8347 | **/ |
| 8348 | static int |
| 8349 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 8350 | { |
| 8351 | int rc, i; |
| 8352 | LPFC_MBOXQ_t *pmb; |
| 8353 | |
| 8354 | /* Set up MSI-X multi-message vectors */ |
| 8355 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8356 | phba->msix_entries[i].entry = i; |
| 8357 | |
| 8358 | /* Configure MSI-X capability structure */ |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 8359 | rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries, |
| 8360 | LPFC_MSIX_VECTORS); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8361 | if (rc) { |
| 8362 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8363 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8364 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8365 | } |
| 8366 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8367 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8368 | "0477 MSI-X entry[%d]: vector=x%x " |
| 8369 | "message=%d\n", i, |
| 8370 | phba->msix_entries[i].vector, |
| 8371 | phba->msix_entries[i].entry); |
| 8372 | /* |
| 8373 | * Assign MSI-X vectors to interrupt handlers |
| 8374 | */ |
| 8375 | |
| 8376 | /* vector-0 is associated to slow-path handler */ |
| 8377 | rc = request_irq(phba->msix_entries[0].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8378 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8379 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 8380 | if (rc) { |
| 8381 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8382 | "0421 MSI-X slow-path request_irq failed " |
| 8383 | "(%d)\n", rc); |
| 8384 | goto msi_fail_out; |
| 8385 | } |
| 8386 | |
| 8387 | /* vector-1 is associated to fast-path handler */ |
| 8388 | rc = request_irq(phba->msix_entries[1].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8389 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8390 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 8391 | |
| 8392 | if (rc) { |
| 8393 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8394 | "0429 MSI-X fast-path request_irq failed " |
| 8395 | "(%d)\n", rc); |
| 8396 | goto irq_fail_out; |
| 8397 | } |
| 8398 | |
| 8399 | /* |
| 8400 | * Configure HBA MSI-X attention conditions to messages |
| 8401 | */ |
| 8402 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8403 | |
| 8404 | if (!pmb) { |
| 8405 | rc = -ENOMEM; |
| 8406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8407 | "0474 Unable to allocate memory for issuing " |
| 8408 | "MBOX_CONFIG_MSI command\n"); |
| 8409 | goto mem_fail_out; |
| 8410 | } |
| 8411 | rc = lpfc_config_msi(phba, pmb); |
| 8412 | if (rc) |
| 8413 | goto mbx_fail_out; |
| 8414 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8415 | if (rc != MBX_SUCCESS) { |
| 8416 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 8417 | "0351 Config MSI mailbox command failed, " |
| 8418 | "mbxCmd x%x, mbxStatus x%x\n", |
| 8419 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 8420 | goto mbx_fail_out; |
| 8421 | } |
| 8422 | |
| 8423 | /* Free memory allocated for mailbox command */ |
| 8424 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8425 | return rc; |
| 8426 | |
| 8427 | mbx_fail_out: |
| 8428 | /* Free memory allocated for mailbox command */ |
| 8429 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8430 | |
| 8431 | mem_fail_out: |
| 8432 | /* free the irq already requested */ |
| 8433 | free_irq(phba->msix_entries[1].vector, phba); |
| 8434 | |
| 8435 | irq_fail_out: |
| 8436 | /* free the irq already requested */ |
| 8437 | free_irq(phba->msix_entries[0].vector, phba); |
| 8438 | |
| 8439 | msi_fail_out: |
| 8440 | /* Unconfigure MSI-X capability structure */ |
| 8441 | pci_disable_msix(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8442 | |
| 8443 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8444 | return rc; |
| 8445 | } |
| 8446 | |
| 8447 | /** |
| 8448 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 8449 | * @phba: pointer to lpfc hba data structure. |
| 8450 | * |
| 8451 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8452 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 8453 | **/ |
| 8454 | static void |
| 8455 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 8456 | { |
| 8457 | int i; |
| 8458 | |
| 8459 | /* Free up MSI-X multi-message vectors */ |
| 8460 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8461 | free_irq(phba->msix_entries[i].vector, phba); |
| 8462 | /* Disable MSI-X */ |
| 8463 | pci_disable_msix(phba->pcidev); |
| 8464 | |
| 8465 | return; |
| 8466 | } |
| 8467 | |
| 8468 | /** |
| 8469 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 8470 | * @phba: pointer to lpfc hba data structure. |
| 8471 | * |
| 8472 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8473 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 8474 | * enable the MSI vector. The device driver is responsible for calling the |
| 8475 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 8476 | * is done in this function. |
| 8477 | * |
| 8478 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8479 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8480 | * other values - error |
| 8481 | */ |
| 8482 | static int |
| 8483 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 8484 | { |
| 8485 | int rc; |
| 8486 | |
| 8487 | rc = pci_enable_msi(phba->pcidev); |
| 8488 | if (!rc) |
| 8489 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8490 | "0462 PCI enable MSI mode success.\n"); |
| 8491 | else { |
| 8492 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8493 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 8494 | return rc; |
| 8495 | } |
| 8496 | |
| 8497 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8498 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8499 | if (rc) { |
| 8500 | pci_disable_msi(phba->pcidev); |
| 8501 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8502 | "0478 MSI request_irq failed (%d)\n", rc); |
| 8503 | } |
| 8504 | return rc; |
| 8505 | } |
| 8506 | |
| 8507 | /** |
| 8508 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 8509 | * @phba: pointer to lpfc hba data structure. |
| 8510 | * |
| 8511 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8512 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 8513 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8514 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8515 | * its vector. |
| 8516 | */ |
| 8517 | static void |
| 8518 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 8519 | { |
| 8520 | free_irq(phba->pcidev->irq, phba); |
| 8521 | pci_disable_msi(phba->pcidev); |
| 8522 | return; |
| 8523 | } |
| 8524 | |
| 8525 | /** |
| 8526 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 8527 | * @phba: pointer to lpfc hba data structure. |
| 8528 | * |
| 8529 | * This routine is invoked to enable device interrupt and associate driver's |
| 8530 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8531 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8532 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8533 | * mode which is supported by the platform, kernel, and device in the order |
| 8534 | * of: |
| 8535 | * MSI-X -> MSI -> IRQ. |
| 8536 | * |
| 8537 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8538 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8539 | * other values - error |
| 8540 | **/ |
| 8541 | static uint32_t |
| 8542 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8543 | { |
| 8544 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8545 | int retval; |
| 8546 | |
| 8547 | if (cfg_mode == 2) { |
| 8548 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8549 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8550 | if (!retval) { |
| 8551 | /* Now, try to enable MSI-X interrupt mode */ |
| 8552 | retval = lpfc_sli_enable_msix(phba); |
| 8553 | if (!retval) { |
| 8554 | /* Indicate initialization to MSI-X mode */ |
| 8555 | phba->intr_type = MSIX; |
| 8556 | intr_mode = 2; |
| 8557 | } |
| 8558 | } |
| 8559 | } |
| 8560 | |
| 8561 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8562 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8563 | retval = lpfc_sli_enable_msi(phba); |
| 8564 | if (!retval) { |
| 8565 | /* Indicate initialization to MSI mode */ |
| 8566 | phba->intr_type = MSI; |
| 8567 | intr_mode = 1; |
| 8568 | } |
| 8569 | } |
| 8570 | |
| 8571 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8572 | if (phba->intr_type == NONE) { |
| 8573 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8574 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8575 | if (!retval) { |
| 8576 | /* Indicate initialization to INTx mode */ |
| 8577 | phba->intr_type = INTx; |
| 8578 | intr_mode = 0; |
| 8579 | } |
| 8580 | } |
| 8581 | return intr_mode; |
| 8582 | } |
| 8583 | |
| 8584 | /** |
| 8585 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8586 | * @phba: pointer to lpfc hba data structure. |
| 8587 | * |
| 8588 | * This routine is invoked to disable device interrupt and disassociate the |
| 8589 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8590 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8591 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8592 | **/ |
| 8593 | static void |
| 8594 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8595 | { |
| 8596 | /* Disable the currently initialized interrupt mode */ |
| 8597 | if (phba->intr_type == MSIX) |
| 8598 | lpfc_sli_disable_msix(phba); |
| 8599 | else if (phba->intr_type == MSI) |
| 8600 | lpfc_sli_disable_msi(phba); |
| 8601 | else if (phba->intr_type == INTx) |
| 8602 | free_irq(phba->pcidev->irq, phba); |
| 8603 | |
| 8604 | /* Reset interrupt management states */ |
| 8605 | phba->intr_type = NONE; |
| 8606 | phba->sli.slistat.sli_intr = 0; |
| 8607 | |
| 8608 | return; |
| 8609 | } |
| 8610 | |
| 8611 | /** |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8612 | * lpfc_find_next_cpu - Find next available CPU that matches the phys_id |
| 8613 | * @phba: pointer to lpfc hba data structure. |
| 8614 | * |
| 8615 | * Find next available CPU to use for IRQ to CPU affinity. |
| 8616 | */ |
| 8617 | static int |
| 8618 | lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id) |
| 8619 | { |
| 8620 | struct lpfc_vector_map_info *cpup; |
| 8621 | int cpu; |
| 8622 | |
| 8623 | cpup = phba->sli4_hba.cpu_map; |
| 8624 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8625 | /* CPU must be online */ |
| 8626 | if (cpu_online(cpu)) { |
| 8627 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8628 | (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) && |
| 8629 | (cpup->phys_id == phys_id)) { |
| 8630 | return cpu; |
| 8631 | } |
| 8632 | } |
| 8633 | cpup++; |
| 8634 | } |
| 8635 | |
| 8636 | /* |
| 8637 | * If we get here, we have used ALL CPUs for the specific |
| 8638 | * phys_id. Now we need to clear out lpfc_used_cpu and start |
| 8639 | * reusing CPUs. |
| 8640 | */ |
| 8641 | |
| 8642 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8643 | if (lpfc_used_cpu[cpu] == phys_id) |
| 8644 | lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY; |
| 8645 | } |
| 8646 | |
| 8647 | cpup = phba->sli4_hba.cpu_map; |
| 8648 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8649 | /* CPU must be online */ |
| 8650 | if (cpu_online(cpu)) { |
| 8651 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8652 | (cpup->phys_id == phys_id)) { |
| 8653 | return cpu; |
| 8654 | } |
| 8655 | } |
| 8656 | cpup++; |
| 8657 | } |
| 8658 | return LPFC_VECTOR_MAP_EMPTY; |
| 8659 | } |
| 8660 | |
| 8661 | /** |
| 8662 | * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors |
| 8663 | * @phba: pointer to lpfc hba data structure. |
| 8664 | * @vectors: number of HBA vectors |
| 8665 | * |
| 8666 | * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector |
| 8667 | * affinization across multple physical CPUs (numa nodes). |
| 8668 | * In addition, this routine will assign an IO channel for each CPU |
| 8669 | * to use when issuing I/Os. |
| 8670 | */ |
| 8671 | static int |
| 8672 | lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors) |
| 8673 | { |
| 8674 | int i, idx, saved_chann, used_chann, cpu, phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8675 | int max_phys_id, min_phys_id; |
| 8676 | int num_io_channel, first_cpu, chan; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8677 | struct lpfc_vector_map_info *cpup; |
| 8678 | #ifdef CONFIG_X86 |
| 8679 | struct cpuinfo_x86 *cpuinfo; |
| 8680 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8681 | uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1]; |
| 8682 | |
| 8683 | /* If there is no mapping, just return */ |
| 8684 | if (!phba->cfg_fcp_cpu_map) |
| 8685 | return 1; |
| 8686 | |
| 8687 | /* Init cpu_map array */ |
| 8688 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 8689 | (sizeof(struct lpfc_vector_map_info) * |
| 8690 | phba->sli4_hba.num_present_cpu)); |
| 8691 | |
| 8692 | max_phys_id = 0; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8693 | min_phys_id = 0xff; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8694 | phys_id = 0; |
| 8695 | num_io_channel = 0; |
| 8696 | first_cpu = LPFC_VECTOR_MAP_EMPTY; |
| 8697 | |
| 8698 | /* Update CPU map with physical id and core id of each CPU */ |
| 8699 | cpup = phba->sli4_hba.cpu_map; |
| 8700 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8701 | #ifdef CONFIG_X86 |
| 8702 | cpuinfo = &cpu_data(cpu); |
| 8703 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 8704 | cpup->core_id = cpuinfo->cpu_core_id; |
| 8705 | #else |
| 8706 | /* No distinction between CPUs for other platforms */ |
| 8707 | cpup->phys_id = 0; |
| 8708 | cpup->core_id = 0; |
| 8709 | #endif |
| 8710 | |
| 8711 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8712 | "3328 CPU physid %d coreid %d\n", |
| 8713 | cpup->phys_id, cpup->core_id); |
| 8714 | |
| 8715 | if (cpup->phys_id > max_phys_id) |
| 8716 | max_phys_id = cpup->phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8717 | if (cpup->phys_id < min_phys_id) |
| 8718 | min_phys_id = cpup->phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8719 | cpup++; |
| 8720 | } |
| 8721 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8722 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8723 | /* Now associate the HBA vectors with specific CPUs */ |
| 8724 | for (idx = 0; idx < vectors; idx++) { |
| 8725 | cpup = phba->sli4_hba.cpu_map; |
| 8726 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8727 | if (cpu == LPFC_VECTOR_MAP_EMPTY) { |
| 8728 | |
| 8729 | /* Try for all phys_id's */ |
| 8730 | for (i = 1; i < max_phys_id; i++) { |
| 8731 | phys_id++; |
| 8732 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8733 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8734 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8735 | if (cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8736 | continue; |
| 8737 | goto found; |
| 8738 | } |
| 8739 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8740 | /* Use round robin for scheduling */ |
| 8741 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN; |
| 8742 | chan = 0; |
| 8743 | cpup = phba->sli4_hba.cpu_map; |
| 8744 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 8745 | cpup->channel_id = chan; |
| 8746 | cpup++; |
| 8747 | chan++; |
| 8748 | if (chan >= phba->cfg_fcp_io_channel) |
| 8749 | chan = 0; |
| 8750 | } |
| 8751 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8753 | "3329 Cannot set affinity:" |
| 8754 | "Error mapping vector %d (%d)\n", |
| 8755 | idx, vectors); |
| 8756 | return 0; |
| 8757 | } |
| 8758 | found: |
| 8759 | cpup += cpu; |
| 8760 | if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP) |
| 8761 | lpfc_used_cpu[cpu] = phys_id; |
| 8762 | |
| 8763 | /* Associate vector with selected CPU */ |
| 8764 | cpup->irq = phba->sli4_hba.msix_entries[idx].vector; |
| 8765 | |
| 8766 | /* Associate IO channel with selected CPU */ |
| 8767 | cpup->channel_id = idx; |
| 8768 | num_io_channel++; |
| 8769 | |
| 8770 | if (first_cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8771 | first_cpu = cpu; |
| 8772 | |
| 8773 | /* Now affinitize to the selected CPU */ |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8774 | i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx]. |
Ian Mitchell | c0365c0 | 2015-08-31 16:48:12 -0400 | [diff] [blame^] | 8775 | vector, get_cpu_mask(cpu)); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8776 | |
| 8777 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8778 | "3330 Set Affinity: CPU %d channel %d " |
| 8779 | "irq %d (%x)\n", |
| 8780 | cpu, cpup->channel_id, |
| 8781 | phba->sli4_hba.msix_entries[idx].vector, i); |
| 8782 | |
| 8783 | /* Spread vector mapping across multple physical CPU nodes */ |
| 8784 | phys_id++; |
| 8785 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8786 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8787 | } |
| 8788 | |
| 8789 | /* |
| 8790 | * Finally fill in the IO channel for any remaining CPUs. |
| 8791 | * At this point, all IO channels have been assigned to a specific |
| 8792 | * MSIx vector, mapped to a specific CPU. |
| 8793 | * Base the remaining IO channel assigned, to IO channels already |
| 8794 | * assigned to other CPUs on the same phys_id. |
| 8795 | */ |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8796 | for (i = min_phys_id; i <= max_phys_id; i++) { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8797 | /* |
| 8798 | * If there are no io channels already mapped to |
| 8799 | * this phys_id, just round robin thru the io_channels. |
| 8800 | * Setup chann[] for round robin. |
| 8801 | */ |
| 8802 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8803 | chann[idx] = idx; |
| 8804 | |
| 8805 | saved_chann = 0; |
| 8806 | used_chann = 0; |
| 8807 | |
| 8808 | /* |
| 8809 | * First build a list of IO channels already assigned |
| 8810 | * to this phys_id before reassigning the same IO |
| 8811 | * channels to the remaining CPUs. |
| 8812 | */ |
| 8813 | cpup = phba->sli4_hba.cpu_map; |
| 8814 | cpu = first_cpu; |
| 8815 | cpup += cpu; |
| 8816 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; |
| 8817 | idx++) { |
| 8818 | if (cpup->phys_id == i) { |
| 8819 | /* |
| 8820 | * Save any IO channels that are |
| 8821 | * already mapped to this phys_id. |
| 8822 | */ |
| 8823 | if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) { |
| 8824 | chann[saved_chann] = |
| 8825 | cpup->channel_id; |
| 8826 | saved_chann++; |
| 8827 | goto out; |
| 8828 | } |
| 8829 | |
| 8830 | /* See if we are using round-robin */ |
| 8831 | if (saved_chann == 0) |
| 8832 | saved_chann = |
| 8833 | phba->cfg_fcp_io_channel; |
| 8834 | |
| 8835 | /* Associate next IO channel with CPU */ |
| 8836 | cpup->channel_id = chann[used_chann]; |
| 8837 | num_io_channel++; |
| 8838 | used_chann++; |
| 8839 | if (used_chann == saved_chann) |
| 8840 | used_chann = 0; |
| 8841 | |
| 8842 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8843 | "3331 Set IO_CHANN " |
| 8844 | "CPU %d channel %d\n", |
| 8845 | idx, cpup->channel_id); |
| 8846 | } |
| 8847 | out: |
| 8848 | cpu++; |
| 8849 | if (cpu >= phba->sli4_hba.num_present_cpu) { |
| 8850 | cpup = phba->sli4_hba.cpu_map; |
| 8851 | cpu = 0; |
| 8852 | } else { |
| 8853 | cpup++; |
| 8854 | } |
| 8855 | } |
| 8856 | } |
| 8857 | |
| 8858 | if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) { |
| 8859 | cpup = phba->sli4_hba.cpu_map; |
| 8860 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) { |
| 8861 | if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) { |
| 8862 | cpup->channel_id = 0; |
| 8863 | num_io_channel++; |
| 8864 | |
| 8865 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8866 | "3332 Assign IO_CHANN " |
| 8867 | "CPU %d channel %d\n", |
| 8868 | idx, cpup->channel_id); |
| 8869 | } |
| 8870 | cpup++; |
| 8871 | } |
| 8872 | } |
| 8873 | |
| 8874 | /* Sanity check */ |
| 8875 | if (num_io_channel != phba->sli4_hba.num_present_cpu) |
| 8876 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8877 | "3333 Set affinity mismatch:" |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8878 | "%d chann != %d cpus: %d vectors\n", |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8879 | num_io_channel, phba->sli4_hba.num_present_cpu, |
| 8880 | vectors); |
| 8881 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8882 | /* Enable using cpu affinity for scheduling */ |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8883 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU; |
| 8884 | return 1; |
| 8885 | } |
| 8886 | |
| 8887 | |
| 8888 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8889 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8890 | * @phba: pointer to lpfc hba data structure. |
| 8891 | * |
| 8892 | * 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] | 8893 | * with SLI-4 interface spec. The kernel function pci_enable_msix_range() |
| 8894 | * is called to enable the MSI-X vectors. The device driver is responsible |
| 8895 | * for calling the individual request_irq() to register each MSI-X vector |
| 8896 | * with a interrupt handler, which is done in this function. Note that |
| 8897 | * later when device is unloading, the driver should always call free_irq() |
| 8898 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8899 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8900 | * will be left with MSI-X enabled and leaks its vectors. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8901 | * |
| 8902 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8903 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8904 | * other values - error |
| 8905 | **/ |
| 8906 | static int |
| 8907 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8908 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8909 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8910 | |
| 8911 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8912 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8913 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8914 | |
| 8915 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8916 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8917 | if (phba->cfg_fof) { |
| 8918 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8919 | vectors++; |
| 8920 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 8921 | rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries, |
| 8922 | 2, vectors); |
| 8923 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8924 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8925 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8926 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8927 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 8928 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8929 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8930 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8931 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8932 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8933 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8934 | "message=%d\n", index, |
| 8935 | phba->sli4_hba.msix_entries[index].vector, |
| 8936 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8937 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8938 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8939 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8940 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8941 | snprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8942 | LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8943 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8944 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8945 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8946 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8947 | 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] | 8948 | if (phba->cfg_fof && (index == (vectors - 1))) |
| 8949 | rc = request_irq( |
| 8950 | phba->sli4_hba.msix_entries[index].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8951 | &lpfc_sli4_fof_intr_handler, 0, |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8952 | (char *)&phba->sli4_hba.handler_name[index], |
| 8953 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 8954 | else |
| 8955 | rc = request_irq( |
| 8956 | phba->sli4_hba.msix_entries[index].vector, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 8957 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8958 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8959 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8960 | if (rc) { |
| 8961 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8962 | "0486 MSI-X fast-path (%d) " |
| 8963 | "request_irq failed (%d)\n", index, rc); |
| 8964 | goto cfg_fail_out; |
| 8965 | } |
| 8966 | } |
| 8967 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8968 | if (phba->cfg_fof) |
| 8969 | vectors--; |
| 8970 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8971 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8972 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8973 | "3238 Reducing IO channels to match number of " |
| 8974 | "MSI-X vectors, requested %d got %d\n", |
| 8975 | phba->cfg_fcp_io_channel, vectors); |
| 8976 | phba->cfg_fcp_io_channel = vectors; |
| 8977 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8978 | |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 8979 | if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport))) |
| 8980 | lpfc_sli4_set_affinity(phba, vectors); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8981 | return rc; |
| 8982 | |
| 8983 | cfg_fail_out: |
| 8984 | /* free the irq already requested */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8985 | for (--index; index >= 0; index--) { |
| 8986 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 8987 | vector, NULL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8988 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8989 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8990 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8991 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8992 | /* Unconfigure MSI-X capability structure */ |
| 8993 | pci_disable_msix(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 8994 | |
| 8995 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8996 | return rc; |
| 8997 | } |
| 8998 | |
| 8999 | /** |
| 9000 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 9001 | * @phba: pointer to lpfc hba data structure. |
| 9002 | * |
| 9003 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 9004 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 9005 | **/ |
| 9006 | static void |
| 9007 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 9008 | { |
| 9009 | int index; |
| 9010 | |
| 9011 | /* Free up MSI-X multi-message vectors */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9012 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
| 9013 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 9014 | vector, NULL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9015 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9016 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 9017 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9018 | if (phba->cfg_fof) { |
| 9019 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 9020 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 9021 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9022 | /* Disable MSI-X */ |
| 9023 | pci_disable_msix(phba->pcidev); |
| 9024 | |
| 9025 | return; |
| 9026 | } |
| 9027 | |
| 9028 | /** |
| 9029 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 9030 | * @phba: pointer to lpfc hba data structure. |
| 9031 | * |
| 9032 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 9033 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 9034 | * to enable the MSI vector. The device driver is responsible for calling |
| 9035 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 9036 | * which is done in this function. |
| 9037 | * |
| 9038 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9039 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9040 | * other values - error |
| 9041 | **/ |
| 9042 | static int |
| 9043 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 9044 | { |
| 9045 | int rc, index; |
| 9046 | |
| 9047 | rc = pci_enable_msi(phba->pcidev); |
| 9048 | if (!rc) |
| 9049 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9050 | "0487 PCI enable MSI mode success.\n"); |
| 9051 | else { |
| 9052 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9053 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 9054 | return rc; |
| 9055 | } |
| 9056 | |
| 9057 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9058 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9059 | if (rc) { |
| 9060 | pci_disable_msi(phba->pcidev); |
| 9061 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9062 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9063 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9064 | } |
| 9065 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9066 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9067 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9068 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9069 | } |
| 9070 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9071 | if (phba->cfg_fof) { |
| 9072 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9073 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9074 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9075 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9076 | } |
| 9077 | |
| 9078 | /** |
| 9079 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 9080 | * @phba: pointer to lpfc hba data structure. |
| 9081 | * |
| 9082 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 9083 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 9084 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 9085 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 9086 | * its vector. |
| 9087 | **/ |
| 9088 | static void |
| 9089 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 9090 | { |
| 9091 | free_irq(phba->pcidev->irq, phba); |
| 9092 | pci_disable_msi(phba->pcidev); |
| 9093 | return; |
| 9094 | } |
| 9095 | |
| 9096 | /** |
| 9097 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 9098 | * @phba: pointer to lpfc hba data structure. |
| 9099 | * |
| 9100 | * This routine is invoked to enable device interrupt and associate driver's |
| 9101 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 9102 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 9103 | * the driver will try to fallback from the configured interrupt mode to an |
| 9104 | * interrupt mode which is supported by the platform, kernel, and device in |
| 9105 | * the order of: |
| 9106 | * MSI-X -> MSI -> IRQ. |
| 9107 | * |
| 9108 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9109 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9110 | * other values - error |
| 9111 | **/ |
| 9112 | static uint32_t |
| 9113 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 9114 | { |
| 9115 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 9116 | int retval, index; |
| 9117 | |
| 9118 | if (cfg_mode == 2) { |
| 9119 | /* Preparation before conf_msi mbox cmd */ |
| 9120 | retval = 0; |
| 9121 | if (!retval) { |
| 9122 | /* Now, try to enable MSI-X interrupt mode */ |
| 9123 | retval = lpfc_sli4_enable_msix(phba); |
| 9124 | if (!retval) { |
| 9125 | /* Indicate initialization to MSI-X mode */ |
| 9126 | phba->intr_type = MSIX; |
| 9127 | intr_mode = 2; |
| 9128 | } |
| 9129 | } |
| 9130 | } |
| 9131 | |
| 9132 | /* Fallback to MSI if MSI-X initialization failed */ |
| 9133 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 9134 | retval = lpfc_sli4_enable_msi(phba); |
| 9135 | if (!retval) { |
| 9136 | /* Indicate initialization to MSI mode */ |
| 9137 | phba->intr_type = MSI; |
| 9138 | intr_mode = 1; |
| 9139 | } |
| 9140 | } |
| 9141 | |
| 9142 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 9143 | if (phba->intr_type == NONE) { |
| 9144 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 9145 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 9146 | if (!retval) { |
| 9147 | /* Indicate initialization to INTx mode */ |
| 9148 | phba->intr_type = INTx; |
| 9149 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9150 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9151 | index++) { |
| 9152 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9153 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9154 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 9155 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9156 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9157 | if (phba->cfg_fof) { |
| 9158 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 9159 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 9160 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 9161 | fcp_eq_in_use, 1); |
| 9162 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9163 | } |
| 9164 | } |
| 9165 | return intr_mode; |
| 9166 | } |
| 9167 | |
| 9168 | /** |
| 9169 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 9170 | * @phba: pointer to lpfc hba data structure. |
| 9171 | * |
| 9172 | * This routine is invoked to disable device interrupt and disassociate |
| 9173 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 9174 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 9175 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 9176 | **/ |
| 9177 | static void |
| 9178 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 9179 | { |
| 9180 | /* Disable the currently initialized interrupt mode */ |
| 9181 | if (phba->intr_type == MSIX) |
| 9182 | lpfc_sli4_disable_msix(phba); |
| 9183 | else if (phba->intr_type == MSI) |
| 9184 | lpfc_sli4_disable_msi(phba); |
| 9185 | else if (phba->intr_type == INTx) |
| 9186 | free_irq(phba->pcidev->irq, phba); |
| 9187 | |
| 9188 | /* Reset interrupt management states */ |
| 9189 | phba->intr_type = NONE; |
| 9190 | phba->sli.slistat.sli_intr = 0; |
| 9191 | |
| 9192 | return; |
| 9193 | } |
| 9194 | |
| 9195 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9196 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 9197 | * @phba: pointer to lpfc hba data structure. |
| 9198 | * |
| 9199 | * This routine is invoked to unset the HBA device initialization steps to |
| 9200 | * a device with SLI-3 interface spec. |
| 9201 | **/ |
| 9202 | static void |
| 9203 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 9204 | { |
| 9205 | struct lpfc_vport *vport = phba->pport; |
| 9206 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9207 | |
| 9208 | spin_lock_irq(shost->host_lock); |
| 9209 | vport->load_flag |= FC_UNLOADING; |
| 9210 | spin_unlock_irq(shost->host_lock); |
| 9211 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9212 | kfree(phba->vpi_bmask); |
| 9213 | kfree(phba->vpi_ids); |
| 9214 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9215 | lpfc_stop_hba_timers(phba); |
| 9216 | |
| 9217 | phba->pport->work_port_events = 0; |
| 9218 | |
| 9219 | lpfc_sli_hba_down(phba); |
| 9220 | |
| 9221 | lpfc_sli_brdrestart(phba); |
| 9222 | |
| 9223 | lpfc_sli_disable_intr(phba); |
| 9224 | |
| 9225 | return; |
| 9226 | } |
| 9227 | |
| 9228 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9229 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 9230 | * @phba: Pointer to HBA context object. |
| 9231 | * |
| 9232 | * This function is called in the SLI4 code path to wait for completion |
| 9233 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 9234 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 9235 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 9236 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 9237 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 9238 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 9239 | * the rest of the driver unload resource release. |
| 9240 | **/ |
| 9241 | static void |
| 9242 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 9243 | { |
| 9244 | int wait_time = 0; |
| 9245 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9246 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9247 | |
| 9248 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 9249 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 9250 | if (!fcp_xri_cmpl) |
| 9251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9252 | "2877 FCP XRI exchange busy " |
| 9253 | "wait time: %d seconds.\n", |
| 9254 | wait_time/1000); |
| 9255 | if (!els_xri_cmpl) |
| 9256 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9257 | "2878 ELS XRI exchange busy " |
| 9258 | "wait time: %d seconds.\n", |
| 9259 | wait_time/1000); |
| 9260 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 9261 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 9262 | } else { |
| 9263 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 9264 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 9265 | } |
| 9266 | fcp_xri_cmpl = |
| 9267 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9268 | els_xri_cmpl = |
| 9269 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9270 | } |
| 9271 | } |
| 9272 | |
| 9273 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9274 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 9275 | * @phba: Pointer to HBA context object. |
| 9276 | * |
| 9277 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 9278 | * function. The caller is not required to hold any lock. This routine |
| 9279 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 9280 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 9281 | * free any pending commands. |
| 9282 | **/ |
| 9283 | static void |
| 9284 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 9285 | { |
| 9286 | int wait_cnt = 0; |
| 9287 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9288 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9289 | |
| 9290 | lpfc_stop_hba_timers(phba); |
| 9291 | phba->sli4_hba.intr_enable = 0; |
| 9292 | |
| 9293 | /* |
| 9294 | * Gracefully wait out the potential current outstanding asynchronous |
| 9295 | * mailbox command. |
| 9296 | */ |
| 9297 | |
| 9298 | /* First, block any pending async mailbox command from posted */ |
| 9299 | spin_lock_irq(&phba->hbalock); |
| 9300 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 9301 | spin_unlock_irq(&phba->hbalock); |
| 9302 | /* Now, trying to wait it out if we can */ |
| 9303 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9304 | msleep(10); |
| 9305 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 9306 | break; |
| 9307 | } |
| 9308 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 9309 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9310 | spin_lock_irq(&phba->hbalock); |
| 9311 | mboxq = phba->sli.mbox_active; |
| 9312 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9313 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9314 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9315 | phba->sli.mbox_active = NULL; |
| 9316 | spin_unlock_irq(&phba->hbalock); |
| 9317 | } |
| 9318 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9319 | /* Abort all iocbs associated with the hba */ |
| 9320 | lpfc_sli_hba_iocb_abort(phba); |
| 9321 | |
| 9322 | /* Wait for completion of device XRI exchange busy */ |
| 9323 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 9324 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9325 | /* Disable PCI subsystem interrupt */ |
| 9326 | lpfc_sli4_disable_intr(phba); |
| 9327 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9328 | /* Disable SR-IOV if enabled */ |
| 9329 | if (phba->cfg_sriov_nr_virtfn) |
| 9330 | pci_disable_sriov(pdev); |
| 9331 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9332 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9333 | kthread_stop(phba->worker_thread); |
| 9334 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9335 | /* Reset SLI4 HBA FCoE function */ |
| 9336 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9337 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9338 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9339 | /* Stop the SLI4 device port */ |
| 9340 | phba->pport->work_port_events = 0; |
| 9341 | } |
| 9342 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9343 | /** |
| 9344 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 9345 | * @phba: Pointer to HBA context object. |
| 9346 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9347 | * |
| 9348 | * This function is called in the SLI4 code path to read the port's |
| 9349 | * sli4 capabilities. |
| 9350 | * |
| 9351 | * This function may be be called from any context that can block-wait |
| 9352 | * for the completion. The expectation is that this routine is called |
| 9353 | * typically from probe_one or from the online routine. |
| 9354 | **/ |
| 9355 | int |
| 9356 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9357 | { |
| 9358 | int rc; |
| 9359 | struct lpfc_mqe *mqe; |
| 9360 | struct lpfc_pc_sli4_params *sli4_params; |
| 9361 | uint32_t mbox_tmo; |
| 9362 | |
| 9363 | rc = 0; |
| 9364 | mqe = &mboxq->u.mqe; |
| 9365 | |
| 9366 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9367 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9368 | if (!phba->sli4_hba.intr_enable) |
| 9369 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9370 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9371 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9372 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9373 | } |
| 9374 | |
| 9375 | if (unlikely(rc)) |
| 9376 | return 1; |
| 9377 | |
| 9378 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9379 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 9380 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 9381 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 9382 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 9383 | &mqe->un.sli4_params); |
| 9384 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 9385 | &mqe->un.sli4_params); |
| 9386 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 9387 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 9388 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 9389 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 9390 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 9391 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 9392 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 9393 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 9394 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 9395 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 9396 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 9397 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 9398 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 9399 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 9400 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 9401 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 9402 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 9403 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 9404 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 9405 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 9406 | 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] | 9407 | |
| 9408 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9409 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9410 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9411 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9412 | return rc; |
| 9413 | } |
| 9414 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9415 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9416 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 9417 | * @phba: Pointer to HBA context object. |
| 9418 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9419 | * |
| 9420 | * This function is called in the SLI4 code path to read the port's |
| 9421 | * sli4 capabilities. |
| 9422 | * |
| 9423 | * This function may be be called from any context that can block-wait |
| 9424 | * for the completion. The expectation is that this routine is called |
| 9425 | * typically from probe_one or from the online routine. |
| 9426 | **/ |
| 9427 | int |
| 9428 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9429 | { |
| 9430 | int rc; |
| 9431 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 9432 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9433 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9434 | int length; |
| 9435 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 9436 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9437 | /* |
| 9438 | * By default, the driver assumes the SLI4 port requires RPI |
| 9439 | * header postings. The SLI4_PARAM response will correct this |
| 9440 | * assumption. |
| 9441 | */ |
| 9442 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 9443 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9444 | /* Read the port's SLI4 Config Parameters */ |
| 9445 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 9446 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9447 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9448 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 9449 | length, LPFC_SLI4_MBX_EMBED); |
| 9450 | if (!phba->sli4_hba.intr_enable) |
| 9451 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9452 | else { |
| 9453 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 9454 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9455 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9456 | if (unlikely(rc)) |
| 9457 | return rc; |
| 9458 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9459 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 9460 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 9461 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 9462 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 9463 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 9464 | mbx_sli4_parameters); |
| 9465 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 9466 | mbx_sli4_parameters); |
| 9467 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 9468 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 9469 | else |
| 9470 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 9471 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 9472 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9473 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9474 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 9475 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 9476 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 9477 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 9478 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9479 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 9480 | mbx_sli4_parameters); |
| 9481 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 9482 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9483 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 9484 | 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] | 9485 | |
| 9486 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9487 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9488 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9489 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9490 | return 0; |
| 9491 | } |
| 9492 | |
| 9493 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9494 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 9495 | * @pdev: pointer to PCI device |
| 9496 | * @pid: pointer to PCI device identifier |
| 9497 | * |
| 9498 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 9499 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9500 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9501 | * information of the device and driver to see if the driver state that it can |
| 9502 | * support this kind of device. If the match is successful, the driver core |
| 9503 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 9504 | * does all the initialization that it needs to do to handle the HBA properly. |
| 9505 | * |
| 9506 | * Return code |
| 9507 | * 0 - driver can claim the device |
| 9508 | * negative value - driver can not claim the device |
| 9509 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9510 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9511 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9512 | { |
| 9513 | struct lpfc_hba *phba; |
| 9514 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9515 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9516 | int error; |
| 9517 | uint32_t cfg_mode, intr_mode; |
| 9518 | |
| 9519 | /* Allocate memory for HBA structure */ |
| 9520 | phba = lpfc_hba_alloc(pdev); |
| 9521 | if (!phba) |
| 9522 | return -ENOMEM; |
| 9523 | |
| 9524 | /* Perform generic PCI device enabling operation */ |
| 9525 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9526 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9527 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9528 | |
| 9529 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 9530 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 9531 | if (error) |
| 9532 | goto out_disable_pci_dev; |
| 9533 | |
| 9534 | /* Set up SLI-3 specific device PCI memory space */ |
| 9535 | error = lpfc_sli_pci_mem_setup(phba); |
| 9536 | if (error) { |
| 9537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9538 | "1402 Failed to set up pci memory space.\n"); |
| 9539 | goto out_disable_pci_dev; |
| 9540 | } |
| 9541 | |
| 9542 | /* Set up phase-1 common device driver resources */ |
| 9543 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9544 | if (error) { |
| 9545 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9546 | "1403 Failed to set up driver resource.\n"); |
| 9547 | goto out_unset_pci_mem_s3; |
| 9548 | } |
| 9549 | |
| 9550 | /* Set up SLI-3 specific device driver resources */ |
| 9551 | error = lpfc_sli_driver_resource_setup(phba); |
| 9552 | if (error) { |
| 9553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9554 | "1404 Failed to set up driver resource.\n"); |
| 9555 | goto out_unset_pci_mem_s3; |
| 9556 | } |
| 9557 | |
| 9558 | /* Initialize and populate the iocb list per host */ |
| 9559 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 9560 | if (error) { |
| 9561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9562 | "1405 Failed to initialize iocb list.\n"); |
| 9563 | goto out_unset_driver_resource_s3; |
| 9564 | } |
| 9565 | |
| 9566 | /* Set up common device driver resources */ |
| 9567 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9568 | if (error) { |
| 9569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9570 | "1406 Failed to set up driver resource.\n"); |
| 9571 | goto out_free_iocb_list; |
| 9572 | } |
| 9573 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9574 | /* Get the default values for Model Name and Description */ |
| 9575 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9576 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9577 | /* Create SCSI host to the physical port */ |
| 9578 | error = lpfc_create_shost(phba); |
| 9579 | if (error) { |
| 9580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9581 | "1407 Failed to create scsi host.\n"); |
| 9582 | goto out_unset_driver_resource; |
| 9583 | } |
| 9584 | |
| 9585 | /* Configure sysfs attributes */ |
| 9586 | vport = phba->pport; |
| 9587 | error = lpfc_alloc_sysfs_attr(vport); |
| 9588 | if (error) { |
| 9589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9590 | "1476 Failed to allocate sysfs attr\n"); |
| 9591 | goto out_destroy_shost; |
| 9592 | } |
| 9593 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9594 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9595 | /* Now, trying to enable interrupt and bring up the device */ |
| 9596 | cfg_mode = phba->cfg_use_msi; |
| 9597 | while (true) { |
| 9598 | /* Put device to a known state before enabling interrupt */ |
| 9599 | lpfc_stop_port(phba); |
| 9600 | /* Configure and enable interrupt */ |
| 9601 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 9602 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9604 | "0431 Failed to enable interrupt.\n"); |
| 9605 | error = -ENODEV; |
| 9606 | goto out_free_sysfs_attr; |
| 9607 | } |
| 9608 | /* SLI-3 HBA setup */ |
| 9609 | if (lpfc_sli_hba_setup(phba)) { |
| 9610 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9611 | "1477 Failed to set up hba\n"); |
| 9612 | error = -ENODEV; |
| 9613 | goto out_remove_device; |
| 9614 | } |
| 9615 | |
| 9616 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 9617 | msleep(50); |
| 9618 | /* Check active interrupts on message signaled interrupts */ |
| 9619 | if (intr_mode == 0 || |
| 9620 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 9621 | /* Log the current active interrupt mode */ |
| 9622 | phba->intr_mode = intr_mode; |
| 9623 | lpfc_log_intr_mode(phba, intr_mode); |
| 9624 | break; |
| 9625 | } else { |
| 9626 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9627 | "0447 Configure interrupt mode (%d) " |
| 9628 | "failed active interrupt test.\n", |
| 9629 | intr_mode); |
| 9630 | /* Disable the current interrupt mode */ |
| 9631 | lpfc_sli_disable_intr(phba); |
| 9632 | /* Try next level of interrupt mode */ |
| 9633 | cfg_mode = --intr_mode; |
| 9634 | } |
| 9635 | } |
| 9636 | |
| 9637 | /* Perform post initialization setup */ |
| 9638 | lpfc_post_init_setup(phba); |
| 9639 | |
| 9640 | /* Check if there are static vports to be created. */ |
| 9641 | lpfc_create_static_vport(phba); |
| 9642 | |
| 9643 | return 0; |
| 9644 | |
| 9645 | out_remove_device: |
| 9646 | lpfc_unset_hba(phba); |
| 9647 | out_free_sysfs_attr: |
| 9648 | lpfc_free_sysfs_attr(vport); |
| 9649 | out_destroy_shost: |
| 9650 | lpfc_destroy_shost(phba); |
| 9651 | out_unset_driver_resource: |
| 9652 | lpfc_unset_driver_resource_phase2(phba); |
| 9653 | out_free_iocb_list: |
| 9654 | lpfc_free_iocb_list(phba); |
| 9655 | out_unset_driver_resource_s3: |
| 9656 | lpfc_sli_driver_resource_unset(phba); |
| 9657 | out_unset_pci_mem_s3: |
| 9658 | lpfc_sli_pci_mem_unset(phba); |
| 9659 | out_disable_pci_dev: |
| 9660 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9661 | if (shost) |
| 9662 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9663 | out_free_phba: |
| 9664 | lpfc_hba_free(phba); |
| 9665 | return error; |
| 9666 | } |
| 9667 | |
| 9668 | /** |
| 9669 | * 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] | 9670 | * @pdev: pointer to PCI device |
| 9671 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9672 | * This routine is to be called to disattach a device with SLI-3 interface |
| 9673 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9674 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9675 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9676 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9677 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9678 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9679 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9680 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9681 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9682 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9683 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9684 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9685 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 9686 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9687 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9688 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9689 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9690 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9691 | lpfc_free_sysfs_attr(vport); |
| 9692 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9693 | /* Release all the vports against this physical port */ |
| 9694 | vports = lpfc_create_vport_work_array(phba); |
| 9695 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9696 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9697 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9698 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9699 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9700 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9701 | lpfc_destroy_vport_work_array(phba, vports); |
| 9702 | |
| 9703 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9704 | fc_remove_host(shost); |
| 9705 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 9706 | lpfc_cleanup(vport); |
| 9707 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9708 | /* |
| 9709 | * Bring down the SLI Layer. This step disable all interrupts, |
| 9710 | * clears the rings, discards all mailbox commands, and resets |
| 9711 | * the HBA. |
| 9712 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9713 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 9714 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9715 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9716 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9717 | kthread_stop(phba->worker_thread); |
| 9718 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9719 | lpfc_sli_brdrestart(phba); |
| 9720 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9721 | kfree(phba->vpi_bmask); |
| 9722 | kfree(phba->vpi_ids); |
| 9723 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9724 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9725 | spin_lock_irq(&phba->hbalock); |
| 9726 | list_del_init(&vport->listentry); |
| 9727 | spin_unlock_irq(&phba->hbalock); |
| 9728 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9729 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9730 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9731 | /* Disable SR-IOV if enabled */ |
| 9732 | if (phba->cfg_sriov_nr_virtfn) |
| 9733 | pci_disable_sriov(pdev); |
| 9734 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9735 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9736 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9737 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9738 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9739 | |
| 9740 | /* |
| 9741 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 9742 | * corresponding pools here. |
| 9743 | */ |
| 9744 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9745 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9746 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9747 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9748 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9749 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9750 | /* Free resources associated with SLI2 interface */ |
| 9751 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9752 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9753 | |
| 9754 | /* unmap adapter SLIM and Control Registers */ |
| 9755 | iounmap(phba->ctrl_regs_memmap_p); |
| 9756 | iounmap(phba->slim_memmap_p); |
| 9757 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9758 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9759 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9760 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9761 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9762 | } |
| 9763 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9764 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9765 | * 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] | 9766 | * @pdev: pointer to PCI device |
| 9767 | * @msg: power management message |
| 9768 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9769 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9770 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 9771 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 9772 | * worker thread for the device, turning off device's interrupt and DMA, |
| 9773 | * and bring the device offline. Note that as the driver implements the |
| 9774 | * minimum PM requirements to a power-aware driver's PM support for the |
| 9775 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9776 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 9777 | * fully reinitialize its device during resume() method call, the driver will |
| 9778 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 9779 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9780 | * |
| 9781 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9782 | * 0 - driver suspended the device |
| 9783 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9784 | **/ |
| 9785 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9786 | 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] | 9787 | { |
| 9788 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9789 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9790 | |
| 9791 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9792 | "0473 PCI device Power Management suspend.\n"); |
| 9793 | |
| 9794 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9795 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9796 | lpfc_offline(phba); |
| 9797 | kthread_stop(phba->worker_thread); |
| 9798 | |
| 9799 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9800 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9801 | |
| 9802 | /* Save device state to PCI config space */ |
| 9803 | pci_save_state(pdev); |
| 9804 | pci_set_power_state(pdev, PCI_D3hot); |
| 9805 | |
| 9806 | return 0; |
| 9807 | } |
| 9808 | |
| 9809 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9810 | * 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] | 9811 | * @pdev: pointer to PCI device |
| 9812 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9813 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9814 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9815 | * invokes this method, it restores the device's PCI config space state and |
| 9816 | * fully reinitializes the device and brings it online. Note that as the |
| 9817 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9818 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9819 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9820 | * driver will fully reinitialize its device during resume() method call, |
| 9821 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9822 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9823 | * |
| 9824 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9825 | * 0 - driver suspended the device |
| 9826 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9827 | **/ |
| 9828 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9829 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9830 | { |
| 9831 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9832 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9833 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9834 | int error; |
| 9835 | |
| 9836 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9837 | "0452 PCI device Power Management resume.\n"); |
| 9838 | |
| 9839 | /* Restore device state from PCI config space */ |
| 9840 | pci_set_power_state(pdev, PCI_D0); |
| 9841 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9842 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9843 | /* |
| 9844 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9845 | * device saved_state flag, need to save the restored state again. |
| 9846 | */ |
| 9847 | pci_save_state(pdev); |
| 9848 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9849 | if (pdev->is_busmaster) |
| 9850 | pci_set_master(pdev); |
| 9851 | |
| 9852 | /* Startup the kernel thread for this host adapter. */ |
| 9853 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9854 | "lpfc_worker_%d", phba->brd_no); |
| 9855 | if (IS_ERR(phba->worker_thread)) { |
| 9856 | error = PTR_ERR(phba->worker_thread); |
| 9857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9858 | "0434 PM resume failed to start worker " |
| 9859 | "thread: error=x%x.\n", error); |
| 9860 | return error; |
| 9861 | } |
| 9862 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9863 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9864 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9865 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9866 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9867 | "0430 PM resume Failed to enable interrupt\n"); |
| 9868 | return -EIO; |
| 9869 | } else |
| 9870 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9871 | |
| 9872 | /* Restart HBA and bring it online */ |
| 9873 | lpfc_sli_brdrestart(phba); |
| 9874 | lpfc_online(phba); |
| 9875 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9876 | /* Log the current active interrupt mode */ |
| 9877 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9878 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9879 | return 0; |
| 9880 | } |
| 9881 | |
| 9882 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9883 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9884 | * @phba: pointer to lpfc hba data structure. |
| 9885 | * |
| 9886 | * 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] | 9887 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9888 | **/ |
| 9889 | static void |
| 9890 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9891 | { |
| 9892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9893 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9894 | |
| 9895 | /* |
| 9896 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9897 | * and let the SCSI mid-layer to retry them to recover. |
| 9898 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 9899 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9900 | } |
| 9901 | |
| 9902 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9903 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9904 | * @phba: pointer to lpfc hba data structure. |
| 9905 | * |
| 9906 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9907 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9908 | * pending I/Os. |
| 9909 | **/ |
| 9910 | static void |
| 9911 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9912 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9913 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9914 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9915 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9916 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9917 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9918 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9919 | /* Block all SCSI devices' I/Os on the host */ |
| 9920 | lpfc_scsi_dev_block(phba); |
| 9921 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 9922 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9923 | lpfc_sli_flush_fcp_rings(phba); |
| 9924 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9925 | /* stop all timers */ |
| 9926 | lpfc_stop_hba_timers(phba); |
| 9927 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9928 | /* Disable interrupt and pci device */ |
| 9929 | lpfc_sli_disable_intr(phba); |
| 9930 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9931 | } |
| 9932 | |
| 9933 | /** |
| 9934 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9935 | * @phba: pointer to lpfc hba data structure. |
| 9936 | * |
| 9937 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9938 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9939 | * pending I/Os. |
| 9940 | **/ |
| 9941 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9942 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9943 | { |
| 9944 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9945 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9946 | /* Block all SCSI devices' I/Os on the host */ |
| 9947 | lpfc_scsi_dev_block(phba); |
| 9948 | |
| 9949 | /* stop all timers */ |
| 9950 | lpfc_stop_hba_timers(phba); |
| 9951 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9952 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9953 | lpfc_sli_flush_fcp_rings(phba); |
| 9954 | } |
| 9955 | |
| 9956 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9957 | * 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] | 9958 | * @pdev: pointer to PCI device. |
| 9959 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9960 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9961 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9962 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9963 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9964 | * When this function is invoked, it will need to stop all the I/Os and |
| 9965 | * interrupt(s) to the device. Once that is done, it will return |
| 9966 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9967 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9968 | * |
| 9969 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9970 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9971 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9972 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9973 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9974 | static pci_ers_result_t |
| 9975 | 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] | 9976 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9977 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9978 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9979 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9980 | switch (state) { |
| 9981 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9982 | /* Non-fatal error, prepare for recovery */ |
| 9983 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9984 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9985 | case pci_channel_io_frozen: |
| 9986 | /* Fatal error, prepare for slot reset */ |
| 9987 | lpfc_sli_prep_dev_for_reset(phba); |
| 9988 | return PCI_ERS_RESULT_NEED_RESET; |
| 9989 | case pci_channel_io_perm_failure: |
| 9990 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9991 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9992 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9993 | default: |
| 9994 | /* Unknown state, prepare and request slot reset */ |
| 9995 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9996 | "0472 Unknown PCI error state: x%x\n", state); |
| 9997 | lpfc_sli_prep_dev_for_reset(phba); |
| 9998 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9999 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10000 | } |
| 10001 | |
| 10002 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10003 | * 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] | 10004 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10005 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10006 | * This routine is called from the PCI subsystem for error handling to |
| 10007 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 10008 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 10009 | * During the PCI subsystem error recovery, after driver returns |
| 10010 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10011 | * recovery and then call this routine before calling the .resume method |
| 10012 | * to recover the device. This function will initialize the HBA device, |
| 10013 | * enable the interrupt, but it will just put the HBA to offline state |
| 10014 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10015 | * |
| 10016 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10017 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10018 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10019 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10020 | static pci_ers_result_t |
| 10021 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10022 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10023 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10024 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10025 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10026 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10027 | |
| 10028 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 10029 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10030 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10031 | "PCI device after reset.\n"); |
| 10032 | return PCI_ERS_RESULT_DISCONNECT; |
| 10033 | } |
| 10034 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 10035 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10036 | |
| 10037 | /* |
| 10038 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10039 | * device saved_state flag, need to save the restored state again. |
| 10040 | */ |
| 10041 | pci_save_state(pdev); |
| 10042 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 10043 | if (pdev->is_busmaster) |
| 10044 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10045 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10046 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10047 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10048 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10049 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10050 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10051 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10052 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10053 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10054 | "0427 Cannot re-enable interrupt after " |
| 10055 | "slot reset.\n"); |
| 10056 | return PCI_ERS_RESULT_DISCONNECT; |
| 10057 | } else |
| 10058 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10059 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10060 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10061 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10062 | lpfc_offline(phba); |
| 10063 | lpfc_sli_brdrestart(phba); |
| 10064 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10065 | /* Log the current active interrupt mode */ |
| 10066 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10067 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10068 | return PCI_ERS_RESULT_RECOVERED; |
| 10069 | } |
| 10070 | |
| 10071 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10072 | * 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] | 10073 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10074 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10075 | * This routine is called from the PCI subsystem for error handling to device |
| 10076 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 10077 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10078 | * error recovery. After this call, traffic can start to flow from this device |
| 10079 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10080 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10081 | static void |
| 10082 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10083 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10084 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10085 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10086 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10087 | /* 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] | 10088 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10089 | |
| 10090 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10091 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10092 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10093 | } |
| 10094 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10095 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10096 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 10097 | * @phba: pointer to lpfc hba data structure. |
| 10098 | * |
| 10099 | * returns the number of ELS/CT IOCBs to reserve |
| 10100 | **/ |
| 10101 | int |
| 10102 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 10103 | { |
| 10104 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 10105 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10106 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 10107 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10108 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10109 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10110 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10111 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10112 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10113 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10114 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 10115 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10116 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 10117 | else if (max_xri <= 2048) |
| 10118 | return 200; |
| 10119 | else |
| 10120 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 10121 | } else |
| 10122 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10123 | } |
| 10124 | |
| 10125 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10126 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10127 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10128 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10129 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10130 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10131 | static void |
| 10132 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10133 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10134 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10135 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10136 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10137 | struct list_head dma_buffer_list; |
| 10138 | int i, rc = 0; |
| 10139 | struct lpfc_dmabuf *dmabuf, *next; |
| 10140 | uint32_t offset = 0, temp_offset = 0; |
| 10141 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10142 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10143 | if (!fw) { |
| 10144 | rc = -ENXIO; |
| 10145 | goto out; |
| 10146 | } |
| 10147 | image = (struct lpfc_grp_hdr *)fw->data; |
| 10148 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10149 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10150 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 10151 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 10152 | LPFC_FILE_TYPE_GROUP) || |
| 10153 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 10154 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10156 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10157 | "Magic:%x Type:%x ID:%x\n", |
| 10158 | be32_to_cpu(image->magic_number), |
| 10159 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 10160 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10161 | rc = -EINVAL; |
| 10162 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10163 | } |
| 10164 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10165 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10166 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10167 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10168 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10169 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10170 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 10171 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 10172 | GFP_KERNEL); |
| 10173 | if (!dmabuf) { |
| 10174 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10175 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10176 | } |
| 10177 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 10178 | SLI4_PAGE_SIZE, |
| 10179 | &dmabuf->phys, |
| 10180 | GFP_KERNEL); |
| 10181 | if (!dmabuf->virt) { |
| 10182 | kfree(dmabuf); |
| 10183 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10184 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10185 | } |
| 10186 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 10187 | } |
| 10188 | while (offset < fw->size) { |
| 10189 | temp_offset = offset; |
| 10190 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10191 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10192 | memcpy(dmabuf->virt, |
| 10193 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10194 | fw->size - temp_offset); |
| 10195 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10196 | break; |
| 10197 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10198 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 10199 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10200 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10201 | } |
| 10202 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 10203 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10204 | if (rc) |
| 10205 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10206 | } |
| 10207 | rc = offset; |
| 10208 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10209 | |
| 10210 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10211 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 10212 | list_del(&dmabuf->list); |
| 10213 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 10214 | dmabuf->virt, dmabuf->phys); |
| 10215 | kfree(dmabuf); |
| 10216 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10217 | release_firmware(fw); |
| 10218 | out: |
| 10219 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10220 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10221 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10222 | } |
| 10223 | |
| 10224 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10225 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 10226 | * @phba: pointer to lpfc hba data structure. |
| 10227 | * |
| 10228 | * This routine is called to perform Linux generic firmware upgrade on device |
| 10229 | * that supports such feature. |
| 10230 | **/ |
| 10231 | int |
| 10232 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 10233 | { |
| 10234 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 10235 | int ret; |
| 10236 | const struct firmware *fw; |
| 10237 | |
| 10238 | /* Only supported on SLI4 interface type 2 for now */ |
| 10239 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 10240 | LPFC_SLI_INTF_IF_TYPE_2) |
| 10241 | return -EPERM; |
| 10242 | |
| 10243 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 10244 | |
| 10245 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 10246 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 10247 | file_name, &phba->pcidev->dev, |
| 10248 | GFP_KERNEL, (void *)phba, |
| 10249 | lpfc_write_firmware); |
| 10250 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 10251 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 10252 | if (!ret) |
| 10253 | lpfc_write_firmware(fw, (void *)phba); |
| 10254 | } else { |
| 10255 | ret = -EINVAL; |
| 10256 | } |
| 10257 | |
| 10258 | return ret; |
| 10259 | } |
| 10260 | |
| 10261 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10262 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 10263 | * @pdev: pointer to PCI device |
| 10264 | * @pid: pointer to PCI device identifier |
| 10265 | * |
| 10266 | * This routine is called from the kernel's PCI subsystem to device with |
| 10267 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10268 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 10269 | * information of the device and driver to see if the driver state that it |
| 10270 | * can support this kind of device. If the match is successful, the driver |
| 10271 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 10272 | * it does all the initialization that it needs to do to handle the HBA |
| 10273 | * properly. |
| 10274 | * |
| 10275 | * Return code |
| 10276 | * 0 - driver can claim the device |
| 10277 | * negative value - driver can not claim the device |
| 10278 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10279 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10280 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10281 | { |
| 10282 | struct lpfc_hba *phba; |
| 10283 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10284 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10285 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10286 | uint32_t cfg_mode, intr_mode; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10287 | int adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10288 | |
| 10289 | /* Allocate memory for HBA structure */ |
| 10290 | phba = lpfc_hba_alloc(pdev); |
| 10291 | if (!phba) |
| 10292 | return -ENOMEM; |
| 10293 | |
| 10294 | /* Perform generic PCI device enabling operation */ |
| 10295 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10296 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10297 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10298 | |
| 10299 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 10300 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 10301 | if (error) |
| 10302 | goto out_disable_pci_dev; |
| 10303 | |
| 10304 | /* Set up SLI-4 specific device PCI memory space */ |
| 10305 | error = lpfc_sli4_pci_mem_setup(phba); |
| 10306 | if (error) { |
| 10307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10308 | "1410 Failed to set up pci memory space.\n"); |
| 10309 | goto out_disable_pci_dev; |
| 10310 | } |
| 10311 | |
| 10312 | /* Set up phase-1 common device driver resources */ |
| 10313 | error = lpfc_setup_driver_resource_phase1(phba); |
| 10314 | if (error) { |
| 10315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10316 | "1411 Failed to set up driver resource.\n"); |
| 10317 | goto out_unset_pci_mem_s4; |
| 10318 | } |
| 10319 | |
| 10320 | /* Set up SLI-4 Specific device driver resources */ |
| 10321 | error = lpfc_sli4_driver_resource_setup(phba); |
| 10322 | if (error) { |
| 10323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10324 | "1412 Failed to set up driver resource.\n"); |
| 10325 | goto out_unset_pci_mem_s4; |
| 10326 | } |
| 10327 | |
| 10328 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10329 | |
| 10330 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10331 | "2821 initialize iocb list %d.\n", |
| 10332 | phba->cfg_iocb_cnt*1024); |
| 10333 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 10334 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10335 | if (error) { |
| 10336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10337 | "1413 Failed to initialize iocb list.\n"); |
| 10338 | goto out_unset_driver_resource_s4; |
| 10339 | } |
| 10340 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10341 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 10342 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10343 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10344 | /* Set up common device driver resources */ |
| 10345 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10346 | if (error) { |
| 10347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10348 | "1414 Failed to set up driver resource.\n"); |
| 10349 | goto out_free_iocb_list; |
| 10350 | } |
| 10351 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10352 | /* Get the default values for Model Name and Description */ |
| 10353 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10354 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10355 | /* Create SCSI host to the physical port */ |
| 10356 | error = lpfc_create_shost(phba); |
| 10357 | if (error) { |
| 10358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10359 | "1415 Failed to create scsi host.\n"); |
| 10360 | goto out_unset_driver_resource; |
| 10361 | } |
| 10362 | |
| 10363 | /* Configure sysfs attributes */ |
| 10364 | vport = phba->pport; |
| 10365 | error = lpfc_alloc_sysfs_attr(vport); |
| 10366 | if (error) { |
| 10367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10368 | "1416 Failed to allocate sysfs attr\n"); |
| 10369 | goto out_destroy_shost; |
| 10370 | } |
| 10371 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10372 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10373 | /* Now, trying to enable interrupt and bring up the device */ |
| 10374 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10375 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10376 | /* Put device to a known state before enabling interrupt */ |
| 10377 | lpfc_stop_port(phba); |
| 10378 | /* Configure and enable interrupt */ |
| 10379 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 10380 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10382 | "0426 Failed to enable interrupt.\n"); |
| 10383 | error = -ENODEV; |
| 10384 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10385 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10386 | /* Default to single EQ for non-MSI-X */ |
| 10387 | if (phba->intr_type != MSIX) |
| 10388 | adjusted_fcp_io_channel = 1; |
| 10389 | else |
| 10390 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 10391 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
| 10392 | /* Set up SLI-4 HBA */ |
| 10393 | if (lpfc_sli4_hba_setup(phba)) { |
| 10394 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10395 | "1421 Failed to set up hba\n"); |
| 10396 | error = -ENODEV; |
| 10397 | goto out_disable_intr; |
| 10398 | } |
| 10399 | |
| 10400 | /* Log the current active interrupt mode */ |
| 10401 | phba->intr_mode = intr_mode; |
| 10402 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10403 | |
| 10404 | /* Perform post initialization setup */ |
| 10405 | lpfc_post_init_setup(phba); |
| 10406 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10407 | /* check for firmware upgrade or downgrade */ |
| 10408 | if (phba->cfg_request_firmware_upgrade) |
| 10409 | ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10410 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 10411 | /* Check if there are static vports to be created. */ |
| 10412 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10413 | return 0; |
| 10414 | |
| 10415 | out_disable_intr: |
| 10416 | lpfc_sli4_disable_intr(phba); |
| 10417 | out_free_sysfs_attr: |
| 10418 | lpfc_free_sysfs_attr(vport); |
| 10419 | out_destroy_shost: |
| 10420 | lpfc_destroy_shost(phba); |
| 10421 | out_unset_driver_resource: |
| 10422 | lpfc_unset_driver_resource_phase2(phba); |
| 10423 | out_free_iocb_list: |
| 10424 | lpfc_free_iocb_list(phba); |
| 10425 | out_unset_driver_resource_s4: |
| 10426 | lpfc_sli4_driver_resource_unset(phba); |
| 10427 | out_unset_pci_mem_s4: |
| 10428 | lpfc_sli4_pci_mem_unset(phba); |
| 10429 | out_disable_pci_dev: |
| 10430 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10431 | if (shost) |
| 10432 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10433 | out_free_phba: |
| 10434 | lpfc_hba_free(phba); |
| 10435 | return error; |
| 10436 | } |
| 10437 | |
| 10438 | /** |
| 10439 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 10440 | * @pdev: pointer to PCI device |
| 10441 | * |
| 10442 | * This routine is called from the kernel's PCI subsystem to device with |
| 10443 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10444 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10445 | * device to be removed from the PCI subsystem properly. |
| 10446 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10447 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10448 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 10449 | { |
| 10450 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10451 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 10452 | struct lpfc_vport **vports; |
| 10453 | struct lpfc_hba *phba = vport->phba; |
| 10454 | int i; |
| 10455 | |
| 10456 | /* Mark the device unloading flag */ |
| 10457 | spin_lock_irq(&phba->hbalock); |
| 10458 | vport->load_flag |= FC_UNLOADING; |
| 10459 | spin_unlock_irq(&phba->hbalock); |
| 10460 | |
| 10461 | /* Free the HBA sysfs attributes */ |
| 10462 | lpfc_free_sysfs_attr(vport); |
| 10463 | |
| 10464 | /* Release all the vports against this physical port */ |
| 10465 | vports = lpfc_create_vport_work_array(phba); |
| 10466 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10467 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10468 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10469 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10470 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10471 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10472 | lpfc_destroy_vport_work_array(phba, vports); |
| 10473 | |
| 10474 | /* Remove FC host and then SCSI host with the physical port */ |
| 10475 | fc_remove_host(shost); |
| 10476 | scsi_remove_host(shost); |
| 10477 | |
| 10478 | /* Perform cleanup on the physical port */ |
| 10479 | lpfc_cleanup(vport); |
| 10480 | |
| 10481 | /* |
| 10482 | * Bring down the SLI Layer. This step disables all interrupts, |
| 10483 | * clears the rings, discards all mailbox commands, and resets |
| 10484 | * the HBA FCoE function. |
| 10485 | */ |
| 10486 | lpfc_debugfs_terminate(vport); |
| 10487 | lpfc_sli4_hba_unset(phba); |
| 10488 | |
| 10489 | spin_lock_irq(&phba->hbalock); |
| 10490 | list_del_init(&vport->listentry); |
| 10491 | spin_unlock_irq(&phba->hbalock); |
| 10492 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10493 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10494 | * buffers are released to their corresponding pools here. |
| 10495 | */ |
| 10496 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10497 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10498 | lpfc_sli4_driver_resource_unset(phba); |
| 10499 | |
| 10500 | /* Unmap adapter Control and Doorbell registers */ |
| 10501 | lpfc_sli4_pci_mem_unset(phba); |
| 10502 | |
| 10503 | /* Release PCI resources and disable device's PCI function */ |
| 10504 | scsi_host_put(shost); |
| 10505 | lpfc_disable_pci_dev(phba); |
| 10506 | |
| 10507 | /* Finally, free the driver's device data structure */ |
| 10508 | lpfc_hba_free(phba); |
| 10509 | |
| 10510 | return; |
| 10511 | } |
| 10512 | |
| 10513 | /** |
| 10514 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 10515 | * @pdev: pointer to PCI device |
| 10516 | * @msg: power management message |
| 10517 | * |
| 10518 | * This routine is called from the kernel's PCI subsystem to support system |
| 10519 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 10520 | * this method, it quiesces the device by stopping the driver's worker |
| 10521 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 10522 | * the device offline. Note that as the driver implements the minimum PM |
| 10523 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 10524 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 10525 | * method call will be treated as SUSPEND and the driver will fully |
| 10526 | * reinitialize its device during resume() method call, the driver will set |
| 10527 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 10528 | * according to the @msg provided by the PM. |
| 10529 | * |
| 10530 | * Return code |
| 10531 | * 0 - driver suspended the device |
| 10532 | * Error otherwise |
| 10533 | **/ |
| 10534 | static int |
| 10535 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 10536 | { |
| 10537 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10538 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10539 | |
| 10540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10541 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10542 | |
| 10543 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10544 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10545 | lpfc_offline(phba); |
| 10546 | kthread_stop(phba->worker_thread); |
| 10547 | |
| 10548 | /* Disable interrupt from device */ |
| 10549 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10550 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10551 | |
| 10552 | /* Save device state to PCI config space */ |
| 10553 | pci_save_state(pdev); |
| 10554 | pci_set_power_state(pdev, PCI_D3hot); |
| 10555 | |
| 10556 | return 0; |
| 10557 | } |
| 10558 | |
| 10559 | /** |
| 10560 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 10561 | * @pdev: pointer to PCI device |
| 10562 | * |
| 10563 | * This routine is called from the kernel's PCI subsystem to support system |
| 10564 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 10565 | * this method, it restores the device's PCI config space state and fully |
| 10566 | * reinitializes the device and brings it online. Note that as the driver |
| 10567 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 10568 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 10569 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 10570 | * will fully reinitialize its device during resume() method call, the device |
| 10571 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 10572 | * state. |
| 10573 | * |
| 10574 | * Return code |
| 10575 | * 0 - driver suspended the device |
| 10576 | * Error otherwise |
| 10577 | **/ |
| 10578 | static int |
| 10579 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 10580 | { |
| 10581 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10582 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10583 | uint32_t intr_mode; |
| 10584 | int error; |
| 10585 | |
| 10586 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10587 | "0292 PCI device Power Management resume.\n"); |
| 10588 | |
| 10589 | /* Restore device state from PCI config space */ |
| 10590 | pci_set_power_state(pdev, PCI_D0); |
| 10591 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10592 | |
| 10593 | /* |
| 10594 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10595 | * device saved_state flag, need to save the restored state again. |
| 10596 | */ |
| 10597 | pci_save_state(pdev); |
| 10598 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10599 | if (pdev->is_busmaster) |
| 10600 | pci_set_master(pdev); |
| 10601 | |
| 10602 | /* Startup the kernel thread for this host adapter. */ |
| 10603 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 10604 | "lpfc_worker_%d", phba->brd_no); |
| 10605 | if (IS_ERR(phba->worker_thread)) { |
| 10606 | error = PTR_ERR(phba->worker_thread); |
| 10607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10608 | "0293 PM resume failed to start worker " |
| 10609 | "thread: error=x%x.\n", error); |
| 10610 | return error; |
| 10611 | } |
| 10612 | |
| 10613 | /* Configure and enable interrupt */ |
| 10614 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10615 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10616 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10617 | "0294 PM resume Failed to enable interrupt\n"); |
| 10618 | return -EIO; |
| 10619 | } else |
| 10620 | phba->intr_mode = intr_mode; |
| 10621 | |
| 10622 | /* Restart HBA and bring it online */ |
| 10623 | lpfc_sli_brdrestart(phba); |
| 10624 | lpfc_online(phba); |
| 10625 | |
| 10626 | /* Log the current active interrupt mode */ |
| 10627 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10628 | |
| 10629 | return 0; |
| 10630 | } |
| 10631 | |
| 10632 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10633 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 10634 | * @phba: pointer to lpfc hba data structure. |
| 10635 | * |
| 10636 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 10637 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 10638 | **/ |
| 10639 | static void |
| 10640 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10641 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10643 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 10644 | /* |
| 10645 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10646 | * and let the SCSI mid-layer to retry them to recover. |
| 10647 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10648 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10649 | } |
| 10650 | |
| 10651 | /** |
| 10652 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 10653 | * @phba: pointer to lpfc hba data structure. |
| 10654 | * |
| 10655 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 10656 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10657 | * pending I/Os. |
| 10658 | **/ |
| 10659 | static void |
| 10660 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10661 | { |
| 10662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10663 | "2826 PCI channel disable preparing for reset\n"); |
| 10664 | |
| 10665 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10666 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10667 | |
| 10668 | /* Block all SCSI devices' I/Os on the host */ |
| 10669 | lpfc_scsi_dev_block(phba); |
| 10670 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10671 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10672 | lpfc_sli_flush_fcp_rings(phba); |
| 10673 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10674 | /* stop all timers */ |
| 10675 | lpfc_stop_hba_timers(phba); |
| 10676 | |
| 10677 | /* Disable interrupt and pci device */ |
| 10678 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10679 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10680 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10681 | } |
| 10682 | |
| 10683 | /** |
| 10684 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 10685 | * @phba: pointer to lpfc hba data structure. |
| 10686 | * |
| 10687 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 10688 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10689 | * pending I/Os. |
| 10690 | **/ |
| 10691 | static void |
| 10692 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 10693 | { |
| 10694 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10695 | "2827 PCI channel permanent disable for failure\n"); |
| 10696 | |
| 10697 | /* Block all SCSI devices' I/Os on the host */ |
| 10698 | lpfc_scsi_dev_block(phba); |
| 10699 | |
| 10700 | /* stop all timers */ |
| 10701 | lpfc_stop_hba_timers(phba); |
| 10702 | |
| 10703 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10704 | lpfc_sli_flush_fcp_rings(phba); |
| 10705 | } |
| 10706 | |
| 10707 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10708 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 10709 | * @pdev: pointer to PCI device. |
| 10710 | * @state: the current PCI connection state. |
| 10711 | * |
| 10712 | * This routine is called from the PCI subsystem for error handling to device |
| 10713 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 10714 | * after a PCI bus error affecting this device has been detected. When this |
| 10715 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 10716 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 10717 | * for the PCI subsystem to perform proper recovery as desired. |
| 10718 | * |
| 10719 | * Return codes |
| 10720 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10721 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10722 | **/ |
| 10723 | static pci_ers_result_t |
| 10724 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 10725 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10726 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10727 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10728 | |
| 10729 | switch (state) { |
| 10730 | case pci_channel_io_normal: |
| 10731 | /* Non-fatal error, prepare for recovery */ |
| 10732 | lpfc_sli4_prep_dev_for_recover(phba); |
| 10733 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10734 | case pci_channel_io_frozen: |
| 10735 | /* Fatal error, prepare for slot reset */ |
| 10736 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10737 | return PCI_ERS_RESULT_NEED_RESET; |
| 10738 | case pci_channel_io_perm_failure: |
| 10739 | /* Permanent failure, prepare for device down */ |
| 10740 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 10741 | return PCI_ERS_RESULT_DISCONNECT; |
| 10742 | default: |
| 10743 | /* Unknown state, prepare and request slot reset */ |
| 10744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10745 | "2825 Unknown PCI error state: x%x\n", state); |
| 10746 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10747 | return PCI_ERS_RESULT_NEED_RESET; |
| 10748 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10749 | } |
| 10750 | |
| 10751 | /** |
| 10752 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 10753 | * @pdev: pointer to PCI device. |
| 10754 | * |
| 10755 | * This routine is called from the PCI subsystem for error handling to device |
| 10756 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 10757 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 10758 | * PCI subsystem error recovery, after the driver returns |
| 10759 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10760 | * recovery and then call this routine before calling the .resume method to |
| 10761 | * recover the device. This function will initialize the HBA device, enable |
| 10762 | * the interrupt, but it will just put the HBA to offline state without |
| 10763 | * passing any I/O traffic. |
| 10764 | * |
| 10765 | * Return codes |
| 10766 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10767 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10768 | */ |
| 10769 | static pci_ers_result_t |
| 10770 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 10771 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10772 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10773 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10774 | struct lpfc_sli *psli = &phba->sli; |
| 10775 | uint32_t intr_mode; |
| 10776 | |
| 10777 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 10778 | if (pci_enable_device_mem(pdev)) { |
| 10779 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10780 | "PCI device after reset.\n"); |
| 10781 | return PCI_ERS_RESULT_DISCONNECT; |
| 10782 | } |
| 10783 | |
| 10784 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 10785 | |
| 10786 | /* |
| 10787 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10788 | * device saved_state flag, need to save the restored state again. |
| 10789 | */ |
| 10790 | pci_save_state(pdev); |
| 10791 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10792 | if (pdev->is_busmaster) |
| 10793 | pci_set_master(pdev); |
| 10794 | |
| 10795 | spin_lock_irq(&phba->hbalock); |
| 10796 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 10797 | spin_unlock_irq(&phba->hbalock); |
| 10798 | |
| 10799 | /* Configure and enable interrupt */ |
| 10800 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10801 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10803 | "2824 Cannot re-enable interrupt after " |
| 10804 | "slot reset.\n"); |
| 10805 | return PCI_ERS_RESULT_DISCONNECT; |
| 10806 | } else |
| 10807 | phba->intr_mode = intr_mode; |
| 10808 | |
| 10809 | /* Log the current active interrupt mode */ |
| 10810 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10811 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10812 | return PCI_ERS_RESULT_RECOVERED; |
| 10813 | } |
| 10814 | |
| 10815 | /** |
| 10816 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10817 | * @pdev: pointer to PCI device |
| 10818 | * |
| 10819 | * This routine is called from the PCI subsystem for error handling to device |
| 10820 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10821 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10822 | * error recovery. After this call, traffic can start to flow from this device |
| 10823 | * again. |
| 10824 | **/ |
| 10825 | static void |
| 10826 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10827 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10828 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10829 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10830 | |
| 10831 | /* |
| 10832 | * In case of slot reset, as function reset is performed through |
| 10833 | * mailbox command which needs DMA to be enabled, this operation |
| 10834 | * has to be moved to the io resume phase. Taking device offline |
| 10835 | * will perform the necessary cleanup. |
| 10836 | */ |
| 10837 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10838 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10839 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10840 | lpfc_offline(phba); |
| 10841 | lpfc_sli_brdrestart(phba); |
| 10842 | /* Bring the device back online */ |
| 10843 | lpfc_online(phba); |
| 10844 | } |
| 10845 | |
| 10846 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10847 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10848 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10849 | } |
| 10850 | |
| 10851 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10852 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10853 | * @pdev: pointer to PCI device |
| 10854 | * @pid: pointer to PCI device identifier |
| 10855 | * |
| 10856 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10857 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10858 | * at PCI device-specific information of the device and driver to see if the |
| 10859 | * driver state that it can support this kind of device. If the match is |
| 10860 | * successful, the driver core invokes this routine. This routine dispatches |
| 10861 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10862 | * do all the initialization that it needs to do to handle the HBA device |
| 10863 | * properly. |
| 10864 | * |
| 10865 | * Return code |
| 10866 | * 0 - driver can claim the device |
| 10867 | * negative value - driver can not claim the device |
| 10868 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10869 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10870 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10871 | { |
| 10872 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10873 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10874 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10875 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10876 | return -ENODEV; |
| 10877 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10878 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10879 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10880 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10881 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10882 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10883 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10884 | return rc; |
| 10885 | } |
| 10886 | |
| 10887 | /** |
| 10888 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10889 | * @pdev: pointer to PCI device |
| 10890 | * |
| 10891 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10892 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10893 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10894 | * remove routine, which will perform all the necessary cleanup for the |
| 10895 | * device to be removed from the PCI subsystem properly. |
| 10896 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10897 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10898 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10899 | { |
| 10900 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10901 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10902 | |
| 10903 | switch (phba->pci_dev_grp) { |
| 10904 | case LPFC_PCI_DEV_LP: |
| 10905 | lpfc_pci_remove_one_s3(pdev); |
| 10906 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10907 | case LPFC_PCI_DEV_OC: |
| 10908 | lpfc_pci_remove_one_s4(pdev); |
| 10909 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10910 | default: |
| 10911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10912 | "1424 Invalid PCI device group: 0x%x\n", |
| 10913 | phba->pci_dev_grp); |
| 10914 | break; |
| 10915 | } |
| 10916 | return; |
| 10917 | } |
| 10918 | |
| 10919 | /** |
| 10920 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10921 | * @pdev: pointer to PCI device |
| 10922 | * @msg: power management message |
| 10923 | * |
| 10924 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10925 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10926 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10927 | * suspend the device. |
| 10928 | * |
| 10929 | * Return code |
| 10930 | * 0 - driver suspended the device |
| 10931 | * Error otherwise |
| 10932 | **/ |
| 10933 | static int |
| 10934 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10935 | { |
| 10936 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10937 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10938 | int rc = -ENODEV; |
| 10939 | |
| 10940 | switch (phba->pci_dev_grp) { |
| 10941 | case LPFC_PCI_DEV_LP: |
| 10942 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10943 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10944 | case LPFC_PCI_DEV_OC: |
| 10945 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10946 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10947 | default: |
| 10948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10949 | "1425 Invalid PCI device group: 0x%x\n", |
| 10950 | phba->pci_dev_grp); |
| 10951 | break; |
| 10952 | } |
| 10953 | return rc; |
| 10954 | } |
| 10955 | |
| 10956 | /** |
| 10957 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10958 | * @pdev: pointer to PCI device |
| 10959 | * |
| 10960 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10961 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10962 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10963 | * resume the device. |
| 10964 | * |
| 10965 | * Return code |
| 10966 | * 0 - driver suspended the device |
| 10967 | * Error otherwise |
| 10968 | **/ |
| 10969 | static int |
| 10970 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10971 | { |
| 10972 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10973 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10974 | int rc = -ENODEV; |
| 10975 | |
| 10976 | switch (phba->pci_dev_grp) { |
| 10977 | case LPFC_PCI_DEV_LP: |
| 10978 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10979 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10980 | case LPFC_PCI_DEV_OC: |
| 10981 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10982 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10983 | default: |
| 10984 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10985 | "1426 Invalid PCI device group: 0x%x\n", |
| 10986 | phba->pci_dev_grp); |
| 10987 | break; |
| 10988 | } |
| 10989 | return rc; |
| 10990 | } |
| 10991 | |
| 10992 | /** |
| 10993 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10994 | * @pdev: pointer to PCI device. |
| 10995 | * @state: the current PCI connection state. |
| 10996 | * |
| 10997 | * This routine is registered to the PCI subsystem for error handling. This |
| 10998 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10999 | * this device has been detected. When this routine is invoked, it dispatches |
| 11000 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 11001 | * routine, which will perform the proper error detected operation. |
| 11002 | * |
| 11003 | * Return codes |
| 11004 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 11005 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11006 | **/ |
| 11007 | static pci_ers_result_t |
| 11008 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 11009 | { |
| 11010 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11011 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11012 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 11013 | |
| 11014 | switch (phba->pci_dev_grp) { |
| 11015 | case LPFC_PCI_DEV_LP: |
| 11016 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 11017 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11018 | case LPFC_PCI_DEV_OC: |
| 11019 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 11020 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11021 | default: |
| 11022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11023 | "1427 Invalid PCI device group: 0x%x\n", |
| 11024 | phba->pci_dev_grp); |
| 11025 | break; |
| 11026 | } |
| 11027 | return rc; |
| 11028 | } |
| 11029 | |
| 11030 | /** |
| 11031 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 11032 | * @pdev: pointer to PCI device. |
| 11033 | * |
| 11034 | * This routine is registered to the PCI subsystem for error handling. This |
| 11035 | * function is called after PCI bus has been reset to restart the PCI card |
| 11036 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 11037 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 11038 | * routine, which will perform the proper device reset. |
| 11039 | * |
| 11040 | * Return codes |
| 11041 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 11042 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11043 | **/ |
| 11044 | static pci_ers_result_t |
| 11045 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 11046 | { |
| 11047 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11048 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11049 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 11050 | |
| 11051 | switch (phba->pci_dev_grp) { |
| 11052 | case LPFC_PCI_DEV_LP: |
| 11053 | rc = lpfc_io_slot_reset_s3(pdev); |
| 11054 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11055 | case LPFC_PCI_DEV_OC: |
| 11056 | rc = lpfc_io_slot_reset_s4(pdev); |
| 11057 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11058 | default: |
| 11059 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11060 | "1428 Invalid PCI device group: 0x%x\n", |
| 11061 | phba->pci_dev_grp); |
| 11062 | break; |
| 11063 | } |
| 11064 | return rc; |
| 11065 | } |
| 11066 | |
| 11067 | /** |
| 11068 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 11069 | * @pdev: pointer to PCI device |
| 11070 | * |
| 11071 | * This routine is registered to the PCI subsystem for error handling. It |
| 11072 | * is called when kernel error recovery tells the lpfc driver that it is |
| 11073 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 11074 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 11075 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 11076 | **/ |
| 11077 | static void |
| 11078 | lpfc_io_resume(struct pci_dev *pdev) |
| 11079 | { |
| 11080 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11081 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11082 | |
| 11083 | switch (phba->pci_dev_grp) { |
| 11084 | case LPFC_PCI_DEV_LP: |
| 11085 | lpfc_io_resume_s3(pdev); |
| 11086 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11087 | case LPFC_PCI_DEV_OC: |
| 11088 | lpfc_io_resume_s4(pdev); |
| 11089 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11090 | default: |
| 11091 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11092 | "1429 Invalid PCI device group: 0x%x\n", |
| 11093 | phba->pci_dev_grp); |
| 11094 | break; |
| 11095 | } |
| 11096 | return; |
| 11097 | } |
| 11098 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11099 | /** |
| 11100 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 11101 | * @phba: pointer to lpfc hba data structure. |
| 11102 | * |
| 11103 | * This routine checks to see if OAS is supported for this adapter. If |
| 11104 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 11105 | * the enable oas flag is cleared and the pool created for OAS device data |
| 11106 | * is destroyed. |
| 11107 | * |
| 11108 | **/ |
| 11109 | void |
| 11110 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 11111 | { |
| 11112 | |
| 11113 | if (!phba->cfg_EnableXLane) |
| 11114 | return; |
| 11115 | |
| 11116 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 11117 | phba->cfg_fof = 1; |
| 11118 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11119 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11120 | if (phba->device_data_mem_pool) |
| 11121 | mempool_destroy(phba->device_data_mem_pool); |
| 11122 | phba->device_data_mem_pool = NULL; |
| 11123 | } |
| 11124 | |
| 11125 | return; |
| 11126 | } |
| 11127 | |
| 11128 | /** |
| 11129 | * lpfc_fof_queue_setup - Set up all the fof queues |
| 11130 | * @phba: pointer to lpfc hba data structure. |
| 11131 | * |
| 11132 | * This routine is invoked to set up all the fof queues for the FC HBA |
| 11133 | * operation. |
| 11134 | * |
| 11135 | * Return codes |
| 11136 | * 0 - successful |
| 11137 | * -ENOMEM - No available memory |
| 11138 | **/ |
| 11139 | int |
| 11140 | lpfc_fof_queue_setup(struct lpfc_hba *phba) |
| 11141 | { |
| 11142 | struct lpfc_sli *psli = &phba->sli; |
| 11143 | int rc; |
| 11144 | |
| 11145 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); |
| 11146 | if (rc) |
| 11147 | return -ENOMEM; |
| 11148 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11149 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11150 | |
| 11151 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, |
| 11152 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); |
| 11153 | if (rc) |
| 11154 | goto out_oas_cq; |
| 11155 | |
| 11156 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, |
| 11157 | phba->sli4_hba.oas_cq, LPFC_FCP); |
| 11158 | if (rc) |
| 11159 | goto out_oas_wq; |
| 11160 | |
| 11161 | phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 11162 | phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 11163 | } |
| 11164 | |
| 11165 | return 0; |
| 11166 | |
| 11167 | out_oas_wq: |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11168 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11169 | out_oas_cq: |
| 11170 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); |
| 11171 | return rc; |
| 11172 | |
| 11173 | } |
| 11174 | |
| 11175 | /** |
| 11176 | * lpfc_fof_queue_create - Create all the fof queues |
| 11177 | * @phba: pointer to lpfc hba data structure. |
| 11178 | * |
| 11179 | * This routine is invoked to allocate all the fof queues for the FC HBA |
| 11180 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 11181 | * count (queue depth) shall be taken from the module parameter. For now, |
| 11182 | * we just use some constant number as place holder. |
| 11183 | * |
| 11184 | * Return codes |
| 11185 | * 0 - successful |
| 11186 | * -ENOMEM - No availble memory |
| 11187 | * -EIO - The mailbox failed to complete successfully. |
| 11188 | **/ |
| 11189 | int |
| 11190 | lpfc_fof_queue_create(struct lpfc_hba *phba) |
| 11191 | { |
| 11192 | struct lpfc_queue *qdesc; |
| 11193 | |
| 11194 | /* Create FOF EQ */ |
| 11195 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 11196 | phba->sli4_hba.eq_ecount); |
| 11197 | if (!qdesc) |
| 11198 | goto out_error; |
| 11199 | |
| 11200 | phba->sli4_hba.fof_eq = qdesc; |
| 11201 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11202 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11203 | |
| 11204 | /* Create OAS CQ */ |
| 11205 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 11206 | phba->sli4_hba.cq_ecount); |
| 11207 | if (!qdesc) |
| 11208 | goto out_error; |
| 11209 | |
| 11210 | phba->sli4_hba.oas_cq = qdesc; |
| 11211 | |
| 11212 | /* Create OAS WQ */ |
| 11213 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 11214 | phba->sli4_hba.wq_ecount); |
| 11215 | if (!qdesc) |
| 11216 | goto out_error; |
| 11217 | |
| 11218 | phba->sli4_hba.oas_wq = qdesc; |
| 11219 | |
| 11220 | } |
| 11221 | return 0; |
| 11222 | |
| 11223 | out_error: |
| 11224 | lpfc_fof_queue_destroy(phba); |
| 11225 | return -ENOMEM; |
| 11226 | } |
| 11227 | |
| 11228 | /** |
| 11229 | * lpfc_fof_queue_destroy - Destroy all the fof queues |
| 11230 | * @phba: pointer to lpfc hba data structure. |
| 11231 | * |
| 11232 | * This routine is invoked to release all the SLI4 queues with the FC HBA |
| 11233 | * operation. |
| 11234 | * |
| 11235 | * Return codes |
| 11236 | * 0 - successful |
| 11237 | **/ |
| 11238 | int |
| 11239 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) |
| 11240 | { |
| 11241 | /* Release FOF Event queue */ |
| 11242 | if (phba->sli4_hba.fof_eq != NULL) { |
| 11243 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); |
| 11244 | phba->sli4_hba.fof_eq = NULL; |
| 11245 | } |
| 11246 | |
| 11247 | /* Release OAS Completion queue */ |
| 11248 | if (phba->sli4_hba.oas_cq != NULL) { |
| 11249 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); |
| 11250 | phba->sli4_hba.oas_cq = NULL; |
| 11251 | } |
| 11252 | |
| 11253 | /* Release OAS Work queue */ |
| 11254 | if (phba->sli4_hba.oas_wq != NULL) { |
| 11255 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); |
| 11256 | phba->sli4_hba.oas_wq = NULL; |
| 11257 | } |
| 11258 | return 0; |
| 11259 | } |
| 11260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11261 | static struct pci_device_id lpfc_id_table[] = { |
| 11262 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 11263 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 11264 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 11265 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11266 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 11267 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11268 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 11269 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11270 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 11271 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11272 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 11273 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11274 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 11275 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11276 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 11277 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11278 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 11279 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11280 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 11281 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11282 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 11283 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11284 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 11285 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11286 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 11287 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11288 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 11289 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11290 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 11291 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11292 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 11293 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11294 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 11295 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11296 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 11297 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11298 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 11299 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11300 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 11301 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11302 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 11303 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11304 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 11305 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11306 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 11307 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11308 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 11309 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11310 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 11311 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11312 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 11313 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11314 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 11315 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11316 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 11317 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 11318 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 11319 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11320 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 11321 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11322 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 11323 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11324 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 11325 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11326 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 11327 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11328 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 11329 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11330 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 11331 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11332 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 11333 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11334 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 11335 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11336 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 11337 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11338 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 11339 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11340 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11341 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11342 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 11343 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 11344 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 11345 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11346 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 11347 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 11348 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 11349 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11350 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 11351 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 11352 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 11353 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11354 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 11355 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11356 | { 0 } |
| 11357 | }; |
| 11358 | |
| 11359 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 11360 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 11361 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11362 | .error_detected = lpfc_io_error_detected, |
| 11363 | .slot_reset = lpfc_io_slot_reset, |
| 11364 | .resume = lpfc_io_resume, |
| 11365 | }; |
| 11366 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11367 | static struct pci_driver lpfc_driver = { |
| 11368 | .name = LPFC_DRIVER_NAME, |
| 11369 | .id_table = lpfc_id_table, |
| 11370 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11371 | .remove = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11372 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11373 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11374 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11375 | }; |
| 11376 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11377 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 11378 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11379 | }; |
| 11380 | |
| 11381 | static struct miscdevice lpfc_mgmt_dev = { |
| 11382 | .minor = MISC_DYNAMIC_MINOR, |
| 11383 | .name = "lpfcmgmt", |
| 11384 | .fops = &lpfc_mgmt_fop, |
| 11385 | }; |
| 11386 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11387 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11388 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11389 | * |
| 11390 | * This routine is to be invoked when the lpfc module is loaded into the |
| 11391 | * kernel. The special kernel macro module_init() is used to indicate the |
| 11392 | * role of this routine to the kernel as lpfc module entry point. |
| 11393 | * |
| 11394 | * Return codes |
| 11395 | * 0 - successful |
| 11396 | * -ENOMEM - FC attach transport failed |
| 11397 | * all others - failed |
| 11398 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11399 | static int __init |
| 11400 | lpfc_init(void) |
| 11401 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11402 | int cpu; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11403 | int error = 0; |
| 11404 | |
| 11405 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 11406 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11407 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11408 | error = misc_register(&lpfc_mgmt_dev); |
| 11409 | if (error) |
| 11410 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 11411 | "misc_register returned with status %d", error); |
| 11412 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11413 | if (lpfc_enable_npiv) { |
| 11414 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 11415 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 11416 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11417 | lpfc_transport_template = |
| 11418 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11419 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11420 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11421 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11422 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11423 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 11424 | if (lpfc_vport_transport_template == NULL) { |
| 11425 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11426 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11427 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11428 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11429 | |
| 11430 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11431 | lpfc_used_cpu = NULL; |
| 11432 | lpfc_present_cpu = 0; |
| 11433 | for_each_present_cpu(cpu) |
| 11434 | lpfc_present_cpu++; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11436 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11437 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11438 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11439 | if (lpfc_enable_npiv) |
| 11440 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11441 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11442 | |
| 11443 | return error; |
| 11444 | } |
| 11445 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11446 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11447 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11448 | * |
| 11449 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 11450 | * The special kernel macro module_exit() is used to indicate the role of |
| 11451 | * this routine to the kernel as lpfc module exit point. |
| 11452 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11453 | static void __exit |
| 11454 | lpfc_exit(void) |
| 11455 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11456 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11457 | pci_unregister_driver(&lpfc_driver); |
| 11458 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11459 | if (lpfc_enable_npiv) |
| 11460 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11461 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11462 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 11463 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11464 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 11465 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 11466 | } |
| 11467 | |
| 11468 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11469 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 11470 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11471 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 11472 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 11473 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11474 | kfree(lpfc_used_cpu); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 11475 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11476 | } |
| 11477 | |
| 11478 | module_init(lpfc_init); |
| 11479 | module_exit(lpfc_exit); |
| 11480 | MODULE_LICENSE("GPL"); |
| 11481 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 11482 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 11483 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |