| 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 | 16a59fb | 2014-04-04 13:52:41 -0400 | [diff] [blame^] | 4 | * Copyright (C) 2004-2014 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)) |
| 309 | sprintf(phba->OptionROMVersion, "%d.%d%d", |
| 310 | prg->ver, prg->rev, prg->lev); |
| 311 | else |
| 312 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", |
| 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 | **/ |
| 652 | 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 | **/ |
| 753 | 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 | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 823 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 824 | * @phba: pointer to lpfc HBA data structure. |
| 825 | * |
| 826 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 827 | * when bringing down the SLI Layer. |
| 828 | * |
| 829 | * |
| 830 | * Return codes |
| 831 | * void. |
| 832 | **/ |
| 833 | static void |
| 834 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 835 | { |
| 836 | struct lpfc_sli *psli = &phba->sli; |
| 837 | struct lpfc_sli_ring *pring; |
| 838 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 839 | LIST_HEAD(buflist); |
| 840 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 841 | |
| 842 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 843 | lpfc_sli_hbqbuf_free_all(phba); |
| 844 | else { |
| 845 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 846 | pring = &psli->ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 847 | spin_lock_irq(&phba->hbalock); |
| 848 | list_splice_init(&pring->postbufq, &buflist); |
| 849 | spin_unlock_irq(&phba->hbalock); |
| 850 | |
| 851 | count = 0; |
| 852 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 853 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 854 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 855 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 856 | kfree(mp); |
| 857 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 858 | |
| 859 | spin_lock_irq(&phba->hbalock); |
| 860 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 861 | spin_unlock_irq(&phba->hbalock); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 867 | * @phba: pointer to lpfc HBA data structure. |
| 868 | * |
| 869 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 870 | * down the SLI Layer. |
| 871 | * |
| 872 | * Return codes |
| 873 | * void |
| 874 | **/ |
| 875 | static void |
| 876 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 877 | { |
| 878 | struct lpfc_sli *psli = &phba->sli; |
| 879 | struct lpfc_sli_ring *pring; |
| 880 | LIST_HEAD(completions); |
| 881 | int i; |
| 882 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 883 | for (i = 0; i < psli->num_rings; i++) { |
| 884 | pring = &psli->ring[i]; |
| 885 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 886 | spin_lock_irq(&pring->ring_lock); |
| 887 | else |
| 888 | spin_lock_irq(&phba->hbalock); |
| 889 | /* At this point in time the HBA is either reset or DOA. Either |
| 890 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 891 | */ |
| 892 | list_splice_init(&pring->txcmplq, &completions); |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 893 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 894 | |
| 895 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 896 | spin_unlock_irq(&pring->ring_lock); |
| 897 | else |
| 898 | spin_unlock_irq(&phba->hbalock); |
| 899 | |
| 900 | /* Cancel all the IOCBs from the completions list */ |
| 901 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 902 | IOERR_SLI_ABORTED); |
| 903 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 908 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 909 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 910 | * @phba: pointer to lpfc HBA data structure. |
| 911 | * |
| 912 | * This routine will do uninitialization after the HBA is reset when bring |
| 913 | * down the SLI Layer. |
| 914 | * |
| 915 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 916 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 917 | * Any other value - error. |
| 918 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 919 | static int |
| 920 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 921 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 922 | lpfc_hba_free_post_buf(phba); |
| 923 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 924 | return 0; |
| 925 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 926 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 927 | /** |
| 928 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 929 | * @phba: pointer to lpfc HBA data structure. |
| 930 | * |
| 931 | * This routine will do uninitialization after the HBA is reset when bring |
| 932 | * down the SLI Layer. |
| 933 | * |
| 934 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 935 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 936 | * Any other value - error. |
| 937 | **/ |
| 938 | static int |
| 939 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 940 | { |
| 941 | struct lpfc_scsi_buf *psb, *psb_next; |
| 942 | LIST_HEAD(aborts); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 943 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 944 | struct lpfc_sglq *sglq_entry = NULL; |
| 945 | |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 946 | lpfc_hba_free_post_buf(phba); |
| 947 | lpfc_hba_clean_txcmplq(phba); |
| 948 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 949 | /* At this point in time the HBA is either reset or DOA. Either |
| 950 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 951 | * on the lpfc_sgl_list so that it can either be freed if the |
| 952 | * driver is unloading or reposted if the driver is restarting |
| 953 | * the port. |
| 954 | */ |
| 955 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 956 | /* scsl_buf_list */ |
| 957 | /* abts_sgl_list_lock required because worker thread uses this |
| 958 | * list. |
| 959 | */ |
| 960 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 961 | list_for_each_entry(sglq_entry, |
| 962 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 963 | sglq_entry->state = SGL_FREED; |
| 964 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 965 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 966 | &phba->sli4_hba.lpfc_sgl_list); |
| 967 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 968 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 969 | * list. |
| 970 | */ |
| 971 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 972 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 973 | &aborts); |
| 974 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 975 | spin_unlock_irq(&phba->hbalock); |
| 976 | |
| 977 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 978 | psb->pCmd = NULL; |
| 979 | psb->status = IOSTAT_SUCCESS; |
| 980 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 981 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 982 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 983 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | /** |
| 988 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 989 | * @phba: pointer to lpfc HBA data structure. |
| 990 | * |
| 991 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 992 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 993 | * |
| 994 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 995 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 996 | * Any other value - error. |
| 997 | **/ |
| 998 | int |
| 999 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1000 | { |
| 1001 | return (*phba->lpfc_hba_down_post)(phba); |
| 1002 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1004 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1005 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1006 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1007 | * |
| 1008 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1009 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1010 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1011 | * event will be used by the worker thread to invoke the actual timeout |
| 1012 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1013 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1014 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1015 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1016 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1017 | lpfc_hb_timeout(unsigned long ptr) |
| 1018 | { |
| 1019 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1020 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1021 | unsigned long iflag; |
| 1022 | |
| 1023 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1024 | |
| 1025 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1026 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1027 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1028 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1029 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1030 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1031 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1032 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1033 | if (!tmo_posted) |
| 1034 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1035 | return; |
| 1036 | } |
| 1037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1038 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1039 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1040 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1041 | * |
| 1042 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1043 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1044 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1045 | * event will be used by the worker thread to invoke the actual timeout |
| 1046 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1047 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1048 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1049 | **/ |
| 1050 | static void |
| 1051 | lpfc_rrq_timeout(unsigned long ptr) |
| 1052 | { |
| 1053 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1054 | unsigned long iflag; |
| 1055 | |
| 1056 | phba = (struct lpfc_hba *)ptr; |
| 1057 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1058 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1059 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1060 | else |
| 1061 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1062 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1063 | |
| 1064 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1065 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1069 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1070 | * @phba: pointer to lpfc hba data structure. |
| 1071 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1072 | * |
| 1073 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1074 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1075 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1076 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1077 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1078 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1079 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1080 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1081 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1082 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1083 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1084 | static void |
| 1085 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1086 | { |
| 1087 | unsigned long drvr_flag; |
| 1088 | |
| 1089 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1090 | phba->hb_outstanding = 0; |
| 1091 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1092 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1093 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1094 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1095 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1096 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1097 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1098 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1099 | jiffies + |
| 1100 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1105 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1106 | * @phba: pointer to lpfc hba data structure. |
| 1107 | * |
| 1108 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1109 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1110 | * handler performs any periodic operations needed for the device. If such |
| 1111 | * periodic event has already been attended to either in the interrupt handler |
| 1112 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1113 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1114 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1115 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1116 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1117 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1118 | * to offline. |
| 1119 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1120 | void |
| 1121 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1122 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1123 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1124 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1125 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1126 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1127 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1128 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1129 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1130 | vports = lpfc_create_vport_work_array(phba); |
| 1131 | if (vports != NULL) |
| 1132 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1133 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1134 | lpfc_destroy_vport_work_array(phba, vports); |
| 1135 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1136 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1137 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1138 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1139 | return; |
| 1140 | |
| 1141 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1142 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1143 | if (time_after(phba->last_completion_time + |
| 1144 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1145 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1146 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1147 | if (!phba->hb_outstanding) |
| 1148 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1149 | jiffies + |
| 1150 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1151 | else |
| 1152 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1153 | jiffies + |
| 1154 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1155 | return; |
| 1156 | } |
| 1157 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1158 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1159 | if (phba->elsbuf_cnt && |
| 1160 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1161 | spin_lock_irq(&phba->hbalock); |
| 1162 | list_splice_init(&phba->elsbuf, &completions); |
| 1163 | phba->elsbuf_cnt = 0; |
| 1164 | phba->elsbuf_prev_cnt = 0; |
| 1165 | spin_unlock_irq(&phba->hbalock); |
| 1166 | |
| 1167 | while (!list_empty(&completions)) { |
| 1168 | list_remove_head(&completions, buf_ptr, |
| 1169 | struct lpfc_dmabuf, list); |
| 1170 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1171 | kfree(buf_ptr); |
| 1172 | } |
| 1173 | } |
| 1174 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1175 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1176 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1177 | if (phba->cfg_enable_hba_heartbeat) { |
| 1178 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1179 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1180 | (list_empty(&psli->mboxq))) { |
| 1181 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1182 | GFP_KERNEL); |
| 1183 | if (!pmboxq) { |
| 1184 | mod_timer(&phba->hb_tmofunc, |
| 1185 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1186 | msecs_to_jiffies(1000 * |
| 1187 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1188 | return; |
| 1189 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1190 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1191 | lpfc_heart_beat(phba, pmboxq); |
| 1192 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1193 | pmboxq->vport = phba->pport; |
| 1194 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1195 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1196 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1197 | if (retval != MBX_BUSY && |
| 1198 | retval != MBX_SUCCESS) { |
| 1199 | mempool_free(pmboxq, |
| 1200 | phba->mbox_mem_pool); |
| 1201 | mod_timer(&phba->hb_tmofunc, |
| 1202 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1203 | msecs_to_jiffies(1000 * |
| 1204 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1205 | return; |
| 1206 | } |
| 1207 | phba->skipped_hb = 0; |
| 1208 | phba->hb_outstanding = 1; |
| 1209 | } else if (time_before_eq(phba->last_completion_time, |
| 1210 | phba->skipped_hb)) { |
| 1211 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1212 | "2857 Last completion time not " |
| 1213 | " updated in %d ms\n", |
| 1214 | jiffies_to_msecs(jiffies |
| 1215 | - phba->last_completion_time)); |
| 1216 | } else |
| 1217 | phba->skipped_hb = jiffies; |
| 1218 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1219 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1220 | jiffies + |
| 1221 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1222 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1223 | } else { |
| 1224 | /* |
| 1225 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1226 | * we need to give the hb mailbox cmd a chance to |
| 1227 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1228 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1229 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1230 | "0459 Adapter heartbeat still out" |
| 1231 | "standing:last compl time was %d ms.\n", |
| 1232 | jiffies_to_msecs(jiffies |
| 1233 | - phba->last_completion_time)); |
| 1234 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1235 | jiffies + |
| 1236 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1237 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1242 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1243 | * @phba: pointer to lpfc hba data structure. |
| 1244 | * |
| 1245 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1246 | * other than Port Error 6 has been detected. |
| 1247 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1248 | static void |
| 1249 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1250 | { |
| 1251 | struct lpfc_sli *psli = &phba->sli; |
| 1252 | |
| 1253 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1254 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1255 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1256 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1257 | |
| 1258 | lpfc_offline(phba); |
| 1259 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1260 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1261 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1262 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1263 | lpfc_hba_down_post(phba); |
| 1264 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1265 | lpfc_unblock_mgmt_io(phba); |
| 1266 | phba->link_state = LPFC_HBA_ERROR; |
| 1267 | return; |
| 1268 | } |
| 1269 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1270 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1271 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1272 | * @phba: pointer to lpfc hba data structure. |
| 1273 | * |
| 1274 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1275 | * other than Port Error 6 has been detected. |
| 1276 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1277 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1278 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1279 | { |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1280 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1281 | lpfc_offline(phba); |
| 1282 | lpfc_sli4_brdreset(phba); |
| 1283 | lpfc_hba_down_post(phba); |
| 1284 | lpfc_sli4_post_status_check(phba); |
| 1285 | lpfc_unblock_mgmt_io(phba); |
| 1286 | phba->link_state = LPFC_HBA_ERROR; |
| 1287 | } |
| 1288 | |
| 1289 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1290 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1291 | * @phba: pointer to lpfc hba data structure. |
| 1292 | * |
| 1293 | * This routine is invoked to handle the deferred HBA hardware error |
| 1294 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1295 | * and another ER bit in the host status register. The driver will |
| 1296 | * wait until the ER1 bit clears before handling the error condition. |
| 1297 | **/ |
| 1298 | static void |
| 1299 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1300 | { |
| 1301 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1302 | struct lpfc_sli *psli = &phba->sli; |
| 1303 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1304 | /* If the pci channel is offline, ignore possible errors, |
| 1305 | * since we cannot communicate with the pci card anyway. |
| 1306 | */ |
| 1307 | if (pci_channel_offline(phba->pcidev)) { |
| 1308 | spin_lock_irq(&phba->hbalock); |
| 1309 | phba->hba_flag &= ~DEFER_ERATT; |
| 1310 | spin_unlock_irq(&phba->hbalock); |
| 1311 | return; |
| 1312 | } |
| 1313 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1315 | "0479 Deferred Adapter Hardware Error " |
| 1316 | "Data: x%x x%x x%x\n", |
| 1317 | phba->work_hs, |
| 1318 | phba->work_status[0], phba->work_status[1]); |
| 1319 | |
| 1320 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1321 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1322 | spin_unlock_irq(&phba->hbalock); |
| 1323 | |
| 1324 | |
| 1325 | /* |
| 1326 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1327 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1328 | * SCSI layer retry it after re-establishing link. |
| 1329 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1330 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1331 | |
| 1332 | /* |
| 1333 | * There was a firmware error. Take the hba offline and then |
| 1334 | * attempt to restart it. |
| 1335 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1336 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1337 | lpfc_offline(phba); |
| 1338 | |
| 1339 | /* Wait for the ER1 bit to clear.*/ |
| 1340 | while (phba->work_hs & HS_FFER1) { |
| 1341 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1342 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1343 | phba->work_hs = UNPLUG_ERR ; |
| 1344 | break; |
| 1345 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1346 | /* If driver is unloading let the worker thread continue */ |
| 1347 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1348 | phba->work_hs = 0; |
| 1349 | break; |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | /* |
| 1354 | * This is to ptrotect against a race condition in which |
| 1355 | * first write to the host attention register clear the |
| 1356 | * host status register. |
| 1357 | */ |
| 1358 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1359 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1360 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1361 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1362 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1363 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1364 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1365 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1366 | } |
| 1367 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1368 | static void |
| 1369 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1370 | { |
| 1371 | struct lpfc_board_event_header board_event; |
| 1372 | struct Scsi_Host *shost; |
| 1373 | |
| 1374 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1375 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1376 | shost = lpfc_shost_from_vport(phba->pport); |
| 1377 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1378 | sizeof(board_event), |
| 1379 | (char *) &board_event, |
| 1380 | LPFC_NL_VENDOR_ID); |
| 1381 | } |
| 1382 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1383 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1384 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1385 | * @phba: pointer to lpfc hba data structure. |
| 1386 | * |
| 1387 | * This routine is invoked to handle the following HBA hardware error |
| 1388 | * conditions: |
| 1389 | * 1 - HBA error attention interrupt |
| 1390 | * 2 - DMA ring index out of range |
| 1391 | * 3 - Mailbox command came back as unknown |
| 1392 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1393 | static void |
| 1394 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1395 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1396 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1397 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1398 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1399 | unsigned long temperature; |
| 1400 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1401 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1402 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1403 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1404 | * since we cannot communicate with the pci card anyway. |
| 1405 | */ |
| 1406 | if (pci_channel_offline(phba->pcidev)) { |
| 1407 | spin_lock_irq(&phba->hbalock); |
| 1408 | phba->hba_flag &= ~DEFER_ERATT; |
| 1409 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1410 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1411 | } |
| 1412 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1413 | /* If resets are disabled then leave the HBA alone and return */ |
| 1414 | if (!phba->cfg_enable_hba_reset) |
| 1415 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1417 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1418 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1419 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1420 | if (phba->hba_flag & DEFER_ERATT) |
| 1421 | lpfc_handle_deferred_eratt(phba); |
| 1422 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1423 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1424 | if (phba->work_hs & HS_FFER6) |
| 1425 | /* Re-establishing Link */ |
| 1426 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1427 | "1301 Re-establishing Link " |
| 1428 | "Data: x%x x%x x%x\n", |
| 1429 | phba->work_hs, phba->work_status[0], |
| 1430 | phba->work_status[1]); |
| 1431 | if (phba->work_hs & HS_FFER8) |
| 1432 | /* Device Zeroization */ |
| 1433 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1434 | "2861 Host Authentication device " |
| 1435 | "zeroization Data:x%x x%x x%x\n", |
| 1436 | phba->work_hs, phba->work_status[0], |
| 1437 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1438 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1439 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1440 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1441 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | |
| 1443 | /* |
| 1444 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1445 | * That could cause the I/Os dropped by the firmware. |
| 1446 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1447 | * retry it after re-establishing link. |
| 1448 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1449 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1451 | /* |
| 1452 | * There was a firmware error. Take the hba offline and then |
| 1453 | * attempt to restart it. |
| 1454 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1455 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1457 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1459 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | return; |
| 1461 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1462 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1463 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1464 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1465 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1466 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1467 | temp_event_data.data = (uint32_t)temperature; |
| 1468 | |
| 1469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1470 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1471 | "(%ld), taking this port offline " |
| 1472 | "Data: x%x x%x x%x\n", |
| 1473 | temperature, phba->work_hs, |
| 1474 | phba->work_status[0], phba->work_status[1]); |
| 1475 | |
| 1476 | shost = lpfc_shost_from_vport(phba->pport); |
| 1477 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1478 | sizeof(temp_event_data), |
| 1479 | (char *) &temp_event_data, |
| 1480 | SCSI_NL_VID_TYPE_PCI |
| 1481 | | PCI_VENDOR_ID_EMULEX); |
| 1482 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1483 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1484 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1485 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1486 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | } else { |
| 1489 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1490 | * failure is a value other than FFER6. Do not call the offline |
| 1491 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | */ |
| 1493 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1494 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1496 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | phba->work_status[0], phba->work_status[1]); |
| 1498 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1499 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1500 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1501 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1502 | sizeof(event_data), (char *) &event_data, |
| 1503 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1504 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1505 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1507 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | } |
| 1509 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1510 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1511 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1512 | * @phba: pointer to lpfc hba data structure. |
| 1513 | * @mbx_action: flag for mailbox shutdown action. |
| 1514 | * |
| 1515 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1516 | * response to port status register polling attention. It waits for port |
| 1517 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1518 | * During this process, interrupt vectors are freed and later requested |
| 1519 | * for handling possible port resource change. |
| 1520 | **/ |
| 1521 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1522 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1523 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1524 | { |
| 1525 | int rc; |
| 1526 | uint32_t intr_mode; |
| 1527 | |
| 1528 | /* |
| 1529 | * On error status condition, driver need to wait for port |
| 1530 | * ready before performing reset. |
| 1531 | */ |
| 1532 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1533 | if (!rc) { |
| 1534 | /* need reset: attempt for port recovery */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1535 | if (en_rn_msg) |
| 1536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1537 | "2887 Reset Needed: Attempting Port " |
| 1538 | "Recovery...\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1539 | lpfc_offline_prep(phba, mbx_action); |
| 1540 | lpfc_offline(phba); |
| 1541 | /* release interrupt for possible resource change */ |
| 1542 | lpfc_sli4_disable_intr(phba); |
| 1543 | lpfc_sli_brdrestart(phba); |
| 1544 | /* request and enable interrupt */ |
| 1545 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1546 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1548 | "3175 Failed to enable interrupt\n"); |
| 1549 | return -EIO; |
| 1550 | } else { |
| 1551 | phba->intr_mode = intr_mode; |
| 1552 | } |
| 1553 | rc = lpfc_online(phba); |
| 1554 | if (rc == 0) |
| 1555 | lpfc_unblock_mgmt_io(phba); |
| 1556 | } |
| 1557 | return rc; |
| 1558 | } |
| 1559 | |
| 1560 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1561 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1562 | * @phba: pointer to lpfc hba data structure. |
| 1563 | * |
| 1564 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1565 | * conditions. |
| 1566 | **/ |
| 1567 | static void |
| 1568 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1569 | { |
| 1570 | struct lpfc_vport *vport = phba->pport; |
| 1571 | uint32_t event_data; |
| 1572 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1573 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1574 | struct lpfc_register portstat_reg = {0}; |
| 1575 | uint32_t reg_err1, reg_err2; |
| 1576 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1577 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1578 | bool en_rn_msg = true; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1579 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1580 | |
| 1581 | /* If the pci channel is offline, ignore possible errors, since |
| 1582 | * we cannot communicate with the pci card anyway. |
| 1583 | */ |
| 1584 | if (pci_channel_offline(phba->pcidev)) |
| 1585 | return; |
| 1586 | /* If resets are disabled then leave the HBA alone and return */ |
| 1587 | if (!phba->cfg_enable_hba_reset) |
| 1588 | return; |
| 1589 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1590 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1591 | switch (if_type) { |
| 1592 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1593 | pci_rd_rc1 = lpfc_readl( |
| 1594 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1595 | &uerrlo_reg); |
| 1596 | pci_rd_rc2 = lpfc_readl( |
| 1597 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1598 | &uemasklo_reg); |
| 1599 | /* consider PCI bus read error as pci_channel_offline */ |
| 1600 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1601 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1602 | lpfc_sli4_offline_eratt(phba); |
| 1603 | break; |
| 1604 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1605 | pci_rd_rc1 = lpfc_readl( |
| 1606 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1607 | &portstat_reg.word0); |
| 1608 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1609 | if (pci_rd_rc1 == -EIO) { |
| 1610 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1611 | "3151 PCI bus read access failure: x%x\n", |
| 1612 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1613 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1614 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1615 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1616 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1617 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
| 1618 | /* TODO: Register for Overtemp async events. */ |
| 1619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1620 | "2889 Port Overtemperature event, " |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 1621 | "taking port offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1622 | spin_lock_irq(&phba->hbalock); |
| 1623 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1624 | spin_unlock_irq(&phba->hbalock); |
| 1625 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1626 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1627 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1628 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1629 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1631 | "3143 Port Down: Firmware Update " |
| 1632 | "Detected\n"); |
| 1633 | en_rn_msg = false; |
| 1634 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1635 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1637 | "3144 Port Down: Debug Dump\n"); |
| 1638 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1639 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1641 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1642 | |
| 1643 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1644 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1645 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1646 | if (rc == 0) { |
| 1647 | /* don't report event on forced debug dump */ |
| 1648 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1649 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1650 | return; |
| 1651 | else |
| 1652 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1653 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1654 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1656 | "3152 Unrecoverable error, bring the port " |
| 1657 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1658 | lpfc_sli4_offline_eratt(phba); |
| 1659 | break; |
| 1660 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1661 | default: |
| 1662 | break; |
| 1663 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1664 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1665 | "3123 Report dump event to upper layer\n"); |
| 1666 | /* Send an internal error event to mgmt application */ |
| 1667 | lpfc_board_errevt_to_mgmt(phba); |
| 1668 | |
| 1669 | event_data = FC_REG_DUMP_EVENT; |
| 1670 | shost = lpfc_shost_from_vport(vport); |
| 1671 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1672 | sizeof(event_data), (char *) &event_data, |
| 1673 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | /** |
| 1677 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1678 | * @phba: pointer to lpfc HBA data structure. |
| 1679 | * |
| 1680 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1681 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1682 | * |
| 1683 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1684 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1685 | * Any other value - error. |
| 1686 | **/ |
| 1687 | void |
| 1688 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1689 | { |
| 1690 | (*phba->lpfc_handle_eratt)(phba); |
| 1691 | } |
| 1692 | |
| 1693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1694 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1695 | * @phba: pointer to lpfc hba data structure. |
| 1696 | * |
| 1697 | * This routine is invoked from the worker thread to handle a HBA host |
| 1698 | * attention link event. |
| 1699 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1700 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1701 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1703 | struct lpfc_vport *vport = phba->pport; |
| 1704 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1705 | LPFC_MBOXQ_t *pmb; |
| 1706 | volatile uint32_t control; |
| 1707 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1708 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | |
| 1710 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1711 | if (!pmb) { |
| 1712 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1714 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | |
| 1716 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1717 | if (!mp) { |
| 1718 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | |
| 1722 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1723 | if (!mp->virt) { |
| 1724 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1726 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1727 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1728 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1729 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | |
| 1731 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1732 | lpfc_read_topology(phba, pmb, mp); |
| 1733 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1734 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1735 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1736 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1737 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1738 | if (rc == MBX_NOT_FINISHED) { |
| 1739 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1740 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1741 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | |
| 1743 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1745 | writel(HA_LATT, phba->HAregaddr); |
| 1746 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | |
| 1749 | return; |
| 1750 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1751 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1752 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1753 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | lpfc_handle_latt_free_mp: |
| 1755 | kfree(mp); |
| 1756 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1757 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | lpfc_handle_latt_err_exit: |
| 1759 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1762 | control = readl(phba->HCregaddr); |
| 1763 | control |= HC_LAINT_ENA; |
| 1764 | writel(control, phba->HCregaddr); |
| 1765 | readl(phba->HCregaddr); /* flush */ |
| 1766 | |
| 1767 | /* Clear Link Attention in HA REG */ |
| 1768 | writel(HA_LATT, phba->HAregaddr); |
| 1769 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1770 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1772 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1774 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1775 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | |
| 1777 | return; |
| 1778 | } |
| 1779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1781 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1782 | * @phba: pointer to lpfc hba data structure. |
| 1783 | * @vpd: pointer to the vital product data. |
| 1784 | * @len: length of the vital product data in bytes. |
| 1785 | * |
| 1786 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1787 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1788 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1789 | * |
| 1790 | * Return codes |
| 1791 | * 0 - pointer to the VPD passed in is NULL |
| 1792 | * 1 - success |
| 1793 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1794 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1796 | { |
| 1797 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1798 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | int i, j; |
| 1800 | int finished = 0; |
| 1801 | int index = 0; |
| 1802 | |
| 1803 | if (!vpd) |
| 1804 | return 0; |
| 1805 | |
| 1806 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1807 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1808 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1810 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1811 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1812 | switch (vpd[index]) { |
| 1813 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1814 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | index += 1; |
| 1816 | lenlo = vpd[index]; |
| 1817 | index += 1; |
| 1818 | lenhi = vpd[index]; |
| 1819 | index += 1; |
| 1820 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1821 | index += i; |
| 1822 | break; |
| 1823 | case 0x90: |
| 1824 | index += 1; |
| 1825 | lenlo = vpd[index]; |
| 1826 | index += 1; |
| 1827 | lenhi = vpd[index]; |
| 1828 | index += 1; |
| 1829 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1830 | if (Length > len - index) |
| 1831 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | while (Length > 0) { |
| 1833 | /* Look for Serial Number */ |
| 1834 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1835 | index += 2; |
| 1836 | i = vpd[index]; |
| 1837 | index += 1; |
| 1838 | j = 0; |
| 1839 | Length -= (3+i); |
| 1840 | while(i--) { |
| 1841 | phba->SerialNumber[j++] = vpd[index++]; |
| 1842 | if (j == 31) |
| 1843 | break; |
| 1844 | } |
| 1845 | phba->SerialNumber[j] = 0; |
| 1846 | continue; |
| 1847 | } |
| 1848 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1849 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1850 | index += 2; |
| 1851 | i = vpd[index]; |
| 1852 | index += 1; |
| 1853 | j = 0; |
| 1854 | Length -= (3+i); |
| 1855 | while(i--) { |
| 1856 | phba->ModelDesc[j++] = vpd[index++]; |
| 1857 | if (j == 255) |
| 1858 | break; |
| 1859 | } |
| 1860 | phba->ModelDesc[j] = 0; |
| 1861 | continue; |
| 1862 | } |
| 1863 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1864 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1865 | index += 2; |
| 1866 | i = vpd[index]; |
| 1867 | index += 1; |
| 1868 | j = 0; |
| 1869 | Length -= (3+i); |
| 1870 | while(i--) { |
| 1871 | phba->ModelName[j++] = vpd[index++]; |
| 1872 | if (j == 79) |
| 1873 | break; |
| 1874 | } |
| 1875 | phba->ModelName[j] = 0; |
| 1876 | continue; |
| 1877 | } |
| 1878 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1879 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1880 | index += 2; |
| 1881 | i = vpd[index]; |
| 1882 | index += 1; |
| 1883 | j = 0; |
| 1884 | Length -= (3+i); |
| 1885 | while(i--) { |
| 1886 | phba->ProgramType[j++] = vpd[index++]; |
| 1887 | if (j == 255) |
| 1888 | break; |
| 1889 | } |
| 1890 | phba->ProgramType[j] = 0; |
| 1891 | continue; |
| 1892 | } |
| 1893 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1894 | phba->vpd_flag |= VPD_PORT; |
| 1895 | index += 2; |
| 1896 | i = vpd[index]; |
| 1897 | index += 1; |
| 1898 | j = 0; |
| 1899 | Length -= (3+i); |
| 1900 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1901 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1902 | (phba->sli4_hba.pport_name_sta == |
| 1903 | LPFC_SLI4_PPNAME_GET)) { |
| 1904 | j++; |
| 1905 | index++; |
| 1906 | } else |
| 1907 | phba->Port[j++] = vpd[index++]; |
| 1908 | if (j == 19) |
| 1909 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1911 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1912 | (phba->sli4_hba.pport_name_sta == |
| 1913 | LPFC_SLI4_PPNAME_NON)) |
| 1914 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | continue; |
| 1916 | } |
| 1917 | else { |
| 1918 | index += 2; |
| 1919 | i = vpd[index]; |
| 1920 | index += 1; |
| 1921 | index += i; |
| 1922 | Length -= (3 + i); |
| 1923 | } |
| 1924 | } |
| 1925 | finished = 0; |
| 1926 | break; |
| 1927 | case 0x78: |
| 1928 | finished = 1; |
| 1929 | break; |
| 1930 | default: |
| 1931 | index ++; |
| 1932 | break; |
| 1933 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | |
| 1936 | return(1); |
| 1937 | } |
| 1938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1939 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1940 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1941 | * @phba: pointer to lpfc hba data structure. |
| 1942 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1943 | * @descp: pointer to the data structure to hold the derived description. |
| 1944 | * |
| 1945 | * This routine retrieves HBA's description based on its registered PCI device |
| 1946 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1947 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1948 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1949 | * function returns, the @mdp will be filled with the model name. |
| 1950 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1952 | 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] | 1953 | { |
| 1954 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1955 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1956 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1957 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1958 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1959 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1960 | char *name; |
| 1961 | char *bus; |
| 1962 | char *function; |
| 1963 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1964 | |
| 1965 | if (mdp && mdp[0] != '\0' |
| 1966 | && descp && descp[0] != '\0') |
| 1967 | return; |
| 1968 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 1969 | if (phba->lmt & LMT_16Gb) |
| 1970 | max_speed = 16; |
| 1971 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1972 | max_speed = 10; |
| 1973 | else if (phba->lmt & LMT_8Gb) |
| 1974 | max_speed = 8; |
| 1975 | else if (phba->lmt & LMT_4Gb) |
| 1976 | max_speed = 4; |
| 1977 | else if (phba->lmt & LMT_2Gb) |
| 1978 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1979 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1980 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1981 | else |
| 1982 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | |
| 1984 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1986 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1987 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1988 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1989 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | case PCI_DEVICE_ID_SUPERFLY: |
| 1991 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1992 | m = (typeof(m)){"LP7000", "PCI", |
| 1993 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1995 | m = (typeof(m)){"LP7000E", "PCI", |
| 1996 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | break; |
| 1998 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1999 | m = (typeof(m)){"LP8000", "PCI", |
| 2000 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2001 | break; |
| 2002 | case PCI_DEVICE_ID_CENTAUR: |
| 2003 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2004 | m = (typeof(m)){"LP9002", "PCI", |
| 2005 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2007 | m = (typeof(m)){"LP9000", "PCI", |
| 2008 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | break; |
| 2010 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2011 | m = (typeof(m)){"LP952", "PCI", |
| 2012 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | break; |
| 2014 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2015 | m = (typeof(m)){"LP9802", "PCI-X", |
| 2016 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | break; |
| 2018 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2019 | m = (typeof(m)){"LP10000", "PCI-X", |
| 2020 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2021 | break; |
| 2022 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2023 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 2024 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2025 | break; |
| 2026 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2027 | m = (typeof(m)){"LP982", "PCI-X", |
| 2028 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | break; |
| 2030 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2031 | m = (typeof(m)){"LP1050", "PCI-X", |
| 2032 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | break; |
| 2034 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2035 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 2036 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2038 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2039 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 2040 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2041 | break; |
| 2042 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2043 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 2044 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2045 | break; |
| 2046 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2047 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2048 | break; |
| 2049 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2050 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2051 | break; |
| 2052 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2053 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2054 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2056 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | break; |
| 2058 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2059 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | break; |
| 2061 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2062 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2064 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2065 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2066 | break; |
| 2067 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2068 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2069 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2070 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2072 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | break; |
| 2074 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2075 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | break; |
| 2077 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2078 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | break; |
| 2080 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2081 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2082 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2083 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2084 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2085 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2086 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2087 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2088 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2089 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2090 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2091 | break; |
| 2092 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2093 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2094 | break; |
| 2095 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2096 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2097 | break; |
| 2098 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2099 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2100 | break; |
| 2101 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2102 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2103 | break; |
| 2104 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2105 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2106 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2107 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2108 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2109 | GE = 1; |
| 2110 | break; |
| 2111 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2112 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2113 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2114 | break; |
| 2115 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2116 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2117 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2118 | break; |
| 2119 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2120 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 2121 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2122 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2123 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2124 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2125 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2126 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2127 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2128 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2129 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2130 | break; |
| 2131 | case PCI_DEVICE_ID_FALCON: |
| 2132 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2133 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2134 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2135 | case PCI_DEVICE_ID_BALIUS: |
| 2136 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2137 | "Fibre Channel Adapter"}; |
| 2138 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2139 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2140 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2141 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2142 | break; |
| 2143 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2144 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2145 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2146 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2147 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2148 | case PCI_DEVICE_ID_SKYHAWK: |
| 2149 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2150 | oneConnect = 1; |
| 2151 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2152 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2153 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2154 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2155 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2157 | |
| 2158 | if (mdp && mdp[0] == '\0') |
| 2159 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2160 | /* |
| 2161 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2162 | * and we put the port number on the end |
| 2163 | */ |
| 2164 | if (descp && descp[0] == '\0') { |
| 2165 | if (oneConnect) |
| 2166 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2167 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2168 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2169 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2170 | else if (max_speed == 0) |
| 2171 | snprintf(descp, 255, |
| 2172 | "Emulex %s %s %s ", |
| 2173 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2174 | else |
| 2175 | snprintf(descp, 255, |
| 2176 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2177 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2178 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2179 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | } |
| 2181 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2182 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2183 | * 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] | 2184 | * @phba: pointer to lpfc hba data structure. |
| 2185 | * @pring: pointer to a IOCB ring. |
| 2186 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2187 | * |
| 2188 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2189 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2190 | * |
| 2191 | * Return codes |
| 2192 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2193 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2195 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | { |
| 2197 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2198 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | struct lpfc_dmabuf *mp1, *mp2; |
| 2200 | |
| 2201 | cnt += pring->missbufcnt; |
| 2202 | |
| 2203 | /* While there are buffers to post */ |
| 2204 | while (cnt > 0) { |
| 2205 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2206 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | if (iocb == NULL) { |
| 2208 | pring->missbufcnt = cnt; |
| 2209 | return cnt; |
| 2210 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | icmd = &iocb->iocb; |
| 2212 | |
| 2213 | /* 2 buffers can be posted per command */ |
| 2214 | /* Allocate buffer to post */ |
| 2215 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2216 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2217 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2218 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2219 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2220 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | pring->missbufcnt = cnt; |
| 2222 | return cnt; |
| 2223 | } |
| 2224 | |
| 2225 | INIT_LIST_HEAD(&mp1->list); |
| 2226 | /* Allocate buffer to post */ |
| 2227 | if (cnt > 1) { |
| 2228 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2229 | if (mp2) |
| 2230 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2231 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2232 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2233 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2235 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2236 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2237 | pring->missbufcnt = cnt; |
| 2238 | return cnt; |
| 2239 | } |
| 2240 | |
| 2241 | INIT_LIST_HEAD(&mp2->list); |
| 2242 | } else { |
| 2243 | mp2 = NULL; |
| 2244 | } |
| 2245 | |
| 2246 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2247 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2248 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2249 | icmd->ulpBdeCount = 1; |
| 2250 | cnt--; |
| 2251 | if (mp2) { |
| 2252 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2253 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2254 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2255 | cnt--; |
| 2256 | icmd->ulpBdeCount = 2; |
| 2257 | } |
| 2258 | |
| 2259 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2260 | icmd->ulpLe = 1; |
| 2261 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2262 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2263 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2264 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2265 | kfree(mp1); |
| 2266 | cnt++; |
| 2267 | if (mp2) { |
| 2268 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2269 | kfree(mp2); |
| 2270 | cnt++; |
| 2271 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2272 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2274 | return cnt; |
| 2275 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2276 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2277 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2278 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | } |
| 2280 | pring->missbufcnt = 0; |
| 2281 | return 0; |
| 2282 | } |
| 2283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2285 | * 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] | 2286 | * @phba: pointer to lpfc hba data structure. |
| 2287 | * |
| 2288 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2289 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2290 | * set to 64 IOCBs. |
| 2291 | * |
| 2292 | * Return codes |
| 2293 | * 0 - success (currently always success) |
| 2294 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2295 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2296 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2297 | { |
| 2298 | struct lpfc_sli *psli = &phba->sli; |
| 2299 | |
| 2300 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2301 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | /* Ring 2 - FCP no buffers needed */ |
| 2303 | |
| 2304 | return 0; |
| 2305 | } |
| 2306 | |
| 2307 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2310 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2311 | * @HashResultPointer: pointer to an array as hash table. |
| 2312 | * |
| 2313 | * This routine sets up the initial values to the array of hash table entries |
| 2314 | * for the LC HBAs. |
| 2315 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | static void |
| 2317 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2318 | { |
| 2319 | HashResultPointer[0] = 0x67452301; |
| 2320 | HashResultPointer[1] = 0xEFCDAB89; |
| 2321 | HashResultPointer[2] = 0x98BADCFE; |
| 2322 | HashResultPointer[3] = 0x10325476; |
| 2323 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2324 | } |
| 2325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2327 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2328 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2329 | * @HashWorkingPointer: pointer to an working hash table. |
| 2330 | * |
| 2331 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2332 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2333 | * The results are putting back to the initial hash table, returned through |
| 2334 | * the @HashResultPointer as the result hash table. |
| 2335 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | static void |
| 2337 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2338 | { |
| 2339 | int t; |
| 2340 | uint32_t TEMP; |
| 2341 | uint32_t A, B, C, D, E; |
| 2342 | t = 16; |
| 2343 | do { |
| 2344 | HashWorkingPointer[t] = |
| 2345 | S(1, |
| 2346 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2347 | 8] ^ |
| 2348 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2349 | } while (++t <= 79); |
| 2350 | t = 0; |
| 2351 | A = HashResultPointer[0]; |
| 2352 | B = HashResultPointer[1]; |
| 2353 | C = HashResultPointer[2]; |
| 2354 | D = HashResultPointer[3]; |
| 2355 | E = HashResultPointer[4]; |
| 2356 | |
| 2357 | do { |
| 2358 | if (t < 20) { |
| 2359 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2360 | } else if (t < 40) { |
| 2361 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2362 | } else if (t < 60) { |
| 2363 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2364 | } else { |
| 2365 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2366 | } |
| 2367 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2368 | E = D; |
| 2369 | D = C; |
| 2370 | C = S(30, B); |
| 2371 | B = A; |
| 2372 | A = TEMP; |
| 2373 | } while (++t <= 79); |
| 2374 | |
| 2375 | HashResultPointer[0] += A; |
| 2376 | HashResultPointer[1] += B; |
| 2377 | HashResultPointer[2] += C; |
| 2378 | HashResultPointer[3] += D; |
| 2379 | HashResultPointer[4] += E; |
| 2380 | |
| 2381 | } |
| 2382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2384 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2385 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2386 | * @HashWorking: pointer to the entry of the working hash array. |
| 2387 | * |
| 2388 | * This routine calculates the working hash array referred by @HashWorking |
| 2389 | * from the challenge random numbers associated with the host, referred by |
| 2390 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2391 | * array and returned by reference through @HashWorking. |
| 2392 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | static void |
| 2394 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2395 | { |
| 2396 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2397 | } |
| 2398 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2399 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2400 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2401 | * @phba: pointer to lpfc hba data structure. |
| 2402 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2403 | * |
| 2404 | * This routine performs the special handling for LC HBA initialization. |
| 2405 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | void |
| 2407 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2408 | { |
| 2409 | int t; |
| 2410 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2411 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2412 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2413 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | if (!HashWorking) |
| 2415 | return; |
| 2416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2418 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2419 | |
| 2420 | for (t = 0; t < 7; t++) |
| 2421 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2422 | |
| 2423 | lpfc_sha_init(hbainit); |
| 2424 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2425 | kfree(HashWorking); |
| 2426 | } |
| 2427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2429 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2430 | * @vport: pointer to a virtual N_Port data structure. |
| 2431 | * |
| 2432 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2433 | * It invokes the discovery state machine to perform necessary state |
| 2434 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2435 | * the physical port is treated as @vport 0. |
| 2436 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2437 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2440 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2442 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2444 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2445 | lpfc_port_link_failure(vport); |
| 2446 | |
| 2447 | 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] | 2448 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2449 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2450 | NLP_STE_UNUSED_NODE); |
| 2451 | if (!ndlp) |
| 2452 | continue; |
| 2453 | spin_lock_irq(&phba->ndlp_lock); |
| 2454 | NLP_SET_FREE_REQ(ndlp); |
| 2455 | spin_unlock_irq(&phba->ndlp_lock); |
| 2456 | /* Trigger the release of the ndlp memory */ |
| 2457 | lpfc_nlp_put(ndlp); |
| 2458 | continue; |
| 2459 | } |
| 2460 | spin_lock_irq(&phba->ndlp_lock); |
| 2461 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2462 | /* The ndlp should not be in memory free mode already */ |
| 2463 | spin_unlock_irq(&phba->ndlp_lock); |
| 2464 | continue; |
| 2465 | } else |
| 2466 | /* Indicate request for freeing ndlp memory */ |
| 2467 | NLP_SET_FREE_REQ(ndlp); |
| 2468 | spin_unlock_irq(&phba->ndlp_lock); |
| 2469 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2470 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2471 | ndlp->nlp_DID == Fabric_DID) { |
| 2472 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2473 | lpfc_nlp_put(ndlp); |
| 2474 | continue; |
| 2475 | } |
| 2476 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2477 | /* take care of nodes in unused state before the state |
| 2478 | * machine taking action. |
| 2479 | */ |
| 2480 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2481 | lpfc_nlp_put(ndlp); |
| 2482 | continue; |
| 2483 | } |
| 2484 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2485 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2486 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2487 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2488 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2489 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2490 | NLP_EVT_DEVICE_RM); |
| 2491 | } |
| 2492 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2493 | /* At this point, ALL ndlp's should be gone |
| 2494 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2495 | * Lets wait for this to happen, if needed. |
| 2496 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2497 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2498 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2499 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2500 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2501 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2502 | &vport->fc_nodes, nlp_listp) { |
| 2503 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2504 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2505 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2506 | "usgmap:x%x refcnt:%d\n", |
| 2507 | ndlp->nlp_DID, (void *)ndlp, |
| 2508 | ndlp->nlp_usg_map, |
| 2509 | atomic_read( |
| 2510 | &ndlp->kref.refcount)); |
| 2511 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2512 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2513 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2514 | |
| 2515 | /* Wait for any activity on ndlps to settle */ |
| 2516 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2517 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2518 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2519 | } |
| 2520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2522 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2523 | * @vport: pointer to a virtual N_Port data structure. |
| 2524 | * |
| 2525 | * This routine stops all the timers associated with a @vport. This function |
| 2526 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2527 | * port is treated as @vport 0. |
| 2528 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2529 | void |
| 2530 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2531 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2532 | del_timer_sync(&vport->els_tmofunc); |
| 2533 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2534 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2535 | lpfc_can_disctmo(vport); |
| 2536 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2537 | } |
| 2538 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2539 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2540 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2541 | * @phba: pointer to lpfc hba data structure. |
| 2542 | * |
| 2543 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2544 | * caller of this routine should already hold the host lock. |
| 2545 | **/ |
| 2546 | void |
| 2547 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2548 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2549 | /* Clear pending FCF rediscovery wait flag */ |
| 2550 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2551 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2552 | /* Now, try to stop the timer */ |
| 2553 | del_timer(&phba->fcf.redisc_wait); |
| 2554 | } |
| 2555 | |
| 2556 | /** |
| 2557 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2558 | * @phba: pointer to lpfc hba data structure. |
| 2559 | * |
| 2560 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2561 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2562 | * lock held before proceeding with disabling the timer and clearing the |
| 2563 | * wait timer pendig flag. |
| 2564 | **/ |
| 2565 | void |
| 2566 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2567 | { |
| 2568 | spin_lock_irq(&phba->hbalock); |
| 2569 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2570 | /* FCF rediscovery timer already fired or stopped */ |
| 2571 | spin_unlock_irq(&phba->hbalock); |
| 2572 | return; |
| 2573 | } |
| 2574 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2575 | /* Clear failover in progress flags */ |
| 2576 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2577 | spin_unlock_irq(&phba->hbalock); |
| 2578 | } |
| 2579 | |
| 2580 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2581 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2582 | * @phba: pointer to lpfc hba data structure. |
| 2583 | * |
| 2584 | * This routine stops all the timers associated with a HBA. This function is |
| 2585 | * invoked before either putting a HBA offline or unloading the driver. |
| 2586 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2587 | void |
| 2588 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2590 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2591 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2592 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2593 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2594 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2595 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2596 | del_timer_sync(&phba->rrq_tmr); |
| 2597 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2598 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2599 | phba->hb_outstanding = 0; |
| 2600 | |
| 2601 | switch (phba->pci_dev_grp) { |
| 2602 | case LPFC_PCI_DEV_LP: |
| 2603 | /* Stop any LightPulse device specific driver timers */ |
| 2604 | del_timer_sync(&phba->fcp_poll_timer); |
| 2605 | break; |
| 2606 | case LPFC_PCI_DEV_OC: |
| 2607 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2608 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2609 | break; |
| 2610 | default: |
| 2611 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2612 | "0297 Invalid device group (x%x)\n", |
| 2613 | phba->pci_dev_grp); |
| 2614 | break; |
| 2615 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2616 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2617 | } |
| 2618 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2619 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2620 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2621 | * @phba: pointer to lpfc hba data structure. |
| 2622 | * |
| 2623 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2624 | * management interface is marked as blocked, all the user space access to |
| 2625 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2626 | * all be blocked. The HBA is set to block the management interface when the |
| 2627 | * driver prepares the HBA interface for online or offline. |
| 2628 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2629 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2630 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2631 | { |
| 2632 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2633 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2634 | unsigned long timeout; |
| 2635 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2636 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2637 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2639 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2640 | return; |
| 2641 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2642 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2643 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2644 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2645 | /* Determine how long we might wait for the active mailbox |
| 2646 | * command to be gracefully completed by firmware. |
| 2647 | */ |
| 2648 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2649 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2650 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2651 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2652 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2653 | /* Wait for the outstnading mailbox command to complete */ |
| 2654 | while (phba->sli.mbox_active) { |
| 2655 | /* Check active mailbox complete status every 2ms */ |
| 2656 | msleep(2); |
| 2657 | if (time_after(jiffies, timeout)) { |
| 2658 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2659 | "2813 Mgmt IO is Blocked %x " |
| 2660 | "- mbox cmd %x still active\n", |
| 2661 | phba->sli.sli_flag, actcmd); |
| 2662 | break; |
| 2663 | } |
| 2664 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2665 | } |
| 2666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2667 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2668 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2669 | * @phba: pointer to lpfc hba data structure. |
| 2670 | * |
| 2671 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2672 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2673 | * is to fixup the temporary rpi assignments. |
| 2674 | **/ |
| 2675 | void |
| 2676 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2677 | { |
| 2678 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2679 | struct lpfc_vport **vports; |
| 2680 | int i; |
| 2681 | |
| 2682 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2683 | return; |
| 2684 | |
| 2685 | vports = lpfc_create_vport_work_array(phba); |
| 2686 | if (vports != NULL) { |
| 2687 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2688 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2689 | continue; |
| 2690 | |
| 2691 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2692 | &vports[i]->fc_nodes, |
| 2693 | nlp_listp) { |
| 2694 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2695 | ndlp->nlp_rpi = |
| 2696 | lpfc_sli4_alloc_rpi(phba); |
| 2697 | } |
| 2698 | } |
| 2699 | } |
| 2700 | lpfc_destroy_vport_work_array(phba, vports); |
| 2701 | } |
| 2702 | |
| 2703 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2704 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2705 | * @phba: pointer to lpfc hba data structure. |
| 2706 | * |
| 2707 | * This routine initializes the HBA and brings a HBA online. During this |
| 2708 | * process, the management interface is blocked to prevent user space access |
| 2709 | * to the HBA interfering with the driver initialization. |
| 2710 | * |
| 2711 | * Return codes |
| 2712 | * 0 - successful |
| 2713 | * 1 - failed |
| 2714 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2716 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2718 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2719 | struct lpfc_vport **vports; |
| 2720 | int i; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2721 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2722 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | if (!phba) |
| 2724 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2725 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2727 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | return 0; |
| 2729 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2730 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2731 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2733 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2735 | if (!lpfc_sli_queue_setup(phba)) { |
| 2736 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2738 | } |
| 2739 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2740 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2741 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2742 | lpfc_unblock_mgmt_io(phba); |
| 2743 | return 1; |
| 2744 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2745 | spin_lock_irq(&phba->hbalock); |
| 2746 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 2747 | vpis_cleared = true; |
| 2748 | spin_unlock_irq(&phba->hbalock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2749 | } else { |
| 2750 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2751 | lpfc_unblock_mgmt_io(phba); |
| 2752 | return 1; |
| 2753 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2754 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2756 | vports = lpfc_create_vport_work_array(phba); |
| 2757 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2758 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2759 | struct Scsi_Host *shost; |
| 2760 | shost = lpfc_shost_from_vport(vports[i]); |
| 2761 | spin_lock_irq(shost->host_lock); |
| 2762 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2763 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2764 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2765 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2766 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2767 | if ((vpis_cleared) && |
| 2768 | (vports[i]->port_type != |
| 2769 | LPFC_PHYSICAL_PORT)) |
| 2770 | vports[i]->vpi = 0; |
| 2771 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2772 | spin_unlock_irq(shost->host_lock); |
| 2773 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2774 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2776 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2777 | return 0; |
| 2778 | } |
| 2779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2781 | * 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] | 2782 | * @phba: pointer to lpfc hba data structure. |
| 2783 | * |
| 2784 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2785 | * HBA's management interface is marked as not blocked, all the user space |
| 2786 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2787 | * interface will be allowed. The HBA is set to block the management interface |
| 2788 | * when the driver prepares the HBA interface for online or offline and then |
| 2789 | * set to unblock the management interface afterwards. |
| 2790 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2791 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2792 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2793 | { |
| 2794 | unsigned long iflag; |
| 2795 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2796 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2797 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2798 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2799 | } |
| 2800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2801 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2802 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2803 | * @phba: pointer to lpfc hba data structure. |
| 2804 | * |
| 2805 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2806 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2807 | * queue to make it ready to be brought offline. |
| 2808 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2809 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2810 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2811 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2812 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2813 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2814 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2815 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2816 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2818 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2819 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2821 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | |
| 2823 | lpfc_linkdown(phba); |
| 2824 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2825 | /* Issue an unreg_login to all nodes on all vports */ |
| 2826 | vports = lpfc_create_vport_work_array(phba); |
| 2827 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2828 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2829 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2830 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2831 | shost = lpfc_shost_from_vport(vports[i]); |
| 2832 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2833 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2834 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2835 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2836 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2837 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2838 | shost = lpfc_shost_from_vport(vports[i]); |
| 2839 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2840 | &vports[i]->fc_nodes, |
| 2841 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2842 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2843 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2844 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2845 | continue; |
| 2846 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2847 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2848 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2849 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2850 | NULL, NLP_EVT_DEVICE_RM); |
| 2851 | } |
| 2852 | spin_lock_irq(shost->host_lock); |
| 2853 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2854 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2855 | /* |
| 2856 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2857 | * RPI. Get a new RPI when the adapter port |
| 2858 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2859 | */ |
| 2860 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2861 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2862 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2863 | } |
| 2864 | } |
| 2865 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2866 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2868 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2869 | } |
| 2870 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2871 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2872 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2873 | * @phba: pointer to lpfc hba data structure. |
| 2874 | * |
| 2875 | * This routine actually brings a HBA offline. It stops all the timers |
| 2876 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2877 | * marks the HBA as in offline state for the upper layer protocol. |
| 2878 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2879 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2880 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2881 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2882 | struct Scsi_Host *shost; |
| 2883 | struct lpfc_vport **vports; |
| 2884 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2885 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2886 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2887 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2888 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2889 | /* stop port and all timers associated with this hba */ |
| 2890 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2891 | vports = lpfc_create_vport_work_array(phba); |
| 2892 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2893 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2894 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2895 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2896 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2897 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2899 | now. */ |
| 2900 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2901 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2902 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2903 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2904 | vports = lpfc_create_vport_work_array(phba); |
| 2905 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2906 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2907 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2908 | spin_lock_irq(shost->host_lock); |
| 2909 | vports[i]->work_port_events = 0; |
| 2910 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2911 | spin_unlock_irq(shost->host_lock); |
| 2912 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2913 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | } |
| 2915 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2916 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2917 | * 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] | 2918 | * @phba: pointer to lpfc hba data structure. |
| 2919 | * |
| 2920 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2921 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2922 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2923 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2924 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2926 | { |
| 2927 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2928 | struct lpfc_iocbq *io, *io_next; |
| 2929 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2930 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2933 | |
| 2934 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 2935 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 2936 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2937 | list_del(&sb->list); |
| 2938 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2939 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2940 | kfree(sb); |
| 2941 | phba->total_scsi_bufs--; |
| 2942 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2943 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 2944 | |
| 2945 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 2946 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 2947 | list) { |
| 2948 | list_del(&sb->list); |
| 2949 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
| 2950 | sb->dma_handle); |
| 2951 | kfree(sb); |
| 2952 | phba->total_scsi_bufs--; |
| 2953 | } |
| 2954 | spin_unlock(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | |
| 2956 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2957 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2958 | list_del(&io->list); |
| 2959 | kfree(io); |
| 2960 | phba->total_iocbq_bufs--; |
| 2961 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2962 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2963 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | /** |
| 2967 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 2968 | * @phba: pointer to lpfc hba data structure. |
| 2969 | * |
| 2970 | * This routine first calculates the sizes of the current els and allocated |
| 2971 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 2972 | * XRIs assigned due to port function reset. During port initialization, the |
| 2973 | * current els and allocated scsi sgl lists are 0s. |
| 2974 | * |
| 2975 | * Return codes |
| 2976 | * 0 - successful (for now, it always returns 0) |
| 2977 | **/ |
| 2978 | int |
| 2979 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 2980 | { |
| 2981 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 2982 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 2983 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 2984 | LIST_HEAD(els_sgl_list); |
| 2985 | LIST_HEAD(scsi_sgl_list); |
| 2986 | int rc; |
| 2987 | |
| 2988 | /* |
| 2989 | * update on pci function's els xri-sgl list |
| 2990 | */ |
| 2991 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 2992 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 2993 | /* els xri-sgl expanded */ |
| 2994 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 2995 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2996 | "3157 ELS xri-sgl count increased from " |
| 2997 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2998 | els_xri_cnt); |
| 2999 | /* allocate the additional els sgls */ |
| 3000 | for (i = 0; i < xri_cnt; i++) { |
| 3001 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3002 | GFP_KERNEL); |
| 3003 | if (sglq_entry == NULL) { |
| 3004 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3005 | "2562 Failure to allocate an " |
| 3006 | "ELS sgl entry:%d\n", i); |
| 3007 | rc = -ENOMEM; |
| 3008 | goto out_free_mem; |
| 3009 | } |
| 3010 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3011 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3012 | &sglq_entry->phys); |
| 3013 | if (sglq_entry->virt == NULL) { |
| 3014 | kfree(sglq_entry); |
| 3015 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3016 | "2563 Failure to allocate an " |
| 3017 | "ELS mbuf:%d\n", i); |
| 3018 | rc = -ENOMEM; |
| 3019 | goto out_free_mem; |
| 3020 | } |
| 3021 | sglq_entry->sgl = sglq_entry->virt; |
| 3022 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3023 | sglq_entry->state = SGL_FREED; |
| 3024 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3025 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3026 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3027 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3028 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3029 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3030 | /* els xri-sgl shrinked */ |
| 3031 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3032 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3033 | "3158 ELS xri-sgl count decreased from " |
| 3034 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3035 | els_xri_cnt); |
| 3036 | spin_lock_irq(&phba->hbalock); |
| 3037 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
| 3038 | spin_unlock_irq(&phba->hbalock); |
| 3039 | /* release extra els sgls from list */ |
| 3040 | for (i = 0; i < xri_cnt; i++) { |
| 3041 | list_remove_head(&els_sgl_list, |
| 3042 | sglq_entry, struct lpfc_sglq, list); |
| 3043 | if (sglq_entry) { |
| 3044 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3045 | sglq_entry->phys); |
| 3046 | kfree(sglq_entry); |
| 3047 | } |
| 3048 | } |
| 3049 | spin_lock_irq(&phba->hbalock); |
| 3050 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 3051 | spin_unlock_irq(&phba->hbalock); |
| 3052 | } else |
| 3053 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3054 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3055 | els_xri_cnt); |
| 3056 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3057 | |
| 3058 | /* update xris to els sgls on the list */ |
| 3059 | sglq_entry = NULL; |
| 3060 | sglq_entry_next = NULL; |
| 3061 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3062 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 3063 | lxri = lpfc_sli4_next_xritag(phba); |
| 3064 | if (lxri == NO_XRI) { |
| 3065 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3066 | "2400 Failed to allocate xri for " |
| 3067 | "ELS sgl\n"); |
| 3068 | rc = -ENOMEM; |
| 3069 | goto out_free_mem; |
| 3070 | } |
| 3071 | sglq_entry->sli4_lxritag = lxri; |
| 3072 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3073 | } |
| 3074 | |
| 3075 | /* |
| 3076 | * update on pci function's allocated scsi xri-sgl list |
| 3077 | */ |
| 3078 | phba->total_scsi_bufs = 0; |
| 3079 | |
| 3080 | /* maximum number of xris available for scsi buffers */ |
| 3081 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3082 | els_xri_cnt; |
| 3083 | |
| 3084 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3085 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 3086 | "maximum SCSI xri count:%d\n", |
| 3087 | phba->sli4_hba.scsi_xri_cnt, |
| 3088 | phba->sli4_hba.scsi_xri_max); |
| 3089 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3090 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3091 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3092 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3093 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3094 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3095 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3096 | |
| 3097 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3098 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3099 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3100 | phba->sli4_hba.scsi_xri_max; |
| 3101 | /* release the extra allocated scsi buffers */ |
| 3102 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3103 | list_remove_head(&scsi_sgl_list, psb, |
| 3104 | struct lpfc_scsi_buf, list); |
| 3105 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, |
| 3106 | psb->dma_handle); |
| 3107 | kfree(psb); |
| 3108 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3109 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3110 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3111 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | /* update xris associated to remaining allocated scsi buffers */ |
| 3115 | psb = NULL; |
| 3116 | psb_next = NULL; |
| 3117 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3118 | lxri = lpfc_sli4_next_xritag(phba); |
| 3119 | if (lxri == NO_XRI) { |
| 3120 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3121 | "2560 Failed to allocate xri for " |
| 3122 | "scsi buffer\n"); |
| 3123 | rc = -ENOMEM; |
| 3124 | goto out_free_mem; |
| 3125 | } |
| 3126 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3127 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3128 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3129 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3130 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3131 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3132 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3133 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3134 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3136 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3137 | |
| 3138 | out_free_mem: |
| 3139 | lpfc_free_els_sgl_list(phba); |
| 3140 | lpfc_scsi_free(phba); |
| 3141 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | } |
| 3143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3144 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3145 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3146 | * @phba: pointer to lpfc hba data structure. |
| 3147 | * @instance: a unique integer ID to this FC port. |
| 3148 | * @dev: pointer to the device data structure. |
| 3149 | * |
| 3150 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3151 | * can be created on top of either a physical port or a virtual port provided |
| 3152 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3153 | * and associates the FC port created before adding the shost into the SCSI |
| 3154 | * layer. |
| 3155 | * |
| 3156 | * Return codes |
| 3157 | * @vport - pointer to the virtual N_Port data structure. |
| 3158 | * NULL - port create failed. |
| 3159 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3161 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3162 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3163 | struct lpfc_vport *vport; |
| 3164 | struct Scsi_Host *shost; |
| 3165 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3166 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3167 | if (dev != &phba->pcidev->dev) |
| 3168 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3169 | sizeof(struct lpfc_vport)); |
| 3170 | else |
| 3171 | shost = scsi_host_alloc(&lpfc_template, |
| 3172 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3173 | if (!shost) |
| 3174 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3175 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3176 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3177 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3178 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3179 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3180 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3181 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3182 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3183 | shost->unique_id = instance; |
| 3184 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3185 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3186 | shost->this_id = -1; |
| 3187 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3188 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3189 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3190 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3191 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3192 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3193 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3194 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 | * Set initial can_queue value since 0 is no longer supported and |
| 3196 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3197 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3198 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3199 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3200 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3201 | shost->transportt = lpfc_vport_transport_template; |
| 3202 | vport->port_type = LPFC_NPIV_PORT; |
| 3203 | } else { |
| 3204 | shost->transportt = lpfc_transport_template; |
| 3205 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3206 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3207 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3208 | /* Initialize all internally managed lists. */ |
| 3209 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3210 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3211 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3212 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3213 | init_timer(&vport->fc_disctmo); |
| 3214 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3215 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3216 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3217 | init_timer(&vport->fc_fdmitmo); |
| 3218 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3219 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3220 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3221 | init_timer(&vport->els_tmofunc); |
| 3222 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3223 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3224 | |
| 3225 | init_timer(&vport->delayed_disc_tmo); |
| 3226 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3227 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3228 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3229 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | if (error) |
| 3231 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3232 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3233 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3234 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3235 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3236 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3237 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3238 | out_put_shost: |
| 3239 | scsi_host_put(shost); |
| 3240 | out: |
| 3241 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3242 | } |
| 3243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3244 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3245 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3246 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3247 | * |
| 3248 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3249 | * resources associated with the port are released. |
| 3250 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3251 | void |
| 3252 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3253 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3254 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3255 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3256 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3257 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3258 | fc_remove_host(shost); |
| 3259 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3260 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3261 | spin_lock_irq(&phba->hbalock); |
| 3262 | list_del_init(&vport->listentry); |
| 3263 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3264 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3265 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3266 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3267 | } |
| 3268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3270 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3271 | * |
| 3272 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3273 | * uses the kernel idr facility to perform the task. |
| 3274 | * |
| 3275 | * Return codes: |
| 3276 | * instance - a unique integer ID allocated as the new instance. |
| 3277 | * -1 - lpfc get instance failed. |
| 3278 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3279 | int |
| 3280 | lpfc_get_instance(void) |
| 3281 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3282 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3283 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3284 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 3285 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3286 | } |
| 3287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3289 | * 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] | 3290 | * @shost: pointer to SCSI host data structure. |
| 3291 | * @time: elapsed time of the scan in jiffies. |
| 3292 | * |
| 3293 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3294 | * whether the scan host is finished. |
| 3295 | * |
| 3296 | * Note: there is no scan_start function as adapter initialization will have |
| 3297 | * asynchronously kicked off the link initialization. |
| 3298 | * |
| 3299 | * Return codes |
| 3300 | * 0 - SCSI host scan is not over yet. |
| 3301 | * 1 - SCSI host scan is over. |
| 3302 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3303 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3304 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3305 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3306 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3307 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3308 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3309 | spin_lock_irq(shost->host_lock); |
| 3310 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3311 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3312 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3313 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3314 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3315 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3316 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3317 | "0461 Scanning longer than 30 " |
| 3318 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3319 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3320 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3321 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3322 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 3323 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3324 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3325 | "0465 Link down longer than 15 " |
| 3326 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3327 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3328 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3329 | } |
| 3330 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3331 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3332 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3333 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3334 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3335 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3336 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3337 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3338 | goto finished; |
| 3339 | |
| 3340 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3341 | |
| 3342 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3343 | spin_unlock_irq(shost->host_lock); |
| 3344 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3345 | } |
| 3346 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3348 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3349 | * @shost: pointer to SCSI host data structure. |
| 3350 | * |
| 3351 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3352 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3353 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3354 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3355 | { |
| 3356 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3357 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3358 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3359 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3360 | */ |
| 3361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3363 | 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] | 3364 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3365 | |
| 3366 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3368 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3369 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3370 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3371 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3372 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3373 | |
| 3374 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3375 | if (phba->lmt & LMT_16Gb) |
| 3376 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3377 | if (phba->lmt & LMT_10Gb) |
| 3378 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3379 | if (phba->lmt & LMT_8Gb) |
| 3380 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3381 | if (phba->lmt & LMT_4Gb) |
| 3382 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3383 | if (phba->lmt & LMT_2Gb) |
| 3384 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3385 | if (phba->lmt & LMT_1Gb) |
| 3386 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3387 | |
| 3388 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3390 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3391 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3392 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3393 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3394 | /* This value is also unchanging */ |
| 3395 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3396 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3397 | fc_host_active_fc4s(shost)[2] = 1; |
| 3398 | fc_host_active_fc4s(shost)[7] = 1; |
| 3399 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3400 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3401 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3402 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3403 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3404 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3406 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3407 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3408 | * @phba: pointer to lpfc hba data structure. |
| 3409 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3410 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3411 | * from generating interrupts and stops the device driver's timers for the |
| 3412 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3413 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3414 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3415 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3416 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3417 | /* Clear all interrupt enable conditions */ |
| 3418 | writel(0, phba->HCregaddr); |
| 3419 | readl(phba->HCregaddr); /* flush */ |
| 3420 | /* Clear all pending interrupts */ |
| 3421 | writel(0xffffffff, phba->HAregaddr); |
| 3422 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3423 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3424 | /* Reset some HBA SLI setup states */ |
| 3425 | lpfc_stop_hba_timers(phba); |
| 3426 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3427 | } |
| 3428 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3429 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3430 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3431 | * @phba: pointer to lpfc hba data structure. |
| 3432 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3433 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3434 | * from generating interrupts and stops the device driver's timers for the |
| 3435 | * device. |
| 3436 | **/ |
| 3437 | static void |
| 3438 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3439 | { |
| 3440 | /* Reset some HBA SLI4 setup states */ |
| 3441 | lpfc_stop_hba_timers(phba); |
| 3442 | phba->pport->work_port_events = 0; |
| 3443 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | /** |
| 3447 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3448 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3449 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3450 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3451 | * the API jump table function pointer from the lpfc_hba struct. |
| 3452 | **/ |
| 3453 | void |
| 3454 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3455 | { |
| 3456 | phba->lpfc_stop_port(phba); |
| 3457 | } |
| 3458 | |
| 3459 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3460 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3461 | * @phba: Pointer to hba for which this call is being executed. |
| 3462 | * |
| 3463 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3464 | **/ |
| 3465 | void |
| 3466 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3467 | { |
| 3468 | unsigned long fcf_redisc_wait_tmo = |
| 3469 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3470 | /* Start fcf rediscovery wait period timer */ |
| 3471 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3472 | spin_lock_irq(&phba->hbalock); |
| 3473 | /* Allow action to new fcf asynchronous event */ |
| 3474 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3475 | /* Mark the FCF rediscovery pending state */ |
| 3476 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3477 | spin_unlock_irq(&phba->hbalock); |
| 3478 | } |
| 3479 | |
| 3480 | /** |
| 3481 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3482 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3483 | * |
| 3484 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3485 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3486 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3487 | * list, and then worker thread shall be waked up for processing from the |
| 3488 | * worker thread context. |
| 3489 | **/ |
| 3490 | void |
| 3491 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3492 | { |
| 3493 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3494 | |
| 3495 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3496 | spin_lock_irq(&phba->hbalock); |
| 3497 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3498 | spin_unlock_irq(&phba->hbalock); |
| 3499 | return; |
| 3500 | } |
| 3501 | /* Clear FCF rediscovery timer pending flag */ |
| 3502 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3503 | /* FCF rediscovery event to worker thread */ |
| 3504 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3505 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3506 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3507 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3508 | /* wake up worker thread */ |
| 3509 | lpfc_worker_wake_up(phba); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3513 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3514 | * @phba: pointer to lpfc hba data structure. |
| 3515 | * @acqe_link: pointer to the async link completion queue entry. |
| 3516 | * |
| 3517 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3518 | * translate it into the base driver's read link attention mailbox command |
| 3519 | * status. |
| 3520 | * |
| 3521 | * Return: Link-attention status in terms of base driver's coding. |
| 3522 | **/ |
| 3523 | static uint16_t |
| 3524 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3525 | struct lpfc_acqe_link *acqe_link) |
| 3526 | { |
| 3527 | uint16_t latt_fault; |
| 3528 | |
| 3529 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3530 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3531 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3532 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3533 | latt_fault = 0; |
| 3534 | break; |
| 3535 | default: |
| 3536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3537 | "0398 Invalid link fault code: x%x\n", |
| 3538 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3539 | latt_fault = MBXERR_ERROR; |
| 3540 | break; |
| 3541 | } |
| 3542 | return latt_fault; |
| 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3547 | * @phba: pointer to lpfc hba data structure. |
| 3548 | * @acqe_link: pointer to the async link completion queue entry. |
| 3549 | * |
| 3550 | * This routine is to parse the SLI4 link attention type and translate it |
| 3551 | * into the base driver's link attention type coding. |
| 3552 | * |
| 3553 | * Return: Link attention type in terms of base driver's coding. |
| 3554 | **/ |
| 3555 | static uint8_t |
| 3556 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3557 | struct lpfc_acqe_link *acqe_link) |
| 3558 | { |
| 3559 | uint8_t att_type; |
| 3560 | |
| 3561 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3562 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3563 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3564 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3565 | break; |
| 3566 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3567 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3568 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3569 | break; |
| 3570 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3571 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3572 | break; |
| 3573 | default: |
| 3574 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3575 | "0399 Invalid link attention type: x%x\n", |
| 3576 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3577 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3578 | break; |
| 3579 | } |
| 3580 | return att_type; |
| 3581 | } |
| 3582 | |
| 3583 | /** |
| 3584 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3585 | * @phba: pointer to lpfc hba data structure. |
| 3586 | * @acqe_link: pointer to the async link completion queue entry. |
| 3587 | * |
| 3588 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3589 | * it into the base driver's link-attention link speed coding. |
| 3590 | * |
| 3591 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3592 | **/ |
| 3593 | static uint8_t |
| 3594 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3595 | struct lpfc_acqe_link *acqe_link) |
| 3596 | { |
| 3597 | uint8_t link_speed; |
| 3598 | |
| 3599 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3600 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3601 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3602 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3603 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3604 | break; |
| 3605 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3606 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3607 | break; |
| 3608 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3609 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3610 | break; |
| 3611 | default: |
| 3612 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3613 | "0483 Invalid link-attention link speed: x%x\n", |
| 3614 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3615 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3616 | break; |
| 3617 | } |
| 3618 | return link_speed; |
| 3619 | } |
| 3620 | |
| 3621 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3622 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 3623 | * @phba: pointer to lpfc hba data structure. |
| 3624 | * |
| 3625 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 3626 | * |
| 3627 | * Return: link speed in terms of Mbps. |
| 3628 | **/ |
| 3629 | uint32_t |
| 3630 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 3631 | { |
| 3632 | uint32_t link_speed; |
| 3633 | |
| 3634 | if (!lpfc_is_link_up(phba)) |
| 3635 | return 0; |
| 3636 | |
| 3637 | switch (phba->fc_linkspeed) { |
| 3638 | case LPFC_LINK_SPEED_1GHZ: |
| 3639 | link_speed = 1000; |
| 3640 | break; |
| 3641 | case LPFC_LINK_SPEED_2GHZ: |
| 3642 | link_speed = 2000; |
| 3643 | break; |
| 3644 | case LPFC_LINK_SPEED_4GHZ: |
| 3645 | link_speed = 4000; |
| 3646 | break; |
| 3647 | case LPFC_LINK_SPEED_8GHZ: |
| 3648 | link_speed = 8000; |
| 3649 | break; |
| 3650 | case LPFC_LINK_SPEED_10GHZ: |
| 3651 | link_speed = 10000; |
| 3652 | break; |
| 3653 | case LPFC_LINK_SPEED_16GHZ: |
| 3654 | link_speed = 16000; |
| 3655 | break; |
| 3656 | default: |
| 3657 | link_speed = 0; |
| 3658 | } |
| 3659 | return link_speed; |
| 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 3664 | * @phba: pointer to lpfc hba data structure. |
| 3665 | * @evt_code: asynchronous event code. |
| 3666 | * @speed_code: asynchronous event link speed code. |
| 3667 | * |
| 3668 | * This routine is to parse the giving SLI4 async event link speed code into |
| 3669 | * value of Mbps for the link speed. |
| 3670 | * |
| 3671 | * Return: link speed in terms of Mbps. |
| 3672 | **/ |
| 3673 | static uint32_t |
| 3674 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 3675 | uint8_t speed_code) |
| 3676 | { |
| 3677 | uint32_t port_speed; |
| 3678 | |
| 3679 | switch (evt_code) { |
| 3680 | case LPFC_TRAILER_CODE_LINK: |
| 3681 | switch (speed_code) { |
| 3682 | case LPFC_EVT_CODE_LINK_NO_LINK: |
| 3683 | port_speed = 0; |
| 3684 | break; |
| 3685 | case LPFC_EVT_CODE_LINK_10_MBIT: |
| 3686 | port_speed = 10; |
| 3687 | break; |
| 3688 | case LPFC_EVT_CODE_LINK_100_MBIT: |
| 3689 | port_speed = 100; |
| 3690 | break; |
| 3691 | case LPFC_EVT_CODE_LINK_1_GBIT: |
| 3692 | port_speed = 1000; |
| 3693 | break; |
| 3694 | case LPFC_EVT_CODE_LINK_10_GBIT: |
| 3695 | port_speed = 10000; |
| 3696 | break; |
| 3697 | default: |
| 3698 | port_speed = 0; |
| 3699 | } |
| 3700 | break; |
| 3701 | case LPFC_TRAILER_CODE_FC: |
| 3702 | switch (speed_code) { |
| 3703 | case LPFC_EVT_CODE_FC_NO_LINK: |
| 3704 | port_speed = 0; |
| 3705 | break; |
| 3706 | case LPFC_EVT_CODE_FC_1_GBAUD: |
| 3707 | port_speed = 1000; |
| 3708 | break; |
| 3709 | case LPFC_EVT_CODE_FC_2_GBAUD: |
| 3710 | port_speed = 2000; |
| 3711 | break; |
| 3712 | case LPFC_EVT_CODE_FC_4_GBAUD: |
| 3713 | port_speed = 4000; |
| 3714 | break; |
| 3715 | case LPFC_EVT_CODE_FC_8_GBAUD: |
| 3716 | port_speed = 8000; |
| 3717 | break; |
| 3718 | case LPFC_EVT_CODE_FC_10_GBAUD: |
| 3719 | port_speed = 10000; |
| 3720 | break; |
| 3721 | case LPFC_EVT_CODE_FC_16_GBAUD: |
| 3722 | port_speed = 16000; |
| 3723 | break; |
| 3724 | default: |
| 3725 | port_speed = 0; |
| 3726 | } |
| 3727 | break; |
| 3728 | default: |
| 3729 | port_speed = 0; |
| 3730 | } |
| 3731 | return port_speed; |
| 3732 | } |
| 3733 | |
| 3734 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3735 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3736 | * @phba: pointer to lpfc hba data structure. |
| 3737 | * @acqe_link: pointer to the async link completion queue entry. |
| 3738 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3739 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3740 | **/ |
| 3741 | static void |
| 3742 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3743 | struct lpfc_acqe_link *acqe_link) |
| 3744 | { |
| 3745 | struct lpfc_dmabuf *mp; |
| 3746 | LPFC_MBOXQ_t *pmb; |
| 3747 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3748 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3749 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3750 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3751 | |
| 3752 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3753 | 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] | 3754 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3755 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3756 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3757 | if (!pmb) { |
| 3758 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3759 | "0395 The mboxq allocation failed\n"); |
| 3760 | return; |
| 3761 | } |
| 3762 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3763 | if (!mp) { |
| 3764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3765 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3766 | goto out_free_pmb; |
| 3767 | } |
| 3768 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3769 | if (!mp->virt) { |
| 3770 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3771 | "0397 The mbuf allocation failed\n"); |
| 3772 | goto out_free_dmabuf; |
| 3773 | } |
| 3774 | |
| 3775 | /* Cleanup any outstanding ELS commands */ |
| 3776 | lpfc_els_flush_all_cmd(phba); |
| 3777 | |
| 3778 | /* Block ELS IOCBs until we have done process link event */ |
| 3779 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3780 | |
| 3781 | /* Update link event statistics */ |
| 3782 | phba->sli.slistat.link_event++; |
| 3783 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3784 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3785 | lpfc_read_topology(phba, pmb, mp); |
| 3786 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3787 | pmb->vport = phba->pport; |
| 3788 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3789 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3790 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3791 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 3792 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3793 | phba->sli4_hba.link_state.duplex = |
| 3794 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3795 | phba->sli4_hba.link_state.status = |
| 3796 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3797 | phba->sli4_hba.link_state.type = |
| 3798 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3799 | phba->sli4_hba.link_state.number = |
| 3800 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3801 | phba->sli4_hba.link_state.fault = |
| 3802 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3803 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3804 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 3805 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3806 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3807 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3808 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3809 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3810 | phba->sli4_hba.link_state.speed, |
| 3811 | phba->sli4_hba.link_state.topology, |
| 3812 | phba->sli4_hba.link_state.status, |
| 3813 | phba->sli4_hba.link_state.type, |
| 3814 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3815 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3816 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3817 | /* |
| 3818 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3819 | * topology info. Note: Optional for non FC-AL ports. |
| 3820 | */ |
| 3821 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3822 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3823 | if (rc == MBX_NOT_FINISHED) |
| 3824 | goto out_free_dmabuf; |
| 3825 | return; |
| 3826 | } |
| 3827 | /* |
| 3828 | * For FCoE Mode: fill in all the topology information we need and call |
| 3829 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3830 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3831 | */ |
| 3832 | /* Parse and translate status field */ |
| 3833 | mb = &pmb->u.mb; |
| 3834 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3835 | |
| 3836 | /* Parse and translate link attention fields */ |
| 3837 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3838 | la->eventTag = acqe_link->event_tag; |
| 3839 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3840 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3841 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3842 | |
| 3843 | /* Fake the the following irrelvant fields */ |
| 3844 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3845 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3846 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3847 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3848 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3849 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3850 | |
| 3851 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3852 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3853 | |
| 3854 | return; |
| 3855 | |
| 3856 | out_free_dmabuf: |
| 3857 | kfree(mp); |
| 3858 | out_free_pmb: |
| 3859 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3860 | } |
| 3861 | |
| 3862 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3863 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3864 | * @phba: pointer to lpfc hba data structure. |
| 3865 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3866 | * |
| 3867 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3868 | * that the event was received and then issue a read_topology mailbox command so |
| 3869 | * that the rest of the driver will treat it the same as SLI3. |
| 3870 | **/ |
| 3871 | static void |
| 3872 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3873 | { |
| 3874 | struct lpfc_dmabuf *mp; |
| 3875 | LPFC_MBOXQ_t *pmb; |
| 3876 | int rc; |
| 3877 | |
| 3878 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3879 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3880 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3881 | "2895 Non FC link Event detected.(%d)\n", |
| 3882 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3883 | return; |
| 3884 | } |
| 3885 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3886 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3887 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 3888 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3889 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3890 | phba->sli4_hba.link_state.topology = |
| 3891 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3892 | phba->sli4_hba.link_state.status = |
| 3893 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3894 | phba->sli4_hba.link_state.type = |
| 3895 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3896 | phba->sli4_hba.link_state.number = |
| 3897 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3898 | phba->sli4_hba.link_state.fault = |
| 3899 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3900 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3901 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3902 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3903 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3904 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3905 | "%dMbps Fault:%d\n", |
| 3906 | phba->sli4_hba.link_state.speed, |
| 3907 | phba->sli4_hba.link_state.topology, |
| 3908 | phba->sli4_hba.link_state.status, |
| 3909 | phba->sli4_hba.link_state.type, |
| 3910 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3911 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3912 | phba->sli4_hba.link_state.fault); |
| 3913 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3914 | if (!pmb) { |
| 3915 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3916 | "2897 The mboxq allocation failed\n"); |
| 3917 | return; |
| 3918 | } |
| 3919 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3920 | if (!mp) { |
| 3921 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3922 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3923 | goto out_free_pmb; |
| 3924 | } |
| 3925 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3926 | if (!mp->virt) { |
| 3927 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3928 | "2899 The mbuf allocation failed\n"); |
| 3929 | goto out_free_dmabuf; |
| 3930 | } |
| 3931 | |
| 3932 | /* Cleanup any outstanding ELS commands */ |
| 3933 | lpfc_els_flush_all_cmd(phba); |
| 3934 | |
| 3935 | /* Block ELS IOCBs until we have done process link event */ |
| 3936 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3937 | |
| 3938 | /* Update link event statistics */ |
| 3939 | phba->sli.slistat.link_event++; |
| 3940 | |
| 3941 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3942 | lpfc_read_topology(phba, pmb, mp); |
| 3943 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3944 | pmb->vport = phba->pport; |
| 3945 | |
| 3946 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3947 | if (rc == MBX_NOT_FINISHED) |
| 3948 | goto out_free_dmabuf; |
| 3949 | return; |
| 3950 | |
| 3951 | out_free_dmabuf: |
| 3952 | kfree(mp); |
| 3953 | out_free_pmb: |
| 3954 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3955 | } |
| 3956 | |
| 3957 | /** |
| 3958 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3959 | * @phba: pointer to lpfc hba data structure. |
| 3960 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3961 | * |
| 3962 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3963 | **/ |
| 3964 | static void |
| 3965 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3966 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3967 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 3968 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3969 | uint8_t status; |
| 3970 | struct lpfc_acqe_misconfigured_event *misconfigured; |
| 3971 | |
| 3972 | /* special case misconfigured event as it contains data for all ports */ |
| 3973 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3974 | LPFC_SLI_INTF_IF_TYPE_2) || |
| 3975 | (bf_get(lpfc_trailer_type, acqe_sli) != |
| 3976 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { |
| 3977 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3978 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3979 | "x%08x SLI Event Type:%d\n", |
| 3980 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3981 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3982 | return; |
| 3983 | } |
| 3984 | |
| 3985 | port_name = phba->Port[0]; |
| 3986 | if (port_name == 0x00) |
| 3987 | port_name = '?'; /* get port name is empty */ |
| 3988 | |
| 3989 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
| 3990 | &acqe_sli->event_data1; |
| 3991 | |
| 3992 | /* fetch the status for this port */ |
| 3993 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 3994 | case LPFC_LINK_NUMBER_0: |
| 3995 | status = bf_get(lpfc_sli_misconfigured_port0, |
| 3996 | &misconfigured->theEvent); |
| 3997 | break; |
| 3998 | case LPFC_LINK_NUMBER_1: |
| 3999 | status = bf_get(lpfc_sli_misconfigured_port1, |
| 4000 | &misconfigured->theEvent); |
| 4001 | break; |
| 4002 | case LPFC_LINK_NUMBER_2: |
| 4003 | status = bf_get(lpfc_sli_misconfigured_port2, |
| 4004 | &misconfigured->theEvent); |
| 4005 | break; |
| 4006 | case LPFC_LINK_NUMBER_3: |
| 4007 | status = bf_get(lpfc_sli_misconfigured_port3, |
| 4008 | &misconfigured->theEvent); |
| 4009 | break; |
| 4010 | default: |
| 4011 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 4012 | break; |
| 4013 | } |
| 4014 | |
| 4015 | switch (status) { |
| 4016 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 4017 | return; /* no message if the sfp is okay */ |
| 4018 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4019 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
| 4020 | "installed - Reseat optics, if issue not " |
| 4021 | "resolved, replace."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4022 | break; |
| 4023 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 4024 | sprintf(message, |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4025 | "Optics of two types installed - Remove one optic or " \ |
| 4026 | "install matching pair of optics."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4027 | break; |
| 4028 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4029 | sprintf(message, "Incompatible optics - Replace with " \ |
| 4030 | "compatible optics for card to function."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4031 | break; |
| 4032 | default: |
| 4033 | /* firmware is reporting a status we don't know about */ |
| 4034 | sprintf(message, "Unknown event status x%02x", status); |
| 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4039 | "3176 Misconfigured Physical Port - " |
| 4040 | "Port Name %c %s\n", port_name, message); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4044 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 4045 | * @vport: pointer to vport data structure. |
| 4046 | * |
| 4047 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 4048 | * response to a CVL event. |
| 4049 | * |
| 4050 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 4051 | * return NULL. |
| 4052 | **/ |
| 4053 | static struct lpfc_nodelist * |
| 4054 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 4055 | { |
| 4056 | struct lpfc_nodelist *ndlp; |
| 4057 | struct Scsi_Host *shost; |
| 4058 | struct lpfc_hba *phba; |
| 4059 | |
| 4060 | if (!vport) |
| 4061 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4062 | phba = vport->phba; |
| 4063 | if (!phba) |
| 4064 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4065 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4066 | if (!ndlp) { |
| 4067 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 4068 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4069 | if (!ndlp) |
| 4070 | return 0; |
| 4071 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 4072 | /* Set the node type */ |
| 4073 | ndlp->nlp_type |= NLP_FABRIC; |
| 4074 | /* Put ndlp onto node list */ |
| 4075 | lpfc_enqueue_node(vport, ndlp); |
| 4076 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4077 | /* re-setup ndlp without removing from node list */ |
| 4078 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4079 | if (!ndlp) |
| 4080 | return 0; |
| 4081 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4082 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4083 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4084 | return NULL; |
| 4085 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4086 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4087 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4088 | return NULL; |
| 4089 | shost = lpfc_shost_from_vport(vport); |
| 4090 | if (!shost) |
| 4091 | return NULL; |
| 4092 | lpfc_linkdown_port(vport); |
| 4093 | lpfc_cleanup_pending_mbox(vport); |
| 4094 | spin_lock_irq(shost->host_lock); |
| 4095 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4096 | spin_unlock_irq(shost->host_lock); |
| 4097 | |
| 4098 | return ndlp; |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4103 | * @vport: pointer to lpfc hba data structure. |
| 4104 | * |
| 4105 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4106 | * response to a FCF dead event. |
| 4107 | **/ |
| 4108 | static void |
| 4109 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4110 | { |
| 4111 | struct lpfc_vport **vports; |
| 4112 | int i; |
| 4113 | |
| 4114 | vports = lpfc_create_vport_work_array(phba); |
| 4115 | if (vports) |
| 4116 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4117 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4118 | lpfc_destroy_vport_work_array(phba, vports); |
| 4119 | } |
| 4120 | |
| 4121 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4122 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4123 | * @phba: pointer to lpfc hba data structure. |
| 4124 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4125 | * |
| 4126 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4127 | **/ |
| 4128 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4129 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4130 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4131 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4132 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4133 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4134 | struct lpfc_vport *vport; |
| 4135 | struct lpfc_nodelist *ndlp; |
| 4136 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4137 | int active_vlink_present; |
| 4138 | struct lpfc_vport **vports; |
| 4139 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4140 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4141 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4142 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4143 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4144 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4145 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4146 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4147 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4148 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4149 | "2546 New FCF event, evt_tag:x%x, " |
| 4150 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4151 | acqe_fip->event_tag, |
| 4152 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4153 | else |
| 4154 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4155 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4156 | "2788 FCF param modified event, " |
| 4157 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4158 | acqe_fip->event_tag, |
| 4159 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4160 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4161 | /* |
| 4162 | * During period of FCF discovery, read the FCF |
| 4163 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4164 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4165 | */ |
| 4166 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4167 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4168 | "2779 Read FCF (x%x) for updating " |
| 4169 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4170 | acqe_fip->index); |
| 4171 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4172 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4173 | |
| 4174 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4175 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4176 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4177 | spin_unlock_irq(&phba->hbalock); |
| 4178 | break; |
| 4179 | } |
| 4180 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 4181 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 4182 | spin_unlock_irq(&phba->hbalock); |
| 4183 | break; |
| 4184 | } |
| 4185 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4186 | /* If the FCF has been in discovered state, do nothing. */ |
| 4187 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4188 | spin_unlock_irq(&phba->hbalock); |
| 4189 | break; |
| 4190 | } |
| 4191 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4192 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4193 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 4194 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4195 | "2770 Start FCF table scan per async FCF " |
| 4196 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4197 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4198 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 4199 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4200 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4201 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4202 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4203 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4204 | break; |
| 4205 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4206 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4207 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4208 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4209 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 4210 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4211 | break; |
| 4212 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4213 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4214 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4215 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4216 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4217 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4218 | /* |
| 4219 | * If we are in the middle of FCF failover process, clear |
| 4220 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4221 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4222 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4223 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4224 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4225 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4226 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4227 | break; |
| 4228 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4229 | spin_unlock_irq(&phba->hbalock); |
| 4230 | |
| 4231 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4232 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4233 | break; |
| 4234 | |
| 4235 | /* |
| 4236 | * Otherwise, request the port to rediscover the entire FCF |
| 4237 | * table for a fast recovery from case that the current FCF |
| 4238 | * is no longer valid as we are not in the middle of FCF |
| 4239 | * failover process already. |
| 4240 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4241 | spin_lock_irq(&phba->hbalock); |
| 4242 | /* Mark the fast failover process in progress */ |
| 4243 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 4244 | spin_unlock_irq(&phba->hbalock); |
| 4245 | |
| 4246 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4247 | "2771 Start FCF fast failover process due to " |
| 4248 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 4249 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 4250 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4251 | if (rc) { |
| 4252 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4253 | LOG_DISCOVERY, |
| 4254 | "2772 Issue FCF rediscover mabilbox " |
| 4255 | "command failed, fail through to FCF " |
| 4256 | "dead event\n"); |
| 4257 | spin_lock_irq(&phba->hbalock); |
| 4258 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 4259 | spin_unlock_irq(&phba->hbalock); |
| 4260 | /* |
| 4261 | * Last resort will fail over by treating this |
| 4262 | * as a link down to FCF registration. |
| 4263 | */ |
| 4264 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 4265 | } else { |
| 4266 | /* Reset FCF roundrobin bmask for new discovery */ |
| 4267 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 4268 | /* |
| 4269 | * Handling fast FCF failover to a DEAD FCF event is |
| 4270 | * considered equalivant to receiving CVL to all vports. |
| 4271 | */ |
| 4272 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 4273 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4274 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4275 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4276 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4277 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4278 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4279 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4280 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4281 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4282 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4283 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4284 | if (!ndlp) |
| 4285 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4286 | active_vlink_present = 0; |
| 4287 | |
| 4288 | vports = lpfc_create_vport_work_array(phba); |
| 4289 | if (vports) { |
| 4290 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4291 | i++) { |
| 4292 | if ((!(vports[i]->fc_flag & |
| 4293 | FC_VPORT_CVL_RCVD)) && |
| 4294 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4295 | active_vlink_present = 1; |
| 4296 | break; |
| 4297 | } |
| 4298 | } |
| 4299 | lpfc_destroy_vport_work_array(phba, vports); |
| 4300 | } |
| 4301 | |
| 4302 | if (active_vlink_present) { |
| 4303 | /* |
| 4304 | * If there are other active VLinks present, |
| 4305 | * re-instantiate the Vlink using FDISC. |
| 4306 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4307 | mod_timer(&ndlp->nlp_delayfunc, |
| 4308 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4309 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4310 | spin_lock_irq(shost->host_lock); |
| 4311 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4312 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4313 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4314 | vport->port_state = LPFC_FDISC; |
| 4315 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4316 | /* |
| 4317 | * Otherwise, we request port to rediscover |
| 4318 | * the entire FCF table for a fast recovery |
| 4319 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4320 | * is no longer valid if we are not already |
| 4321 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4322 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4323 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4324 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4325 | spin_unlock_irq(&phba->hbalock); |
| 4326 | break; |
| 4327 | } |
| 4328 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4329 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4330 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4331 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4332 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4333 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4334 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4335 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4336 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4337 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4338 | LOG_DISCOVERY, |
| 4339 | "2774 Issue FCF rediscover " |
| 4340 | "mabilbox command failed, " |
| 4341 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4342 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4343 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4344 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4345 | /* |
| 4346 | * Last resort will be re-try on the |
| 4347 | * the current registered FCF entry. |
| 4348 | */ |
| 4349 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4350 | } else |
| 4351 | /* |
| 4352 | * Reset FCF roundrobin bmask for new |
| 4353 | * discovery. |
| 4354 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4355 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4356 | } |
| 4357 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4358 | default: |
| 4359 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4360 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4361 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4362 | break; |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | /** |
| 4367 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4368 | * @phba: pointer to lpfc hba data structure. |
| 4369 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4370 | * |
| 4371 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4372 | **/ |
| 4373 | static void |
| 4374 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4375 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4376 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4377 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4378 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4379 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4380 | "handled yet\n"); |
| 4381 | } |
| 4382 | |
| 4383 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4384 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4385 | * @phba: pointer to lpfc hba data structure. |
| 4386 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4387 | * |
| 4388 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4389 | * is an asynchronous notified of a logical link speed change. The Port |
| 4390 | * reports the logical link speed in units of 10Mbps. |
| 4391 | **/ |
| 4392 | static void |
| 4393 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4394 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4395 | { |
| 4396 | uint16_t prev_ll_spd; |
| 4397 | |
| 4398 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4399 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4400 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4401 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4402 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4403 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4404 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4405 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 4406 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4410 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4411 | * @phba: pointer to lpfc hba data structure. |
| 4412 | * |
| 4413 | * This routine is invoked by the worker thread to process all the pending |
| 4414 | * SLI4 asynchronous events. |
| 4415 | **/ |
| 4416 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4417 | { |
| 4418 | struct lpfc_cq_event *cq_event; |
| 4419 | |
| 4420 | /* First, declare the async event has been handled */ |
| 4421 | spin_lock_irq(&phba->hbalock); |
| 4422 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4423 | spin_unlock_irq(&phba->hbalock); |
| 4424 | /* Now, handle all the async events */ |
| 4425 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4426 | /* Get the first event from the head of the event queue */ |
| 4427 | spin_lock_irq(&phba->hbalock); |
| 4428 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4429 | cq_event, struct lpfc_cq_event, list); |
| 4430 | spin_unlock_irq(&phba->hbalock); |
| 4431 | /* Process the asynchronous event */ |
| 4432 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4433 | case LPFC_TRAILER_CODE_LINK: |
| 4434 | lpfc_sli4_async_link_evt(phba, |
| 4435 | &cq_event->cqe.acqe_link); |
| 4436 | break; |
| 4437 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4438 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4439 | break; |
| 4440 | case LPFC_TRAILER_CODE_DCBX: |
| 4441 | lpfc_sli4_async_dcbx_evt(phba, |
| 4442 | &cq_event->cqe.acqe_dcbx); |
| 4443 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4444 | case LPFC_TRAILER_CODE_GRP5: |
| 4445 | lpfc_sli4_async_grp5_evt(phba, |
| 4446 | &cq_event->cqe.acqe_grp5); |
| 4447 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4448 | case LPFC_TRAILER_CODE_FC: |
| 4449 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4450 | break; |
| 4451 | case LPFC_TRAILER_CODE_SLI: |
| 4452 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4453 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4454 | default: |
| 4455 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4456 | "1804 Invalid asynchrous event code: " |
| 4457 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4458 | &cq_event->cqe.mcqe_cmpl)); |
| 4459 | break; |
| 4460 | } |
| 4461 | /* Free the completion event processed to the free pool */ |
| 4462 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4467 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4468 | * @phba: pointer to lpfc hba data structure. |
| 4469 | * |
| 4470 | * This routine is invoked by the worker thread to process FCF table |
| 4471 | * rediscovery pending completion event. |
| 4472 | **/ |
| 4473 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4474 | { |
| 4475 | int rc; |
| 4476 | |
| 4477 | spin_lock_irq(&phba->hbalock); |
| 4478 | /* Clear FCF rediscovery timeout event */ |
| 4479 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4480 | /* Clear driver fast failover FCF record flag */ |
| 4481 | phba->fcf.failover_rec.flag = 0; |
| 4482 | /* Set state for FCF fast failover */ |
| 4483 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4484 | spin_unlock_irq(&phba->hbalock); |
| 4485 | |
| 4486 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4487 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4488 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4489 | 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] | 4490 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4491 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4492 | "2747 Issue FCF scan read FCF mailbox " |
| 4493 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4497 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4498 | * @phba: pointer to lpfc hba data structure. |
| 4499 | * @dev_grp: The HBA PCI-Device group number. |
| 4500 | * |
| 4501 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4502 | * API jump table entries. |
| 4503 | * |
| 4504 | * Return: 0 if success, otherwise -ENODEV |
| 4505 | **/ |
| 4506 | int |
| 4507 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4508 | { |
| 4509 | int rc; |
| 4510 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4511 | /* Set up lpfc PCI-device group */ |
| 4512 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4513 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4514 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4515 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4516 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4517 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4518 | /* Set up device INIT API function jump table */ |
| 4519 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4520 | if (rc) |
| 4521 | return -ENODEV; |
| 4522 | /* Set up SCSI API function jump table */ |
| 4523 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4524 | if (rc) |
| 4525 | return -ENODEV; |
| 4526 | /* Set up SLI API function jump table */ |
| 4527 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4528 | if (rc) |
| 4529 | return -ENODEV; |
| 4530 | /* Set up MBOX API function jump table */ |
| 4531 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4532 | if (rc) |
| 4533 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4534 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4535 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4539 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4540 | * @phba: pointer to lpfc hba data structure. |
| 4541 | * @intr_mode: active interrupt mode adopted. |
| 4542 | * |
| 4543 | * This routine it invoked to log the currently used active interrupt mode |
| 4544 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4545 | **/ |
| 4546 | 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] | 4547 | { |
| 4548 | switch (intr_mode) { |
| 4549 | case 0: |
| 4550 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4551 | "0470 Enable INTx interrupt mode.\n"); |
| 4552 | break; |
| 4553 | case 1: |
| 4554 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4555 | "0481 Enabled MSI interrupt mode.\n"); |
| 4556 | break; |
| 4557 | case 2: |
| 4558 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4559 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4560 | break; |
| 4561 | default: |
| 4562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4563 | "0482 Illegal interrupt mode.\n"); |
| 4564 | break; |
| 4565 | } |
| 4566 | return; |
| 4567 | } |
| 4568 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4569 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4570 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4571 | * @phba: pointer to lpfc hba data structure. |
| 4572 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4573 | * This routine is invoked to enable the PCI device that is common to all |
| 4574 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4575 | * |
| 4576 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4577 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4578 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4579 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4580 | static int |
| 4581 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4582 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4583 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4584 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4585 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4586 | /* Obtain PCI device reference */ |
| 4587 | if (!phba->pcidev) |
| 4588 | goto out_error; |
| 4589 | else |
| 4590 | pdev = phba->pcidev; |
| 4591 | /* Select PCI BARs */ |
| 4592 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4593 | /* Enable PCI device */ |
| 4594 | if (pci_enable_device_mem(pdev)) |
| 4595 | goto out_error; |
| 4596 | /* Request PCI resource for the device */ |
| 4597 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4598 | goto out_disable_device; |
| 4599 | /* Set up device as PCI master and save state for EEH */ |
| 4600 | pci_set_master(pdev); |
| 4601 | pci_try_set_mwi(pdev); |
| 4602 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4603 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4604 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 4605 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4606 | pdev->needs_freset = 1; |
| 4607 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4608 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4609 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4610 | out_disable_device: |
| 4611 | pci_disable_device(pdev); |
| 4612 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4614 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4615 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4619 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4620 | * @phba: pointer to lpfc hba data structure. |
| 4621 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4622 | * This routine is invoked to disable the PCI device that is common to all |
| 4623 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4624 | **/ |
| 4625 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4626 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4627 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4628 | struct pci_dev *pdev; |
| 4629 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4630 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4631 | /* Obtain PCI device reference */ |
| 4632 | if (!phba->pcidev) |
| 4633 | return; |
| 4634 | else |
| 4635 | pdev = phba->pcidev; |
| 4636 | /* Select PCI BARs */ |
| 4637 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4638 | /* Release PCI resource and disable PCI device */ |
| 4639 | pci_release_selected_regions(pdev, bars); |
| 4640 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4641 | |
| 4642 | return; |
| 4643 | } |
| 4644 | |
| 4645 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4646 | * lpfc_reset_hba - Reset a hba |
| 4647 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4648 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4649 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4650 | * offline, performs a board restart, and then brings the board back |
| 4651 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4652 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4653 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4654 | void |
| 4655 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4656 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4657 | /* If resets are disabled then set error state and return. */ |
| 4658 | if (!phba->cfg_enable_hba_reset) { |
| 4659 | phba->link_state = LPFC_HBA_ERROR; |
| 4660 | return; |
| 4661 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 4662 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 4663 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 4664 | else |
| 4665 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4666 | lpfc_offline(phba); |
| 4667 | lpfc_sli_brdrestart(phba); |
| 4668 | lpfc_online(phba); |
| 4669 | lpfc_unblock_mgmt_io(phba); |
| 4670 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4671 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4672 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4673 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4674 | * @phba: pointer to lpfc hba data structure. |
| 4675 | * |
| 4676 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4677 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4678 | * enable the number of virtual functions to the physical function. As |
| 4679 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4680 | * API call does not considered as an error condition for most of the device. |
| 4681 | **/ |
| 4682 | uint16_t |
| 4683 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4684 | { |
| 4685 | struct pci_dev *pdev = phba->pcidev; |
| 4686 | uint16_t nr_virtfn; |
| 4687 | int pos; |
| 4688 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4689 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4690 | if (pos == 0) |
| 4691 | return 0; |
| 4692 | |
| 4693 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4694 | return nr_virtfn; |
| 4695 | } |
| 4696 | |
| 4697 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4698 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4699 | * @phba: pointer to lpfc hba data structure. |
| 4700 | * @nr_vfn: number of virtual functions to be enabled. |
| 4701 | * |
| 4702 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4703 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4704 | * enable the number of virtual functions to the physical function. As |
| 4705 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4706 | * API call does not considered as an error condition for most of the device. |
| 4707 | **/ |
| 4708 | int |
| 4709 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4710 | { |
| 4711 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4712 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4713 | int rc; |
| 4714 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4715 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4716 | if (nr_vfn > max_nr_vfn) { |
| 4717 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4718 | "3057 Requested vfs (%d) greater than " |
| 4719 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4720 | return -EINVAL; |
| 4721 | } |
| 4722 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4723 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4724 | if (rc) { |
| 4725 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4726 | "2806 Failed to enable sriov on this device " |
| 4727 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4728 | nr_vfn, rc); |
| 4729 | } else |
| 4730 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4731 | "2807 Successful enable sriov on this device " |
| 4732 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4733 | return rc; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4737 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4738 | * @phba: pointer to lpfc hba data structure. |
| 4739 | * |
| 4740 | * This routine is invoked to set up the driver internal resources specific to |
| 4741 | * support the SLI-3 HBA device it attached to. |
| 4742 | * |
| 4743 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4744 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4745 | * other values - error |
| 4746 | **/ |
| 4747 | static int |
| 4748 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4749 | { |
| 4750 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4751 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4753 | /* |
| 4754 | * Initialize timers used by driver |
| 4755 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4757 | /* Heartbeat timer */ |
| 4758 | init_timer(&phba->hb_tmofunc); |
| 4759 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4760 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4761 | |
| 4762 | psli = &phba->sli; |
| 4763 | /* MBOX heartbeat timer */ |
| 4764 | init_timer(&psli->mbox_tmo); |
| 4765 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4766 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4767 | /* FCP polling mode timer */ |
| 4768 | init_timer(&phba->fcp_poll_timer); |
| 4769 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4770 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4771 | /* Fabric block timer */ |
| 4772 | init_timer(&phba->fabric_block_timer); |
| 4773 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4774 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4775 | /* EA polling mode timer */ |
| 4776 | init_timer(&phba->eratt_poll); |
| 4777 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4778 | phba->eratt_poll.data = (unsigned long) phba; |
| 4779 | |
| 4780 | /* Host attention work mask setup */ |
| 4781 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4782 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4783 | |
| 4784 | /* Get all the module params for configuring this host */ |
| 4785 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4786 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4787 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4788 | /* check for menlo minimum sg count */ |
| 4789 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4790 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4791 | } |
| 4792 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4793 | if (!phba->sli.ring) |
| 4794 | phba->sli.ring = (struct lpfc_sli_ring *) |
| 4795 | kzalloc(LPFC_SLI3_MAX_RING * |
| 4796 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4797 | if (!phba->sli.ring) |
| 4798 | return -ENOMEM; |
| 4799 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4800 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4801 | * 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] | 4802 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4803 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4804 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4805 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4806 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4807 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4808 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4809 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 4810 | if (phba->cfg_enable_bg) { |
| 4811 | /* |
| 4812 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 4813 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 4814 | * over how many protection data segments the SCSI Layer |
| 4815 | * will hand us (ie: there could be one for every block |
| 4816 | * in the IO), we just allocate enough BDEs to accomidate |
| 4817 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 4818 | * minimize the risk of running out. |
| 4819 | */ |
| 4820 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4821 | sizeof(struct fcp_rsp) + |
| 4822 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 4823 | |
| 4824 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 4825 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 4826 | |
| 4827 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 4828 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4829 | } else { |
| 4830 | /* |
| 4831 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 4832 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 4833 | * cfg_sg_seg_cnt data segments. |
| 4834 | */ |
| 4835 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4836 | sizeof(struct fcp_rsp) + |
| 4837 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4838 | |
| 4839 | /* Total BDEs in BPL for scsi_sg_list */ |
| 4840 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 4841 | } |
| 4842 | |
| 4843 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4844 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 4845 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 4846 | phba->cfg_total_seg_cnt); |
| 4847 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4848 | phba->max_vpi = LPFC_MAX_VPI; |
| 4849 | /* This will be set to correct value after config_port mbox */ |
| 4850 | phba->max_vports = 0; |
| 4851 | |
| 4852 | /* |
| 4853 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4854 | */ |
| 4855 | lpfc_sli_setup(phba); |
| 4856 | lpfc_sli_queue_setup(phba); |
| 4857 | |
| 4858 | /* Allocate device driver memory */ |
| 4859 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4860 | return -ENOMEM; |
| 4861 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4862 | /* |
| 4863 | * Enable sr-iov virtual functions if supported and configured |
| 4864 | * through the module parameter. |
| 4865 | */ |
| 4866 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4867 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4868 | phba->cfg_sriov_nr_virtfn); |
| 4869 | if (rc) { |
| 4870 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4871 | "2808 Requested number of SR-IOV " |
| 4872 | "virtual functions (%d) is not " |
| 4873 | "supported\n", |
| 4874 | phba->cfg_sriov_nr_virtfn); |
| 4875 | phba->cfg_sriov_nr_virtfn = 0; |
| 4876 | } |
| 4877 | } |
| 4878 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4879 | return 0; |
| 4880 | } |
| 4881 | |
| 4882 | /** |
| 4883 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4884 | * @phba: pointer to lpfc hba data structure. |
| 4885 | * |
| 4886 | * This routine is invoked to unset the driver internal resources set up |
| 4887 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4888 | **/ |
| 4889 | static void |
| 4890 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4891 | { |
| 4892 | /* Free device driver memory allocated */ |
| 4893 | lpfc_mem_free_all(phba); |
| 4894 | |
| 4895 | return; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4899 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4900 | * @phba: pointer to lpfc hba data structure. |
| 4901 | * |
| 4902 | * This routine is invoked to set up the driver internal resources specific to |
| 4903 | * support the SLI-4 HBA device it attached to. |
| 4904 | * |
| 4905 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4906 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4907 | * other values - error |
| 4908 | **/ |
| 4909 | static int |
| 4910 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4911 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 4912 | struct lpfc_vector_map_info *cpup; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4913 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4914 | LPFC_MBOXQ_t *mboxq; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4915 | int rc, i, hbq_count, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4916 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4917 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4918 | int longs; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 4919 | int fof_vectors = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4920 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 4921 | /* Get all the module params for configuring this host */ |
| 4922 | lpfc_get_cfgparam(phba); |
| 4923 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4924 | /* Before proceed, wait for POST done and device ready */ |
| 4925 | rc = lpfc_sli4_post_status_check(phba); |
| 4926 | if (rc) |
| 4927 | return -ENODEV; |
| 4928 | |
| 4929 | /* |
| 4930 | * Initialize timers used by driver |
| 4931 | */ |
| 4932 | |
| 4933 | /* Heartbeat timer */ |
| 4934 | init_timer(&phba->hb_tmofunc); |
| 4935 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4936 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4937 | init_timer(&phba->rrq_tmr); |
| 4938 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4939 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4940 | |
| 4941 | psli = &phba->sli; |
| 4942 | /* MBOX heartbeat timer */ |
| 4943 | init_timer(&psli->mbox_tmo); |
| 4944 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4945 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4946 | /* Fabric block timer */ |
| 4947 | init_timer(&phba->fabric_block_timer); |
| 4948 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4949 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4950 | /* EA polling mode timer */ |
| 4951 | init_timer(&phba->eratt_poll); |
| 4952 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4953 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4954 | /* FCF rediscover timer */ |
| 4955 | init_timer(&phba->fcf.redisc_wait); |
| 4956 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4957 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4958 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4959 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4960 | * Control structure for handling external multi-buffer mailbox |
| 4961 | * command pass-through. |
| 4962 | */ |
| 4963 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4964 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4965 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4966 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4967 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4968 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4969 | /* This will be set to correct value after the read_config mbox */ |
| 4970 | phba->max_vports = 0; |
| 4971 | |
| 4972 | /* Program the default value of vlan_id and fc_map */ |
| 4973 | phba->valid_vlan = 0; |
| 4974 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4975 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4976 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4977 | |
| 4978 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4979 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 4980 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 4981 | */ |
| 4982 | if (!phba->sli.ring) |
| 4983 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4984 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4985 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4986 | if (!phba->sli.ring) |
| 4987 | return -ENOMEM; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4988 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4989 | /* |
| 4990 | * It doesn't matter what family our adapter is in, we are |
| 4991 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 4992 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 4993 | */ |
| 4994 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 4995 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) |
| 4996 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4997 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4998 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4999 | * 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] | 5000 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5001 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5002 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5003 | if (phba->cfg_enable_bg) { |
| 5004 | /* |
| 5005 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5006 | * the FCP rsp, and a SGE for each. Sice we have no control |
| 5007 | * over how many protection data segments the SCSI Layer |
| 5008 | * will hand us (ie: there could be one for every block |
| 5009 | * in the IO), we just allocate enough SGEs to accomidate |
| 5010 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5011 | * minimize the risk of running out. |
| 5012 | */ |
| 5013 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5014 | sizeof(struct fcp_rsp) + max_buf_size; |
| 5015 | |
| 5016 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 5017 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 5018 | |
| 5019 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
| 5020 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
| 5021 | } else { |
| 5022 | /* |
| 5023 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5024 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 5025 | * cfg_sg_seg_cnt data segments. |
| 5026 | */ |
| 5027 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5028 | sizeof(struct fcp_rsp) + |
| 5029 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); |
| 5030 | |
| 5031 | /* Total SGEs for scsi_sg_list */ |
| 5032 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5033 | /* |
| 5034 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need |
| 5035 | * to post 1 page for the SGL. |
| 5036 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5037 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5038 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5039 | /* Initialize the host templates with the updated values. */ |
| 5040 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5041 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5042 | |
| 5043 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5044 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5045 | else |
| 5046 | phba->cfg_sg_dma_buf_size = |
| 5047 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5048 | |
| 5049 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5050 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5051 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5052 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5053 | |
| 5054 | /* Initialize buffer queue management fields */ |
| 5055 | hbq_count = lpfc_sli_hbq_count(); |
| 5056 | for (i = 0; i < hbq_count; ++i) |
| 5057 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5058 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5059 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5060 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5061 | |
| 5062 | /* |
| 5063 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5064 | */ |
| 5065 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5066 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5067 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5068 | /* This abort list used by worker thread */ |
| 5069 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 5070 | |
| 5071 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5072 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | */ |
| 5074 | |
| 5075 | /* Driver internel slow-path CQ Event pool */ |
| 5076 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5077 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5078 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5079 | /* Asynchronous event CQ Event work queue list */ |
| 5080 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5081 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5082 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5083 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5084 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5085 | /* Receive queue CQ Event work queue list */ |
| 5086 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5087 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5088 | /* Initialize extent block lists. */ |
| 5089 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 5090 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 5091 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 5092 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 5093 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5094 | /* Initialize the driver internal SLI layer lists. */ |
| 5095 | lpfc_sli_setup(phba); |
| 5096 | lpfc_sli_queue_setup(phba); |
| 5097 | |
| 5098 | /* Allocate device driver memory */ |
| 5099 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 5100 | if (rc) |
| 5101 | return -ENOMEM; |
| 5102 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5103 | /* IF Type 2 ports get initialized now. */ |
| 5104 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5105 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 5106 | rc = lpfc_pci_function_reset(phba); |
| 5107 | if (unlikely(rc)) |
| 5108 | return -ENODEV; |
| 5109 | } |
| 5110 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5111 | /* Create the bootstrap mailbox command */ |
| 5112 | rc = lpfc_create_bootstrap_mbox(phba); |
| 5113 | if (unlikely(rc)) |
| 5114 | goto out_free_mem; |
| 5115 | |
| 5116 | /* Set up the host's endian order with the device. */ |
| 5117 | rc = lpfc_setup_endian_order(phba); |
| 5118 | if (unlikely(rc)) |
| 5119 | goto out_free_bsmbx; |
| 5120 | |
| 5121 | /* Set up the hba's configuration parameters. */ |
| 5122 | rc = lpfc_sli4_read_config(phba); |
| 5123 | if (unlikely(rc)) |
| 5124 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 5125 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 5126 | if (unlikely(rc)) |
| 5127 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5128 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5129 | /* IF Type 0 ports get initialized now. */ |
| 5130 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5131 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 5132 | rc = lpfc_pci_function_reset(phba); |
| 5133 | if (unlikely(rc)) |
| 5134 | goto out_free_bsmbx; |
| 5135 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5136 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5137 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 5138 | GFP_KERNEL); |
| 5139 | if (!mboxq) { |
| 5140 | rc = -ENOMEM; |
| 5141 | goto out_free_bsmbx; |
| 5142 | } |
| 5143 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5144 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5145 | lpfc_supported_pages(mboxq); |
| 5146 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5147 | if (!rc) { |
| 5148 | mqe = &mboxq->u.mqe; |
| 5149 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 5150 | LPFC_MAX_SUPPORTED_PAGES); |
| 5151 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 5152 | switch (pn_page[i]) { |
| 5153 | case LPFC_SLI4_PARAMETERS: |
| 5154 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 5155 | break; |
| 5156 | default: |
| 5157 | break; |
| 5158 | } |
| 5159 | } |
| 5160 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 5161 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 5162 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 5163 | if (rc) { |
| 5164 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5165 | rc = -EIO; |
| 5166 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5167 | } |
| 5168 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5169 | /* |
| 5170 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5171 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 5172 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5173 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5174 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 5175 | if (rc) { |
| 5176 | if (phba->sli4_hba.extents_in_use && |
| 5177 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 5178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5179 | "2999 Unsupported SLI4 Parameters " |
| 5180 | "Extents and RPI headers enabled.\n"); |
| 5181 | goto out_free_bsmbx; |
| 5182 | } |
| 5183 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5184 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5185 | |
| 5186 | /* Verify OAS is supported */ |
| 5187 | lpfc_sli4_oas_verify(phba); |
| 5188 | if (phba->cfg_fof) |
| 5189 | fof_vectors = 1; |
| 5190 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5191 | /* Verify all the SLI4 queues */ |
| 5192 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5193 | if (rc) |
| 5194 | goto out_free_bsmbx; |
| 5195 | |
| 5196 | /* Create driver internal CQE event pool */ |
| 5197 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 5198 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5199 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5200 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5201 | /* Initialize sgl lists per host */ |
| 5202 | lpfc_init_sgl_list(phba); |
| 5203 | |
| 5204 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5205 | rc = lpfc_init_active_sgl_array(phba); |
| 5206 | if (rc) { |
| 5207 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5208 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5209 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5210 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5211 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 5212 | if (rc) { |
| 5213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5214 | "1432 Failed to initialize rpi headers.\n"); |
| 5215 | goto out_free_active_sgl; |
| 5216 | } |
| 5217 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5218 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5219 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 5220 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 5221 | GFP_KERNEL); |
| 5222 | if (!phba->fcf.fcf_rr_bmask) { |
| 5223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5224 | "2759 Failed allocate memory for FCF round " |
| 5225 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5226 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5227 | goto out_remove_rpi_hdrs; |
| 5228 | } |
| 5229 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5230 | phba->sli4_hba.fcp_eq_hdl = |
| 5231 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5232 | (fof_vectors + phba->cfg_fcp_io_channel)), |
| 5233 | GFP_KERNEL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5234 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 5235 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5236 | "2572 Failed allocate memory for " |
| 5237 | "fast-path per-EQ handle array\n"); |
| 5238 | rc = -ENOMEM; |
| 5239 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5243 | (fof_vectors + |
| 5244 | phba->cfg_fcp_io_channel)), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5245 | if (!phba->sli4_hba.msix_entries) { |
| 5246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5247 | "2573 Failed allocate memory for msi-x " |
| 5248 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5249 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5250 | goto out_free_fcp_eq_hdl; |
| 5251 | } |
| 5252 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5253 | phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) * |
| 5254 | phba->sli4_hba.num_present_cpu), |
| 5255 | GFP_KERNEL); |
| 5256 | if (!phba->sli4_hba.cpu_map) { |
| 5257 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5258 | "3327 Failed allocate memory for msi-x " |
| 5259 | "interrupt vector mapping\n"); |
| 5260 | rc = -ENOMEM; |
| 5261 | goto out_free_msix; |
| 5262 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 5263 | if (lpfc_used_cpu == NULL) { |
| 5264 | lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu), |
| 5265 | GFP_KERNEL); |
| 5266 | if (!lpfc_used_cpu) { |
| 5267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5268 | "3335 Failed allocate memory for msi-x " |
| 5269 | "interrupt vector mapping\n"); |
| 5270 | kfree(phba->sli4_hba.cpu_map); |
| 5271 | rc = -ENOMEM; |
| 5272 | goto out_free_msix; |
| 5273 | } |
| 5274 | for (i = 0; i < lpfc_present_cpu; i++) |
| 5275 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 5276 | } |
| 5277 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5278 | /* Initialize io channels for round robin */ |
| 5279 | cpup = phba->sli4_hba.cpu_map; |
| 5280 | rc = 0; |
| 5281 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 5282 | cpup->channel_id = rc; |
| 5283 | rc++; |
| 5284 | if (rc >= phba->cfg_fcp_io_channel) |
| 5285 | rc = 0; |
| 5286 | } |
| 5287 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5288 | /* |
| 5289 | * Enable sr-iov virtual functions if supported and configured |
| 5290 | * through the module parameter. |
| 5291 | */ |
| 5292 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5293 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5294 | phba->cfg_sriov_nr_virtfn); |
| 5295 | if (rc) { |
| 5296 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5297 | "3020 Requested number of SR-IOV " |
| 5298 | "virtual functions (%d) is not " |
| 5299 | "supported\n", |
| 5300 | phba->cfg_sriov_nr_virtfn); |
| 5301 | phba->cfg_sriov_nr_virtfn = 0; |
| 5302 | } |
| 5303 | } |
| 5304 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5305 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5306 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5307 | out_free_msix: |
| 5308 | kfree(phba->sli4_hba.msix_entries); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5309 | out_free_fcp_eq_hdl: |
| 5310 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5311 | out_free_fcf_rr_bmask: |
| 5312 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5313 | out_remove_rpi_hdrs: |
| 5314 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 5315 | out_free_active_sgl: |
| 5316 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5317 | out_destroy_cq_event_pool: |
| 5318 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5319 | out_free_bsmbx: |
| 5320 | lpfc_destroy_bootstrap_mbox(phba); |
| 5321 | out_free_mem: |
| 5322 | lpfc_mem_free(phba); |
| 5323 | return rc; |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5328 | * @phba: pointer to lpfc hba data structure. |
| 5329 | * |
| 5330 | * This routine is invoked to unset the driver internal resources set up |
| 5331 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5332 | **/ |
| 5333 | static void |
| 5334 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5335 | { |
| 5336 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5337 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5338 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 5339 | kfree(phba->sli4_hba.cpu_map); |
| 5340 | phba->sli4_hba.num_present_cpu = 0; |
| 5341 | phba->sli4_hba.num_online_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 5342 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5343 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5344 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5345 | kfree(phba->sli4_hba.msix_entries); |
| 5346 | |
| 5347 | /* Free memory allocated for fast-path work queue handles */ |
| 5348 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5349 | |
| 5350 | /* Free the allocated rpi headers. */ |
| 5351 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5352 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5353 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5354 | /* Free eligible FCF index bmask */ |
| 5355 | kfree(phba->fcf.fcf_rr_bmask); |
| 5356 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5357 | /* Free the ELS sgl list */ |
| 5358 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5359 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5360 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5361 | /* Free the completion queue EQ event pool */ |
| 5362 | lpfc_sli4_cq_event_release_all(phba); |
| 5363 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5364 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5365 | /* Release resource identifiers. */ |
| 5366 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5367 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5368 | /* Free the bsmbx region. */ |
| 5369 | lpfc_destroy_bootstrap_mbox(phba); |
| 5370 | |
| 5371 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5372 | lpfc_mem_free_all(phba); |
| 5373 | |
| 5374 | /* Free the current connect table */ |
| 5375 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5376 | &phba->fcf_conn_rec_list, list) { |
| 5377 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5378 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5379 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5380 | |
| 5381 | return; |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5385 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5386 | * @phba: The hba struct for which this call is being executed. |
| 5387 | * @dev_grp: The HBA PCI-Device group number. |
| 5388 | * |
| 5389 | * This routine sets up the device INIT interface API function jump table |
| 5390 | * in @phba struct. |
| 5391 | * |
| 5392 | * Returns: 0 - success, -ENODEV - failure. |
| 5393 | **/ |
| 5394 | int |
| 5395 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5396 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5397 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5398 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5399 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5400 | switch (dev_grp) { |
| 5401 | case LPFC_PCI_DEV_LP: |
| 5402 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5403 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5404 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5405 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5406 | case LPFC_PCI_DEV_OC: |
| 5407 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5408 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5409 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5410 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5411 | default: |
| 5412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5413 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5414 | dev_grp); |
| 5415 | return -ENODEV; |
| 5416 | break; |
| 5417 | } |
| 5418 | return 0; |
| 5419 | } |
| 5420 | |
| 5421 | /** |
| 5422 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5423 | * @phba: pointer to lpfc hba data structure. |
| 5424 | * |
| 5425 | * This routine is invoked to set up the driver internal resources before the |
| 5426 | * device specific resource setup to support the HBA device it attached to. |
| 5427 | * |
| 5428 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5429 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5430 | * other values - error |
| 5431 | **/ |
| 5432 | static int |
| 5433 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5434 | { |
| 5435 | /* |
| 5436 | * Driver resources common to all SLI revisions |
| 5437 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5438 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5439 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5440 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5441 | /* Initialize ndlp management spinlock */ |
| 5442 | spin_lock_init(&phba->ndlp_lock); |
| 5443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5444 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5445 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5446 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5447 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5448 | /* Initialize the wait queue head for the kernel thread */ |
| 5449 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5450 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5451 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 5452 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5453 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5454 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5455 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5457 | /* Initialize the fabric iocb list */ |
| 5458 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5459 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5460 | /* Initialize list to save ELS buffers */ |
| 5461 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5462 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5463 | /* Initialize FCF connection rec list */ |
| 5464 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5466 | /* Initialize OAS configuration list */ |
| 5467 | spin_lock_init(&phba->devicelock); |
| 5468 | INIT_LIST_HEAD(&phba->luns); |
| 5469 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5470 | return 0; |
| 5471 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5472 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5473 | /** |
| 5474 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5475 | * @phba: pointer to lpfc hba data structure. |
| 5476 | * |
| 5477 | * This routine is invoked to set up the driver internal resources after the |
| 5478 | * device specific resource setup to support the HBA device it attached to. |
| 5479 | * |
| 5480 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5481 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5482 | * other values - error |
| 5483 | **/ |
| 5484 | static int |
| 5485 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5486 | { |
| 5487 | int error; |
| 5488 | |
| 5489 | /* Startup the kernel thread for this host adapter. */ |
| 5490 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5491 | "lpfc_worker_%d", phba->brd_no); |
| 5492 | if (IS_ERR(phba->worker_thread)) { |
| 5493 | error = PTR_ERR(phba->worker_thread); |
| 5494 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5495 | } |
| 5496 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5497 | return 0; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
| 5501 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5502 | * @phba: pointer to lpfc hba data structure. |
| 5503 | * |
| 5504 | * This routine is invoked to unset the driver internal resources set up after |
| 5505 | * the device specific resource setup for supporting the HBA device it |
| 5506 | * attached to. |
| 5507 | **/ |
| 5508 | static void |
| 5509 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5510 | { |
| 5511 | /* Stop kernel worker thread */ |
| 5512 | kthread_stop(phba->worker_thread); |
| 5513 | } |
| 5514 | |
| 5515 | /** |
| 5516 | * lpfc_free_iocb_list - Free iocb list. |
| 5517 | * @phba: pointer to lpfc hba data structure. |
| 5518 | * |
| 5519 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5520 | **/ |
| 5521 | static void |
| 5522 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5523 | { |
| 5524 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5525 | |
| 5526 | spin_lock_irq(&phba->hbalock); |
| 5527 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5528 | &phba->lpfc_iocb_list, list) { |
| 5529 | list_del(&iocbq_entry->list); |
| 5530 | kfree(iocbq_entry); |
| 5531 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5532 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5533 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5535 | return; |
| 5536 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5537 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5538 | /** |
| 5539 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5540 | * @phba: pointer to lpfc hba data structure. |
| 5541 | * |
| 5542 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5543 | * list and set up the IOCB tag array accordingly. |
| 5544 | * |
| 5545 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5546 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5547 | * other values - error |
| 5548 | **/ |
| 5549 | static int |
| 5550 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5551 | { |
| 5552 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5553 | uint16_t iotag; |
| 5554 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5555 | |
| 5556 | /* Initialize and populate the iocb list per host. */ |
| 5557 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5558 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5559 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5560 | if (iocbq_entry == NULL) { |
| 5561 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5562 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5563 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5564 | goto out_free_iocbq; |
| 5565 | } |
| 5566 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5567 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5568 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5569 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5570 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5571 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5572 | goto out_free_iocbq; |
| 5573 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5574 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5575 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5576 | |
| 5577 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5578 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5579 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5580 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5581 | } |
| 5582 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5583 | return 0; |
| 5584 | |
| 5585 | out_free_iocbq: |
| 5586 | lpfc_free_iocb_list(phba); |
| 5587 | |
| 5588 | return -ENOMEM; |
| 5589 | } |
| 5590 | |
| 5591 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5592 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5593 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5594 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5595 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5596 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5597 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5598 | void |
| 5599 | 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] | 5600 | { |
| 5601 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5602 | |
| 5603 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5604 | list_del(&sglq_entry->list); |
| 5605 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5606 | kfree(sglq_entry); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /** |
| 5611 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5612 | * @phba: pointer to lpfc hba data structure. |
| 5613 | * |
| 5614 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5615 | **/ |
| 5616 | static void |
| 5617 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5618 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5619 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5620 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5621 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5622 | spin_lock_irq(&phba->hbalock); |
| 5623 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5624 | spin_unlock_irq(&phba->hbalock); |
| 5625 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5626 | /* Now free the sgl list */ |
| 5627 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | /** |
| 5631 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5632 | * @phba: pointer to lpfc hba data structure. |
| 5633 | * |
| 5634 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5635 | * This array will hold the sglq_entry's for active IOs. |
| 5636 | **/ |
| 5637 | static int |
| 5638 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5639 | { |
| 5640 | int size; |
| 5641 | size = sizeof(struct lpfc_sglq *); |
| 5642 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5643 | |
| 5644 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5645 | kzalloc(size, GFP_KERNEL); |
| 5646 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5647 | return -ENOMEM; |
| 5648 | return 0; |
| 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5653 | * @phba: pointer to lpfc hba data structure. |
| 5654 | * |
| 5655 | * This routine is invoked to walk through the array of active sglq entries |
| 5656 | * and free all of the resources. |
| 5657 | * This is just a place holder for now. |
| 5658 | **/ |
| 5659 | static void |
| 5660 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5661 | { |
| 5662 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5663 | } |
| 5664 | |
| 5665 | /** |
| 5666 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5667 | * @phba: pointer to lpfc hba data structure. |
| 5668 | * |
| 5669 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5670 | * list and set up the sgl xritag tag array accordingly. |
| 5671 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5672 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5673 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5674 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5675 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5676 | /* Initialize and populate the sglq list per host/VF. */ |
| 5677 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5678 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5679 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5680 | /* els xri-sgl book keeping */ |
| 5681 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5682 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5683 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5684 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | /** |
| 5688 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5689 | * @phba: pointer to lpfc hba data structure. |
| 5690 | * |
| 5691 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5692 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5693 | * 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] | 5694 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5695 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5696 | * |
| 5697 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5698 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5699 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5700 | **/ |
| 5701 | int |
| 5702 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5703 | { |
| 5704 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5705 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5706 | |
| 5707 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5708 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5709 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5710 | if (phba->sli4_hba.extents_in_use) |
| 5711 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5712 | |
| 5713 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5714 | if (!rpi_hdr) { |
| 5715 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5716 | "0391 Error during rpi post operation\n"); |
| 5717 | lpfc_sli4_remove_rpis(phba); |
| 5718 | rc = -ENODEV; |
| 5719 | } |
| 5720 | |
| 5721 | return rc; |
| 5722 | } |
| 5723 | |
| 5724 | /** |
| 5725 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5726 | * @phba: pointer to lpfc hba data structure. |
| 5727 | * |
| 5728 | * This routine is invoked to allocate a single 4KB memory region to |
| 5729 | * support rpis and stores them in the phba. This single region |
| 5730 | * provides support for up to 64 rpis. The region is used globally |
| 5731 | * by the device. |
| 5732 | * |
| 5733 | * Returns: |
| 5734 | * A valid rpi hdr on success. |
| 5735 | * A NULL pointer on any failure. |
| 5736 | **/ |
| 5737 | struct lpfc_rpi_hdr * |
| 5738 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5739 | { |
| 5740 | uint16_t rpi_limit, curr_rpi_range; |
| 5741 | struct lpfc_dmabuf *dmabuf; |
| 5742 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5743 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5744 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5745 | /* |
| 5746 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5747 | * required. Set the expected maximum count and let the actual value |
| 5748 | * get set when extents are fully allocated. |
| 5749 | */ |
| 5750 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5751 | return NULL; |
| 5752 | if (phba->sli4_hba.extents_in_use) |
| 5753 | return NULL; |
| 5754 | |
| 5755 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5756 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5757 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5758 | |
| 5759 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5760 | /* |
| 5761 | * Establish the starting RPI in this header block. The starting |
| 5762 | * rpi is normalized to a zero base because the physical rpi is |
| 5763 | * port based. |
| 5764 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5765 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5766 | spin_unlock_irq(&phba->hbalock); |
| 5767 | |
| 5768 | /* |
| 5769 | * The port has a limited number of rpis. The increment here |
| 5770 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5771 | * and to allow the full max_rpi range per port. |
| 5772 | */ |
| 5773 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5774 | rpi_count = rpi_limit - curr_rpi_range; |
| 5775 | else |
| 5776 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5777 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5778 | if (!rpi_count) |
| 5779 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5780 | /* |
| 5781 | * First allocate the protocol header region for the port. The |
| 5782 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5783 | */ |
| 5784 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5785 | if (!dmabuf) |
| 5786 | return NULL; |
| 5787 | |
| 5788 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5789 | LPFC_HDR_TEMPLATE_SIZE, |
| 5790 | &dmabuf->phys, |
| 5791 | GFP_KERNEL); |
| 5792 | if (!dmabuf->virt) { |
| 5793 | rpi_hdr = NULL; |
| 5794 | goto err_free_dmabuf; |
| 5795 | } |
| 5796 | |
| 5797 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5798 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5799 | rpi_hdr = NULL; |
| 5800 | goto err_free_coherent; |
| 5801 | } |
| 5802 | |
| 5803 | /* Save the rpi header data for cleanup later. */ |
| 5804 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5805 | if (!rpi_hdr) |
| 5806 | goto err_free_coherent; |
| 5807 | |
| 5808 | rpi_hdr->dmabuf = dmabuf; |
| 5809 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5810 | rpi_hdr->page_count = 1; |
| 5811 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5812 | |
| 5813 | /* The rpi_hdr stores the logical index only. */ |
| 5814 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5815 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5816 | |
| 5817 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5818 | * The next_rpi stores the next logical module-64 rpi value used |
| 5819 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5820 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5821 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5822 | spin_unlock_irq(&phba->hbalock); |
| 5823 | return rpi_hdr; |
| 5824 | |
| 5825 | err_free_coherent: |
| 5826 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5827 | dmabuf->virt, dmabuf->phys); |
| 5828 | err_free_dmabuf: |
| 5829 | kfree(dmabuf); |
| 5830 | return NULL; |
| 5831 | } |
| 5832 | |
| 5833 | /** |
| 5834 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5835 | * @phba: pointer to lpfc hba data structure. |
| 5836 | * |
| 5837 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5838 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5839 | * presumes the caller has released all rpis consumed by fabric or port |
| 5840 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5841 | **/ |
| 5842 | void |
| 5843 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5844 | { |
| 5845 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5846 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5847 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5848 | goto exit; |
| 5849 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5850 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5851 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5852 | list_del(&rpi_hdr->list); |
| 5853 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5854 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5855 | kfree(rpi_hdr->dmabuf); |
| 5856 | kfree(rpi_hdr); |
| 5857 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5858 | exit: |
| 5859 | /* There are no rpis available to the port now. */ |
| 5860 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5864 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5865 | * @pdev: pointer to pci device data structure. |
| 5866 | * |
| 5867 | * This routine is invoked to allocate the driver hba data structure for an |
| 5868 | * HBA device. If the allocation is successful, the phba reference to the |
| 5869 | * PCI device data structure is set. |
| 5870 | * |
| 5871 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5872 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5873 | * NULL - error |
| 5874 | **/ |
| 5875 | static struct lpfc_hba * |
| 5876 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5877 | { |
| 5878 | struct lpfc_hba *phba; |
| 5879 | |
| 5880 | /* Allocate memory for HBA structure */ |
| 5881 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5882 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5883 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5884 | return NULL; |
| 5885 | } |
| 5886 | |
| 5887 | /* Set reference to PCI device in HBA structure */ |
| 5888 | phba->pcidev = pdev; |
| 5889 | |
| 5890 | /* Assign an unused board number */ |
| 5891 | phba->brd_no = lpfc_get_instance(); |
| 5892 | if (phba->brd_no < 0) { |
| 5893 | kfree(phba); |
| 5894 | return NULL; |
| 5895 | } |
| 5896 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5897 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5898 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5899 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5900 | return phba; |
| 5901 | } |
| 5902 | |
| 5903 | /** |
| 5904 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5905 | * @phba: pointer to lpfc hba data structure. |
| 5906 | * |
| 5907 | * This routine is invoked to free the driver hba data structure with an |
| 5908 | * HBA device. |
| 5909 | **/ |
| 5910 | static void |
| 5911 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5912 | { |
| 5913 | /* Release the driver assigned board number */ |
| 5914 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5915 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5916 | /* Free memory allocated with sli rings */ |
| 5917 | kfree(phba->sli.ring); |
| 5918 | phba->sli.ring = NULL; |
| 5919 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5920 | kfree(phba); |
| 5921 | return; |
| 5922 | } |
| 5923 | |
| 5924 | /** |
| 5925 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5926 | * @phba: pointer to lpfc hba data structure. |
| 5927 | * |
| 5928 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5929 | * host with it. |
| 5930 | * |
| 5931 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5932 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5933 | * other values - error |
| 5934 | **/ |
| 5935 | static int |
| 5936 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5937 | { |
| 5938 | struct lpfc_vport *vport; |
| 5939 | struct Scsi_Host *shost; |
| 5940 | |
| 5941 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5942 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5943 | phba->fc_ratov = FF_DEF_RATOV; |
| 5944 | phba->fc_altov = FF_DEF_ALTOV; |
| 5945 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5946 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5947 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5948 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5949 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5950 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5951 | |
| 5952 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5953 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5954 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5955 | /* Put reference to SCSI host to driver's device private data */ |
| 5956 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5957 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5958 | return 0; |
| 5959 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5960 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5961 | /** |
| 5962 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5963 | * @phba: pointer to lpfc hba data structure. |
| 5964 | * |
| 5965 | * This routine is invoked to destroy HBA physical port and the associated |
| 5966 | * SCSI host. |
| 5967 | **/ |
| 5968 | static void |
| 5969 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5970 | { |
| 5971 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5972 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5973 | /* Destroy physical port that associated with the SCSI host */ |
| 5974 | destroy_port(vport); |
| 5975 | |
| 5976 | return; |
| 5977 | } |
| 5978 | |
| 5979 | /** |
| 5980 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5981 | * @phba: pointer to lpfc hba data structure. |
| 5982 | * @shost: the shost to be used to detect Block guard settings. |
| 5983 | * |
| 5984 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5985 | * This routine also allocates memory for debugging bg buffers. |
| 5986 | **/ |
| 5987 | static void |
| 5988 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5989 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5990 | uint32_t old_mask; |
| 5991 | uint32_t old_guard; |
| 5992 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5993 | int pagecnt = 10; |
| 5994 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5995 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5996 | "1478 Registering BlockGuard with the " |
| 5997 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5998 | |
| 5999 | old_mask = lpfc_prot_mask; |
| 6000 | old_guard = lpfc_prot_guard; |
| 6001 | |
| 6002 | /* Only allow supported values */ |
| 6003 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 6004 | SHOST_DIX_TYPE0_PROTECTION | |
| 6005 | SHOST_DIX_TYPE1_PROTECTION); |
| 6006 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 6007 | |
| 6008 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 6009 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 6010 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 6011 | |
| 6012 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 6013 | if ((old_mask != lpfc_prot_mask) || |
| 6014 | (old_guard != lpfc_prot_guard)) |
| 6015 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6016 | "1475 Registering BlockGuard with the " |
| 6017 | "SCSI layer: mask %d guard %d\n", |
| 6018 | lpfc_prot_mask, lpfc_prot_guard); |
| 6019 | |
| 6020 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 6021 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 6022 | } else |
| 6023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6024 | "1479 Not Registering BlockGuard with the SCSI " |
| 6025 | "layer, Bad protection parameters: %d %d\n", |
| 6026 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 6027 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6028 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6029 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6030 | while (pagecnt) { |
| 6031 | spin_lock_init(&_dump_buf_lock); |
| 6032 | _dump_buf_data = |
| 6033 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6034 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6035 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6036 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6037 | "_dump_buf_data at 0x%p\n", |
| 6038 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6039 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6040 | memset(_dump_buf_data, 0, |
| 6041 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6042 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6043 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6044 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6045 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6046 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6047 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6048 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6049 | "memory for hexdump\n"); |
| 6050 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6051 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6052 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6053 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6054 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6055 | while (pagecnt) { |
| 6056 | _dump_buf_dif = |
| 6057 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 6058 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6059 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6060 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6061 | "_dump_buf_dif at 0x%p\n", |
| 6062 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6063 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6064 | memset(_dump_buf_dif, 0, |
| 6065 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6066 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6067 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6068 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6069 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6070 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6071 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6072 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6073 | "memory for hexdump\n"); |
| 6074 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6075 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6076 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6077 | _dump_buf_dif); |
| 6078 | } |
| 6079 | |
| 6080 | /** |
| 6081 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 6082 | * @phba: pointer to lpfc hba data structure. |
| 6083 | * |
| 6084 | * This routine is invoked to perform all the necessary post initialization |
| 6085 | * setup for the device. |
| 6086 | **/ |
| 6087 | static void |
| 6088 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 6089 | { |
| 6090 | struct Scsi_Host *shost; |
| 6091 | struct lpfc_adapter_event_header adapter_event; |
| 6092 | |
| 6093 | /* Get the default values for Model Name and Description */ |
| 6094 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 6095 | |
| 6096 | /* |
| 6097 | * hba setup may have changed the hba_queue_depth so we need to |
| 6098 | * adjust the value of can_queue. |
| 6099 | */ |
| 6100 | shost = pci_get_drvdata(phba->pcidev); |
| 6101 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 6102 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 6103 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6104 | |
| 6105 | lpfc_host_attrib_init(shost); |
| 6106 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6107 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6108 | spin_lock_irq(shost->host_lock); |
| 6109 | lpfc_poll_start_timer(phba); |
| 6110 | spin_unlock_irq(shost->host_lock); |
| 6111 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 6112 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6113 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6114 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6115 | /* Send board arrival event to upper layer */ |
| 6116 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 6117 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 6118 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6119 | sizeof(adapter_event), |
| 6120 | (char *) &adapter_event, |
| 6121 | LPFC_NL_VENDOR_ID); |
| 6122 | return; |
| 6123 | } |
| 6124 | |
| 6125 | /** |
| 6126 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 6127 | * @phba: pointer to lpfc hba data structure. |
| 6128 | * |
| 6129 | * This routine is invoked to set up the PCI device memory space for device |
| 6130 | * with SLI-3 interface spec. |
| 6131 | * |
| 6132 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6133 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6134 | * other values - error |
| 6135 | **/ |
| 6136 | static int |
| 6137 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 6138 | { |
| 6139 | struct pci_dev *pdev; |
| 6140 | unsigned long bar0map_len, bar2map_len; |
| 6141 | int i, hbq_count; |
| 6142 | void *ptr; |
| 6143 | int error = -ENODEV; |
| 6144 | |
| 6145 | /* Obtain PCI device reference */ |
| 6146 | if (!phba->pcidev) |
| 6147 | return error; |
| 6148 | else |
| 6149 | pdev = phba->pcidev; |
| 6150 | |
| 6151 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6152 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 6153 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 6154 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 6155 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6156 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6157 | } |
| 6158 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6159 | |
| 6160 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 6161 | * required by each mapping. |
| 6162 | */ |
| 6163 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 6164 | bar0map_len = pci_resource_len(pdev, 0); |
| 6165 | |
| 6166 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 6167 | bar2map_len = pci_resource_len(pdev, 2); |
| 6168 | |
| 6169 | /* Map HBA SLIM to a kernel virtual address. */ |
| 6170 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 6171 | if (!phba->slim_memmap_p) { |
| 6172 | dev_printk(KERN_ERR, &pdev->dev, |
| 6173 | "ioremap failed for SLIM memory.\n"); |
| 6174 | goto out; |
| 6175 | } |
| 6176 | |
| 6177 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 6178 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 6179 | if (!phba->ctrl_regs_memmap_p) { |
| 6180 | dev_printk(KERN_ERR, &pdev->dev, |
| 6181 | "ioremap failed for HBA control registers.\n"); |
| 6182 | goto out_iounmap_slim; |
| 6183 | } |
| 6184 | |
| 6185 | /* Allocate memory for SLI-2 structures */ |
| 6186 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 6187 | SLI2_SLIM_SIZE, |
| 6188 | &phba->slim2p.phys, |
| 6189 | GFP_KERNEL); |
| 6190 | if (!phba->slim2p.virt) |
| 6191 | goto out_iounmap; |
| 6192 | |
| 6193 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 6194 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6195 | phba->mbox_ext = (phba->slim2p.virt + |
| 6196 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6197 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 6198 | phba->IOCBs = (phba->slim2p.virt + |
| 6199 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 6200 | |
| 6201 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 6202 | lpfc_sli_hbq_size(), |
| 6203 | &phba->hbqslimp.phys, |
| 6204 | GFP_KERNEL); |
| 6205 | if (!phba->hbqslimp.virt) |
| 6206 | goto out_free_slim; |
| 6207 | |
| 6208 | hbq_count = lpfc_sli_hbq_count(); |
| 6209 | ptr = phba->hbqslimp.virt; |
| 6210 | for (i = 0; i < hbq_count; ++i) { |
| 6211 | phba->hbqs[i].hbq_virt = ptr; |
| 6212 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 6213 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 6214 | sizeof(struct lpfc_hbq_entry)); |
| 6215 | } |
| 6216 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 6217 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 6218 | |
| 6219 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 6220 | |
| 6221 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 6222 | |
| 6223 | phba->MBslimaddr = phba->slim_memmap_p; |
| 6224 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 6225 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 6226 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 6227 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6228 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6229 | return 0; |
| 6230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6231 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6232 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6233 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6234 | out_iounmap: |
| 6235 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6236 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6237 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6238 | out: |
| 6239 | return error; |
| 6240 | } |
| 6241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6242 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6243 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 6244 | * @phba: pointer to lpfc hba data structure. |
| 6245 | * |
| 6246 | * This routine is invoked to unset the PCI device memory space for device |
| 6247 | * with SLI-3 interface spec. |
| 6248 | **/ |
| 6249 | static void |
| 6250 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 6251 | { |
| 6252 | struct pci_dev *pdev; |
| 6253 | |
| 6254 | /* Obtain PCI device reference */ |
| 6255 | if (!phba->pcidev) |
| 6256 | return; |
| 6257 | else |
| 6258 | pdev = phba->pcidev; |
| 6259 | |
| 6260 | /* Free coherent DMA memory allocated */ |
| 6261 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 6262 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 6263 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6264 | phba->slim2p.virt, phba->slim2p.phys); |
| 6265 | |
| 6266 | /* I/O memory unmap */ |
| 6267 | iounmap(phba->ctrl_regs_memmap_p); |
| 6268 | iounmap(phba->slim_memmap_p); |
| 6269 | |
| 6270 | return; |
| 6271 | } |
| 6272 | |
| 6273 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6274 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 6275 | * @phba: pointer to lpfc hba data structure. |
| 6276 | * |
| 6277 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 6278 | * done and check status. |
| 6279 | * |
| 6280 | * Return 0 if successful, otherwise -ENODEV. |
| 6281 | **/ |
| 6282 | int |
| 6283 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 6284 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6285 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 6286 | struct lpfc_register reg_data; |
| 6287 | int i, port_error = 0; |
| 6288 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6289 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6290 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 6291 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6292 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6293 | return -ENODEV; |
| 6294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6295 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 6296 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6297 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 6298 | &portsmphr_reg.word0) || |
| 6299 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6300 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6301 | port_error = -ENODEV; |
| 6302 | break; |
| 6303 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6304 | if (LPFC_POST_STAGE_PORT_READY == |
| 6305 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6306 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6307 | msleep(10); |
| 6308 | } |
| 6309 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6310 | /* |
| 6311 | * If there was a port error during POST, then don't proceed with |
| 6312 | * other register reads as the data may not be valid. Just exit. |
| 6313 | */ |
| 6314 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6316 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 6317 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 6318 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 6319 | portsmphr_reg.word0, |
| 6320 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 6321 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 6322 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 6323 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 6324 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 6325 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 6326 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 6327 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 6328 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6329 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6330 | "2534 Device Info: SLIFamily=0x%x, " |
| 6331 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 6332 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6333 | bf_get(lpfc_sli_intf_sli_family, |
| 6334 | &phba->sli4_hba.sli_intf), |
| 6335 | bf_get(lpfc_sli_intf_slirev, |
| 6336 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6337 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6338 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6339 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6340 | &phba->sli4_hba.sli_intf), |
| 6341 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6342 | &phba->sli4_hba.sli_intf), |
| 6343 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6344 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6345 | /* |
| 6346 | * Check for other Port errors during the initialization |
| 6347 | * process. Fail the load if the port did not come up |
| 6348 | * correctly. |
| 6349 | */ |
| 6350 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6351 | &phba->sli4_hba.sli_intf); |
| 6352 | switch (if_type) { |
| 6353 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6354 | phba->sli4_hba.ue_mask_lo = |
| 6355 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6356 | phba->sli4_hba.ue_mask_hi = |
| 6357 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6358 | uerrlo_reg.word0 = |
| 6359 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6360 | uerrhi_reg.word0 = |
| 6361 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6362 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6363 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6365 | "1422 Unrecoverable Error " |
| 6366 | "Detected during POST " |
| 6367 | "uerr_lo_reg=0x%x, " |
| 6368 | "uerr_hi_reg=0x%x, " |
| 6369 | "ue_mask_lo_reg=0x%x, " |
| 6370 | "ue_mask_hi_reg=0x%x\n", |
| 6371 | uerrlo_reg.word0, |
| 6372 | uerrhi_reg.word0, |
| 6373 | phba->sli4_hba.ue_mask_lo, |
| 6374 | phba->sli4_hba.ue_mask_hi); |
| 6375 | port_error = -ENODEV; |
| 6376 | } |
| 6377 | break; |
| 6378 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6379 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6380 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6381 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6382 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6383 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6384 | phba->work_status[0] = |
| 6385 | readl(phba->sli4_hba.u.if_type2. |
| 6386 | ERR1regaddr); |
| 6387 | phba->work_status[1] = |
| 6388 | readl(phba->sli4_hba.u.if_type2. |
| 6389 | ERR2regaddr); |
| 6390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6391 | "2888 Unrecoverable port error " |
| 6392 | "following POST: port status reg " |
| 6393 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6394 | "error 1=0x%x, error 2=0x%x\n", |
| 6395 | reg_data.word0, |
| 6396 | portsmphr_reg.word0, |
| 6397 | phba->work_status[0], |
| 6398 | phba->work_status[1]); |
| 6399 | port_error = -ENODEV; |
| 6400 | } |
| 6401 | break; |
| 6402 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6403 | default: |
| 6404 | break; |
| 6405 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6406 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6407 | return port_error; |
| 6408 | } |
| 6409 | |
| 6410 | /** |
| 6411 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6412 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6413 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6414 | * |
| 6415 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6416 | * memory map. |
| 6417 | **/ |
| 6418 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6419 | 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] | 6420 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6421 | switch (if_type) { |
| 6422 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6423 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6424 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6425 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6426 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6427 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6428 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6429 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6430 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6431 | phba->sli4_hba.SLIINTFregaddr = |
| 6432 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6433 | break; |
| 6434 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6435 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6436 | phba->sli4_hba.conf_regs_memmap_p + |
| 6437 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6438 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6439 | phba->sli4_hba.conf_regs_memmap_p + |
| 6440 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6441 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6442 | phba->sli4_hba.conf_regs_memmap_p + |
| 6443 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6444 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6445 | phba->sli4_hba.conf_regs_memmap_p + |
| 6446 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6447 | phba->sli4_hba.SLIINTFregaddr = |
| 6448 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6449 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6450 | phba->sli4_hba.conf_regs_memmap_p + |
| 6451 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6452 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6453 | phba->sli4_hba.conf_regs_memmap_p + |
| 6454 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6455 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6456 | phba->sli4_hba.conf_regs_memmap_p + |
| 6457 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6458 | phba->sli4_hba.EQCQDBregaddr = |
| 6459 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6460 | phba->sli4_hba.MQDBregaddr = |
| 6461 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6462 | phba->sli4_hba.BMBXregaddr = |
| 6463 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6464 | break; |
| 6465 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6466 | default: |
| 6467 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6468 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6469 | if_type); |
| 6470 | break; |
| 6471 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6472 | } |
| 6473 | |
| 6474 | /** |
| 6475 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6476 | * @phba: pointer to lpfc hba data structure. |
| 6477 | * |
| 6478 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6479 | * memory map. |
| 6480 | **/ |
| 6481 | static void |
| 6482 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6483 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6484 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6485 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6486 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6487 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6488 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6489 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6490 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6491 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6496 | * @phba: pointer to lpfc hba data structure. |
| 6497 | * @vf: virtual function number |
| 6498 | * |
| 6499 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6500 | * based on the given viftual function number, @vf. |
| 6501 | * |
| 6502 | * Return 0 if successful, otherwise -ENODEV. |
| 6503 | **/ |
| 6504 | static int |
| 6505 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6506 | { |
| 6507 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6508 | return -ENODEV; |
| 6509 | |
| 6510 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6511 | vf * LPFC_VFR_PAGE_SIZE + |
| 6512 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6513 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6514 | vf * LPFC_VFR_PAGE_SIZE + |
| 6515 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6516 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6517 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6518 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6519 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6520 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6521 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6522 | return 0; |
| 6523 | } |
| 6524 | |
| 6525 | /** |
| 6526 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6527 | * @phba: pointer to lpfc hba data structure. |
| 6528 | * |
| 6529 | * This routine is invoked to create the bootstrap mailbox |
| 6530 | * region consistent with the SLI-4 interface spec. This |
| 6531 | * routine allocates all memory necessary to communicate |
| 6532 | * mailbox commands to the port and sets up all alignment |
| 6533 | * needs. No locks are expected to be held when calling |
| 6534 | * this routine. |
| 6535 | * |
| 6536 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6537 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6538 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6539 | **/ |
| 6540 | static int |
| 6541 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6542 | { |
| 6543 | uint32_t bmbx_size; |
| 6544 | struct lpfc_dmabuf *dmabuf; |
| 6545 | struct dma_address *dma_address; |
| 6546 | uint32_t pa_addr; |
| 6547 | uint64_t phys_addr; |
| 6548 | |
| 6549 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6550 | if (!dmabuf) |
| 6551 | return -ENOMEM; |
| 6552 | |
| 6553 | /* |
| 6554 | * The bootstrap mailbox region is comprised of 2 parts |
| 6555 | * plus an alignment restriction of 16 bytes. |
| 6556 | */ |
| 6557 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 6558 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6559 | bmbx_size, |
| 6560 | &dmabuf->phys, |
| 6561 | GFP_KERNEL); |
| 6562 | if (!dmabuf->virt) { |
| 6563 | kfree(dmabuf); |
| 6564 | return -ENOMEM; |
| 6565 | } |
| 6566 | memset(dmabuf->virt, 0, bmbx_size); |
| 6567 | |
| 6568 | /* |
| 6569 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6570 | * operations are simple later. The mailbox dma address is required |
| 6571 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6572 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6573 | * command to the port. |
| 6574 | */ |
| 6575 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6576 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6577 | |
| 6578 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6579 | LPFC_ALIGN_16_BYTE); |
| 6580 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6581 | LPFC_ALIGN_16_BYTE); |
| 6582 | |
| 6583 | /* |
| 6584 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6585 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6586 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6587 | * the 30-bit address is the high or low address. |
| 6588 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6589 | * clean on 32 bit machines. |
| 6590 | */ |
| 6591 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6592 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6593 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6594 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6595 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6596 | |
| 6597 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6598 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6599 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6600 | return 0; |
| 6601 | } |
| 6602 | |
| 6603 | /** |
| 6604 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6605 | * @phba: pointer to lpfc hba data structure. |
| 6606 | * |
| 6607 | * This routine is invoked to teardown the bootstrap mailbox |
| 6608 | * region and release all host resources. This routine requires |
| 6609 | * the caller to ensure all mailbox commands recovered, no |
| 6610 | * additional mailbox comands are sent, and interrupts are disabled |
| 6611 | * before calling this routine. |
| 6612 | * |
| 6613 | **/ |
| 6614 | static void |
| 6615 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6616 | { |
| 6617 | dma_free_coherent(&phba->pcidev->dev, |
| 6618 | phba->sli4_hba.bmbx.bmbx_size, |
| 6619 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6620 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6621 | |
| 6622 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6623 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6624 | } |
| 6625 | |
| 6626 | /** |
| 6627 | * lpfc_sli4_read_config - Get the config parameters. |
| 6628 | * @phba: pointer to lpfc hba data structure. |
| 6629 | * |
| 6630 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6631 | * The configuration parameters are used to set the base and maximum values |
| 6632 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6633 | * allocation for the port. |
| 6634 | * |
| 6635 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6636 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6637 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6638 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6639 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6640 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6641 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6642 | { |
| 6643 | LPFC_MBOXQ_t *pmb; |
| 6644 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6645 | union lpfc_sli4_cfg_shdr *shdr; |
| 6646 | uint32_t shdr_status, shdr_add_status; |
| 6647 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6648 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6649 | char *pdesc_0; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6650 | uint32_t desc_count; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6651 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6652 | |
| 6653 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6654 | if (!pmb) { |
| 6655 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6656 | "2011 Unable to allocate memory for issuing " |
| 6657 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6658 | return -ENOMEM; |
| 6659 | } |
| 6660 | |
| 6661 | lpfc_read_config(phba, pmb); |
| 6662 | |
| 6663 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6664 | if (rc != MBX_SUCCESS) { |
| 6665 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6666 | "2012 Mailbox failed , mbxCmd x%x " |
| 6667 | "READ_CONFIG, mbxStatus x%x\n", |
| 6668 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6669 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6670 | rc = -EIO; |
| 6671 | } else { |
| 6672 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6673 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6674 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6675 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6676 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6677 | phba->sli4_hba.lnk_info.lnk_no = |
| 6678 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6679 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6680 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6681 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6682 | phba->sli4_hba.lnk_info.lnk_no); |
| 6683 | } else |
| 6684 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6685 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6686 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6687 | phba->sli4_hba.extents_in_use = |
| 6688 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6689 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6690 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6691 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6692 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6693 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6694 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6695 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6696 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6697 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6698 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6699 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6700 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6701 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6702 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6703 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6704 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6705 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6706 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6707 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6708 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6709 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6710 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6711 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6712 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6713 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6714 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6715 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6716 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6717 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6718 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6719 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6720 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6721 | phba->max_vports = phba->max_vpi; |
| 6722 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6723 | "2003 cfg params Extents? %d " |
| 6724 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6725 | "VPI(B:%d M:%d) " |
| 6726 | "VFI(B:%d M:%d) " |
| 6727 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6728 | "FCFI(Count:%d)\n", |
| 6729 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6730 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6731 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6732 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6733 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6734 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6735 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6736 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6737 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6738 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6739 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6740 | |
| 6741 | if (rc) |
| 6742 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6743 | |
| 6744 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6745 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 6746 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 6747 | if (phba->cfg_hba_queue_depth > length) { |
| 6748 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6749 | "3361 HBA queue depth changed from %d to %d\n", |
| 6750 | phba->cfg_hba_queue_depth, length); |
| 6751 | phba->cfg_hba_queue_depth = length; |
| 6752 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6753 | |
| 6754 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6755 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6756 | goto read_cfg_out; |
| 6757 | |
| 6758 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6759 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6760 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6761 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6762 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6763 | length, LPFC_SLI4_MBX_EMBED); |
| 6764 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6765 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6766 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6767 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6768 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6769 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6770 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6771 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6772 | "3026 Mailbox failed , mbxCmd x%x " |
| 6773 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6774 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6775 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6776 | goto read_cfg_out; |
| 6777 | } |
| 6778 | |
| 6779 | /* search for fc_fcoe resrouce descriptor */ |
| 6780 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6781 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6782 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6783 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6784 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6785 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6786 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6787 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6788 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6789 | goto read_cfg_out; |
| 6790 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6791 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6792 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6793 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6794 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6795 | phba->sli4_hba.iov.pf_number = |
| 6796 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6797 | phba->sli4_hba.iov.vf_number = |
| 6798 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6799 | break; |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6804 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6805 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6806 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6807 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6808 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6809 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6810 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6811 | "Resrouce Descriptor:x%x\n", |
| 6812 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6813 | |
| 6814 | read_cfg_out: |
| 6815 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6816 | return rc; |
| 6817 | } |
| 6818 | |
| 6819 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6820 | * 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] | 6821 | * @phba: pointer to lpfc hba data structure. |
| 6822 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6823 | * This routine is invoked to setup the port-side endian order when |
| 6824 | * the port if_type is 0. This routine has no function for other |
| 6825 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6826 | * |
| 6827 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6828 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6829 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6830 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6831 | **/ |
| 6832 | static int |
| 6833 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6834 | { |
| 6835 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6836 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6837 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6838 | HOST_ENDIAN_HIGH_WORD1}; |
| 6839 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6840 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6841 | switch (if_type) { |
| 6842 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6843 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6844 | GFP_KERNEL); |
| 6845 | if (!mboxq) { |
| 6846 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6847 | "0492 Unable to allocate memory for " |
| 6848 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6849 | "command\n"); |
| 6850 | return -ENOMEM; |
| 6851 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6852 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6853 | /* |
| 6854 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6855 | * two words to contain special data values and no other data. |
| 6856 | */ |
| 6857 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6858 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6859 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6860 | if (rc != MBX_SUCCESS) { |
| 6861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6862 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6863 | "failed with status x%x\n", |
| 6864 | rc); |
| 6865 | rc = -EIO; |
| 6866 | } |
| 6867 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6868 | break; |
| 6869 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6870 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6871 | default: |
| 6872 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6873 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6874 | return rc; |
| 6875 | } |
| 6876 | |
| 6877 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6878 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6879 | * @phba: pointer to lpfc hba data structure. |
| 6880 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6881 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6882 | * CQs. after this routine is called the counts will be set to valid values that |
| 6883 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6884 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6885 | * |
| 6886 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6887 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6888 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6889 | **/ |
| 6890 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6891 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6892 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6893 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6894 | uint32_t cpu; |
| 6895 | uint32_t i = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6896 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6897 | |
| 6898 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6899 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6900 | * device parameters |
| 6901 | */ |
| 6902 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6903 | /* Sanity check on HBA EQ parameters */ |
| 6904 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6905 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6906 | /* It doesn't make sense to have more io channels then online CPUs */ |
| 6907 | for_each_present_cpu(cpu) { |
| 6908 | if (cpu_online(cpu)) |
| 6909 | i++; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6910 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6911 | phba->sli4_hba.num_online_cpu = i; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6912 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6913 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6914 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6915 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6916 | lpfc_printf_log(phba, |
| 6917 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6918 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6919 | "online CPUs: from %d to %d\n", |
| 6920 | cfg_fcp_io_channel, i); |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6921 | cfg_fcp_io_channel = i; |
| 6922 | } |
| 6923 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6924 | if (cfg_fcp_io_channel + fof_vectors > |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6925 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6926 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 6927 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6928 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6929 | "2574 Not enough EQs (%d) from the " |
| 6930 | "pci function for supporting FCP " |
| 6931 | "EQs (%d)\n", |
| 6932 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6933 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6934 | goto out_error; |
| 6935 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6937 | "2575 Reducing IO channels to match number of " |
| 6938 | "available EQs: from %d to %d\n", |
| 6939 | cfg_fcp_io_channel, |
| 6940 | phba->sli4_hba.max_cfg_param.max_eq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6941 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq - |
| 6942 | fof_vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6943 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6944 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6945 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6946 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6947 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6948 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6949 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6950 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6951 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6952 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6953 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6954 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6955 | |
| 6956 | return 0; |
| 6957 | out_error: |
| 6958 | return -ENOMEM; |
| 6959 | } |
| 6960 | |
| 6961 | /** |
| 6962 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6963 | * @phba: pointer to lpfc hba data structure. |
| 6964 | * |
| 6965 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6966 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6967 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6968 | * we just use some constant number as place holder. |
| 6969 | * |
| 6970 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 6971 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6972 | * -ENOMEM - No availble memory |
| 6973 | * -EIO - The mailbox failed to complete successfully. |
| 6974 | **/ |
| 6975 | int |
| 6976 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6977 | { |
| 6978 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6979 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6980 | |
| 6981 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6982 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6983 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6984 | if (!phba->cfg_fcp_io_channel) |
| 6985 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6986 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6987 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6988 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6989 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6990 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6991 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6992 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6993 | |
| 6994 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6995 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6996 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6997 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6998 | "2576 Failed allocate memory for " |
| 6999 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7000 | goto out_error; |
| 7001 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7002 | |
| 7003 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7004 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7005 | if (!phba->sli4_hba.fcp_cq) { |
| 7006 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7007 | "2577 Failed allocate memory for fast-path " |
| 7008 | "CQ record array\n"); |
| 7009 | goto out_error; |
| 7010 | } |
| 7011 | |
| 7012 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 7013 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7014 | if (!phba->sli4_hba.fcp_wq) { |
| 7015 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7016 | "2578 Failed allocate memory for fast-path " |
| 7017 | "WQ record array\n"); |
| 7018 | goto out_error; |
| 7019 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7020 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7021 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7022 | * Since the first EQ can have multiple CQs associated with it, |
| 7023 | * this array is used to quickly see if we have a FCP fast-path |
| 7024 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7025 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7026 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 7027 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 7028 | if (!phba->sli4_hba.fcp_cq_map) { |
| 7029 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7030 | "2545 Failed allocate memory for fast-path " |
| 7031 | "CQ map\n"); |
| 7032 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7033 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7034 | |
| 7035 | /* |
| 7036 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 7037 | * how many EQs to create. |
| 7038 | */ |
| 7039 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7040 | |
| 7041 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7042 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 7043 | phba->sli4_hba.eq_ecount); |
| 7044 | if (!qdesc) { |
| 7045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7046 | "0497 Failed allocate EQ (%d)\n", idx); |
| 7047 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7048 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7049 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 7050 | |
| 7051 | /* Create Fast Path FCP CQs */ |
| 7052 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7053 | phba->sli4_hba.cq_ecount); |
| 7054 | if (!qdesc) { |
| 7055 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7056 | "0499 Failed allocate fast-path FCP " |
| 7057 | "CQ (%d)\n", idx); |
| 7058 | goto out_error; |
| 7059 | } |
| 7060 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 7061 | |
| 7062 | /* Create Fast Path FCP WQs */ |
| 7063 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7064 | phba->sli4_hba.wq_ecount); |
| 7065 | if (!qdesc) { |
| 7066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7067 | "0503 Failed allocate fast-path FCP " |
| 7068 | "WQ (%d)\n", idx); |
| 7069 | goto out_error; |
| 7070 | } |
| 7071 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7072 | } |
| 7073 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7074 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7075 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7076 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7077 | */ |
| 7078 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7079 | /* Create slow-path Mailbox Command Complete Queue */ |
| 7080 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7081 | phba->sli4_hba.cq_ecount); |
| 7082 | if (!qdesc) { |
| 7083 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7084 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7085 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7086 | } |
| 7087 | phba->sli4_hba.mbx_cq = qdesc; |
| 7088 | |
| 7089 | /* Create slow-path ELS Complete Queue */ |
| 7090 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7091 | phba->sli4_hba.cq_ecount); |
| 7092 | if (!qdesc) { |
| 7093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7094 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7095 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7096 | } |
| 7097 | phba->sli4_hba.els_cq = qdesc; |
| 7098 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7099 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7100 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7101 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7102 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7103 | |
| 7104 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7105 | |
| 7106 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 7107 | phba->sli4_hba.mq_ecount); |
| 7108 | if (!qdesc) { |
| 7109 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7110 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7111 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7112 | } |
| 7113 | phba->sli4_hba.mbx_wq = qdesc; |
| 7114 | |
| 7115 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7116 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7117 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7118 | |
| 7119 | /* Create slow-path ELS Work Queue */ |
| 7120 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7121 | phba->sli4_hba.wq_ecount); |
| 7122 | if (!qdesc) { |
| 7123 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7124 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7125 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7126 | } |
| 7127 | phba->sli4_hba.els_wq = qdesc; |
| 7128 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7129 | /* |
| 7130 | * Create Receive Queue (RQ) |
| 7131 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7132 | |
| 7133 | /* Create Receive Queue for header */ |
| 7134 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7135 | phba->sli4_hba.rq_ecount); |
| 7136 | if (!qdesc) { |
| 7137 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7138 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7139 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7140 | } |
| 7141 | phba->sli4_hba.hdr_rq = qdesc; |
| 7142 | |
| 7143 | /* Create Receive Queue for data */ |
| 7144 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7145 | phba->sli4_hba.rq_ecount); |
| 7146 | if (!qdesc) { |
| 7147 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7148 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7149 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | } |
| 7151 | phba->sli4_hba.dat_rq = qdesc; |
| 7152 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7153 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
| 7154 | if (phba->cfg_fof) |
| 7155 | lpfc_fof_queue_create(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7156 | return 0; |
| 7157 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7158 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7159 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7160 | return -ENOMEM; |
| 7161 | } |
| 7162 | |
| 7163 | /** |
| 7164 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 7165 | * @phba: pointer to lpfc hba data structure. |
| 7166 | * |
| 7167 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 7168 | * operation. |
| 7169 | * |
| 7170 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7171 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7172 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7173 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7174 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7175 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7176 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 7177 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7178 | int idx; |
| 7179 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7180 | if (phba->cfg_fof) |
| 7181 | lpfc_fof_queue_destroy(phba); |
| 7182 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7183 | if (phba->sli4_hba.hba_eq != NULL) { |
| 7184 | /* Release HBA event queue */ |
| 7185 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7186 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 7187 | lpfc_sli4_queue_free( |
| 7188 | phba->sli4_hba.hba_eq[idx]); |
| 7189 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 7190 | } |
| 7191 | } |
| 7192 | kfree(phba->sli4_hba.hba_eq); |
| 7193 | phba->sli4_hba.hba_eq = NULL; |
| 7194 | } |
| 7195 | |
| 7196 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 7197 | /* Release FCP completion queue */ |
| 7198 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7199 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 7200 | lpfc_sli4_queue_free( |
| 7201 | phba->sli4_hba.fcp_cq[idx]); |
| 7202 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 7203 | } |
| 7204 | } |
| 7205 | kfree(phba->sli4_hba.fcp_cq); |
| 7206 | phba->sli4_hba.fcp_cq = NULL; |
| 7207 | } |
| 7208 | |
| 7209 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 7210 | /* Release FCP work queue */ |
| 7211 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7212 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 7213 | lpfc_sli4_queue_free( |
| 7214 | phba->sli4_hba.fcp_wq[idx]); |
| 7215 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 7216 | } |
| 7217 | } |
| 7218 | kfree(phba->sli4_hba.fcp_wq); |
| 7219 | phba->sli4_hba.fcp_wq = NULL; |
| 7220 | } |
| 7221 | |
| 7222 | /* Release FCP CQ mapping array */ |
| 7223 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 7224 | kfree(phba->sli4_hba.fcp_cq_map); |
| 7225 | phba->sli4_hba.fcp_cq_map = NULL; |
| 7226 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7227 | |
| 7228 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7229 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 7230 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 7231 | phba->sli4_hba.mbx_wq = NULL; |
| 7232 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7233 | |
| 7234 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7235 | if (phba->sli4_hba.els_wq != NULL) { |
| 7236 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 7237 | phba->sli4_hba.els_wq = NULL; |
| 7238 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7239 | |
| 7240 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7241 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 7242 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 7243 | phba->sli4_hba.hdr_rq = NULL; |
| 7244 | } |
| 7245 | if (phba->sli4_hba.dat_rq != NULL) { |
| 7246 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 7247 | phba->sli4_hba.dat_rq = NULL; |
| 7248 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7249 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7250 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7251 | if (phba->sli4_hba.els_cq != NULL) { |
| 7252 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 7253 | phba->sli4_hba.els_cq = NULL; |
| 7254 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7255 | |
| 7256 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7257 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 7258 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 7259 | phba->sli4_hba.mbx_cq = NULL; |
| 7260 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7261 | |
| 7262 | return; |
| 7263 | } |
| 7264 | |
| 7265 | /** |
| 7266 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 7267 | * @phba: pointer to lpfc hba data structure. |
| 7268 | * |
| 7269 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 7270 | * operation. |
| 7271 | * |
| 7272 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7273 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7274 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7275 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7276 | **/ |
| 7277 | int |
| 7278 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 7279 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7280 | struct lpfc_sli *psli = &phba->sli; |
| 7281 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7282 | int rc = -ENOMEM; |
| 7283 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 7284 | int fcp_cq_index = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7285 | uint32_t shdr_status, shdr_add_status; |
| 7286 | union lpfc_sli4_cfg_shdr *shdr; |
| 7287 | LPFC_MBOXQ_t *mboxq; |
| 7288 | uint32_t length; |
| 7289 | |
| 7290 | /* Check for dual-ULP support */ |
| 7291 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7292 | if (!mboxq) { |
| 7293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7294 | "3249 Unable to allocate memory for " |
| 7295 | "QUERY_FW_CFG mailbox command\n"); |
| 7296 | return -ENOMEM; |
| 7297 | } |
| 7298 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 7299 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7300 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7301 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 7302 | length, LPFC_SLI4_MBX_EMBED); |
| 7303 | |
| 7304 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7305 | |
| 7306 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7307 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7308 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7309 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7310 | if (shdr_status || shdr_add_status || rc) { |
| 7311 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7312 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 7313 | "x%x add_status x%x, mbx status x%x\n", |
| 7314 | shdr_status, shdr_add_status, rc); |
| 7315 | if (rc != MBX_TIMEOUT) |
| 7316 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7317 | rc = -ENXIO; |
| 7318 | goto out_error; |
| 7319 | } |
| 7320 | |
| 7321 | phba->sli4_hba.fw_func_mode = |
| 7322 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 7323 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 7324 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; |
| 7325 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7326 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 7327 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 7328 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 7329 | |
| 7330 | if (rc != MBX_TIMEOUT) |
| 7331 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7332 | |
| 7333 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7334 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7335 | */ |
| 7336 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7337 | /* Set up HBA event queue */ |
| 7338 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7340 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7341 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7342 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7343 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7344 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 7345 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7346 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7347 | "0522 Fast-path EQ (%d) not " |
| 7348 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7349 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7350 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7351 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7352 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 7353 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7354 | if (rc) { |
| 7355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7356 | "0523 Failed setup of fast-path EQ " |
| 7357 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7358 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7359 | } |
| 7360 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7361 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7362 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7363 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7364 | } |
| 7365 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7366 | /* Set up fast-path FCP Response Complete Queue */ |
| 7367 | if (!phba->sli4_hba.fcp_cq) { |
| 7368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7369 | "3148 Fast-path FCP CQ array not " |
| 7370 | "allocated\n"); |
| 7371 | rc = -ENOMEM; |
| 7372 | goto out_destroy_hba_eq; |
| 7373 | } |
| 7374 | |
| 7375 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 7376 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 7377 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7378 | "0526 Fast-path FCP CQ (%d) not " |
| 7379 | "allocated\n", fcp_cqidx); |
| 7380 | rc = -ENOMEM; |
| 7381 | goto out_destroy_fcp_cq; |
| 7382 | } |
| 7383 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 7384 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 7385 | if (rc) { |
| 7386 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7387 | "0527 Failed setup of fast-path FCP " |
| 7388 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 7389 | goto out_destroy_fcp_cq; |
| 7390 | } |
| 7391 | |
| 7392 | /* Setup fcp_cq_map for fast lookup */ |
| 7393 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 7394 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7395 | |
| 7396 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7397 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7398 | "parent seq[%d]-id=%d\n", |
| 7399 | fcp_cqidx, |
| 7400 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7401 | fcp_cqidx, |
| 7402 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7403 | } |
| 7404 | |
| 7405 | /* Set up fast-path FCP Work Queue */ |
| 7406 | if (!phba->sli4_hba.fcp_wq) { |
| 7407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7408 | "3149 Fast-path FCP WQ array not " |
| 7409 | "allocated\n"); |
| 7410 | rc = -ENOMEM; |
| 7411 | goto out_destroy_fcp_cq; |
| 7412 | } |
| 7413 | |
| 7414 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7415 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7417 | "0534 Fast-path FCP WQ (%d) not " |
| 7418 | "allocated\n", fcp_wqidx); |
| 7419 | rc = -ENOMEM; |
| 7420 | goto out_destroy_fcp_wq; |
| 7421 | } |
| 7422 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7423 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7424 | LPFC_FCP); |
| 7425 | if (rc) { |
| 7426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7427 | "0535 Failed setup of fast-path FCP " |
| 7428 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 7429 | goto out_destroy_fcp_wq; |
| 7430 | } |
| 7431 | |
| 7432 | /* Bind this WQ to the next FCP ring */ |
| 7433 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7434 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7435 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7436 | |
| 7437 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7438 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7439 | "parent cq[%d]-id=%d\n", |
| 7440 | fcp_wqidx, |
| 7441 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7442 | fcp_cq_index, |
| 7443 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7444 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7445 | /* |
| 7446 | * Set up Complete Queues (CQs) |
| 7447 | */ |
| 7448 | |
| 7449 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7450 | if (!phba->sli4_hba.mbx_cq) { |
| 7451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7452 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7453 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7454 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7455 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7456 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7457 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7458 | if (rc) { |
| 7459 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7460 | "0529 Failed setup of slow-path mailbox CQ: " |
| 7461 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7462 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7463 | } |
| 7464 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7465 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7466 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7467 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7468 | |
| 7469 | /* Set up slow-path ELS Complete Queue */ |
| 7470 | if (!phba->sli4_hba.els_cq) { |
| 7471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7472 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7473 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7474 | goto out_destroy_mbx_cq; |
| 7475 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7476 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7477 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7478 | if (rc) { |
| 7479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7480 | "0531 Failed setup of slow-path ELS CQ: " |
| 7481 | "rc = 0x%x\n", rc); |
| 7482 | goto out_destroy_mbx_cq; |
| 7483 | } |
| 7484 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7485 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7486 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7487 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7488 | |
| 7489 | /* |
| 7490 | * Set up all the Work Queues (WQs) |
| 7491 | */ |
| 7492 | |
| 7493 | /* Set up Mailbox Command Queue */ |
| 7494 | if (!phba->sli4_hba.mbx_wq) { |
| 7495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7496 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7497 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7498 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7499 | } |
| 7500 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7501 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7502 | if (rc) { |
| 7503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7504 | "0539 Failed setup of slow-path MQ: " |
| 7505 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7506 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7507 | } |
| 7508 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7509 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7510 | phba->sli4_hba.mbx_wq->queue_id, |
| 7511 | phba->sli4_hba.mbx_cq->queue_id); |
| 7512 | |
| 7513 | /* Set up slow-path ELS Work Queue */ |
| 7514 | if (!phba->sli4_hba.els_wq) { |
| 7515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7516 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7517 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7518 | goto out_destroy_mbx_wq; |
| 7519 | } |
| 7520 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7521 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7522 | if (rc) { |
| 7523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7524 | "0537 Failed setup of slow-path ELS WQ: " |
| 7525 | "rc = 0x%x\n", rc); |
| 7526 | goto out_destroy_mbx_wq; |
| 7527 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7528 | |
| 7529 | /* Bind this WQ to the ELS ring */ |
| 7530 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7531 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7532 | phba->sli4_hba.els_cq->pring = pring; |
| 7533 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7534 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7535 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7536 | phba->sli4_hba.els_wq->queue_id, |
| 7537 | phba->sli4_hba.els_cq->queue_id); |
| 7538 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7539 | /* |
| 7540 | * Create Receive Queue (RQ) |
| 7541 | */ |
| 7542 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7543 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7544 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7545 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7546 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7547 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7548 | |
| 7549 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7550 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7551 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7552 | 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] | 7553 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7554 | if (rc) { |
| 7555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7556 | "0541 Failed setup of Receive Queue: " |
| 7557 | "rc = 0x%x\n", rc); |
| 7558 | goto out_destroy_fcp_wq; |
| 7559 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7560 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7561 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7562 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7563 | "parent cq-id=%d\n", |
| 7564 | phba->sli4_hba.hdr_rq->queue_id, |
| 7565 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7566 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7567 | |
| 7568 | if (phba->cfg_fof) { |
| 7569 | rc = lpfc_fof_queue_setup(phba); |
| 7570 | if (rc) { |
| 7571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7572 | "0549 Failed setup of FOF Queues: " |
| 7573 | "rc = 0x%x\n", rc); |
| 7574 | goto out_destroy_els_rq; |
| 7575 | } |
| 7576 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7577 | return 0; |
| 7578 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7579 | out_destroy_els_rq: |
| 7580 | 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] | 7581 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7582 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7583 | out_destroy_mbx_wq: |
| 7584 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7585 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7586 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7587 | out_destroy_mbx_cq: |
| 7588 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7589 | out_destroy_fcp_wq: |
| 7590 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7591 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7592 | out_destroy_fcp_cq: |
| 7593 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7594 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7595 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7596 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7597 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7598 | out_error: |
| 7599 | return rc; |
| 7600 | } |
| 7601 | |
| 7602 | /** |
| 7603 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7604 | * @phba: pointer to lpfc hba data structure. |
| 7605 | * |
| 7606 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7607 | * operation. |
| 7608 | * |
| 7609 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7610 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7611 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7612 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7613 | **/ |
| 7614 | void |
| 7615 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7616 | { |
| 7617 | int fcp_qidx; |
| 7618 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7619 | /* Unset the queues created for Flash Optimized Fabric operations */ |
| 7620 | if (phba->cfg_fof) |
| 7621 | lpfc_fof_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7622 | /* Unset mailbox command work queue */ |
| 7623 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7624 | /* Unset ELS work queue */ |
| 7625 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7626 | /* Unset unsolicited receive queue */ |
| 7627 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7628 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7629 | if (phba->sli4_hba.fcp_wq) { |
| 7630 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7631 | fcp_qidx++) |
| 7632 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7633 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7634 | /* Unset mailbox command complete queue */ |
| 7635 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7636 | /* Unset ELS complete queue */ |
| 7637 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7638 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7639 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7640 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7641 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7642 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7643 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7644 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7645 | if (phba->sli4_hba.hba_eq) { |
| 7646 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7647 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7648 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7649 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | /** |
| 7653 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7654 | * @phba: pointer to lpfc hba data structure. |
| 7655 | * |
| 7656 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7657 | * events. The body of the completion queue event is a completion queue entry |
| 7658 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7659 | * the following HBA completion queue events for the worker thread to process: |
| 7660 | * - Mailbox asynchronous events |
| 7661 | * - Receive queue completion unsolicited events |
| 7662 | * Later, this can be used for all the slow-path events. |
| 7663 | * |
| 7664 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7665 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7666 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7667 | **/ |
| 7668 | static int |
| 7669 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7670 | { |
| 7671 | struct lpfc_cq_event *cq_event; |
| 7672 | int i; |
| 7673 | |
| 7674 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7675 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7676 | if (!cq_event) |
| 7677 | goto out_pool_create_fail; |
| 7678 | list_add_tail(&cq_event->list, |
| 7679 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7680 | } |
| 7681 | return 0; |
| 7682 | |
| 7683 | out_pool_create_fail: |
| 7684 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7685 | return -ENOMEM; |
| 7686 | } |
| 7687 | |
| 7688 | /** |
| 7689 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7690 | * @phba: pointer to lpfc hba data structure. |
| 7691 | * |
| 7692 | * This routine is invoked to free the pool of completion queue events at |
| 7693 | * driver unload time. Note that, it is the responsibility of the driver |
| 7694 | * cleanup routine to free all the outstanding completion-queue events |
| 7695 | * allocated from this pool back into the pool before invoking this routine |
| 7696 | * to destroy the pool. |
| 7697 | **/ |
| 7698 | static void |
| 7699 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7700 | { |
| 7701 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7702 | |
| 7703 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7704 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7705 | list_del(&cq_event->list); |
| 7706 | kfree(cq_event); |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | /** |
| 7711 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7712 | * @phba: pointer to lpfc hba data structure. |
| 7713 | * |
| 7714 | * This routine is the lock free version of the API invoked to allocate a |
| 7715 | * completion-queue event from the free pool. |
| 7716 | * |
| 7717 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7718 | * NULL otherwise. |
| 7719 | **/ |
| 7720 | struct lpfc_cq_event * |
| 7721 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7722 | { |
| 7723 | struct lpfc_cq_event *cq_event = NULL; |
| 7724 | |
| 7725 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7726 | struct lpfc_cq_event, list); |
| 7727 | return cq_event; |
| 7728 | } |
| 7729 | |
| 7730 | /** |
| 7731 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7732 | * @phba: pointer to lpfc hba data structure. |
| 7733 | * |
| 7734 | * This routine is the lock version of the API invoked to allocate a |
| 7735 | * completion-queue event from the free pool. |
| 7736 | * |
| 7737 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7738 | * NULL otherwise. |
| 7739 | **/ |
| 7740 | struct lpfc_cq_event * |
| 7741 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7742 | { |
| 7743 | struct lpfc_cq_event *cq_event; |
| 7744 | unsigned long iflags; |
| 7745 | |
| 7746 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7747 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7748 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7749 | return cq_event; |
| 7750 | } |
| 7751 | |
| 7752 | /** |
| 7753 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7754 | * @phba: pointer to lpfc hba data structure. |
| 7755 | * @cq_event: pointer to the completion queue event to be freed. |
| 7756 | * |
| 7757 | * This routine is the lock free version of the API invoked to release a |
| 7758 | * completion-queue event back into the free pool. |
| 7759 | **/ |
| 7760 | void |
| 7761 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7762 | struct lpfc_cq_event *cq_event) |
| 7763 | { |
| 7764 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7765 | } |
| 7766 | |
| 7767 | /** |
| 7768 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7769 | * @phba: pointer to lpfc hba data structure. |
| 7770 | * @cq_event: pointer to the completion queue event to be freed. |
| 7771 | * |
| 7772 | * This routine is the lock version of the API invoked to release a |
| 7773 | * completion-queue event back into the free pool. |
| 7774 | **/ |
| 7775 | void |
| 7776 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7777 | struct lpfc_cq_event *cq_event) |
| 7778 | { |
| 7779 | unsigned long iflags; |
| 7780 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7781 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7782 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7783 | } |
| 7784 | |
| 7785 | /** |
| 7786 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7787 | * @phba: pointer to lpfc hba data structure. |
| 7788 | * |
| 7789 | * This routine is to free all the pending completion-queue events to the |
| 7790 | * back into the free pool for device reset. |
| 7791 | **/ |
| 7792 | static void |
| 7793 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7794 | { |
| 7795 | LIST_HEAD(cqelist); |
| 7796 | struct lpfc_cq_event *cqe; |
| 7797 | unsigned long iflags; |
| 7798 | |
| 7799 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7800 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7801 | /* Pending FCP XRI abort events */ |
| 7802 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7803 | &cqelist); |
| 7804 | /* Pending ELS XRI abort events */ |
| 7805 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7806 | &cqelist); |
| 7807 | /* Pending asynnc events */ |
| 7808 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7809 | &cqelist); |
| 7810 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7811 | |
| 7812 | while (!list_empty(&cqelist)) { |
| 7813 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7814 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7815 | } |
| 7816 | } |
| 7817 | |
| 7818 | /** |
| 7819 | * lpfc_pci_function_reset - Reset pci function. |
| 7820 | * @phba: pointer to lpfc hba data structure. |
| 7821 | * |
| 7822 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7823 | * all resources assigned to the PCI function which originates this request. |
| 7824 | * |
| 7825 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7826 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7827 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7828 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7829 | **/ |
| 7830 | int |
| 7831 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7832 | { |
| 7833 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7834 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7835 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7836 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7837 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7838 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7839 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7840 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7841 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7842 | switch (if_type) { |
| 7843 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7844 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7845 | GFP_KERNEL); |
| 7846 | if (!mboxq) { |
| 7847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7848 | "0494 Unable to allocate memory for " |
| 7849 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7850 | "command\n"); |
| 7851 | return -ENOMEM; |
| 7852 | } |
| 7853 | |
| 7854 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7855 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7856 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7857 | LPFC_SLI4_MBX_EMBED); |
| 7858 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7859 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7860 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7861 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7862 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7863 | &shdr->response); |
| 7864 | if (rc != MBX_TIMEOUT) |
| 7865 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7866 | if (shdr_status || shdr_add_status || rc) { |
| 7867 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7868 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7869 | "failed with status x%x add_status x%x," |
| 7870 | " mbx status x%x\n", |
| 7871 | shdr_status, shdr_add_status, rc); |
| 7872 | rc = -ENXIO; |
| 7873 | } |
| 7874 | break; |
| 7875 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7876 | for (num_resets = 0; |
| 7877 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7878 | num_resets++) { |
| 7879 | reg_data.word0 = 0; |
| 7880 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7881 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7882 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7883 | LPFC_SLIPORT_INIT_PORT); |
| 7884 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7885 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7886 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7887 | pci_read_config_word(phba->pcidev, |
| 7888 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7889 | /* |
| 7890 | * Poll the Port Status Register and wait for RDY for |
| 7891 | * up to 10 seconds. If the port doesn't respond, treat |
| 7892 | * it as an error. If the port responds with RN, start |
| 7893 | * the loop again. |
| 7894 | */ |
| 7895 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7896 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7897 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7898 | STATUSregaddr, ®_data.word0)) { |
| 7899 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7900 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7901 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7902 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7903 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7904 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7905 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | /* |
| 7909 | * If the port responds to the init request with |
| 7910 | * reset needed, delay for a bit and restart the loop. |
| 7911 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7912 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7913 | msleep(10); |
| 7914 | reset_again = 0; |
| 7915 | continue; |
| 7916 | } |
| 7917 | |
| 7918 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7919 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7920 | (rdy_chk >= 1000)) { |
| 7921 | phba->work_status[0] = readl( |
| 7922 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7923 | phba->work_status[1] = readl( |
| 7924 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7926 | "2890 Port error detected during port " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7927 | "reset(%d): wait_tmo:%d ms, " |
| 7928 | "port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7929 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7930 | num_resets, rdy_chk*10, |
| 7931 | reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7932 | phba->work_status[0], |
| 7933 | phba->work_status[1]); |
| 7934 | rc = -ENODEV; |
| 7935 | } |
| 7936 | |
| 7937 | /* |
| 7938 | * Terminate the outer loop provided the Port indicated |
| 7939 | * ready within 10 seconds. |
| 7940 | */ |
| 7941 | if (rdy_chk < 1000) |
| 7942 | break; |
| 7943 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7944 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7945 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7946 | break; |
| 7947 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7948 | default: |
| 7949 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7950 | } |
| 7951 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7952 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7953 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7954 | if (num_resets >= MAX_IF_TYPE_2_RESETS) { |
| 7955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7956 | "3317 HBA not functional: IP Reset Failed " |
| 7957 | "after (%d) retries, try: " |
| 7958 | "echo fw_reset > board_mode\n", num_resets); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7959 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7960 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7961 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7962 | return rc; |
| 7963 | } |
| 7964 | |
| 7965 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7966 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7967 | * @phba: pointer to lpfc hba data structure. |
| 7968 | * |
| 7969 | * This routine is invoked to set up the PCI device memory space for device |
| 7970 | * with SLI-4 interface spec. |
| 7971 | * |
| 7972 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7973 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7974 | * other values - error |
| 7975 | **/ |
| 7976 | static int |
| 7977 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7978 | { |
| 7979 | struct pci_dev *pdev; |
| 7980 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7981 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7982 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7983 | |
| 7984 | /* Obtain PCI device reference */ |
| 7985 | if (!phba->pcidev) |
| 7986 | return error; |
| 7987 | else |
| 7988 | pdev = phba->pcidev; |
| 7989 | |
| 7990 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7991 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7992 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7993 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7994 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7995 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7996 | } |
| 7997 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7998 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7999 | /* |
| 8000 | * The BARs and register set definitions and offset locations are |
| 8001 | * dependent on the if_type. |
| 8002 | */ |
| 8003 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 8004 | &phba->sli4_hba.sli_intf.word0)) { |
| 8005 | return error; |
| 8006 | } |
| 8007 | |
| 8008 | /* There is no SLI3 failback for SLI4 devices. */ |
| 8009 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 8010 | LPFC_SLI_INTF_VALID) { |
| 8011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8012 | "2894 SLI_INTF reg contents invalid " |
| 8013 | "sli_intf reg 0x%x\n", |
| 8014 | phba->sli4_hba.sli_intf.word0); |
| 8015 | return error; |
| 8016 | } |
| 8017 | |
| 8018 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8019 | /* |
| 8020 | * Get the bus address of SLI4 device Bar regions and the |
| 8021 | * number of bytes required by each mapping. The mapping of the |
| 8022 | * particular PCI BARs regions is dependent on the type of |
| 8023 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8024 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8025 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 8026 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 8027 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8028 | |
| 8029 | /* |
| 8030 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 8031 | * addr |
| 8032 | */ |
| 8033 | phba->sli4_hba.conf_regs_memmap_p = |
| 8034 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 8035 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8036 | dev_printk(KERN_ERR, &pdev->dev, |
| 8037 | "ioremap failed for SLI4 PCI config " |
| 8038 | "registers.\n"); |
| 8039 | goto out; |
| 8040 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8041 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8042 | /* Set up BAR0 PCI config space register memory map */ |
| 8043 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 8044 | } else { |
| 8045 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 8046 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8047 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 8048 | dev_printk(KERN_ERR, &pdev->dev, |
| 8049 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 8050 | goto out; |
| 8051 | } |
| 8052 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8053 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8054 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 8055 | dev_printk(KERN_ERR, &pdev->dev, |
| 8056 | "ioremap failed for SLI4 PCI config " |
| 8057 | "registers.\n"); |
| 8058 | goto out; |
| 8059 | } |
| 8060 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8061 | } |
| 8062 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8063 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8064 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8065 | /* |
| 8066 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 8067 | * virtual address and setup the registers. |
| 8068 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8069 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 8070 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8071 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8072 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8073 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 8074 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8075 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8076 | goto out_iounmap_conf; |
| 8077 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8078 | phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8079 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8080 | } |
| 8081 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8082 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8083 | (pci_resource_start(pdev, PCI_64BIT_BAR4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8084 | /* |
| 8085 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 8086 | * virtual address and setup the registers. |
| 8087 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8088 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 8089 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8090 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8091 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8092 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 8093 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8094 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8095 | goto out_iounmap_ctrl; |
| 8096 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 8097 | phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8098 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 8099 | if (error) |
| 8100 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8101 | } |
| 8102 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8103 | return 0; |
| 8104 | |
| 8105 | out_iounmap_all: |
| 8106 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8107 | out_iounmap_ctrl: |
| 8108 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8109 | out_iounmap_conf: |
| 8110 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8111 | out: |
| 8112 | return error; |
| 8113 | } |
| 8114 | |
| 8115 | /** |
| 8116 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 8117 | * @phba: pointer to lpfc hba data structure. |
| 8118 | * |
| 8119 | * This routine is invoked to unset the PCI device memory space for device |
| 8120 | * with SLI-4 interface spec. |
| 8121 | **/ |
| 8122 | static void |
| 8123 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 8124 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8125 | uint32_t if_type; |
| 8126 | 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] | 8127 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8128 | switch (if_type) { |
| 8129 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8130 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8131 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8132 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8133 | break; |
| 8134 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8135 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8136 | break; |
| 8137 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8138 | default: |
| 8139 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8140 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8141 | if_type); |
| 8142 | break; |
| 8143 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8144 | } |
| 8145 | |
| 8146 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8147 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 8148 | * @phba: pointer to lpfc hba data structure. |
| 8149 | * |
| 8150 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8151 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 8152 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 8153 | * invoked, enables either all or nothing, depending on the current |
| 8154 | * availability of PCI vector resources. The device driver is responsible |
| 8155 | * for calling the individual request_irq() to register each MSI-X vector |
| 8156 | * with a interrupt handler, which is done in this function. Note that |
| 8157 | * later when device is unloading, the driver should always call free_irq() |
| 8158 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8159 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8160 | * will be left with MSI-X enabled and leaks its vectors. |
| 8161 | * |
| 8162 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8163 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8164 | * other values - error |
| 8165 | **/ |
| 8166 | static int |
| 8167 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 8168 | { |
| 8169 | int rc, i; |
| 8170 | LPFC_MBOXQ_t *pmb; |
| 8171 | |
| 8172 | /* Set up MSI-X multi-message vectors */ |
| 8173 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8174 | phba->msix_entries[i].entry = i; |
| 8175 | |
| 8176 | /* Configure MSI-X capability structure */ |
| 8177 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 8178 | ARRAY_SIZE(phba->msix_entries)); |
| 8179 | if (rc) { |
| 8180 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8181 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 8182 | goto msi_fail_out; |
| 8183 | } |
| 8184 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8185 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8186 | "0477 MSI-X entry[%d]: vector=x%x " |
| 8187 | "message=%d\n", i, |
| 8188 | phba->msix_entries[i].vector, |
| 8189 | phba->msix_entries[i].entry); |
| 8190 | /* |
| 8191 | * Assign MSI-X vectors to interrupt handlers |
| 8192 | */ |
| 8193 | |
| 8194 | /* vector-0 is associated to slow-path handler */ |
| 8195 | rc = request_irq(phba->msix_entries[0].vector, |
| 8196 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 8197 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 8198 | if (rc) { |
| 8199 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8200 | "0421 MSI-X slow-path request_irq failed " |
| 8201 | "(%d)\n", rc); |
| 8202 | goto msi_fail_out; |
| 8203 | } |
| 8204 | |
| 8205 | /* vector-1 is associated to fast-path handler */ |
| 8206 | rc = request_irq(phba->msix_entries[1].vector, |
| 8207 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 8208 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 8209 | |
| 8210 | if (rc) { |
| 8211 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8212 | "0429 MSI-X fast-path request_irq failed " |
| 8213 | "(%d)\n", rc); |
| 8214 | goto irq_fail_out; |
| 8215 | } |
| 8216 | |
| 8217 | /* |
| 8218 | * Configure HBA MSI-X attention conditions to messages |
| 8219 | */ |
| 8220 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8221 | |
| 8222 | if (!pmb) { |
| 8223 | rc = -ENOMEM; |
| 8224 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8225 | "0474 Unable to allocate memory for issuing " |
| 8226 | "MBOX_CONFIG_MSI command\n"); |
| 8227 | goto mem_fail_out; |
| 8228 | } |
| 8229 | rc = lpfc_config_msi(phba, pmb); |
| 8230 | if (rc) |
| 8231 | goto mbx_fail_out; |
| 8232 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8233 | if (rc != MBX_SUCCESS) { |
| 8234 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 8235 | "0351 Config MSI mailbox command failed, " |
| 8236 | "mbxCmd x%x, mbxStatus x%x\n", |
| 8237 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 8238 | goto mbx_fail_out; |
| 8239 | } |
| 8240 | |
| 8241 | /* Free memory allocated for mailbox command */ |
| 8242 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8243 | return rc; |
| 8244 | |
| 8245 | mbx_fail_out: |
| 8246 | /* Free memory allocated for mailbox command */ |
| 8247 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8248 | |
| 8249 | mem_fail_out: |
| 8250 | /* free the irq already requested */ |
| 8251 | free_irq(phba->msix_entries[1].vector, phba); |
| 8252 | |
| 8253 | irq_fail_out: |
| 8254 | /* free the irq already requested */ |
| 8255 | free_irq(phba->msix_entries[0].vector, phba); |
| 8256 | |
| 8257 | msi_fail_out: |
| 8258 | /* Unconfigure MSI-X capability structure */ |
| 8259 | pci_disable_msix(phba->pcidev); |
| 8260 | return rc; |
| 8261 | } |
| 8262 | |
| 8263 | /** |
| 8264 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 8265 | * @phba: pointer to lpfc hba data structure. |
| 8266 | * |
| 8267 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8268 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 8269 | **/ |
| 8270 | static void |
| 8271 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 8272 | { |
| 8273 | int i; |
| 8274 | |
| 8275 | /* Free up MSI-X multi-message vectors */ |
| 8276 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8277 | free_irq(phba->msix_entries[i].vector, phba); |
| 8278 | /* Disable MSI-X */ |
| 8279 | pci_disable_msix(phba->pcidev); |
| 8280 | |
| 8281 | return; |
| 8282 | } |
| 8283 | |
| 8284 | /** |
| 8285 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 8286 | * @phba: pointer to lpfc hba data structure. |
| 8287 | * |
| 8288 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8289 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 8290 | * enable the MSI vector. The device driver is responsible for calling the |
| 8291 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 8292 | * is done in this function. |
| 8293 | * |
| 8294 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8295 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8296 | * other values - error |
| 8297 | */ |
| 8298 | static int |
| 8299 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 8300 | { |
| 8301 | int rc; |
| 8302 | |
| 8303 | rc = pci_enable_msi(phba->pcidev); |
| 8304 | if (!rc) |
| 8305 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8306 | "0462 PCI enable MSI mode success.\n"); |
| 8307 | else { |
| 8308 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8309 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 8310 | return rc; |
| 8311 | } |
| 8312 | |
| 8313 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8314 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8315 | if (rc) { |
| 8316 | pci_disable_msi(phba->pcidev); |
| 8317 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8318 | "0478 MSI request_irq failed (%d)\n", rc); |
| 8319 | } |
| 8320 | return rc; |
| 8321 | } |
| 8322 | |
| 8323 | /** |
| 8324 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 8325 | * @phba: pointer to lpfc hba data structure. |
| 8326 | * |
| 8327 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8328 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 8329 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8330 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8331 | * its vector. |
| 8332 | */ |
| 8333 | static void |
| 8334 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 8335 | { |
| 8336 | free_irq(phba->pcidev->irq, phba); |
| 8337 | pci_disable_msi(phba->pcidev); |
| 8338 | return; |
| 8339 | } |
| 8340 | |
| 8341 | /** |
| 8342 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 8343 | * @phba: pointer to lpfc hba data structure. |
| 8344 | * |
| 8345 | * This routine is invoked to enable device interrupt and associate driver's |
| 8346 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8347 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8348 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8349 | * mode which is supported by the platform, kernel, and device in the order |
| 8350 | * of: |
| 8351 | * MSI-X -> MSI -> IRQ. |
| 8352 | * |
| 8353 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8354 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8355 | * other values - error |
| 8356 | **/ |
| 8357 | static uint32_t |
| 8358 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8359 | { |
| 8360 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8361 | int retval; |
| 8362 | |
| 8363 | if (cfg_mode == 2) { |
| 8364 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8365 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8366 | if (!retval) { |
| 8367 | /* Now, try to enable MSI-X interrupt mode */ |
| 8368 | retval = lpfc_sli_enable_msix(phba); |
| 8369 | if (!retval) { |
| 8370 | /* Indicate initialization to MSI-X mode */ |
| 8371 | phba->intr_type = MSIX; |
| 8372 | intr_mode = 2; |
| 8373 | } |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8378 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8379 | retval = lpfc_sli_enable_msi(phba); |
| 8380 | if (!retval) { |
| 8381 | /* Indicate initialization to MSI mode */ |
| 8382 | phba->intr_type = MSI; |
| 8383 | intr_mode = 1; |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8388 | if (phba->intr_type == NONE) { |
| 8389 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8390 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8391 | if (!retval) { |
| 8392 | /* Indicate initialization to INTx mode */ |
| 8393 | phba->intr_type = INTx; |
| 8394 | intr_mode = 0; |
| 8395 | } |
| 8396 | } |
| 8397 | return intr_mode; |
| 8398 | } |
| 8399 | |
| 8400 | /** |
| 8401 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8402 | * @phba: pointer to lpfc hba data structure. |
| 8403 | * |
| 8404 | * This routine is invoked to disable device interrupt and disassociate the |
| 8405 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8406 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8407 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8408 | **/ |
| 8409 | static void |
| 8410 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8411 | { |
| 8412 | /* Disable the currently initialized interrupt mode */ |
| 8413 | if (phba->intr_type == MSIX) |
| 8414 | lpfc_sli_disable_msix(phba); |
| 8415 | else if (phba->intr_type == MSI) |
| 8416 | lpfc_sli_disable_msi(phba); |
| 8417 | else if (phba->intr_type == INTx) |
| 8418 | free_irq(phba->pcidev->irq, phba); |
| 8419 | |
| 8420 | /* Reset interrupt management states */ |
| 8421 | phba->intr_type = NONE; |
| 8422 | phba->sli.slistat.sli_intr = 0; |
| 8423 | |
| 8424 | return; |
| 8425 | } |
| 8426 | |
| 8427 | /** |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8428 | * lpfc_find_next_cpu - Find next available CPU that matches the phys_id |
| 8429 | * @phba: pointer to lpfc hba data structure. |
| 8430 | * |
| 8431 | * Find next available CPU to use for IRQ to CPU affinity. |
| 8432 | */ |
| 8433 | static int |
| 8434 | lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id) |
| 8435 | { |
| 8436 | struct lpfc_vector_map_info *cpup; |
| 8437 | int cpu; |
| 8438 | |
| 8439 | cpup = phba->sli4_hba.cpu_map; |
| 8440 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8441 | /* CPU must be online */ |
| 8442 | if (cpu_online(cpu)) { |
| 8443 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8444 | (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) && |
| 8445 | (cpup->phys_id == phys_id)) { |
| 8446 | return cpu; |
| 8447 | } |
| 8448 | } |
| 8449 | cpup++; |
| 8450 | } |
| 8451 | |
| 8452 | /* |
| 8453 | * If we get here, we have used ALL CPUs for the specific |
| 8454 | * phys_id. Now we need to clear out lpfc_used_cpu and start |
| 8455 | * reusing CPUs. |
| 8456 | */ |
| 8457 | |
| 8458 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8459 | if (lpfc_used_cpu[cpu] == phys_id) |
| 8460 | lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY; |
| 8461 | } |
| 8462 | |
| 8463 | cpup = phba->sli4_hba.cpu_map; |
| 8464 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8465 | /* CPU must be online */ |
| 8466 | if (cpu_online(cpu)) { |
| 8467 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8468 | (cpup->phys_id == phys_id)) { |
| 8469 | return cpu; |
| 8470 | } |
| 8471 | } |
| 8472 | cpup++; |
| 8473 | } |
| 8474 | return LPFC_VECTOR_MAP_EMPTY; |
| 8475 | } |
| 8476 | |
| 8477 | /** |
| 8478 | * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors |
| 8479 | * @phba: pointer to lpfc hba data structure. |
| 8480 | * @vectors: number of HBA vectors |
| 8481 | * |
| 8482 | * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector |
| 8483 | * affinization across multple physical CPUs (numa nodes). |
| 8484 | * In addition, this routine will assign an IO channel for each CPU |
| 8485 | * to use when issuing I/Os. |
| 8486 | */ |
| 8487 | static int |
| 8488 | lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors) |
| 8489 | { |
| 8490 | int i, idx, saved_chann, used_chann, cpu, phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8491 | int max_phys_id, min_phys_id; |
| 8492 | int num_io_channel, first_cpu, chan; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8493 | struct lpfc_vector_map_info *cpup; |
| 8494 | #ifdef CONFIG_X86 |
| 8495 | struct cpuinfo_x86 *cpuinfo; |
| 8496 | #endif |
| 8497 | struct cpumask *mask; |
| 8498 | uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1]; |
| 8499 | |
| 8500 | /* If there is no mapping, just return */ |
| 8501 | if (!phba->cfg_fcp_cpu_map) |
| 8502 | return 1; |
| 8503 | |
| 8504 | /* Init cpu_map array */ |
| 8505 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 8506 | (sizeof(struct lpfc_vector_map_info) * |
| 8507 | phba->sli4_hba.num_present_cpu)); |
| 8508 | |
| 8509 | max_phys_id = 0; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8510 | min_phys_id = 0xff; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8511 | phys_id = 0; |
| 8512 | num_io_channel = 0; |
| 8513 | first_cpu = LPFC_VECTOR_MAP_EMPTY; |
| 8514 | |
| 8515 | /* Update CPU map with physical id and core id of each CPU */ |
| 8516 | cpup = phba->sli4_hba.cpu_map; |
| 8517 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8518 | #ifdef CONFIG_X86 |
| 8519 | cpuinfo = &cpu_data(cpu); |
| 8520 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 8521 | cpup->core_id = cpuinfo->cpu_core_id; |
| 8522 | #else |
| 8523 | /* No distinction between CPUs for other platforms */ |
| 8524 | cpup->phys_id = 0; |
| 8525 | cpup->core_id = 0; |
| 8526 | #endif |
| 8527 | |
| 8528 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8529 | "3328 CPU physid %d coreid %d\n", |
| 8530 | cpup->phys_id, cpup->core_id); |
| 8531 | |
| 8532 | if (cpup->phys_id > max_phys_id) |
| 8533 | max_phys_id = cpup->phys_id; |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8534 | if (cpup->phys_id < min_phys_id) |
| 8535 | min_phys_id = cpup->phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8536 | cpup++; |
| 8537 | } |
| 8538 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8539 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8540 | /* Now associate the HBA vectors with specific CPUs */ |
| 8541 | for (idx = 0; idx < vectors; idx++) { |
| 8542 | cpup = phba->sli4_hba.cpu_map; |
| 8543 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8544 | if (cpu == LPFC_VECTOR_MAP_EMPTY) { |
| 8545 | |
| 8546 | /* Try for all phys_id's */ |
| 8547 | for (i = 1; i < max_phys_id; i++) { |
| 8548 | phys_id++; |
| 8549 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8550 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8551 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8552 | if (cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8553 | continue; |
| 8554 | goto found; |
| 8555 | } |
| 8556 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8557 | /* Use round robin for scheduling */ |
| 8558 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN; |
| 8559 | chan = 0; |
| 8560 | cpup = phba->sli4_hba.cpu_map; |
| 8561 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 8562 | cpup->channel_id = chan; |
| 8563 | cpup++; |
| 8564 | chan++; |
| 8565 | if (chan >= phba->cfg_fcp_io_channel) |
| 8566 | chan = 0; |
| 8567 | } |
| 8568 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8570 | "3329 Cannot set affinity:" |
| 8571 | "Error mapping vector %d (%d)\n", |
| 8572 | idx, vectors); |
| 8573 | return 0; |
| 8574 | } |
| 8575 | found: |
| 8576 | cpup += cpu; |
| 8577 | if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP) |
| 8578 | lpfc_used_cpu[cpu] = phys_id; |
| 8579 | |
| 8580 | /* Associate vector with selected CPU */ |
| 8581 | cpup->irq = phba->sli4_hba.msix_entries[idx].vector; |
| 8582 | |
| 8583 | /* Associate IO channel with selected CPU */ |
| 8584 | cpup->channel_id = idx; |
| 8585 | num_io_channel++; |
| 8586 | |
| 8587 | if (first_cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8588 | first_cpu = cpu; |
| 8589 | |
| 8590 | /* Now affinitize to the selected CPU */ |
| 8591 | mask = &cpup->maskbits; |
| 8592 | cpumask_clear(mask); |
| 8593 | cpumask_set_cpu(cpu, mask); |
| 8594 | i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx]. |
| 8595 | vector, mask); |
| 8596 | |
| 8597 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8598 | "3330 Set Affinity: CPU %d channel %d " |
| 8599 | "irq %d (%x)\n", |
| 8600 | cpu, cpup->channel_id, |
| 8601 | phba->sli4_hba.msix_entries[idx].vector, i); |
| 8602 | |
| 8603 | /* Spread vector mapping across multple physical CPU nodes */ |
| 8604 | phys_id++; |
| 8605 | if (phys_id > max_phys_id) |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8606 | phys_id = min_phys_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8607 | } |
| 8608 | |
| 8609 | /* |
| 8610 | * Finally fill in the IO channel for any remaining CPUs. |
| 8611 | * At this point, all IO channels have been assigned to a specific |
| 8612 | * MSIx vector, mapped to a specific CPU. |
| 8613 | * Base the remaining IO channel assigned, to IO channels already |
| 8614 | * assigned to other CPUs on the same phys_id. |
| 8615 | */ |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8616 | for (i = min_phys_id; i <= max_phys_id; i++) { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8617 | /* |
| 8618 | * If there are no io channels already mapped to |
| 8619 | * this phys_id, just round robin thru the io_channels. |
| 8620 | * Setup chann[] for round robin. |
| 8621 | */ |
| 8622 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8623 | chann[idx] = idx; |
| 8624 | |
| 8625 | saved_chann = 0; |
| 8626 | used_chann = 0; |
| 8627 | |
| 8628 | /* |
| 8629 | * First build a list of IO channels already assigned |
| 8630 | * to this phys_id before reassigning the same IO |
| 8631 | * channels to the remaining CPUs. |
| 8632 | */ |
| 8633 | cpup = phba->sli4_hba.cpu_map; |
| 8634 | cpu = first_cpu; |
| 8635 | cpup += cpu; |
| 8636 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; |
| 8637 | idx++) { |
| 8638 | if (cpup->phys_id == i) { |
| 8639 | /* |
| 8640 | * Save any IO channels that are |
| 8641 | * already mapped to this phys_id. |
| 8642 | */ |
| 8643 | if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) { |
| 8644 | chann[saved_chann] = |
| 8645 | cpup->channel_id; |
| 8646 | saved_chann++; |
| 8647 | goto out; |
| 8648 | } |
| 8649 | |
| 8650 | /* See if we are using round-robin */ |
| 8651 | if (saved_chann == 0) |
| 8652 | saved_chann = |
| 8653 | phba->cfg_fcp_io_channel; |
| 8654 | |
| 8655 | /* Associate next IO channel with CPU */ |
| 8656 | cpup->channel_id = chann[used_chann]; |
| 8657 | num_io_channel++; |
| 8658 | used_chann++; |
| 8659 | if (used_chann == saved_chann) |
| 8660 | used_chann = 0; |
| 8661 | |
| 8662 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8663 | "3331 Set IO_CHANN " |
| 8664 | "CPU %d channel %d\n", |
| 8665 | idx, cpup->channel_id); |
| 8666 | } |
| 8667 | out: |
| 8668 | cpu++; |
| 8669 | if (cpu >= phba->sli4_hba.num_present_cpu) { |
| 8670 | cpup = phba->sli4_hba.cpu_map; |
| 8671 | cpu = 0; |
| 8672 | } else { |
| 8673 | cpup++; |
| 8674 | } |
| 8675 | } |
| 8676 | } |
| 8677 | |
| 8678 | if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) { |
| 8679 | cpup = phba->sli4_hba.cpu_map; |
| 8680 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) { |
| 8681 | if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) { |
| 8682 | cpup->channel_id = 0; |
| 8683 | num_io_channel++; |
| 8684 | |
| 8685 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8686 | "3332 Assign IO_CHANN " |
| 8687 | "CPU %d channel %d\n", |
| 8688 | idx, cpup->channel_id); |
| 8689 | } |
| 8690 | cpup++; |
| 8691 | } |
| 8692 | } |
| 8693 | |
| 8694 | /* Sanity check */ |
| 8695 | if (num_io_channel != phba->sli4_hba.num_present_cpu) |
| 8696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8697 | "3333 Set affinity mismatch:" |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8698 | "%d chann != %d cpus: %d vectors\n", |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8699 | num_io_channel, phba->sli4_hba.num_present_cpu, |
| 8700 | vectors); |
| 8701 | |
James Smart | ec2087a | 2013-09-06 12:20:36 -0400 | [diff] [blame] | 8702 | /* Enable using cpu affinity for scheduling */ |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8703 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU; |
| 8704 | return 1; |
| 8705 | } |
| 8706 | |
| 8707 | |
| 8708 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8709 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8710 | * @phba: pointer to lpfc hba data structure. |
| 8711 | * |
| 8712 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8713 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 8714 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 8715 | * enables either all or nothing, depending on the current availability of |
| 8716 | * PCI vector resources. The device driver is responsible for calling the |
| 8717 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 8718 | * handler, which is done in this function. Note that later when device is |
| 8719 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 8720 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 8721 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 8722 | * enabled and leaks its vectors. |
| 8723 | * |
| 8724 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8725 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8726 | * other values - error |
| 8727 | **/ |
| 8728 | static int |
| 8729 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8730 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8731 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8732 | |
| 8733 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8734 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8735 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8736 | |
| 8737 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8738 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8739 | if (phba->cfg_fof) { |
| 8740 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8741 | vectors++; |
| 8742 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8743 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8744 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8745 | vectors); |
| 8746 | if (rc > 1) { |
| 8747 | vectors = rc; |
| 8748 | goto enable_msix_vectors; |
| 8749 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8750 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8751 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 8752 | goto msi_fail_out; |
| 8753 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8754 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8755 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8756 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8757 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8758 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8759 | "message=%d\n", index, |
| 8760 | phba->sli4_hba.msix_entries[index].vector, |
| 8761 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8762 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8763 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8764 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8765 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
| 8766 | sprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8767 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8768 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8769 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8770 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8771 | 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] | 8772 | if (phba->cfg_fof && (index == (vectors - 1))) |
| 8773 | rc = request_irq( |
| 8774 | phba->sli4_hba.msix_entries[index].vector, |
| 8775 | &lpfc_sli4_fof_intr_handler, IRQF_SHARED, |
| 8776 | (char *)&phba->sli4_hba.handler_name[index], |
| 8777 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 8778 | else |
| 8779 | rc = request_irq( |
| 8780 | phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8781 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8782 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8783 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8784 | if (rc) { |
| 8785 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8786 | "0486 MSI-X fast-path (%d) " |
| 8787 | "request_irq failed (%d)\n", index, rc); |
| 8788 | goto cfg_fail_out; |
| 8789 | } |
| 8790 | } |
| 8791 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8792 | if (phba->cfg_fof) |
| 8793 | vectors--; |
| 8794 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8795 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8797 | "3238 Reducing IO channels to match number of " |
| 8798 | "MSI-X vectors, requested %d got %d\n", |
| 8799 | phba->cfg_fcp_io_channel, vectors); |
| 8800 | phba->cfg_fcp_io_channel = vectors; |
| 8801 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8802 | |
| 8803 | lpfc_sli4_set_affinity(phba, vectors); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8804 | return rc; |
| 8805 | |
| 8806 | cfg_fail_out: |
| 8807 | /* free the irq already requested */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8808 | for (--index; index >= 0; index--) { |
| 8809 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 8810 | vector, NULL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8811 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8812 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8813 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8814 | |
| 8815 | msi_fail_out: |
| 8816 | /* Unconfigure MSI-X capability structure */ |
| 8817 | pci_disable_msix(phba->pcidev); |
| 8818 | return rc; |
| 8819 | } |
| 8820 | |
| 8821 | /** |
| 8822 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 8823 | * @phba: pointer to lpfc hba data structure. |
| 8824 | * |
| 8825 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8826 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 8827 | **/ |
| 8828 | static void |
| 8829 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 8830 | { |
| 8831 | int index; |
| 8832 | |
| 8833 | /* Free up MSI-X multi-message vectors */ |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8834 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
| 8835 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. |
| 8836 | vector, NULL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8837 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8838 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | acbd861 | 2013-09-06 12:21:19 -0400 | [diff] [blame] | 8839 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8840 | if (phba->cfg_fof) { |
| 8841 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8842 | &phba->sli4_hba.fcp_eq_hdl[index]); |
| 8843 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8844 | /* Disable MSI-X */ |
| 8845 | pci_disable_msix(phba->pcidev); |
| 8846 | |
| 8847 | return; |
| 8848 | } |
| 8849 | |
| 8850 | /** |
| 8851 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8852 | * @phba: pointer to lpfc hba data structure. |
| 8853 | * |
| 8854 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8855 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8856 | * to enable the MSI vector. The device driver is responsible for calling |
| 8857 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8858 | * which is done in this function. |
| 8859 | * |
| 8860 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8861 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8862 | * other values - error |
| 8863 | **/ |
| 8864 | static int |
| 8865 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8866 | { |
| 8867 | int rc, index; |
| 8868 | |
| 8869 | rc = pci_enable_msi(phba->pcidev); |
| 8870 | if (!rc) |
| 8871 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8872 | "0487 PCI enable MSI mode success.\n"); |
| 8873 | else { |
| 8874 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8875 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8876 | return rc; |
| 8877 | } |
| 8878 | |
| 8879 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8880 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8881 | if (rc) { |
| 8882 | pci_disable_msi(phba->pcidev); |
| 8883 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8884 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8885 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8886 | } |
| 8887 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8888 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8889 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8890 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8891 | } |
| 8892 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8893 | if (phba->cfg_fof) { |
| 8894 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8895 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8896 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8897 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8898 | } |
| 8899 | |
| 8900 | /** |
| 8901 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8902 | * @phba: pointer to lpfc hba data structure. |
| 8903 | * |
| 8904 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8905 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8906 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8907 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8908 | * its vector. |
| 8909 | **/ |
| 8910 | static void |
| 8911 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8912 | { |
| 8913 | free_irq(phba->pcidev->irq, phba); |
| 8914 | pci_disable_msi(phba->pcidev); |
| 8915 | return; |
| 8916 | } |
| 8917 | |
| 8918 | /** |
| 8919 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8920 | * @phba: pointer to lpfc hba data structure. |
| 8921 | * |
| 8922 | * This routine is invoked to enable device interrupt and associate driver's |
| 8923 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8924 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8925 | * the driver will try to fallback from the configured interrupt mode to an |
| 8926 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8927 | * the order of: |
| 8928 | * MSI-X -> MSI -> IRQ. |
| 8929 | * |
| 8930 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8931 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8932 | * other values - error |
| 8933 | **/ |
| 8934 | static uint32_t |
| 8935 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8936 | { |
| 8937 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8938 | int retval, index; |
| 8939 | |
| 8940 | if (cfg_mode == 2) { |
| 8941 | /* Preparation before conf_msi mbox cmd */ |
| 8942 | retval = 0; |
| 8943 | if (!retval) { |
| 8944 | /* Now, try to enable MSI-X interrupt mode */ |
| 8945 | retval = lpfc_sli4_enable_msix(phba); |
| 8946 | if (!retval) { |
| 8947 | /* Indicate initialization to MSI-X mode */ |
| 8948 | phba->intr_type = MSIX; |
| 8949 | intr_mode = 2; |
| 8950 | } |
| 8951 | } |
| 8952 | } |
| 8953 | |
| 8954 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8955 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8956 | retval = lpfc_sli4_enable_msi(phba); |
| 8957 | if (!retval) { |
| 8958 | /* Indicate initialization to MSI mode */ |
| 8959 | phba->intr_type = MSI; |
| 8960 | intr_mode = 1; |
| 8961 | } |
| 8962 | } |
| 8963 | |
| 8964 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8965 | if (phba->intr_type == NONE) { |
| 8966 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8967 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8968 | if (!retval) { |
| 8969 | /* Indicate initialization to INTx mode */ |
| 8970 | phba->intr_type = INTx; |
| 8971 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8972 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8973 | index++) { |
| 8974 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8975 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8976 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8977 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8978 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8979 | if (phba->cfg_fof) { |
| 8980 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8981 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8982 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8983 | fcp_eq_in_use, 1); |
| 8984 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8985 | } |
| 8986 | } |
| 8987 | return intr_mode; |
| 8988 | } |
| 8989 | |
| 8990 | /** |
| 8991 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8992 | * @phba: pointer to lpfc hba data structure. |
| 8993 | * |
| 8994 | * This routine is invoked to disable device interrupt and disassociate |
| 8995 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8996 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8997 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8998 | **/ |
| 8999 | static void |
| 9000 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 9001 | { |
| 9002 | /* Disable the currently initialized interrupt mode */ |
| 9003 | if (phba->intr_type == MSIX) |
| 9004 | lpfc_sli4_disable_msix(phba); |
| 9005 | else if (phba->intr_type == MSI) |
| 9006 | lpfc_sli4_disable_msi(phba); |
| 9007 | else if (phba->intr_type == INTx) |
| 9008 | free_irq(phba->pcidev->irq, phba); |
| 9009 | |
| 9010 | /* Reset interrupt management states */ |
| 9011 | phba->intr_type = NONE; |
| 9012 | phba->sli.slistat.sli_intr = 0; |
| 9013 | |
| 9014 | return; |
| 9015 | } |
| 9016 | |
| 9017 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9018 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 9019 | * @phba: pointer to lpfc hba data structure. |
| 9020 | * |
| 9021 | * This routine is invoked to unset the HBA device initialization steps to |
| 9022 | * a device with SLI-3 interface spec. |
| 9023 | **/ |
| 9024 | static void |
| 9025 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 9026 | { |
| 9027 | struct lpfc_vport *vport = phba->pport; |
| 9028 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 9029 | |
| 9030 | spin_lock_irq(shost->host_lock); |
| 9031 | vport->load_flag |= FC_UNLOADING; |
| 9032 | spin_unlock_irq(shost->host_lock); |
| 9033 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9034 | kfree(phba->vpi_bmask); |
| 9035 | kfree(phba->vpi_ids); |
| 9036 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9037 | lpfc_stop_hba_timers(phba); |
| 9038 | |
| 9039 | phba->pport->work_port_events = 0; |
| 9040 | |
| 9041 | lpfc_sli_hba_down(phba); |
| 9042 | |
| 9043 | lpfc_sli_brdrestart(phba); |
| 9044 | |
| 9045 | lpfc_sli_disable_intr(phba); |
| 9046 | |
| 9047 | return; |
| 9048 | } |
| 9049 | |
| 9050 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9051 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 9052 | * @phba: Pointer to HBA context object. |
| 9053 | * |
| 9054 | * This function is called in the SLI4 code path to wait for completion |
| 9055 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 9056 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 9057 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 9058 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 9059 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 9060 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 9061 | * the rest of the driver unload resource release. |
| 9062 | **/ |
| 9063 | static void |
| 9064 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 9065 | { |
| 9066 | int wait_time = 0; |
| 9067 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9068 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9069 | |
| 9070 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 9071 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 9072 | if (!fcp_xri_cmpl) |
| 9073 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9074 | "2877 FCP XRI exchange busy " |
| 9075 | "wait time: %d seconds.\n", |
| 9076 | wait_time/1000); |
| 9077 | if (!els_xri_cmpl) |
| 9078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9079 | "2878 ELS XRI exchange busy " |
| 9080 | "wait time: %d seconds.\n", |
| 9081 | wait_time/1000); |
| 9082 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 9083 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 9084 | } else { |
| 9085 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 9086 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 9087 | } |
| 9088 | fcp_xri_cmpl = |
| 9089 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 9090 | els_xri_cmpl = |
| 9091 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 9092 | } |
| 9093 | } |
| 9094 | |
| 9095 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9096 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 9097 | * @phba: Pointer to HBA context object. |
| 9098 | * |
| 9099 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 9100 | * function. The caller is not required to hold any lock. This routine |
| 9101 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 9102 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 9103 | * free any pending commands. |
| 9104 | **/ |
| 9105 | static void |
| 9106 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 9107 | { |
| 9108 | int wait_cnt = 0; |
| 9109 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9110 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9111 | |
| 9112 | lpfc_stop_hba_timers(phba); |
| 9113 | phba->sli4_hba.intr_enable = 0; |
| 9114 | |
| 9115 | /* |
| 9116 | * Gracefully wait out the potential current outstanding asynchronous |
| 9117 | * mailbox command. |
| 9118 | */ |
| 9119 | |
| 9120 | /* First, block any pending async mailbox command from posted */ |
| 9121 | spin_lock_irq(&phba->hbalock); |
| 9122 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 9123 | spin_unlock_irq(&phba->hbalock); |
| 9124 | /* Now, trying to wait it out if we can */ |
| 9125 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9126 | msleep(10); |
| 9127 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 9128 | break; |
| 9129 | } |
| 9130 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 9131 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9132 | spin_lock_irq(&phba->hbalock); |
| 9133 | mboxq = phba->sli.mbox_active; |
| 9134 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9135 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9136 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9137 | phba->sli.mbox_active = NULL; |
| 9138 | spin_unlock_irq(&phba->hbalock); |
| 9139 | } |
| 9140 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9141 | /* Abort all iocbs associated with the hba */ |
| 9142 | lpfc_sli_hba_iocb_abort(phba); |
| 9143 | |
| 9144 | /* Wait for completion of device XRI exchange busy */ |
| 9145 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 9146 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9147 | /* Disable PCI subsystem interrupt */ |
| 9148 | lpfc_sli4_disable_intr(phba); |
| 9149 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9150 | /* Disable SR-IOV if enabled */ |
| 9151 | if (phba->cfg_sriov_nr_virtfn) |
| 9152 | pci_disable_sriov(pdev); |
| 9153 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9154 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9155 | kthread_stop(phba->worker_thread); |
| 9156 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9157 | /* Reset SLI4 HBA FCoE function */ |
| 9158 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9159 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9160 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9161 | /* Stop the SLI4 device port */ |
| 9162 | phba->pport->work_port_events = 0; |
| 9163 | } |
| 9164 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9165 | /** |
| 9166 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 9167 | * @phba: Pointer to HBA context object. |
| 9168 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9169 | * |
| 9170 | * This function is called in the SLI4 code path to read the port's |
| 9171 | * sli4 capabilities. |
| 9172 | * |
| 9173 | * This function may be be called from any context that can block-wait |
| 9174 | * for the completion. The expectation is that this routine is called |
| 9175 | * typically from probe_one or from the online routine. |
| 9176 | **/ |
| 9177 | int |
| 9178 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9179 | { |
| 9180 | int rc; |
| 9181 | struct lpfc_mqe *mqe; |
| 9182 | struct lpfc_pc_sli4_params *sli4_params; |
| 9183 | uint32_t mbox_tmo; |
| 9184 | |
| 9185 | rc = 0; |
| 9186 | mqe = &mboxq->u.mqe; |
| 9187 | |
| 9188 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9189 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9190 | if (!phba->sli4_hba.intr_enable) |
| 9191 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9192 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9193 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9194 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9195 | } |
| 9196 | |
| 9197 | if (unlikely(rc)) |
| 9198 | return 1; |
| 9199 | |
| 9200 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9201 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 9202 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 9203 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 9204 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 9205 | &mqe->un.sli4_params); |
| 9206 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 9207 | &mqe->un.sli4_params); |
| 9208 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 9209 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 9210 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 9211 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 9212 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 9213 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 9214 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 9215 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 9216 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 9217 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 9218 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 9219 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 9220 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 9221 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 9222 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 9223 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 9224 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 9225 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 9226 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 9227 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 9228 | 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] | 9229 | |
| 9230 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9231 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9232 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9233 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9234 | return rc; |
| 9235 | } |
| 9236 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9237 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9238 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 9239 | * @phba: Pointer to HBA context object. |
| 9240 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9241 | * |
| 9242 | * This function is called in the SLI4 code path to read the port's |
| 9243 | * sli4 capabilities. |
| 9244 | * |
| 9245 | * This function may be be called from any context that can block-wait |
| 9246 | * for the completion. The expectation is that this routine is called |
| 9247 | * typically from probe_one or from the online routine. |
| 9248 | **/ |
| 9249 | int |
| 9250 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9251 | { |
| 9252 | int rc; |
| 9253 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 9254 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9255 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9256 | int length; |
| 9257 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 9258 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9259 | /* |
| 9260 | * By default, the driver assumes the SLI4 port requires RPI |
| 9261 | * header postings. The SLI4_PARAM response will correct this |
| 9262 | * assumption. |
| 9263 | */ |
| 9264 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 9265 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9266 | /* Read the port's SLI4 Config Parameters */ |
| 9267 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 9268 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9269 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9270 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 9271 | length, LPFC_SLI4_MBX_EMBED); |
| 9272 | if (!phba->sli4_hba.intr_enable) |
| 9273 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9274 | else { |
| 9275 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 9276 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9277 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9278 | if (unlikely(rc)) |
| 9279 | return rc; |
| 9280 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9281 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 9282 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 9283 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 9284 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 9285 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 9286 | mbx_sli4_parameters); |
| 9287 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 9288 | mbx_sli4_parameters); |
| 9289 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 9290 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 9291 | else |
| 9292 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 9293 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 9294 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9295 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9296 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 9297 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 9298 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 9299 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 9300 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9301 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 9302 | mbx_sli4_parameters); |
| 9303 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 9304 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9305 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 9306 | 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] | 9307 | |
| 9308 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9309 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9310 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9311 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9312 | return 0; |
| 9313 | } |
| 9314 | |
| 9315 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9316 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 9317 | * @pdev: pointer to PCI device |
| 9318 | * @pid: pointer to PCI device identifier |
| 9319 | * |
| 9320 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 9321 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9322 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9323 | * information of the device and driver to see if the driver state that it can |
| 9324 | * support this kind of device. If the match is successful, the driver core |
| 9325 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 9326 | * does all the initialization that it needs to do to handle the HBA properly. |
| 9327 | * |
| 9328 | * Return code |
| 9329 | * 0 - driver can claim the device |
| 9330 | * negative value - driver can not claim the device |
| 9331 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9332 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9333 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9334 | { |
| 9335 | struct lpfc_hba *phba; |
| 9336 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9337 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9338 | int error; |
| 9339 | uint32_t cfg_mode, intr_mode; |
| 9340 | |
| 9341 | /* Allocate memory for HBA structure */ |
| 9342 | phba = lpfc_hba_alloc(pdev); |
| 9343 | if (!phba) |
| 9344 | return -ENOMEM; |
| 9345 | |
| 9346 | /* Perform generic PCI device enabling operation */ |
| 9347 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9348 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9349 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9350 | |
| 9351 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 9352 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 9353 | if (error) |
| 9354 | goto out_disable_pci_dev; |
| 9355 | |
| 9356 | /* Set up SLI-3 specific device PCI memory space */ |
| 9357 | error = lpfc_sli_pci_mem_setup(phba); |
| 9358 | if (error) { |
| 9359 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9360 | "1402 Failed to set up pci memory space.\n"); |
| 9361 | goto out_disable_pci_dev; |
| 9362 | } |
| 9363 | |
| 9364 | /* Set up phase-1 common device driver resources */ |
| 9365 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9366 | if (error) { |
| 9367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9368 | "1403 Failed to set up driver resource.\n"); |
| 9369 | goto out_unset_pci_mem_s3; |
| 9370 | } |
| 9371 | |
| 9372 | /* Set up SLI-3 specific device driver resources */ |
| 9373 | error = lpfc_sli_driver_resource_setup(phba); |
| 9374 | if (error) { |
| 9375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9376 | "1404 Failed to set up driver resource.\n"); |
| 9377 | goto out_unset_pci_mem_s3; |
| 9378 | } |
| 9379 | |
| 9380 | /* Initialize and populate the iocb list per host */ |
| 9381 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 9382 | if (error) { |
| 9383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9384 | "1405 Failed to initialize iocb list.\n"); |
| 9385 | goto out_unset_driver_resource_s3; |
| 9386 | } |
| 9387 | |
| 9388 | /* Set up common device driver resources */ |
| 9389 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9390 | if (error) { |
| 9391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9392 | "1406 Failed to set up driver resource.\n"); |
| 9393 | goto out_free_iocb_list; |
| 9394 | } |
| 9395 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9396 | /* Get the default values for Model Name and Description */ |
| 9397 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9398 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9399 | /* Create SCSI host to the physical port */ |
| 9400 | error = lpfc_create_shost(phba); |
| 9401 | if (error) { |
| 9402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9403 | "1407 Failed to create scsi host.\n"); |
| 9404 | goto out_unset_driver_resource; |
| 9405 | } |
| 9406 | |
| 9407 | /* Configure sysfs attributes */ |
| 9408 | vport = phba->pport; |
| 9409 | error = lpfc_alloc_sysfs_attr(vport); |
| 9410 | if (error) { |
| 9411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9412 | "1476 Failed to allocate sysfs attr\n"); |
| 9413 | goto out_destroy_shost; |
| 9414 | } |
| 9415 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9416 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9417 | /* Now, trying to enable interrupt and bring up the device */ |
| 9418 | cfg_mode = phba->cfg_use_msi; |
| 9419 | while (true) { |
| 9420 | /* Put device to a known state before enabling interrupt */ |
| 9421 | lpfc_stop_port(phba); |
| 9422 | /* Configure and enable interrupt */ |
| 9423 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 9424 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9426 | "0431 Failed to enable interrupt.\n"); |
| 9427 | error = -ENODEV; |
| 9428 | goto out_free_sysfs_attr; |
| 9429 | } |
| 9430 | /* SLI-3 HBA setup */ |
| 9431 | if (lpfc_sli_hba_setup(phba)) { |
| 9432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9433 | "1477 Failed to set up hba\n"); |
| 9434 | error = -ENODEV; |
| 9435 | goto out_remove_device; |
| 9436 | } |
| 9437 | |
| 9438 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 9439 | msleep(50); |
| 9440 | /* Check active interrupts on message signaled interrupts */ |
| 9441 | if (intr_mode == 0 || |
| 9442 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 9443 | /* Log the current active interrupt mode */ |
| 9444 | phba->intr_mode = intr_mode; |
| 9445 | lpfc_log_intr_mode(phba, intr_mode); |
| 9446 | break; |
| 9447 | } else { |
| 9448 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9449 | "0447 Configure interrupt mode (%d) " |
| 9450 | "failed active interrupt test.\n", |
| 9451 | intr_mode); |
| 9452 | /* Disable the current interrupt mode */ |
| 9453 | lpfc_sli_disable_intr(phba); |
| 9454 | /* Try next level of interrupt mode */ |
| 9455 | cfg_mode = --intr_mode; |
| 9456 | } |
| 9457 | } |
| 9458 | |
| 9459 | /* Perform post initialization setup */ |
| 9460 | lpfc_post_init_setup(phba); |
| 9461 | |
| 9462 | /* Check if there are static vports to be created. */ |
| 9463 | lpfc_create_static_vport(phba); |
| 9464 | |
| 9465 | return 0; |
| 9466 | |
| 9467 | out_remove_device: |
| 9468 | lpfc_unset_hba(phba); |
| 9469 | out_free_sysfs_attr: |
| 9470 | lpfc_free_sysfs_attr(vport); |
| 9471 | out_destroy_shost: |
| 9472 | lpfc_destroy_shost(phba); |
| 9473 | out_unset_driver_resource: |
| 9474 | lpfc_unset_driver_resource_phase2(phba); |
| 9475 | out_free_iocb_list: |
| 9476 | lpfc_free_iocb_list(phba); |
| 9477 | out_unset_driver_resource_s3: |
| 9478 | lpfc_sli_driver_resource_unset(phba); |
| 9479 | out_unset_pci_mem_s3: |
| 9480 | lpfc_sli_pci_mem_unset(phba); |
| 9481 | out_disable_pci_dev: |
| 9482 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9483 | if (shost) |
| 9484 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9485 | out_free_phba: |
| 9486 | lpfc_hba_free(phba); |
| 9487 | return error; |
| 9488 | } |
| 9489 | |
| 9490 | /** |
| 9491 | * 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] | 9492 | * @pdev: pointer to PCI device |
| 9493 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9494 | * This routine is to be called to disattach a device with SLI-3 interface |
| 9495 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9496 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9497 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9498 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9499 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9500 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9501 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9502 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9503 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9504 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9505 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9506 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9507 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 9508 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9509 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9510 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9511 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9512 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9513 | lpfc_free_sysfs_attr(vport); |
| 9514 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9515 | /* Release all the vports against this physical port */ |
| 9516 | vports = lpfc_create_vport_work_array(phba); |
| 9517 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9518 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9519 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9520 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9521 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9522 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9523 | lpfc_destroy_vport_work_array(phba, vports); |
| 9524 | |
| 9525 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9526 | fc_remove_host(shost); |
| 9527 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 9528 | lpfc_cleanup(vport); |
| 9529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9530 | /* |
| 9531 | * Bring down the SLI Layer. This step disable all interrupts, |
| 9532 | * clears the rings, discards all mailbox commands, and resets |
| 9533 | * the HBA. |
| 9534 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9535 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 9536 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9537 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9538 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9539 | kthread_stop(phba->worker_thread); |
| 9540 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9541 | lpfc_sli_brdrestart(phba); |
| 9542 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9543 | kfree(phba->vpi_bmask); |
| 9544 | kfree(phba->vpi_ids); |
| 9545 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9546 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9547 | spin_lock_irq(&phba->hbalock); |
| 9548 | list_del_init(&vport->listentry); |
| 9549 | spin_unlock_irq(&phba->hbalock); |
| 9550 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9551 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9552 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9553 | /* Disable SR-IOV if enabled */ |
| 9554 | if (phba->cfg_sriov_nr_virtfn) |
| 9555 | pci_disable_sriov(pdev); |
| 9556 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9557 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9558 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9559 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9560 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9561 | |
| 9562 | /* |
| 9563 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 9564 | * corresponding pools here. |
| 9565 | */ |
| 9566 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9567 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9568 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9569 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9570 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9572 | /* Free resources associated with SLI2 interface */ |
| 9573 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9574 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9575 | |
| 9576 | /* unmap adapter SLIM and Control Registers */ |
| 9577 | iounmap(phba->ctrl_regs_memmap_p); |
| 9578 | iounmap(phba->slim_memmap_p); |
| 9579 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9580 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9581 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9582 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9583 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9584 | } |
| 9585 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9586 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9587 | * 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] | 9588 | * @pdev: pointer to PCI device |
| 9589 | * @msg: power management message |
| 9590 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9591 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9592 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 9593 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 9594 | * worker thread for the device, turning off device's interrupt and DMA, |
| 9595 | * and bring the device offline. Note that as the driver implements the |
| 9596 | * minimum PM requirements to a power-aware driver's PM support for the |
| 9597 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9598 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 9599 | * fully reinitialize its device during resume() method call, the driver will |
| 9600 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 9601 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9602 | * |
| 9603 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9604 | * 0 - driver suspended the device |
| 9605 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9606 | **/ |
| 9607 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9608 | 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] | 9609 | { |
| 9610 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9611 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9612 | |
| 9613 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9614 | "0473 PCI device Power Management suspend.\n"); |
| 9615 | |
| 9616 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9617 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9618 | lpfc_offline(phba); |
| 9619 | kthread_stop(phba->worker_thread); |
| 9620 | |
| 9621 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9622 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9623 | |
| 9624 | /* Save device state to PCI config space */ |
| 9625 | pci_save_state(pdev); |
| 9626 | pci_set_power_state(pdev, PCI_D3hot); |
| 9627 | |
| 9628 | return 0; |
| 9629 | } |
| 9630 | |
| 9631 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9632 | * 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] | 9633 | * @pdev: pointer to PCI device |
| 9634 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9635 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9636 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9637 | * invokes this method, it restores the device's PCI config space state and |
| 9638 | * fully reinitializes the device and brings it online. Note that as the |
| 9639 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9640 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9641 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9642 | * driver will fully reinitialize its device during resume() method call, |
| 9643 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9644 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9645 | * |
| 9646 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9647 | * 0 - driver suspended the device |
| 9648 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9649 | **/ |
| 9650 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9651 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9652 | { |
| 9653 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9654 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9655 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9656 | int error; |
| 9657 | |
| 9658 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9659 | "0452 PCI device Power Management resume.\n"); |
| 9660 | |
| 9661 | /* Restore device state from PCI config space */ |
| 9662 | pci_set_power_state(pdev, PCI_D0); |
| 9663 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9664 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9665 | /* |
| 9666 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9667 | * device saved_state flag, need to save the restored state again. |
| 9668 | */ |
| 9669 | pci_save_state(pdev); |
| 9670 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9671 | if (pdev->is_busmaster) |
| 9672 | pci_set_master(pdev); |
| 9673 | |
| 9674 | /* Startup the kernel thread for this host adapter. */ |
| 9675 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9676 | "lpfc_worker_%d", phba->brd_no); |
| 9677 | if (IS_ERR(phba->worker_thread)) { |
| 9678 | error = PTR_ERR(phba->worker_thread); |
| 9679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9680 | "0434 PM resume failed to start worker " |
| 9681 | "thread: error=x%x.\n", error); |
| 9682 | return error; |
| 9683 | } |
| 9684 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9685 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9686 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9687 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9688 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9689 | "0430 PM resume Failed to enable interrupt\n"); |
| 9690 | return -EIO; |
| 9691 | } else |
| 9692 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9693 | |
| 9694 | /* Restart HBA and bring it online */ |
| 9695 | lpfc_sli_brdrestart(phba); |
| 9696 | lpfc_online(phba); |
| 9697 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9698 | /* Log the current active interrupt mode */ |
| 9699 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9700 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9701 | return 0; |
| 9702 | } |
| 9703 | |
| 9704 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9705 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9706 | * @phba: pointer to lpfc hba data structure. |
| 9707 | * |
| 9708 | * 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] | 9709 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9710 | **/ |
| 9711 | static void |
| 9712 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9713 | { |
| 9714 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9715 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9716 | |
| 9717 | /* |
| 9718 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9719 | * and let the SCSI mid-layer to retry them to recover. |
| 9720 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 9721 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9722 | } |
| 9723 | |
| 9724 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9725 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9726 | * @phba: pointer to lpfc hba data structure. |
| 9727 | * |
| 9728 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9729 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9730 | * pending I/Os. |
| 9731 | **/ |
| 9732 | static void |
| 9733 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9734 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9736 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9737 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9738 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9739 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9740 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9741 | /* Block all SCSI devices' I/Os on the host */ |
| 9742 | lpfc_scsi_dev_block(phba); |
| 9743 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 9744 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9745 | lpfc_sli_flush_fcp_rings(phba); |
| 9746 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9747 | /* stop all timers */ |
| 9748 | lpfc_stop_hba_timers(phba); |
| 9749 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9750 | /* Disable interrupt and pci device */ |
| 9751 | lpfc_sli_disable_intr(phba); |
| 9752 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9753 | } |
| 9754 | |
| 9755 | /** |
| 9756 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9757 | * @phba: pointer to lpfc hba data structure. |
| 9758 | * |
| 9759 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9760 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9761 | * pending I/Os. |
| 9762 | **/ |
| 9763 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9764 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9765 | { |
| 9766 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9767 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9768 | /* Block all SCSI devices' I/Os on the host */ |
| 9769 | lpfc_scsi_dev_block(phba); |
| 9770 | |
| 9771 | /* stop all timers */ |
| 9772 | lpfc_stop_hba_timers(phba); |
| 9773 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9774 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9775 | lpfc_sli_flush_fcp_rings(phba); |
| 9776 | } |
| 9777 | |
| 9778 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9779 | * 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] | 9780 | * @pdev: pointer to PCI device. |
| 9781 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9782 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9783 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9784 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9785 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9786 | * When this function is invoked, it will need to stop all the I/Os and |
| 9787 | * interrupt(s) to the device. Once that is done, it will return |
| 9788 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9789 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9790 | * |
| 9791 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9792 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9793 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9794 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9795 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9796 | static pci_ers_result_t |
| 9797 | 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] | 9798 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9799 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9800 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9801 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9802 | switch (state) { |
| 9803 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9804 | /* Non-fatal error, prepare for recovery */ |
| 9805 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9806 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9807 | case pci_channel_io_frozen: |
| 9808 | /* Fatal error, prepare for slot reset */ |
| 9809 | lpfc_sli_prep_dev_for_reset(phba); |
| 9810 | return PCI_ERS_RESULT_NEED_RESET; |
| 9811 | case pci_channel_io_perm_failure: |
| 9812 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9813 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9814 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9815 | default: |
| 9816 | /* Unknown state, prepare and request slot reset */ |
| 9817 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9818 | "0472 Unknown PCI error state: x%x\n", state); |
| 9819 | lpfc_sli_prep_dev_for_reset(phba); |
| 9820 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9821 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9822 | } |
| 9823 | |
| 9824 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9825 | * 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] | 9826 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9827 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9828 | * This routine is called from the PCI subsystem for error handling to |
| 9829 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9830 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9831 | * During the PCI subsystem error recovery, after driver returns |
| 9832 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9833 | * recovery and then call this routine before calling the .resume method |
| 9834 | * to recover the device. This function will initialize the HBA device, |
| 9835 | * enable the interrupt, but it will just put the HBA to offline state |
| 9836 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9837 | * |
| 9838 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9839 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9840 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9841 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9842 | static pci_ers_result_t |
| 9843 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9844 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9845 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9846 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9847 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9848 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9849 | |
| 9850 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9851 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9852 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9853 | "PCI device after reset.\n"); |
| 9854 | return PCI_ERS_RESULT_DISCONNECT; |
| 9855 | } |
| 9856 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9857 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9858 | |
| 9859 | /* |
| 9860 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9861 | * device saved_state flag, need to save the restored state again. |
| 9862 | */ |
| 9863 | pci_save_state(pdev); |
| 9864 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9865 | if (pdev->is_busmaster) |
| 9866 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9867 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9868 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9869 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9870 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9871 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9872 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9873 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9874 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9875 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9876 | "0427 Cannot re-enable interrupt after " |
| 9877 | "slot reset.\n"); |
| 9878 | return PCI_ERS_RESULT_DISCONNECT; |
| 9879 | } else |
| 9880 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9881 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9882 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9883 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9884 | lpfc_offline(phba); |
| 9885 | lpfc_sli_brdrestart(phba); |
| 9886 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9887 | /* Log the current active interrupt mode */ |
| 9888 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9889 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9890 | return PCI_ERS_RESULT_RECOVERED; |
| 9891 | } |
| 9892 | |
| 9893 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9894 | * 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] | 9895 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9896 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9897 | * This routine is called from the PCI subsystem for error handling to device |
| 9898 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9899 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9900 | * error recovery. After this call, traffic can start to flow from this device |
| 9901 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9902 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9903 | static void |
| 9904 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9905 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9906 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9907 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9908 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9909 | /* 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] | 9910 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9911 | |
| 9912 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9913 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9914 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9915 | } |
| 9916 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9917 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9918 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9919 | * @phba: pointer to lpfc hba data structure. |
| 9920 | * |
| 9921 | * returns the number of ELS/CT IOCBs to reserve |
| 9922 | **/ |
| 9923 | int |
| 9924 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9925 | { |
| 9926 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9927 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9928 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9929 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9930 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9931 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9932 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9933 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9934 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9935 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9936 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9937 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9938 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9939 | else if (max_xri <= 2048) |
| 9940 | return 200; |
| 9941 | else |
| 9942 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9943 | } else |
| 9944 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9948 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9949 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9950 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9951 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9952 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9953 | static void |
| 9954 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9955 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9956 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9957 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9958 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9959 | struct list_head dma_buffer_list; |
| 9960 | int i, rc = 0; |
| 9961 | struct lpfc_dmabuf *dmabuf, *next; |
| 9962 | uint32_t offset = 0, temp_offset = 0; |
| 9963 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9964 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9965 | if (!fw) { |
| 9966 | rc = -ENXIO; |
| 9967 | goto out; |
| 9968 | } |
| 9969 | image = (struct lpfc_grp_hdr *)fw->data; |
| 9970 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9971 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9972 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9973 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9974 | LPFC_FILE_TYPE_GROUP) || |
| 9975 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9976 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9978 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9979 | "Magic:%x Type:%x ID:%x\n", |
| 9980 | be32_to_cpu(image->magic_number), |
| 9981 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9982 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9983 | rc = -EINVAL; |
| 9984 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9985 | } |
| 9986 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9987 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9989 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9990 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9991 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9992 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9993 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9994 | GFP_KERNEL); |
| 9995 | if (!dmabuf) { |
| 9996 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9997 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9998 | } |
| 9999 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 10000 | SLI4_PAGE_SIZE, |
| 10001 | &dmabuf->phys, |
| 10002 | GFP_KERNEL); |
| 10003 | if (!dmabuf->virt) { |
| 10004 | kfree(dmabuf); |
| 10005 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10006 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10007 | } |
| 10008 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 10009 | } |
| 10010 | while (offset < fw->size) { |
| 10011 | temp_offset = offset; |
| 10012 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10013 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10014 | memcpy(dmabuf->virt, |
| 10015 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10016 | fw->size - temp_offset); |
| 10017 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10018 | break; |
| 10019 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10020 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 10021 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 10022 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10023 | } |
| 10024 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 10025 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10026 | if (rc) |
| 10027 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10028 | } |
| 10029 | rc = offset; |
| 10030 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10031 | |
| 10032 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10033 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 10034 | list_del(&dmabuf->list); |
| 10035 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 10036 | dmabuf->virt, dmabuf->phys); |
| 10037 | kfree(dmabuf); |
| 10038 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10039 | release_firmware(fw); |
| 10040 | out: |
| 10041 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10042 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10043 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10044 | } |
| 10045 | |
| 10046 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10047 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 10048 | * @phba: pointer to lpfc hba data structure. |
| 10049 | * |
| 10050 | * This routine is called to perform Linux generic firmware upgrade on device |
| 10051 | * that supports such feature. |
| 10052 | **/ |
| 10053 | int |
| 10054 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 10055 | { |
| 10056 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 10057 | int ret; |
| 10058 | const struct firmware *fw; |
| 10059 | |
| 10060 | /* Only supported on SLI4 interface type 2 for now */ |
| 10061 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 10062 | LPFC_SLI_INTF_IF_TYPE_2) |
| 10063 | return -EPERM; |
| 10064 | |
| 10065 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 10066 | |
| 10067 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 10068 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 10069 | file_name, &phba->pcidev->dev, |
| 10070 | GFP_KERNEL, (void *)phba, |
| 10071 | lpfc_write_firmware); |
| 10072 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 10073 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 10074 | if (!ret) |
| 10075 | lpfc_write_firmware(fw, (void *)phba); |
| 10076 | } else { |
| 10077 | ret = -EINVAL; |
| 10078 | } |
| 10079 | |
| 10080 | return ret; |
| 10081 | } |
| 10082 | |
| 10083 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10084 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 10085 | * @pdev: pointer to PCI device |
| 10086 | * @pid: pointer to PCI device identifier |
| 10087 | * |
| 10088 | * This routine is called from the kernel's PCI subsystem to device with |
| 10089 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10090 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 10091 | * information of the device and driver to see if the driver state that it |
| 10092 | * can support this kind of device. If the match is successful, the driver |
| 10093 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 10094 | * it does all the initialization that it needs to do to handle the HBA |
| 10095 | * properly. |
| 10096 | * |
| 10097 | * Return code |
| 10098 | * 0 - driver can claim the device |
| 10099 | * negative value - driver can not claim the device |
| 10100 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10101 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10102 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10103 | { |
| 10104 | struct lpfc_hba *phba; |
| 10105 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10106 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 10107 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10108 | uint32_t cfg_mode, intr_mode; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10109 | int adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10110 | |
| 10111 | /* Allocate memory for HBA structure */ |
| 10112 | phba = lpfc_hba_alloc(pdev); |
| 10113 | if (!phba) |
| 10114 | return -ENOMEM; |
| 10115 | |
| 10116 | /* Perform generic PCI device enabling operation */ |
| 10117 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10118 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10119 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10120 | |
| 10121 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 10122 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 10123 | if (error) |
| 10124 | goto out_disable_pci_dev; |
| 10125 | |
| 10126 | /* Set up SLI-4 specific device PCI memory space */ |
| 10127 | error = lpfc_sli4_pci_mem_setup(phba); |
| 10128 | if (error) { |
| 10129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10130 | "1410 Failed to set up pci memory space.\n"); |
| 10131 | goto out_disable_pci_dev; |
| 10132 | } |
| 10133 | |
| 10134 | /* Set up phase-1 common device driver resources */ |
| 10135 | error = lpfc_setup_driver_resource_phase1(phba); |
| 10136 | if (error) { |
| 10137 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10138 | "1411 Failed to set up driver resource.\n"); |
| 10139 | goto out_unset_pci_mem_s4; |
| 10140 | } |
| 10141 | |
| 10142 | /* Set up SLI-4 Specific device driver resources */ |
| 10143 | error = lpfc_sli4_driver_resource_setup(phba); |
| 10144 | if (error) { |
| 10145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10146 | "1412 Failed to set up driver resource.\n"); |
| 10147 | goto out_unset_pci_mem_s4; |
| 10148 | } |
| 10149 | |
| 10150 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10151 | |
| 10152 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10153 | "2821 initialize iocb list %d.\n", |
| 10154 | phba->cfg_iocb_cnt*1024); |
| 10155 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 10156 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10157 | if (error) { |
| 10158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10159 | "1413 Failed to initialize iocb list.\n"); |
| 10160 | goto out_unset_driver_resource_s4; |
| 10161 | } |
| 10162 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10163 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 10164 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10165 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10166 | /* Set up common device driver resources */ |
| 10167 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10168 | if (error) { |
| 10169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10170 | "1414 Failed to set up driver resource.\n"); |
| 10171 | goto out_free_iocb_list; |
| 10172 | } |
| 10173 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10174 | /* Get the default values for Model Name and Description */ |
| 10175 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10176 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10177 | /* Create SCSI host to the physical port */ |
| 10178 | error = lpfc_create_shost(phba); |
| 10179 | if (error) { |
| 10180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10181 | "1415 Failed to create scsi host.\n"); |
| 10182 | goto out_unset_driver_resource; |
| 10183 | } |
| 10184 | |
| 10185 | /* Configure sysfs attributes */ |
| 10186 | vport = phba->pport; |
| 10187 | error = lpfc_alloc_sysfs_attr(vport); |
| 10188 | if (error) { |
| 10189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10190 | "1416 Failed to allocate sysfs attr\n"); |
| 10191 | goto out_destroy_shost; |
| 10192 | } |
| 10193 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10194 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10195 | /* Now, trying to enable interrupt and bring up the device */ |
| 10196 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10197 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10198 | /* Put device to a known state before enabling interrupt */ |
| 10199 | lpfc_stop_port(phba); |
| 10200 | /* Configure and enable interrupt */ |
| 10201 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 10202 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10203 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10204 | "0426 Failed to enable interrupt.\n"); |
| 10205 | error = -ENODEV; |
| 10206 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10207 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10208 | /* Default to single EQ for non-MSI-X */ |
| 10209 | if (phba->intr_type != MSIX) |
| 10210 | adjusted_fcp_io_channel = 1; |
| 10211 | else |
| 10212 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 10213 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
| 10214 | /* Set up SLI-4 HBA */ |
| 10215 | if (lpfc_sli4_hba_setup(phba)) { |
| 10216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10217 | "1421 Failed to set up hba\n"); |
| 10218 | error = -ENODEV; |
| 10219 | goto out_disable_intr; |
| 10220 | } |
| 10221 | |
| 10222 | /* Log the current active interrupt mode */ |
| 10223 | phba->intr_mode = intr_mode; |
| 10224 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10225 | |
| 10226 | /* Perform post initialization setup */ |
| 10227 | lpfc_post_init_setup(phba); |
| 10228 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10229 | /* check for firmware upgrade or downgrade */ |
| 10230 | if (phba->cfg_request_firmware_upgrade) |
| 10231 | ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10232 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 10233 | /* Check if there are static vports to be created. */ |
| 10234 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10235 | return 0; |
| 10236 | |
| 10237 | out_disable_intr: |
| 10238 | lpfc_sli4_disable_intr(phba); |
| 10239 | out_free_sysfs_attr: |
| 10240 | lpfc_free_sysfs_attr(vport); |
| 10241 | out_destroy_shost: |
| 10242 | lpfc_destroy_shost(phba); |
| 10243 | out_unset_driver_resource: |
| 10244 | lpfc_unset_driver_resource_phase2(phba); |
| 10245 | out_free_iocb_list: |
| 10246 | lpfc_free_iocb_list(phba); |
| 10247 | out_unset_driver_resource_s4: |
| 10248 | lpfc_sli4_driver_resource_unset(phba); |
| 10249 | out_unset_pci_mem_s4: |
| 10250 | lpfc_sli4_pci_mem_unset(phba); |
| 10251 | out_disable_pci_dev: |
| 10252 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10253 | if (shost) |
| 10254 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10255 | out_free_phba: |
| 10256 | lpfc_hba_free(phba); |
| 10257 | return error; |
| 10258 | } |
| 10259 | |
| 10260 | /** |
| 10261 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 10262 | * @pdev: pointer to PCI device |
| 10263 | * |
| 10264 | * This routine is called from the kernel's PCI subsystem to device with |
| 10265 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10266 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10267 | * device to be removed from the PCI subsystem properly. |
| 10268 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10269 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10270 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 10271 | { |
| 10272 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10273 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 10274 | struct lpfc_vport **vports; |
| 10275 | struct lpfc_hba *phba = vport->phba; |
| 10276 | int i; |
| 10277 | |
| 10278 | /* Mark the device unloading flag */ |
| 10279 | spin_lock_irq(&phba->hbalock); |
| 10280 | vport->load_flag |= FC_UNLOADING; |
| 10281 | spin_unlock_irq(&phba->hbalock); |
| 10282 | |
| 10283 | /* Free the HBA sysfs attributes */ |
| 10284 | lpfc_free_sysfs_attr(vport); |
| 10285 | |
| 10286 | /* Release all the vports against this physical port */ |
| 10287 | vports = lpfc_create_vport_work_array(phba); |
| 10288 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10289 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10290 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10291 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10292 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10293 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10294 | lpfc_destroy_vport_work_array(phba, vports); |
| 10295 | |
| 10296 | /* Remove FC host and then SCSI host with the physical port */ |
| 10297 | fc_remove_host(shost); |
| 10298 | scsi_remove_host(shost); |
| 10299 | |
| 10300 | /* Perform cleanup on the physical port */ |
| 10301 | lpfc_cleanup(vport); |
| 10302 | |
| 10303 | /* |
| 10304 | * Bring down the SLI Layer. This step disables all interrupts, |
| 10305 | * clears the rings, discards all mailbox commands, and resets |
| 10306 | * the HBA FCoE function. |
| 10307 | */ |
| 10308 | lpfc_debugfs_terminate(vport); |
| 10309 | lpfc_sli4_hba_unset(phba); |
| 10310 | |
| 10311 | spin_lock_irq(&phba->hbalock); |
| 10312 | list_del_init(&vport->listentry); |
| 10313 | spin_unlock_irq(&phba->hbalock); |
| 10314 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10315 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10316 | * buffers are released to their corresponding pools here. |
| 10317 | */ |
| 10318 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10319 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10320 | lpfc_sli4_driver_resource_unset(phba); |
| 10321 | |
| 10322 | /* Unmap adapter Control and Doorbell registers */ |
| 10323 | lpfc_sli4_pci_mem_unset(phba); |
| 10324 | |
| 10325 | /* Release PCI resources and disable device's PCI function */ |
| 10326 | scsi_host_put(shost); |
| 10327 | lpfc_disable_pci_dev(phba); |
| 10328 | |
| 10329 | /* Finally, free the driver's device data structure */ |
| 10330 | lpfc_hba_free(phba); |
| 10331 | |
| 10332 | return; |
| 10333 | } |
| 10334 | |
| 10335 | /** |
| 10336 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 10337 | * @pdev: pointer to PCI device |
| 10338 | * @msg: power management message |
| 10339 | * |
| 10340 | * This routine is called from the kernel's PCI subsystem to support system |
| 10341 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 10342 | * this method, it quiesces the device by stopping the driver's worker |
| 10343 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 10344 | * the device offline. Note that as the driver implements the minimum PM |
| 10345 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 10346 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 10347 | * method call will be treated as SUSPEND and the driver will fully |
| 10348 | * reinitialize its device during resume() method call, the driver will set |
| 10349 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 10350 | * according to the @msg provided by the PM. |
| 10351 | * |
| 10352 | * Return code |
| 10353 | * 0 - driver suspended the device |
| 10354 | * Error otherwise |
| 10355 | **/ |
| 10356 | static int |
| 10357 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 10358 | { |
| 10359 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10360 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10361 | |
| 10362 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10363 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10364 | |
| 10365 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10366 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10367 | lpfc_offline(phba); |
| 10368 | kthread_stop(phba->worker_thread); |
| 10369 | |
| 10370 | /* Disable interrupt from device */ |
| 10371 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10372 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10373 | |
| 10374 | /* Save device state to PCI config space */ |
| 10375 | pci_save_state(pdev); |
| 10376 | pci_set_power_state(pdev, PCI_D3hot); |
| 10377 | |
| 10378 | return 0; |
| 10379 | } |
| 10380 | |
| 10381 | /** |
| 10382 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 10383 | * @pdev: pointer to PCI device |
| 10384 | * |
| 10385 | * This routine is called from the kernel's PCI subsystem to support system |
| 10386 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 10387 | * this method, it restores the device's PCI config space state and fully |
| 10388 | * reinitializes the device and brings it online. Note that as the driver |
| 10389 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 10390 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 10391 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 10392 | * will fully reinitialize its device during resume() method call, the device |
| 10393 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 10394 | * state. |
| 10395 | * |
| 10396 | * Return code |
| 10397 | * 0 - driver suspended the device |
| 10398 | * Error otherwise |
| 10399 | **/ |
| 10400 | static int |
| 10401 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 10402 | { |
| 10403 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10404 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10405 | uint32_t intr_mode; |
| 10406 | int error; |
| 10407 | |
| 10408 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10409 | "0292 PCI device Power Management resume.\n"); |
| 10410 | |
| 10411 | /* Restore device state from PCI config space */ |
| 10412 | pci_set_power_state(pdev, PCI_D0); |
| 10413 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10414 | |
| 10415 | /* |
| 10416 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10417 | * device saved_state flag, need to save the restored state again. |
| 10418 | */ |
| 10419 | pci_save_state(pdev); |
| 10420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10421 | if (pdev->is_busmaster) |
| 10422 | pci_set_master(pdev); |
| 10423 | |
| 10424 | /* Startup the kernel thread for this host adapter. */ |
| 10425 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 10426 | "lpfc_worker_%d", phba->brd_no); |
| 10427 | if (IS_ERR(phba->worker_thread)) { |
| 10428 | error = PTR_ERR(phba->worker_thread); |
| 10429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10430 | "0293 PM resume failed to start worker " |
| 10431 | "thread: error=x%x.\n", error); |
| 10432 | return error; |
| 10433 | } |
| 10434 | |
| 10435 | /* Configure and enable interrupt */ |
| 10436 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10437 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10438 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10439 | "0294 PM resume Failed to enable interrupt\n"); |
| 10440 | return -EIO; |
| 10441 | } else |
| 10442 | phba->intr_mode = intr_mode; |
| 10443 | |
| 10444 | /* Restart HBA and bring it online */ |
| 10445 | lpfc_sli_brdrestart(phba); |
| 10446 | lpfc_online(phba); |
| 10447 | |
| 10448 | /* Log the current active interrupt mode */ |
| 10449 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10450 | |
| 10451 | return 0; |
| 10452 | } |
| 10453 | |
| 10454 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10455 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 10456 | * @phba: pointer to lpfc hba data structure. |
| 10457 | * |
| 10458 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 10459 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 10460 | **/ |
| 10461 | static void |
| 10462 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10463 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10465 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 10466 | /* |
| 10467 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10468 | * and let the SCSI mid-layer to retry them to recover. |
| 10469 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10470 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10471 | } |
| 10472 | |
| 10473 | /** |
| 10474 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 10475 | * @phba: pointer to lpfc hba data structure. |
| 10476 | * |
| 10477 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 10478 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10479 | * pending I/Os. |
| 10480 | **/ |
| 10481 | static void |
| 10482 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10483 | { |
| 10484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10485 | "2826 PCI channel disable preparing for reset\n"); |
| 10486 | |
| 10487 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10488 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10489 | |
| 10490 | /* Block all SCSI devices' I/Os on the host */ |
| 10491 | lpfc_scsi_dev_block(phba); |
| 10492 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10493 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10494 | lpfc_sli_flush_fcp_rings(phba); |
| 10495 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10496 | /* stop all timers */ |
| 10497 | lpfc_stop_hba_timers(phba); |
| 10498 | |
| 10499 | /* Disable interrupt and pci device */ |
| 10500 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10501 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10502 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10503 | } |
| 10504 | |
| 10505 | /** |
| 10506 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 10507 | * @phba: pointer to lpfc hba data structure. |
| 10508 | * |
| 10509 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 10510 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10511 | * pending I/Os. |
| 10512 | **/ |
| 10513 | static void |
| 10514 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 10515 | { |
| 10516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10517 | "2827 PCI channel permanent disable for failure\n"); |
| 10518 | |
| 10519 | /* Block all SCSI devices' I/Os on the host */ |
| 10520 | lpfc_scsi_dev_block(phba); |
| 10521 | |
| 10522 | /* stop all timers */ |
| 10523 | lpfc_stop_hba_timers(phba); |
| 10524 | |
| 10525 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10526 | lpfc_sli_flush_fcp_rings(phba); |
| 10527 | } |
| 10528 | |
| 10529 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10530 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 10531 | * @pdev: pointer to PCI device. |
| 10532 | * @state: the current PCI connection state. |
| 10533 | * |
| 10534 | * This routine is called from the PCI subsystem for error handling to device |
| 10535 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 10536 | * after a PCI bus error affecting this device has been detected. When this |
| 10537 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 10538 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 10539 | * for the PCI subsystem to perform proper recovery as desired. |
| 10540 | * |
| 10541 | * Return codes |
| 10542 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10543 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10544 | **/ |
| 10545 | static pci_ers_result_t |
| 10546 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 10547 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10548 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10549 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10550 | |
| 10551 | switch (state) { |
| 10552 | case pci_channel_io_normal: |
| 10553 | /* Non-fatal error, prepare for recovery */ |
| 10554 | lpfc_sli4_prep_dev_for_recover(phba); |
| 10555 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10556 | case pci_channel_io_frozen: |
| 10557 | /* Fatal error, prepare for slot reset */ |
| 10558 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10559 | return PCI_ERS_RESULT_NEED_RESET; |
| 10560 | case pci_channel_io_perm_failure: |
| 10561 | /* Permanent failure, prepare for device down */ |
| 10562 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 10563 | return PCI_ERS_RESULT_DISCONNECT; |
| 10564 | default: |
| 10565 | /* Unknown state, prepare and request slot reset */ |
| 10566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10567 | "2825 Unknown PCI error state: x%x\n", state); |
| 10568 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10569 | return PCI_ERS_RESULT_NEED_RESET; |
| 10570 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10571 | } |
| 10572 | |
| 10573 | /** |
| 10574 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 10575 | * @pdev: pointer to PCI device. |
| 10576 | * |
| 10577 | * This routine is called from the PCI subsystem for error handling to device |
| 10578 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 10579 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 10580 | * PCI subsystem error recovery, after the driver returns |
| 10581 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10582 | * recovery and then call this routine before calling the .resume method to |
| 10583 | * recover the device. This function will initialize the HBA device, enable |
| 10584 | * the interrupt, but it will just put the HBA to offline state without |
| 10585 | * passing any I/O traffic. |
| 10586 | * |
| 10587 | * Return codes |
| 10588 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10589 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10590 | */ |
| 10591 | static pci_ers_result_t |
| 10592 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 10593 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10594 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10595 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10596 | struct lpfc_sli *psli = &phba->sli; |
| 10597 | uint32_t intr_mode; |
| 10598 | |
| 10599 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 10600 | if (pci_enable_device_mem(pdev)) { |
| 10601 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10602 | "PCI device after reset.\n"); |
| 10603 | return PCI_ERS_RESULT_DISCONNECT; |
| 10604 | } |
| 10605 | |
| 10606 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 10607 | |
| 10608 | /* |
| 10609 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10610 | * device saved_state flag, need to save the restored state again. |
| 10611 | */ |
| 10612 | pci_save_state(pdev); |
| 10613 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10614 | if (pdev->is_busmaster) |
| 10615 | pci_set_master(pdev); |
| 10616 | |
| 10617 | spin_lock_irq(&phba->hbalock); |
| 10618 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 10619 | spin_unlock_irq(&phba->hbalock); |
| 10620 | |
| 10621 | /* Configure and enable interrupt */ |
| 10622 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10623 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10624 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10625 | "2824 Cannot re-enable interrupt after " |
| 10626 | "slot reset.\n"); |
| 10627 | return PCI_ERS_RESULT_DISCONNECT; |
| 10628 | } else |
| 10629 | phba->intr_mode = intr_mode; |
| 10630 | |
| 10631 | /* Log the current active interrupt mode */ |
| 10632 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10633 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10634 | return PCI_ERS_RESULT_RECOVERED; |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10639 | * @pdev: pointer to PCI device |
| 10640 | * |
| 10641 | * This routine is called from the PCI subsystem for error handling to device |
| 10642 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10643 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10644 | * error recovery. After this call, traffic can start to flow from this device |
| 10645 | * again. |
| 10646 | **/ |
| 10647 | static void |
| 10648 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10649 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10650 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10651 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10652 | |
| 10653 | /* |
| 10654 | * In case of slot reset, as function reset is performed through |
| 10655 | * mailbox command which needs DMA to be enabled, this operation |
| 10656 | * has to be moved to the io resume phase. Taking device offline |
| 10657 | * will perform the necessary cleanup. |
| 10658 | */ |
| 10659 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10660 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10661 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10662 | lpfc_offline(phba); |
| 10663 | lpfc_sli_brdrestart(phba); |
| 10664 | /* Bring the device back online */ |
| 10665 | lpfc_online(phba); |
| 10666 | } |
| 10667 | |
| 10668 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10669 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10670 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10671 | } |
| 10672 | |
| 10673 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10674 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10675 | * @pdev: pointer to PCI device |
| 10676 | * @pid: pointer to PCI device identifier |
| 10677 | * |
| 10678 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10679 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10680 | * at PCI device-specific information of the device and driver to see if the |
| 10681 | * driver state that it can support this kind of device. If the match is |
| 10682 | * successful, the driver core invokes this routine. This routine dispatches |
| 10683 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10684 | * do all the initialization that it needs to do to handle the HBA device |
| 10685 | * properly. |
| 10686 | * |
| 10687 | * Return code |
| 10688 | * 0 - driver can claim the device |
| 10689 | * negative value - driver can not claim the device |
| 10690 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10691 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10692 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10693 | { |
| 10694 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10695 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10696 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10697 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10698 | return -ENODEV; |
| 10699 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10700 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10701 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10702 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10703 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10704 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10705 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10706 | return rc; |
| 10707 | } |
| 10708 | |
| 10709 | /** |
| 10710 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10711 | * @pdev: pointer to PCI device |
| 10712 | * |
| 10713 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10714 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10715 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10716 | * remove routine, which will perform all the necessary cleanup for the |
| 10717 | * device to be removed from the PCI subsystem properly. |
| 10718 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10719 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10720 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10721 | { |
| 10722 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10723 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10724 | |
| 10725 | switch (phba->pci_dev_grp) { |
| 10726 | case LPFC_PCI_DEV_LP: |
| 10727 | lpfc_pci_remove_one_s3(pdev); |
| 10728 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10729 | case LPFC_PCI_DEV_OC: |
| 10730 | lpfc_pci_remove_one_s4(pdev); |
| 10731 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10732 | default: |
| 10733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10734 | "1424 Invalid PCI device group: 0x%x\n", |
| 10735 | phba->pci_dev_grp); |
| 10736 | break; |
| 10737 | } |
| 10738 | return; |
| 10739 | } |
| 10740 | |
| 10741 | /** |
| 10742 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10743 | * @pdev: pointer to PCI device |
| 10744 | * @msg: power management message |
| 10745 | * |
| 10746 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10747 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10748 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10749 | * suspend the device. |
| 10750 | * |
| 10751 | * Return code |
| 10752 | * 0 - driver suspended the device |
| 10753 | * Error otherwise |
| 10754 | **/ |
| 10755 | static int |
| 10756 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10757 | { |
| 10758 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10759 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10760 | int rc = -ENODEV; |
| 10761 | |
| 10762 | switch (phba->pci_dev_grp) { |
| 10763 | case LPFC_PCI_DEV_LP: |
| 10764 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10765 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10766 | case LPFC_PCI_DEV_OC: |
| 10767 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10768 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10769 | default: |
| 10770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10771 | "1425 Invalid PCI device group: 0x%x\n", |
| 10772 | phba->pci_dev_grp); |
| 10773 | break; |
| 10774 | } |
| 10775 | return rc; |
| 10776 | } |
| 10777 | |
| 10778 | /** |
| 10779 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10780 | * @pdev: pointer to PCI device |
| 10781 | * |
| 10782 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10783 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10784 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10785 | * resume the device. |
| 10786 | * |
| 10787 | * Return code |
| 10788 | * 0 - driver suspended the device |
| 10789 | * Error otherwise |
| 10790 | **/ |
| 10791 | static int |
| 10792 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10793 | { |
| 10794 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10795 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10796 | int rc = -ENODEV; |
| 10797 | |
| 10798 | switch (phba->pci_dev_grp) { |
| 10799 | case LPFC_PCI_DEV_LP: |
| 10800 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10801 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10802 | case LPFC_PCI_DEV_OC: |
| 10803 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10804 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10805 | default: |
| 10806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10807 | "1426 Invalid PCI device group: 0x%x\n", |
| 10808 | phba->pci_dev_grp); |
| 10809 | break; |
| 10810 | } |
| 10811 | return rc; |
| 10812 | } |
| 10813 | |
| 10814 | /** |
| 10815 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10816 | * @pdev: pointer to PCI device. |
| 10817 | * @state: the current PCI connection state. |
| 10818 | * |
| 10819 | * This routine is registered to the PCI subsystem for error handling. This |
| 10820 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10821 | * this device has been detected. When this routine is invoked, it dispatches |
| 10822 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 10823 | * routine, which will perform the proper error detected operation. |
| 10824 | * |
| 10825 | * Return codes |
| 10826 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10827 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10828 | **/ |
| 10829 | static pci_ers_result_t |
| 10830 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 10831 | { |
| 10832 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10833 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10834 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10835 | |
| 10836 | switch (phba->pci_dev_grp) { |
| 10837 | case LPFC_PCI_DEV_LP: |
| 10838 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10839 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10840 | case LPFC_PCI_DEV_OC: |
| 10841 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10842 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10843 | default: |
| 10844 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10845 | "1427 Invalid PCI device group: 0x%x\n", |
| 10846 | phba->pci_dev_grp); |
| 10847 | break; |
| 10848 | } |
| 10849 | return rc; |
| 10850 | } |
| 10851 | |
| 10852 | /** |
| 10853 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10854 | * @pdev: pointer to PCI device. |
| 10855 | * |
| 10856 | * This routine is registered to the PCI subsystem for error handling. This |
| 10857 | * function is called after PCI bus has been reset to restart the PCI card |
| 10858 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10859 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10860 | * routine, which will perform the proper device reset. |
| 10861 | * |
| 10862 | * Return codes |
| 10863 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10864 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10865 | **/ |
| 10866 | static pci_ers_result_t |
| 10867 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10868 | { |
| 10869 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10870 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10871 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10872 | |
| 10873 | switch (phba->pci_dev_grp) { |
| 10874 | case LPFC_PCI_DEV_LP: |
| 10875 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10876 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10877 | case LPFC_PCI_DEV_OC: |
| 10878 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10879 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10880 | default: |
| 10881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10882 | "1428 Invalid PCI device group: 0x%x\n", |
| 10883 | phba->pci_dev_grp); |
| 10884 | break; |
| 10885 | } |
| 10886 | return rc; |
| 10887 | } |
| 10888 | |
| 10889 | /** |
| 10890 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10891 | * @pdev: pointer to PCI device |
| 10892 | * |
| 10893 | * This routine is registered to the PCI subsystem for error handling. It |
| 10894 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10895 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10896 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10897 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10898 | **/ |
| 10899 | static void |
| 10900 | lpfc_io_resume(struct pci_dev *pdev) |
| 10901 | { |
| 10902 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10903 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10904 | |
| 10905 | switch (phba->pci_dev_grp) { |
| 10906 | case LPFC_PCI_DEV_LP: |
| 10907 | lpfc_io_resume_s3(pdev); |
| 10908 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10909 | case LPFC_PCI_DEV_OC: |
| 10910 | lpfc_io_resume_s4(pdev); |
| 10911 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10912 | default: |
| 10913 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10914 | "1429 Invalid PCI device group: 0x%x\n", |
| 10915 | phba->pci_dev_grp); |
| 10916 | break; |
| 10917 | } |
| 10918 | return; |
| 10919 | } |
| 10920 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10921 | /** |
| 10922 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 10923 | * @phba: pointer to lpfc hba data structure. |
| 10924 | * |
| 10925 | * This routine checks to see if OAS is supported for this adapter. If |
| 10926 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 10927 | * the enable oas flag is cleared and the pool created for OAS device data |
| 10928 | * is destroyed. |
| 10929 | * |
| 10930 | **/ |
| 10931 | void |
| 10932 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 10933 | { |
| 10934 | |
| 10935 | if (!phba->cfg_EnableXLane) |
| 10936 | return; |
| 10937 | |
| 10938 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 10939 | phba->cfg_fof = 1; |
| 10940 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 10941 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10942 | if (phba->device_data_mem_pool) |
| 10943 | mempool_destroy(phba->device_data_mem_pool); |
| 10944 | phba->device_data_mem_pool = NULL; |
| 10945 | } |
| 10946 | |
| 10947 | return; |
| 10948 | } |
| 10949 | |
| 10950 | /** |
| 10951 | * lpfc_fof_queue_setup - Set up all the fof queues |
| 10952 | * @phba: pointer to lpfc hba data structure. |
| 10953 | * |
| 10954 | * This routine is invoked to set up all the fof queues for the FC HBA |
| 10955 | * operation. |
| 10956 | * |
| 10957 | * Return codes |
| 10958 | * 0 - successful |
| 10959 | * -ENOMEM - No available memory |
| 10960 | **/ |
| 10961 | int |
| 10962 | lpfc_fof_queue_setup(struct lpfc_hba *phba) |
| 10963 | { |
| 10964 | struct lpfc_sli *psli = &phba->sli; |
| 10965 | int rc; |
| 10966 | |
| 10967 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); |
| 10968 | if (rc) |
| 10969 | return -ENOMEM; |
| 10970 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 10971 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10972 | |
| 10973 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, |
| 10974 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); |
| 10975 | if (rc) |
| 10976 | goto out_oas_cq; |
| 10977 | |
| 10978 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, |
| 10979 | phba->sli4_hba.oas_cq, LPFC_FCP); |
| 10980 | if (rc) |
| 10981 | goto out_oas_wq; |
| 10982 | |
| 10983 | phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 10984 | phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING]; |
| 10985 | } |
| 10986 | |
| 10987 | return 0; |
| 10988 | |
| 10989 | out_oas_wq: |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 10990 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10991 | out_oas_cq: |
| 10992 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); |
| 10993 | return rc; |
| 10994 | |
| 10995 | } |
| 10996 | |
| 10997 | /** |
| 10998 | * lpfc_fof_queue_create - Create all the fof queues |
| 10999 | * @phba: pointer to lpfc hba data structure. |
| 11000 | * |
| 11001 | * This routine is invoked to allocate all the fof queues for the FC HBA |
| 11002 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 11003 | * count (queue depth) shall be taken from the module parameter. For now, |
| 11004 | * we just use some constant number as place holder. |
| 11005 | * |
| 11006 | * Return codes |
| 11007 | * 0 - successful |
| 11008 | * -ENOMEM - No availble memory |
| 11009 | * -EIO - The mailbox failed to complete successfully. |
| 11010 | **/ |
| 11011 | int |
| 11012 | lpfc_fof_queue_create(struct lpfc_hba *phba) |
| 11013 | { |
| 11014 | struct lpfc_queue *qdesc; |
| 11015 | |
| 11016 | /* Create FOF EQ */ |
| 11017 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 11018 | phba->sli4_hba.eq_ecount); |
| 11019 | if (!qdesc) |
| 11020 | goto out_error; |
| 11021 | |
| 11022 | phba->sli4_hba.fof_eq = qdesc; |
| 11023 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 11024 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11025 | |
| 11026 | /* Create OAS CQ */ |
| 11027 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 11028 | phba->sli4_hba.cq_ecount); |
| 11029 | if (!qdesc) |
| 11030 | goto out_error; |
| 11031 | |
| 11032 | phba->sli4_hba.oas_cq = qdesc; |
| 11033 | |
| 11034 | /* Create OAS WQ */ |
| 11035 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 11036 | phba->sli4_hba.wq_ecount); |
| 11037 | if (!qdesc) |
| 11038 | goto out_error; |
| 11039 | |
| 11040 | phba->sli4_hba.oas_wq = qdesc; |
| 11041 | |
| 11042 | } |
| 11043 | return 0; |
| 11044 | |
| 11045 | out_error: |
| 11046 | lpfc_fof_queue_destroy(phba); |
| 11047 | return -ENOMEM; |
| 11048 | } |
| 11049 | |
| 11050 | /** |
| 11051 | * lpfc_fof_queue_destroy - Destroy all the fof queues |
| 11052 | * @phba: pointer to lpfc hba data structure. |
| 11053 | * |
| 11054 | * This routine is invoked to release all the SLI4 queues with the FC HBA |
| 11055 | * operation. |
| 11056 | * |
| 11057 | * Return codes |
| 11058 | * 0 - successful |
| 11059 | **/ |
| 11060 | int |
| 11061 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) |
| 11062 | { |
| 11063 | /* Release FOF Event queue */ |
| 11064 | if (phba->sli4_hba.fof_eq != NULL) { |
| 11065 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); |
| 11066 | phba->sli4_hba.fof_eq = NULL; |
| 11067 | } |
| 11068 | |
| 11069 | /* Release OAS Completion queue */ |
| 11070 | if (phba->sli4_hba.oas_cq != NULL) { |
| 11071 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); |
| 11072 | phba->sli4_hba.oas_cq = NULL; |
| 11073 | } |
| 11074 | |
| 11075 | /* Release OAS Work queue */ |
| 11076 | if (phba->sli4_hba.oas_wq != NULL) { |
| 11077 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); |
| 11078 | phba->sli4_hba.oas_wq = NULL; |
| 11079 | } |
| 11080 | return 0; |
| 11081 | } |
| 11082 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11083 | static struct pci_device_id lpfc_id_table[] = { |
| 11084 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 11085 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 11086 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 11087 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11088 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 11089 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11090 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 11091 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11092 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 11093 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11094 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 11095 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11096 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 11097 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11098 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 11099 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11100 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 11101 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11102 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 11103 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11104 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 11105 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11106 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 11107 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11108 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 11109 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11110 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 11111 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11112 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 11113 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11114 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 11115 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11116 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 11117 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11118 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 11119 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11120 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 11121 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11122 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 11123 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11124 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 11125 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11126 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 11127 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11128 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 11129 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11130 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 11131 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11132 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 11133 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11134 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 11135 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 11136 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 11137 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11138 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 11139 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 11140 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 11141 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11142 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 11143 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11144 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 11145 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11146 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 11147 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11148 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 11149 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11150 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 11151 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 11152 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 11153 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11154 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 11155 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11156 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 11157 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11158 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 11159 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11160 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 11161 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11162 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11163 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 11164 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 11165 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 11166 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 11167 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11168 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 11169 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 11170 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 11171 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11172 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 11173 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 11174 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 11175 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 11176 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 11177 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11178 | { 0 } |
| 11179 | }; |
| 11180 | |
| 11181 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 11182 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 11183 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11184 | .error_detected = lpfc_io_error_detected, |
| 11185 | .slot_reset = lpfc_io_slot_reset, |
| 11186 | .resume = lpfc_io_resume, |
| 11187 | }; |
| 11188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11189 | static struct pci_driver lpfc_driver = { |
| 11190 | .name = LPFC_DRIVER_NAME, |
| 11191 | .id_table = lpfc_id_table, |
| 11192 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11193 | .remove = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11194 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11195 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11196 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11197 | }; |
| 11198 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11199 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 11200 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11201 | }; |
| 11202 | |
| 11203 | static struct miscdevice lpfc_mgmt_dev = { |
| 11204 | .minor = MISC_DYNAMIC_MINOR, |
| 11205 | .name = "lpfcmgmt", |
| 11206 | .fops = &lpfc_mgmt_fop, |
| 11207 | }; |
| 11208 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11209 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11210 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11211 | * |
| 11212 | * This routine is to be invoked when the lpfc module is loaded into the |
| 11213 | * kernel. The special kernel macro module_init() is used to indicate the |
| 11214 | * role of this routine to the kernel as lpfc module entry point. |
| 11215 | * |
| 11216 | * Return codes |
| 11217 | * 0 - successful |
| 11218 | * -ENOMEM - FC attach transport failed |
| 11219 | * all others - failed |
| 11220 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11221 | static int __init |
| 11222 | lpfc_init(void) |
| 11223 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11224 | int cpu; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11225 | int error = 0; |
| 11226 | |
| 11227 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 11228 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11229 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11230 | error = misc_register(&lpfc_mgmt_dev); |
| 11231 | if (error) |
| 11232 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 11233 | "misc_register returned with status %d", error); |
| 11234 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11235 | if (lpfc_enable_npiv) { |
| 11236 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 11237 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 11238 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11239 | lpfc_transport_template = |
| 11240 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11241 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11242 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11243 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11244 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11245 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 11246 | if (lpfc_vport_transport_template == NULL) { |
| 11247 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11248 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11249 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11250 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11251 | |
| 11252 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11253 | lpfc_used_cpu = NULL; |
| 11254 | lpfc_present_cpu = 0; |
| 11255 | for_each_present_cpu(cpu) |
| 11256 | lpfc_present_cpu++; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11258 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11259 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11260 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11261 | if (lpfc_enable_npiv) |
| 11262 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11263 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11264 | |
| 11265 | return error; |
| 11266 | } |
| 11267 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11268 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11269 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11270 | * |
| 11271 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 11272 | * The special kernel macro module_exit() is used to indicate the role of |
| 11273 | * this routine to the kernel as lpfc module exit point. |
| 11274 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11275 | static void __exit |
| 11276 | lpfc_exit(void) |
| 11277 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 11278 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11279 | pci_unregister_driver(&lpfc_driver); |
| 11280 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 11281 | if (lpfc_enable_npiv) |
| 11282 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11283 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11284 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 11285 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11286 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 11287 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 11288 | } |
| 11289 | |
| 11290 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11291 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 11292 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11293 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 11294 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 11295 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11296 | kfree(lpfc_used_cpu); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11297 | } |
| 11298 | |
| 11299 | module_init(lpfc_init); |
| 11300 | module_exit(lpfc_exit); |
| 11301 | MODULE_LICENSE("GPL"); |
| 11302 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 11303 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 11304 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |