| 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 | 92c13f2 | 2013-05-31 17:05:45 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2013 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); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 83 | |
| 84 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 85 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | static DEFINE_IDR(lpfc_hba_index); |
| 87 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 88 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 89 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 90 | * @phba: pointer to lpfc hba data structure. |
| 91 | * |
| 92 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 93 | * mailbox command. It retrieves the revision information from the HBA and |
| 94 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 95 | * configuration of the HBA. |
| 96 | * |
| 97 | * Return codes: |
| 98 | * 0 - success. |
| 99 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 100 | * Any other value - indicates an error. |
| 101 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 103 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | { |
| 105 | lpfc_vpd_t *vp = &phba->vpd; |
| 106 | int i = 0, rc; |
| 107 | LPFC_MBOXQ_t *pmb; |
| 108 | MAILBOX_t *mb; |
| 109 | char *lpfc_vpd_data = NULL; |
| 110 | uint16_t offset = 0; |
| 111 | static char licensed[56] = |
| 112 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 113 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | |
| 115 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 116 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 117 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | return -ENOMEM; |
| 119 | } |
| 120 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 121 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 122 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 123 | |
| 124 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 125 | if (init_key) { |
| 126 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 127 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 128 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 129 | *ptext = cpu_to_be32(*ptext); |
| 130 | init_key = 0; |
| 131 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | |
| 133 | lpfc_read_nv(phba, pmb); |
| 134 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 135 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 136 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 137 | sizeof (licensed)); |
| 138 | |
| 139 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 140 | |
| 141 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 142 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 143 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | "error, mbxCmd x%x READ_NVPARM, " |
| 145 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | mb->mbxCommand, mb->mbxStatus); |
| 147 | mempool_free(pmb, phba->mbox_mem_pool); |
| 148 | return -ERESTART; |
| 149 | } |
| 150 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 151 | sizeof(phba->wwnn)); |
| 152 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 153 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | } |
| 155 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 156 | phba->sli3_options = 0x0; |
| 157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | /* Setup and issue mailbox READ REV command */ |
| 159 | lpfc_read_rev(phba, pmb); |
| 160 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 161 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 162 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 163 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 165 | mb->mbxCommand, mb->mbxStatus); |
| 166 | mempool_free( pmb, phba->mbox_mem_pool); |
| 167 | return -ERESTART; |
| 168 | } |
| 169 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 170 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 171 | /* |
| 172 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 173 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 174 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 175 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 177 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 178 | "0440 Adapter failed to init, READ_REV has " |
| 179 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 180 | mempool_free(pmb, phba->mbox_mem_pool); |
| 181 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | } |
| 183 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 184 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 185 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 186 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 187 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 190 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 191 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 192 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 193 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 194 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 195 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 197 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 198 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 199 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 200 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 201 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 202 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 203 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 204 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 205 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 206 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 207 | /* If the sli feature level is less then 9, we must |
| 208 | * tear down all RPIs and VPIs on link down if NPIV |
| 209 | * is enabled. |
| 210 | */ |
| 211 | if (vp->rev.feaLevelHigh < 9) |
| 212 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 213 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 215 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 216 | sizeof (phba->RandomData)); |
| 217 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 220 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 221 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 223 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 225 | |
| 226 | if (rc != MBX_SUCCESS) { |
| 227 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 228 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 231 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 233 | /* dump mem may return a zero when finished or we got a |
| 234 | * mailbox error, either way we are done. |
| 235 | */ |
| 236 | if (mb->un.varDmp.word_cnt == 0) |
| 237 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 238 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 239 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 240 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 241 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 242 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 244 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 245 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 246 | |
| 247 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | out_free_mbox: |
| 249 | mempool_free(pmb, phba->mbox_mem_pool); |
| 250 | return 0; |
| 251 | } |
| 252 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 253 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 254 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 255 | * @phba: pointer to lpfc hba data structure. |
| 256 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 257 | * |
| 258 | * This is the completion handler for driver's configuring asynchronous event |
| 259 | * mailbox command to the device. If the mailbox command returns successfully, |
| 260 | * it will set internal async event support flag to 1; otherwise, it will |
| 261 | * set internal async event support flag to 0. |
| 262 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 263 | static void |
| 264 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 265 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 266 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 267 | phba->temp_sensor_support = 1; |
| 268 | else |
| 269 | phba->temp_sensor_support = 0; |
| 270 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 271 | return; |
| 272 | } |
| 273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 275 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 276 | * @phba: pointer to lpfc hba data structure. |
| 277 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 278 | * |
| 279 | * This is the completion handler for dump mailbox command for getting |
| 280 | * wake up parameters. When this command complete, the response contain |
| 281 | * Option rom version of the HBA. This function translate the version number |
| 282 | * into a human readable string and store it in OptionROMVersion. |
| 283 | **/ |
| 284 | static void |
| 285 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 286 | { |
| 287 | struct prog_id *prg; |
| 288 | uint32_t prog_id_word; |
| 289 | char dist = ' '; |
| 290 | /* character array used for decoding dist type. */ |
| 291 | char dist_char[] = "nabx"; |
| 292 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 293 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 294 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 295 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 296 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 297 | |
| 298 | prg = (struct prog_id *) &prog_id_word; |
| 299 | |
| 300 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 301 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 302 | |
| 303 | /* Decode the Option rom version word to a readable string */ |
| 304 | if (prg->dist < 4) |
| 305 | dist = dist_char[prg->dist]; |
| 306 | |
| 307 | if ((prg->dist == 3) && (prg->num == 0)) |
| 308 | sprintf(phba->OptionROMVersion, "%d.%d%d", |
| 309 | prg->ver, prg->rev, prg->lev); |
| 310 | else |
| 311 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", |
| 312 | prg->ver, prg->rev, prg->lev, |
| 313 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 314 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 319 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 320 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 321 | * @vport: pointer to lpfc vport data structure. |
| 322 | * |
| 323 | * |
| 324 | * Return codes |
| 325 | * None. |
| 326 | **/ |
| 327 | void |
| 328 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 329 | { |
| 330 | /* If the soft name exists then update it using the service params */ |
| 331 | if (vport->phba->cfg_soft_wwnn) |
| 332 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 333 | vport->fc_sparam.nodeName.u.wwn); |
| 334 | if (vport->phba->cfg_soft_wwpn) |
| 335 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 336 | vport->fc_sparam.portName.u.wwn); |
| 337 | |
| 338 | /* |
| 339 | * If the name is empty or there exists a soft name |
| 340 | * then copy the service params name, otherwise use the fc name |
| 341 | */ |
| 342 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 343 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 344 | sizeof(struct lpfc_name)); |
| 345 | else |
| 346 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 347 | sizeof(struct lpfc_name)); |
| 348 | |
| 349 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) |
| 350 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 351 | sizeof(struct lpfc_name)); |
| 352 | else |
| 353 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 354 | sizeof(struct lpfc_name)); |
| 355 | } |
| 356 | |
| 357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 358 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 359 | * @phba: pointer to lpfc hba data structure. |
| 360 | * |
| 361 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 362 | * command call. It performs all internal resource and state setups on the |
| 363 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 364 | * ELS ring timers, etc. |
| 365 | * |
| 366 | * Return codes |
| 367 | * 0 - success. |
| 368 | * Any other value - error. |
| 369 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 371 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 372 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 373 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 374 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 375 | LPFC_MBOXQ_t *pmb; |
| 376 | MAILBOX_t *mb; |
| 377 | struct lpfc_dmabuf *mp; |
| 378 | struct lpfc_sli *psli = &phba->sli; |
| 379 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 380 | int i, j; |
| 381 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 383 | spin_lock_irq(&phba->hbalock); |
| 384 | /* |
| 385 | * If the Config port completed correctly the HBA is not |
| 386 | * over heated any more. |
| 387 | */ |
| 388 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 389 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 390 | spin_unlock_irq(&phba->hbalock); |
| 391 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 392 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 393 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 394 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 395 | return -ENOMEM; |
| 396 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 397 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 398 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 399 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 400 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 401 | if (rc) { |
| 402 | mempool_free(pmb, phba->mbox_mem_pool); |
| 403 | return -ENOMEM; |
| 404 | } |
| 405 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 406 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 407 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 409 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 414 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 416 | kfree(mp); |
| 417 | return -EIO; |
| 418 | } |
| 419 | |
| 420 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 421 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 422 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 424 | kfree(mp); |
| 425 | pmb->context1 = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 426 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 427 | |
| 428 | /* Update the fc_host data structures with new wwn. */ |
| 429 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 430 | 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] | 431 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 432 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 434 | /* This should be consolidated into parse_vpd ? - mr */ |
| 435 | if (phba->SerialNumber[0] == 0) { |
| 436 | uint8_t *outptr; |
| 437 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 438 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | for (i = 0; i < 12; i++) { |
| 440 | status = *outptr++; |
| 441 | j = ((status & 0xf0) >> 4); |
| 442 | if (j <= 9) |
| 443 | phba->SerialNumber[i] = |
| 444 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 445 | else |
| 446 | phba->SerialNumber[i] = |
| 447 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 448 | i++; |
| 449 | j = (status & 0xf); |
| 450 | if (j <= 9) |
| 451 | phba->SerialNumber[i] = |
| 452 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 453 | else |
| 454 | phba->SerialNumber[i] = |
| 455 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 456 | } |
| 457 | } |
| 458 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 459 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 460 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 462 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 463 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 464 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 465 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 466 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | mempool_free( pmb, phba->mbox_mem_pool); |
| 468 | return -EIO; |
| 469 | } |
| 470 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 471 | /* Check if the port is disabled */ |
| 472 | lpfc_sli_read_link_ste(phba); |
| 473 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 475 | i = (mb->un.varRdConfig.max_xri + 1); |
| 476 | if (phba->cfg_hba_queue_depth > i) { |
| 477 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 478 | "3359 HBA queue depth changed from %d to %d\n", |
| 479 | phba->cfg_hba_queue_depth, i); |
| 480 | phba->cfg_hba_queue_depth = i; |
| 481 | } |
| 482 | |
| 483 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 484 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 485 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 486 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 487 | "3360 LUN queue depth changed from %d to %d\n", |
| 488 | phba->pport->cfg_lun_queue_depth, i); |
| 489 | phba->pport->cfg_lun_queue_depth = i; |
| 490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | |
| 492 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 493 | |
| 494 | /* Get the default values for Model Name and Description */ |
| 495 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 496 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 497 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 499 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 500 | if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr) |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 501 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 502 | if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 504 | if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 506 | |
| 507 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 508 | if (phba->sli_rev != 3) |
| 509 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 511 | /* |
| 512 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 513 | */ |
| 514 | if (phba->intr_type == MSIX) { |
| 515 | rc = lpfc_config_msi(phba, pmb); |
| 516 | if (rc) { |
| 517 | mempool_free(pmb, phba->mbox_mem_pool); |
| 518 | return -EIO; |
| 519 | } |
| 520 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 521 | if (rc != MBX_SUCCESS) { |
| 522 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 523 | "0352 Config MSI mailbox command " |
| 524 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 525 | pmb->u.mb.mbxCommand, |
| 526 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 527 | mempool_free(pmb, phba->mbox_mem_pool); |
| 528 | return -EIO; |
| 529 | } |
| 530 | } |
| 531 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 532 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 533 | /* Initialize ERATT handling flag */ |
| 534 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 537 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 538 | spin_unlock_irq(&phba->hbalock); |
| 539 | return -EIO; |
| 540 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 542 | if (psli->num_rings > 0) |
| 543 | status |= HC_R0INT_ENA; |
| 544 | if (psli->num_rings > 1) |
| 545 | status |= HC_R1INT_ENA; |
| 546 | if (psli->num_rings > 2) |
| 547 | status |= HC_R2INT_ENA; |
| 548 | if (psli->num_rings > 3) |
| 549 | status |= HC_R3INT_ENA; |
| 550 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 551 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 552 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 553 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 554 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 555 | writel(status, phba->HCregaddr); |
| 556 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 557 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 558 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 559 | /* Set up ring-0 (ELS) timer */ |
| 560 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 561 | mod_timer(&vport->els_tmofunc, |
| 562 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 563 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 564 | mod_timer(&phba->hb_tmofunc, |
| 565 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 566 | phba->hb_outstanding = 0; |
| 567 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 568 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 569 | mod_timer(&phba->eratt_poll, |
| 570 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 572 | if (phba->hba_flag & LINK_DISABLED) { |
| 573 | lpfc_printf_log(phba, |
| 574 | KERN_ERR, LOG_INIT, |
| 575 | "2598 Adapter Link is disabled.\n"); |
| 576 | lpfc_down_link(phba, pmb); |
| 577 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 578 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 579 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 580 | lpfc_printf_log(phba, |
| 581 | KERN_ERR, LOG_INIT, |
| 582 | "2599 Adapter failed to issue DOWN_LINK" |
| 583 | " mbox command rc 0x%x\n", rc); |
| 584 | |
| 585 | mempool_free(pmb, phba->mbox_mem_pool); |
| 586 | return -EIO; |
| 587 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 588 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 589 | mempool_free(pmb, phba->mbox_mem_pool); |
| 590 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 591 | if (rc) |
| 592 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 593 | } |
| 594 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 595 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 596 | if (!pmb) { |
| 597 | phba->link_state = LPFC_HBA_ERROR; |
| 598 | return -ENOMEM; |
| 599 | } |
| 600 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 601 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 602 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 603 | pmb->vport = phba->pport; |
| 604 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 606 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 607 | lpfc_printf_log(phba, |
| 608 | KERN_ERR, |
| 609 | LOG_INIT, |
| 610 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 611 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 612 | rc); |
| 613 | mempool_free(pmb, phba->mbox_mem_pool); |
| 614 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 615 | |
| 616 | /* Get Option rom version */ |
| 617 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 618 | if (!pmb) { |
| 619 | phba->link_state = LPFC_HBA_ERROR; |
| 620 | return -ENOMEM; |
| 621 | } |
| 622 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 623 | lpfc_dump_wakeup_param(phba, pmb); |
| 624 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 625 | pmb->vport = phba->pport; |
| 626 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 627 | |
| 628 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 630 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 631 | mempool_free(pmb, phba->mbox_mem_pool); |
| 632 | } |
| 633 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 634 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 635 | } |
| 636 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 637 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 638 | * lpfc_hba_init_link - Initialize the FC link |
| 639 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 640 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 641 | * |
| 642 | * This routine will issue the INIT_LINK mailbox command call. |
| 643 | * It is available to other drivers through the lpfc_hba data |
| 644 | * structure for use as a delayed link up mechanism with the |
| 645 | * module parameter lpfc_suppress_link_up. |
| 646 | * |
| 647 | * Return code |
| 648 | * 0 - success |
| 649 | * Any other value - error |
| 650 | **/ |
| 651 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 652 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 653 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 654 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 659 | * @phba: pointer to lpfc hba data structure. |
| 660 | * @fc_topology: desired fc topology. |
| 661 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 662 | * |
| 663 | * This routine will issue the INIT_LINK mailbox command call. |
| 664 | * It is available to other drivers through the lpfc_hba data |
| 665 | * structure for use as a delayed link up mechanism with the |
| 666 | * module parameter lpfc_suppress_link_up. |
| 667 | * |
| 668 | * Return code |
| 669 | * 0 - success |
| 670 | * Any other value - error |
| 671 | **/ |
| 672 | int |
| 673 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 674 | uint32_t flag) |
| 675 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 676 | struct lpfc_vport *vport = phba->pport; |
| 677 | LPFC_MBOXQ_t *pmb; |
| 678 | MAILBOX_t *mb; |
| 679 | int rc; |
| 680 | |
| 681 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 682 | if (!pmb) { |
| 683 | phba->link_state = LPFC_HBA_ERROR; |
| 684 | return -ENOMEM; |
| 685 | } |
| 686 | mb = &pmb->u.mb; |
| 687 | pmb->vport = vport; |
| 688 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 689 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 690 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 691 | !(phba->lmt & LMT_1Gb)) || |
| 692 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 693 | !(phba->lmt & LMT_2Gb)) || |
| 694 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 695 | !(phba->lmt & LMT_4Gb)) || |
| 696 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 697 | !(phba->lmt & LMT_8Gb)) || |
| 698 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 699 | !(phba->lmt & LMT_10Gb)) || |
| 700 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
| 701 | !(phba->lmt & LMT_16Gb))) { |
| 702 | /* Reset link speed to auto */ |
| 703 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 704 | "1302 Invalid speed for this board:%d " |
| 705 | "Reset link speed to auto.\n", |
| 706 | phba->cfg_link_speed); |
| 707 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 708 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 709 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 710 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 711 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 712 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 713 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 714 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 716 | "0498 Adapter failed to init, mbxCmd x%x " |
| 717 | "INIT_LINK, mbxStatus x%x\n", |
| 718 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 719 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 720 | /* Clear all interrupt enable conditions */ |
| 721 | writel(0, phba->HCregaddr); |
| 722 | readl(phba->HCregaddr); /* flush */ |
| 723 | /* Clear all pending interrupts */ |
| 724 | writel(0xffffffff, phba->HAregaddr); |
| 725 | readl(phba->HAregaddr); /* flush */ |
| 726 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 727 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 728 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 729 | mempool_free(pmb, phba->mbox_mem_pool); |
| 730 | return -EIO; |
| 731 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 732 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 733 | if (flag == MBX_POLL) |
| 734 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 735 | |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 741 | * @phba: pointer to lpfc hba data structure. |
| 742 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 743 | * |
| 744 | * This routine will issue the DOWN_LINK mailbox command call. |
| 745 | * It is available to other drivers through the lpfc_hba data |
| 746 | * structure for use to stop the link. |
| 747 | * |
| 748 | * Return code |
| 749 | * 0 - success |
| 750 | * Any other value - error |
| 751 | **/ |
| 752 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 753 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 754 | { |
| 755 | LPFC_MBOXQ_t *pmb; |
| 756 | int rc; |
| 757 | |
| 758 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 759 | if (!pmb) { |
| 760 | phba->link_state = LPFC_HBA_ERROR; |
| 761 | return -ENOMEM; |
| 762 | } |
| 763 | |
| 764 | lpfc_printf_log(phba, |
| 765 | KERN_ERR, LOG_INIT, |
| 766 | "0491 Adapter Link is disabled.\n"); |
| 767 | lpfc_down_link(phba, pmb); |
| 768 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 769 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 770 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 771 | lpfc_printf_log(phba, |
| 772 | KERN_ERR, LOG_INIT, |
| 773 | "2522 Adapter failed to issue DOWN_LINK" |
| 774 | " mbox command rc 0x%x\n", rc); |
| 775 | |
| 776 | mempool_free(pmb, phba->mbox_mem_pool); |
| 777 | return -EIO; |
| 778 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 779 | if (flag == MBX_POLL) |
| 780 | mempool_free(pmb, phba->mbox_mem_pool); |
| 781 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 786 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 787 | * @phba: pointer to lpfc HBA data structure. |
| 788 | * |
| 789 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 790 | * bringing down the SLI Layer. |
| 791 | * |
| 792 | * Return codes |
| 793 | * 0 - success. |
| 794 | * Any other value - error. |
| 795 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 797 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 799 | struct lpfc_vport **vports; |
| 800 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 801 | |
| 802 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 803 | /* Disable interrupts */ |
| 804 | writel(0, phba->HCregaddr); |
| 805 | readl(phba->HCregaddr); /* flush */ |
| 806 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 808 | if (phba->pport->load_flag & FC_UNLOADING) |
| 809 | lpfc_cleanup_discovery_resources(phba->pport); |
| 810 | else { |
| 811 | vports = lpfc_create_vport_work_array(phba); |
| 812 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 813 | for (i = 0; i <= phba->max_vports && |
| 814 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 815 | lpfc_cleanup_discovery_resources(vports[i]); |
| 816 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 817 | } |
| 818 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | } |
| 820 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 821 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 822 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 823 | * @phba: pointer to lpfc HBA data structure. |
| 824 | * |
| 825 | * This routine will do uninitialization after the HBA is reset when bring |
| 826 | * down the SLI Layer. |
| 827 | * |
| 828 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 829 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 830 | * Any other value - error. |
| 831 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 832 | static int |
| 833 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 834 | { |
| 835 | struct lpfc_sli *psli = &phba->sli; |
| 836 | struct lpfc_sli_ring *pring; |
| 837 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 838 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 839 | int i; |
| 840 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 841 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 842 | lpfc_sli_hbqbuf_free_all(phba); |
| 843 | else { |
| 844 | /* Cleanup preposted buffers on the ELS ring */ |
| 845 | pring = &psli->ring[LPFC_ELS_RING]; |
| 846 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 847 | list_del(&mp->list); |
| 848 | pring->postbufq_cnt--; |
| 849 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 850 | kfree(mp); |
| 851 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 852 | } |
| 853 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 854 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 855 | for (i = 0; i < psli->num_rings; i++) { |
| 856 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 857 | |
| 858 | /* At this point in time the HBA is either reset or DOA. Either |
| 859 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 860 | */ |
| 861 | list_splice_init(&pring->txcmplq, &completions); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 862 | spin_unlock_irq(&phba->hbalock); |
| 863 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 864 | /* Cancel all the IOCBs from the completions list */ |
| 865 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 866 | IOERR_SLI_ABORTED); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 867 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 868 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 869 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 870 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 871 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 872 | |
| 873 | return 0; |
| 874 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 875 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 876 | /** |
| 877 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 878 | * @phba: pointer to lpfc HBA data structure. |
| 879 | * |
| 880 | * This routine will do uninitialization after the HBA is reset when bring |
| 881 | * down the SLI Layer. |
| 882 | * |
| 883 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 884 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 885 | * Any other value - error. |
| 886 | **/ |
| 887 | static int |
| 888 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 889 | { |
| 890 | struct lpfc_scsi_buf *psb, *psb_next; |
| 891 | LIST_HEAD(aborts); |
| 892 | int ret; |
| 893 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 894 | struct lpfc_sglq *sglq_entry = NULL; |
| 895 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | ret = lpfc_hba_down_post_s3(phba); |
| 897 | if (ret) |
| 898 | return ret; |
| 899 | /* At this point in time the HBA is either reset or DOA. Either |
| 900 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 901 | * on the lpfc_sgl_list so that it can either be freed if the |
| 902 | * driver is unloading or reposted if the driver is restarting |
| 903 | * the port. |
| 904 | */ |
| 905 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 906 | /* scsl_buf_list */ |
| 907 | /* abts_sgl_list_lock required because worker thread uses this |
| 908 | * list. |
| 909 | */ |
| 910 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 911 | list_for_each_entry(sglq_entry, |
| 912 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 913 | sglq_entry->state = SGL_FREED; |
| 914 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 915 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 916 | &phba->sli4_hba.lpfc_sgl_list); |
| 917 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 918 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 919 | * list. |
| 920 | */ |
| 921 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 922 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 923 | &aborts); |
| 924 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 925 | spin_unlock_irq(&phba->hbalock); |
| 926 | |
| 927 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 928 | psb->pCmd = NULL; |
| 929 | psb->status = IOSTAT_SUCCESS; |
| 930 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 931 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 932 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 933 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 939 | * @phba: pointer to lpfc HBA data structure. |
| 940 | * |
| 941 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 942 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 943 | * |
| 944 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 945 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 946 | * Any other value - error. |
| 947 | **/ |
| 948 | int |
| 949 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 950 | { |
| 951 | return (*phba->lpfc_hba_down_post)(phba); |
| 952 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 955 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 956 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 957 | * |
| 958 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 959 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 960 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 961 | * event will be used by the worker thread to invoke the actual timeout |
| 962 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 963 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 964 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 965 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 966 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 967 | lpfc_hb_timeout(unsigned long ptr) |
| 968 | { |
| 969 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 970 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 971 | unsigned long iflag; |
| 972 | |
| 973 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 974 | |
| 975 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 976 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 977 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 978 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 979 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 980 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 981 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 982 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 983 | if (!tmo_posted) |
| 984 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 988 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 989 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 990 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 991 | * |
| 992 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 993 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 994 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 995 | * event will be used by the worker thread to invoke the actual timeout |
| 996 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 997 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 998 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 999 | **/ |
| 1000 | static void |
| 1001 | lpfc_rrq_timeout(unsigned long ptr) |
| 1002 | { |
| 1003 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1004 | unsigned long iflag; |
| 1005 | |
| 1006 | phba = (struct lpfc_hba *)ptr; |
| 1007 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1008 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1009 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1010 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1014 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1015 | * @phba: pointer to lpfc hba data structure. |
| 1016 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1017 | * |
| 1018 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1019 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1020 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1021 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1022 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1023 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1024 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1025 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1026 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1027 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1028 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1029 | static void |
| 1030 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1031 | { |
| 1032 | unsigned long drvr_flag; |
| 1033 | |
| 1034 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1035 | phba->hb_outstanding = 0; |
| 1036 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1037 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1038 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1039 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1040 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1041 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1042 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1043 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1044 | jiffies + |
| 1045 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1046 | return; |
| 1047 | } |
| 1048 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1050 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1051 | * @phba: pointer to lpfc hba data structure. |
| 1052 | * |
| 1053 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1054 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1055 | * handler performs any periodic operations needed for the device. If such |
| 1056 | * periodic event has already been attended to either in the interrupt handler |
| 1057 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1058 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1059 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1060 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1061 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1062 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1063 | * to offline. |
| 1064 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1065 | void |
| 1066 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1067 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1068 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1069 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1070 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1071 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1072 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1073 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1074 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1075 | vports = lpfc_create_vport_work_array(phba); |
| 1076 | if (vports != NULL) |
| 1077 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1078 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1079 | lpfc_destroy_vport_work_array(phba, vports); |
| 1080 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1081 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1082 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1083 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1084 | return; |
| 1085 | |
| 1086 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1087 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1088 | if (time_after(phba->last_completion_time + |
| 1089 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1090 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1091 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1092 | if (!phba->hb_outstanding) |
| 1093 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1094 | jiffies + |
| 1095 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1096 | else |
| 1097 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1098 | jiffies + |
| 1099 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1100 | return; |
| 1101 | } |
| 1102 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1103 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1104 | if (phba->elsbuf_cnt && |
| 1105 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1106 | spin_lock_irq(&phba->hbalock); |
| 1107 | list_splice_init(&phba->elsbuf, &completions); |
| 1108 | phba->elsbuf_cnt = 0; |
| 1109 | phba->elsbuf_prev_cnt = 0; |
| 1110 | spin_unlock_irq(&phba->hbalock); |
| 1111 | |
| 1112 | while (!list_empty(&completions)) { |
| 1113 | list_remove_head(&completions, buf_ptr, |
| 1114 | struct lpfc_dmabuf, list); |
| 1115 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1116 | kfree(buf_ptr); |
| 1117 | } |
| 1118 | } |
| 1119 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1120 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1121 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1122 | if (phba->cfg_enable_hba_heartbeat) { |
| 1123 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1124 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1125 | (list_empty(&psli->mboxq))) { |
| 1126 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1127 | GFP_KERNEL); |
| 1128 | if (!pmboxq) { |
| 1129 | mod_timer(&phba->hb_tmofunc, |
| 1130 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1131 | msecs_to_jiffies(1000 * |
| 1132 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1133 | return; |
| 1134 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1135 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1136 | lpfc_heart_beat(phba, pmboxq); |
| 1137 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1138 | pmboxq->vport = phba->pport; |
| 1139 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1140 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1141 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1142 | if (retval != MBX_BUSY && |
| 1143 | retval != MBX_SUCCESS) { |
| 1144 | mempool_free(pmboxq, |
| 1145 | phba->mbox_mem_pool); |
| 1146 | mod_timer(&phba->hb_tmofunc, |
| 1147 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1148 | msecs_to_jiffies(1000 * |
| 1149 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1150 | return; |
| 1151 | } |
| 1152 | phba->skipped_hb = 0; |
| 1153 | phba->hb_outstanding = 1; |
| 1154 | } else if (time_before_eq(phba->last_completion_time, |
| 1155 | phba->skipped_hb)) { |
| 1156 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1157 | "2857 Last completion time not " |
| 1158 | " updated in %d ms\n", |
| 1159 | jiffies_to_msecs(jiffies |
| 1160 | - phba->last_completion_time)); |
| 1161 | } else |
| 1162 | phba->skipped_hb = jiffies; |
| 1163 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1164 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1165 | jiffies + |
| 1166 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1167 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1168 | } else { |
| 1169 | /* |
| 1170 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1171 | * we need to give the hb mailbox cmd a chance to |
| 1172 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1173 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1174 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1175 | "0459 Adapter heartbeat still out" |
| 1176 | "standing:last compl time was %d ms.\n", |
| 1177 | jiffies_to_msecs(jiffies |
| 1178 | - phba->last_completion_time)); |
| 1179 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1180 | jiffies + |
| 1181 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1182 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1187 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | * @phba: pointer to lpfc hba data structure. |
| 1189 | * |
| 1190 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1191 | * other than Port Error 6 has been detected. |
| 1192 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1193 | static void |
| 1194 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1195 | { |
| 1196 | struct lpfc_sli *psli = &phba->sli; |
| 1197 | |
| 1198 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1199 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1200 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1201 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1202 | |
| 1203 | lpfc_offline(phba); |
| 1204 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1205 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1206 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1207 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1208 | lpfc_hba_down_post(phba); |
| 1209 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1210 | lpfc_unblock_mgmt_io(phba); |
| 1211 | phba->link_state = LPFC_HBA_ERROR; |
| 1212 | return; |
| 1213 | } |
| 1214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1215 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1216 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1217 | * @phba: pointer to lpfc hba data structure. |
| 1218 | * |
| 1219 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1220 | * other than Port Error 6 has been detected. |
| 1221 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1222 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1223 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1224 | { |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1225 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1226 | lpfc_offline(phba); |
| 1227 | lpfc_sli4_brdreset(phba); |
| 1228 | lpfc_hba_down_post(phba); |
| 1229 | lpfc_sli4_post_status_check(phba); |
| 1230 | lpfc_unblock_mgmt_io(phba); |
| 1231 | phba->link_state = LPFC_HBA_ERROR; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1235 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1236 | * @phba: pointer to lpfc hba data structure. |
| 1237 | * |
| 1238 | * This routine is invoked to handle the deferred HBA hardware error |
| 1239 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1240 | * and another ER bit in the host status register. The driver will |
| 1241 | * wait until the ER1 bit clears before handling the error condition. |
| 1242 | **/ |
| 1243 | static void |
| 1244 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1245 | { |
| 1246 | uint32_t old_host_status = phba->work_hs; |
| 1247 | struct lpfc_sli_ring *pring; |
| 1248 | struct lpfc_sli *psli = &phba->sli; |
| 1249 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1250 | /* If the pci channel is offline, ignore possible errors, |
| 1251 | * since we cannot communicate with the pci card anyway. |
| 1252 | */ |
| 1253 | if (pci_channel_offline(phba->pcidev)) { |
| 1254 | spin_lock_irq(&phba->hbalock); |
| 1255 | phba->hba_flag &= ~DEFER_ERATT; |
| 1256 | spin_unlock_irq(&phba->hbalock); |
| 1257 | return; |
| 1258 | } |
| 1259 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1260 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1261 | "0479 Deferred Adapter Hardware Error " |
| 1262 | "Data: x%x x%x x%x\n", |
| 1263 | phba->work_hs, |
| 1264 | phba->work_status[0], phba->work_status[1]); |
| 1265 | |
| 1266 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1267 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1268 | spin_unlock_irq(&phba->hbalock); |
| 1269 | |
| 1270 | |
| 1271 | /* |
| 1272 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1273 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1274 | * SCSI layer retry it after re-establishing link. |
| 1275 | */ |
| 1276 | pring = &psli->ring[psli->fcp_ring]; |
| 1277 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1278 | |
| 1279 | /* |
| 1280 | * There was a firmware error. Take the hba offline and then |
| 1281 | * attempt to restart it. |
| 1282 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1283 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1284 | lpfc_offline(phba); |
| 1285 | |
| 1286 | /* Wait for the ER1 bit to clear.*/ |
| 1287 | while (phba->work_hs & HS_FFER1) { |
| 1288 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1289 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1290 | phba->work_hs = UNPLUG_ERR ; |
| 1291 | break; |
| 1292 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1293 | /* If driver is unloading let the worker thread continue */ |
| 1294 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1295 | phba->work_hs = 0; |
| 1296 | break; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | /* |
| 1301 | * This is to ptrotect against a race condition in which |
| 1302 | * first write to the host attention register clear the |
| 1303 | * host status register. |
| 1304 | */ |
| 1305 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1306 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1307 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1308 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1309 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1310 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1311 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1312 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1313 | } |
| 1314 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1315 | static void |
| 1316 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1317 | { |
| 1318 | struct lpfc_board_event_header board_event; |
| 1319 | struct Scsi_Host *shost; |
| 1320 | |
| 1321 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1322 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1323 | shost = lpfc_shost_from_vport(phba->pport); |
| 1324 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1325 | sizeof(board_event), |
| 1326 | (char *) &board_event, |
| 1327 | LPFC_NL_VENDOR_ID); |
| 1328 | } |
| 1329 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1330 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1331 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1332 | * @phba: pointer to lpfc hba data structure. |
| 1333 | * |
| 1334 | * This routine is invoked to handle the following HBA hardware error |
| 1335 | * conditions: |
| 1336 | * 1 - HBA error attention interrupt |
| 1337 | * 2 - DMA ring index out of range |
| 1338 | * 3 - Mailbox command came back as unknown |
| 1339 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1340 | static void |
| 1341 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1343 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1344 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1346 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1347 | unsigned long temperature; |
| 1348 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1349 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1350 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1351 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1352 | * since we cannot communicate with the pci card anyway. |
| 1353 | */ |
| 1354 | if (pci_channel_offline(phba->pcidev)) { |
| 1355 | spin_lock_irq(&phba->hbalock); |
| 1356 | phba->hba_flag &= ~DEFER_ERATT; |
| 1357 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1358 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1361 | /* If resets are disabled then leave the HBA alone and return */ |
| 1362 | if (!phba->cfg_enable_hba_reset) |
| 1363 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1365 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1366 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1367 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1368 | if (phba->hba_flag & DEFER_ERATT) |
| 1369 | lpfc_handle_deferred_eratt(phba); |
| 1370 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1371 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1372 | if (phba->work_hs & HS_FFER6) |
| 1373 | /* Re-establishing Link */ |
| 1374 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1375 | "1301 Re-establishing Link " |
| 1376 | "Data: x%x x%x x%x\n", |
| 1377 | phba->work_hs, phba->work_status[0], |
| 1378 | phba->work_status[1]); |
| 1379 | if (phba->work_hs & HS_FFER8) |
| 1380 | /* Device Zeroization */ |
| 1381 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1382 | "2861 Host Authentication device " |
| 1383 | "zeroization Data:x%x x%x x%x\n", |
| 1384 | phba->work_hs, phba->work_status[0], |
| 1385 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1386 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1387 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1388 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1389 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1390 | |
| 1391 | /* |
| 1392 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1393 | * That could cause the I/Os dropped by the firmware. |
| 1394 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1395 | * retry it after re-establishing link. |
| 1396 | */ |
| 1397 | pring = &psli->ring[psli->fcp_ring]; |
| 1398 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1399 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | /* |
| 1401 | * There was a firmware error. Take the hba offline and then |
| 1402 | * attempt to restart it. |
| 1403 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1404 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1405 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1406 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1408 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | return; |
| 1410 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1411 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1412 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1413 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1414 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1415 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1416 | temp_event_data.data = (uint32_t)temperature; |
| 1417 | |
| 1418 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1419 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1420 | "(%ld), taking this port offline " |
| 1421 | "Data: x%x x%x x%x\n", |
| 1422 | temperature, phba->work_hs, |
| 1423 | phba->work_status[0], phba->work_status[1]); |
| 1424 | |
| 1425 | shost = lpfc_shost_from_vport(phba->pport); |
| 1426 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1427 | sizeof(temp_event_data), |
| 1428 | (char *) &temp_event_data, |
| 1429 | SCSI_NL_VID_TYPE_PCI |
| 1430 | | PCI_VENDOR_ID_EMULEX); |
| 1431 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1432 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1433 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1434 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1435 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1436 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | } else { |
| 1438 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1439 | * failure is a value other than FFER6. Do not call the offline |
| 1440 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | */ |
| 1442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1443 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1445 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | phba->work_status[0], phba->work_status[1]); |
| 1447 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1448 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1449 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1450 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1451 | sizeof(event_data), (char *) &event_data, |
| 1452 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1453 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1454 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1455 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1456 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1457 | } |
| 1458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1459 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1460 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1461 | * @phba: pointer to lpfc hba data structure. |
| 1462 | * @mbx_action: flag for mailbox shutdown action. |
| 1463 | * |
| 1464 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1465 | * response to port status register polling attention. It waits for port |
| 1466 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1467 | * During this process, interrupt vectors are freed and later requested |
| 1468 | * for handling possible port resource change. |
| 1469 | **/ |
| 1470 | static int |
| 1471 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action) |
| 1472 | { |
| 1473 | int rc; |
| 1474 | uint32_t intr_mode; |
| 1475 | |
| 1476 | /* |
| 1477 | * On error status condition, driver need to wait for port |
| 1478 | * ready before performing reset. |
| 1479 | */ |
| 1480 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1481 | if (!rc) { |
| 1482 | /* need reset: attempt for port recovery */ |
| 1483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1484 | "2887 Reset Needed: Attempting Port " |
| 1485 | "Recovery...\n"); |
| 1486 | lpfc_offline_prep(phba, mbx_action); |
| 1487 | lpfc_offline(phba); |
| 1488 | /* release interrupt for possible resource change */ |
| 1489 | lpfc_sli4_disable_intr(phba); |
| 1490 | lpfc_sli_brdrestart(phba); |
| 1491 | /* request and enable interrupt */ |
| 1492 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1493 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1495 | "3175 Failed to enable interrupt\n"); |
| 1496 | return -EIO; |
| 1497 | } else { |
| 1498 | phba->intr_mode = intr_mode; |
| 1499 | } |
| 1500 | rc = lpfc_online(phba); |
| 1501 | if (rc == 0) |
| 1502 | lpfc_unblock_mgmt_io(phba); |
| 1503 | } |
| 1504 | return rc; |
| 1505 | } |
| 1506 | |
| 1507 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1508 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1509 | * @phba: pointer to lpfc hba data structure. |
| 1510 | * |
| 1511 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1512 | * conditions. |
| 1513 | **/ |
| 1514 | static void |
| 1515 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1516 | { |
| 1517 | struct lpfc_vport *vport = phba->pport; |
| 1518 | uint32_t event_data; |
| 1519 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1520 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1521 | struct lpfc_register portstat_reg = {0}; |
| 1522 | uint32_t reg_err1, reg_err2; |
| 1523 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1524 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1525 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1526 | |
| 1527 | /* If the pci channel is offline, ignore possible errors, since |
| 1528 | * we cannot communicate with the pci card anyway. |
| 1529 | */ |
| 1530 | if (pci_channel_offline(phba->pcidev)) |
| 1531 | return; |
| 1532 | /* If resets are disabled then leave the HBA alone and return */ |
| 1533 | if (!phba->cfg_enable_hba_reset) |
| 1534 | return; |
| 1535 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1536 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1537 | switch (if_type) { |
| 1538 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1539 | pci_rd_rc1 = lpfc_readl( |
| 1540 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1541 | &uerrlo_reg); |
| 1542 | pci_rd_rc2 = lpfc_readl( |
| 1543 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1544 | &uemasklo_reg); |
| 1545 | /* consider PCI bus read error as pci_channel_offline */ |
| 1546 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1547 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1548 | lpfc_sli4_offline_eratt(phba); |
| 1549 | break; |
| 1550 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1551 | pci_rd_rc1 = lpfc_readl( |
| 1552 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1553 | &portstat_reg.word0); |
| 1554 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1555 | if (pci_rd_rc1 == -EIO) { |
| 1556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1557 | "3151 PCI bus read access failure: x%x\n", |
| 1558 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1559 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1560 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1561 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1562 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1563 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
| 1564 | /* TODO: Register for Overtemp async events. */ |
| 1565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1566 | "2889 Port Overtemperature event, " |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 1567 | "taking port offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1568 | spin_lock_irq(&phba->hbalock); |
| 1569 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1570 | spin_unlock_irq(&phba->hbalock); |
| 1571 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1572 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1573 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1574 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1575 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) |
| 1576 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1577 | "3143 Port Down: Firmware Restarted\n"); |
| 1578 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1579 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1581 | "3144 Port Down: Debug Dump\n"); |
| 1582 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1583 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1585 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1586 | |
| 1587 | /* Check port status register for function reset */ |
| 1588 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT); |
| 1589 | if (rc == 0) { |
| 1590 | /* don't report event on forced debug dump */ |
| 1591 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1592 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1593 | return; |
| 1594 | else |
| 1595 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1596 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1597 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1598 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1599 | "3152 Unrecoverable error, bring the port " |
| 1600 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1601 | lpfc_sli4_offline_eratt(phba); |
| 1602 | break; |
| 1603 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1604 | default: |
| 1605 | break; |
| 1606 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1607 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1608 | "3123 Report dump event to upper layer\n"); |
| 1609 | /* Send an internal error event to mgmt application */ |
| 1610 | lpfc_board_errevt_to_mgmt(phba); |
| 1611 | |
| 1612 | event_data = FC_REG_DUMP_EVENT; |
| 1613 | shost = lpfc_shost_from_vport(vport); |
| 1614 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1615 | sizeof(event_data), (char *) &event_data, |
| 1616 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1621 | * @phba: pointer to lpfc HBA data structure. |
| 1622 | * |
| 1623 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1624 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1625 | * |
| 1626 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1627 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1628 | * Any other value - error. |
| 1629 | **/ |
| 1630 | void |
| 1631 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1632 | { |
| 1633 | (*phba->lpfc_handle_eratt)(phba); |
| 1634 | } |
| 1635 | |
| 1636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1637 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1638 | * @phba: pointer to lpfc hba data structure. |
| 1639 | * |
| 1640 | * This routine is invoked from the worker thread to handle a HBA host |
| 1641 | * attention link event. |
| 1642 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1644 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1646 | struct lpfc_vport *vport = phba->pport; |
| 1647 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | LPFC_MBOXQ_t *pmb; |
| 1649 | volatile uint32_t control; |
| 1650 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1651 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | |
| 1653 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1654 | if (!pmb) { |
| 1655 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1657 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | |
| 1659 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1660 | if (!mp) { |
| 1661 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1663 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | |
| 1665 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1666 | if (!mp->virt) { |
| 1667 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1669 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1671 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1672 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1673 | |
| 1674 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1675 | lpfc_read_topology(phba, pmb, mp); |
| 1676 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1677 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1678 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1679 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1680 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1681 | if (rc == MBX_NOT_FINISHED) { |
| 1682 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1683 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1684 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | |
| 1686 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1687 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | writel(HA_LATT, phba->HAregaddr); |
| 1689 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | |
| 1692 | return; |
| 1693 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1694 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1695 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1696 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | lpfc_handle_latt_free_mp: |
| 1698 | kfree(mp); |
| 1699 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1700 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | lpfc_handle_latt_err_exit: |
| 1702 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1703 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1705 | control = readl(phba->HCregaddr); |
| 1706 | control |= HC_LAINT_ENA; |
| 1707 | writel(control, phba->HCregaddr); |
| 1708 | readl(phba->HCregaddr); /* flush */ |
| 1709 | |
| 1710 | /* Clear Link Attention in HA REG */ |
| 1711 | writel(HA_LATT, phba->HAregaddr); |
| 1712 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1713 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1714 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1715 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1717 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1718 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | |
| 1720 | return; |
| 1721 | } |
| 1722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1724 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1725 | * @phba: pointer to lpfc hba data structure. |
| 1726 | * @vpd: pointer to the vital product data. |
| 1727 | * @len: length of the vital product data in bytes. |
| 1728 | * |
| 1729 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1730 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1731 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1732 | * |
| 1733 | * Return codes |
| 1734 | * 0 - pointer to the VPD passed in is NULL |
| 1735 | * 1 - success |
| 1736 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1737 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1739 | { |
| 1740 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1741 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | int i, j; |
| 1743 | int finished = 0; |
| 1744 | int index = 0; |
| 1745 | |
| 1746 | if (!vpd) |
| 1747 | return 0; |
| 1748 | |
| 1749 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1750 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1751 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1753 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1754 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1755 | switch (vpd[index]) { |
| 1756 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1757 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | index += 1; |
| 1759 | lenlo = vpd[index]; |
| 1760 | index += 1; |
| 1761 | lenhi = vpd[index]; |
| 1762 | index += 1; |
| 1763 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1764 | index += i; |
| 1765 | break; |
| 1766 | case 0x90: |
| 1767 | index += 1; |
| 1768 | lenlo = vpd[index]; |
| 1769 | index += 1; |
| 1770 | lenhi = vpd[index]; |
| 1771 | index += 1; |
| 1772 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1773 | if (Length > len - index) |
| 1774 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | while (Length > 0) { |
| 1776 | /* Look for Serial Number */ |
| 1777 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1778 | index += 2; |
| 1779 | i = vpd[index]; |
| 1780 | index += 1; |
| 1781 | j = 0; |
| 1782 | Length -= (3+i); |
| 1783 | while(i--) { |
| 1784 | phba->SerialNumber[j++] = vpd[index++]; |
| 1785 | if (j == 31) |
| 1786 | break; |
| 1787 | } |
| 1788 | phba->SerialNumber[j] = 0; |
| 1789 | continue; |
| 1790 | } |
| 1791 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1792 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1793 | index += 2; |
| 1794 | i = vpd[index]; |
| 1795 | index += 1; |
| 1796 | j = 0; |
| 1797 | Length -= (3+i); |
| 1798 | while(i--) { |
| 1799 | phba->ModelDesc[j++] = vpd[index++]; |
| 1800 | if (j == 255) |
| 1801 | break; |
| 1802 | } |
| 1803 | phba->ModelDesc[j] = 0; |
| 1804 | continue; |
| 1805 | } |
| 1806 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1807 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1808 | index += 2; |
| 1809 | i = vpd[index]; |
| 1810 | index += 1; |
| 1811 | j = 0; |
| 1812 | Length -= (3+i); |
| 1813 | while(i--) { |
| 1814 | phba->ModelName[j++] = vpd[index++]; |
| 1815 | if (j == 79) |
| 1816 | break; |
| 1817 | } |
| 1818 | phba->ModelName[j] = 0; |
| 1819 | continue; |
| 1820 | } |
| 1821 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1822 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1823 | index += 2; |
| 1824 | i = vpd[index]; |
| 1825 | index += 1; |
| 1826 | j = 0; |
| 1827 | Length -= (3+i); |
| 1828 | while(i--) { |
| 1829 | phba->ProgramType[j++] = vpd[index++]; |
| 1830 | if (j == 255) |
| 1831 | break; |
| 1832 | } |
| 1833 | phba->ProgramType[j] = 0; |
| 1834 | continue; |
| 1835 | } |
| 1836 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1837 | phba->vpd_flag |= VPD_PORT; |
| 1838 | index += 2; |
| 1839 | i = vpd[index]; |
| 1840 | index += 1; |
| 1841 | j = 0; |
| 1842 | Length -= (3+i); |
| 1843 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1844 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1845 | (phba->sli4_hba.pport_name_sta == |
| 1846 | LPFC_SLI4_PPNAME_GET)) { |
| 1847 | j++; |
| 1848 | index++; |
| 1849 | } else |
| 1850 | phba->Port[j++] = vpd[index++]; |
| 1851 | if (j == 19) |
| 1852 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1854 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1855 | (phba->sli4_hba.pport_name_sta == |
| 1856 | LPFC_SLI4_PPNAME_NON)) |
| 1857 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1858 | continue; |
| 1859 | } |
| 1860 | else { |
| 1861 | index += 2; |
| 1862 | i = vpd[index]; |
| 1863 | index += 1; |
| 1864 | index += i; |
| 1865 | Length -= (3 + i); |
| 1866 | } |
| 1867 | } |
| 1868 | finished = 0; |
| 1869 | break; |
| 1870 | case 0x78: |
| 1871 | finished = 1; |
| 1872 | break; |
| 1873 | default: |
| 1874 | index ++; |
| 1875 | break; |
| 1876 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1877 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | |
| 1879 | return(1); |
| 1880 | } |
| 1881 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1883 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1884 | * @phba: pointer to lpfc hba data structure. |
| 1885 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1886 | * @descp: pointer to the data structure to hold the derived description. |
| 1887 | * |
| 1888 | * This routine retrieves HBA's description based on its registered PCI device |
| 1889 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1890 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1891 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1892 | * function returns, the @mdp will be filled with the model name. |
| 1893 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | 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] | 1896 | { |
| 1897 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1898 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1899 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1900 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1901 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1902 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1903 | char *name; |
| 1904 | char *bus; |
| 1905 | char *function; |
| 1906 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1907 | |
| 1908 | if (mdp && mdp[0] != '\0' |
| 1909 | && descp && descp[0] != '\0') |
| 1910 | return; |
| 1911 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 1912 | if (phba->lmt & LMT_16Gb) |
| 1913 | max_speed = 16; |
| 1914 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1915 | max_speed = 10; |
| 1916 | else if (phba->lmt & LMT_8Gb) |
| 1917 | max_speed = 8; |
| 1918 | else if (phba->lmt & LMT_4Gb) |
| 1919 | max_speed = 4; |
| 1920 | else if (phba->lmt & LMT_2Gb) |
| 1921 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1922 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1923 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1924 | else |
| 1925 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | |
| 1927 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1929 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1930 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1931 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1932 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | case PCI_DEVICE_ID_SUPERFLY: |
| 1934 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1935 | m = (typeof(m)){"LP7000", "PCI", |
| 1936 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1938 | m = (typeof(m)){"LP7000E", "PCI", |
| 1939 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | break; |
| 1941 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1942 | m = (typeof(m)){"LP8000", "PCI", |
| 1943 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1944 | break; |
| 1945 | case PCI_DEVICE_ID_CENTAUR: |
| 1946 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1947 | m = (typeof(m)){"LP9002", "PCI", |
| 1948 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1950 | m = (typeof(m)){"LP9000", "PCI", |
| 1951 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | break; |
| 1953 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1954 | m = (typeof(m)){"LP952", "PCI", |
| 1955 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1956 | break; |
| 1957 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1958 | m = (typeof(m)){"LP9802", "PCI-X", |
| 1959 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | break; |
| 1961 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1962 | m = (typeof(m)){"LP10000", "PCI-X", |
| 1963 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1964 | break; |
| 1965 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1966 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 1967 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1968 | break; |
| 1969 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1970 | m = (typeof(m)){"LP982", "PCI-X", |
| 1971 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | break; |
| 1973 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1974 | m = (typeof(m)){"LP1050", "PCI-X", |
| 1975 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | break; |
| 1977 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1978 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 1979 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1980 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1981 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1982 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 1983 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1984 | break; |
| 1985 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1986 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 1987 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1988 | break; |
| 1989 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1990 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1991 | break; |
| 1992 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1993 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1994 | break; |
| 1995 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1996 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1997 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1999 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2000 | break; |
| 2001 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2002 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2003 | break; |
| 2004 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2005 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2006 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2007 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2008 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2009 | break; |
| 2010 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2011 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2012 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2013 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2014 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2015 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | break; |
| 2017 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2018 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2019 | break; |
| 2020 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2021 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | break; |
| 2023 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2024 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2025 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2026 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2027 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2028 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2029 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2030 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2031 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2032 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2033 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2034 | break; |
| 2035 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2036 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2037 | break; |
| 2038 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2039 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2040 | break; |
| 2041 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2042 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2043 | break; |
| 2044 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2045 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2046 | break; |
| 2047 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2048 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2049 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2050 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2051 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2052 | GE = 1; |
| 2053 | break; |
| 2054 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2055 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2056 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2057 | break; |
| 2058 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2059 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2060 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2061 | break; |
| 2062 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2063 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 2064 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2065 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2066 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2067 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2068 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2069 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2070 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2071 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2072 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2073 | break; |
| 2074 | case PCI_DEVICE_ID_FALCON: |
| 2075 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2076 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2077 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2078 | case PCI_DEVICE_ID_BALIUS: |
| 2079 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2080 | "Fibre Channel Adapter"}; |
| 2081 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2082 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2083 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2084 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2085 | break; |
| 2086 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2087 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2088 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2089 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2090 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2091 | case PCI_DEVICE_ID_SKYHAWK: |
| 2092 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2093 | oneConnect = 1; |
| 2094 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2095 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2096 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2097 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2098 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2100 | |
| 2101 | if (mdp && mdp[0] == '\0') |
| 2102 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2103 | /* |
| 2104 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2105 | * and we put the port number on the end |
| 2106 | */ |
| 2107 | if (descp && descp[0] == '\0') { |
| 2108 | if (oneConnect) |
| 2109 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2110 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2111 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2112 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2113 | else if (max_speed == 0) |
| 2114 | snprintf(descp, 255, |
| 2115 | "Emulex %s %s %s ", |
| 2116 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2117 | else |
| 2118 | snprintf(descp, 255, |
| 2119 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2120 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2121 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2122 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | } |
| 2124 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2126 | * 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] | 2127 | * @phba: pointer to lpfc hba data structure. |
| 2128 | * @pring: pointer to a IOCB ring. |
| 2129 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2130 | * |
| 2131 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2132 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2133 | * |
| 2134 | * Return codes |
| 2135 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2136 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2138 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | { |
| 2140 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2141 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2142 | struct lpfc_dmabuf *mp1, *mp2; |
| 2143 | |
| 2144 | cnt += pring->missbufcnt; |
| 2145 | |
| 2146 | /* While there are buffers to post */ |
| 2147 | while (cnt > 0) { |
| 2148 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2149 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | if (iocb == NULL) { |
| 2151 | pring->missbufcnt = cnt; |
| 2152 | return cnt; |
| 2153 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | icmd = &iocb->iocb; |
| 2155 | |
| 2156 | /* 2 buffers can be posted per command */ |
| 2157 | /* Allocate buffer to post */ |
| 2158 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2159 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2160 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2161 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2162 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2163 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | pring->missbufcnt = cnt; |
| 2165 | return cnt; |
| 2166 | } |
| 2167 | |
| 2168 | INIT_LIST_HEAD(&mp1->list); |
| 2169 | /* Allocate buffer to post */ |
| 2170 | if (cnt > 1) { |
| 2171 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2172 | if (mp2) |
| 2173 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2174 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2175 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2176 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2178 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2179 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | pring->missbufcnt = cnt; |
| 2181 | return cnt; |
| 2182 | } |
| 2183 | |
| 2184 | INIT_LIST_HEAD(&mp2->list); |
| 2185 | } else { |
| 2186 | mp2 = NULL; |
| 2187 | } |
| 2188 | |
| 2189 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2190 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2191 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2192 | icmd->ulpBdeCount = 1; |
| 2193 | cnt--; |
| 2194 | if (mp2) { |
| 2195 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2196 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2197 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2198 | cnt--; |
| 2199 | icmd->ulpBdeCount = 2; |
| 2200 | } |
| 2201 | |
| 2202 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2203 | icmd->ulpLe = 1; |
| 2204 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2205 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2206 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2208 | kfree(mp1); |
| 2209 | cnt++; |
| 2210 | if (mp2) { |
| 2211 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2212 | kfree(mp2); |
| 2213 | cnt++; |
| 2214 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2215 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | return cnt; |
| 2218 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2220 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | } |
| 2223 | pring->missbufcnt = 0; |
| 2224 | return 0; |
| 2225 | } |
| 2226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2227 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2228 | * 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] | 2229 | * @phba: pointer to lpfc hba data structure. |
| 2230 | * |
| 2231 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2232 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2233 | * set to 64 IOCBs. |
| 2234 | * |
| 2235 | * Return codes |
| 2236 | * 0 - success (currently always success) |
| 2237 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2238 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2239 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2240 | { |
| 2241 | struct lpfc_sli *psli = &phba->sli; |
| 2242 | |
| 2243 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2244 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2245 | /* Ring 2 - FCP no buffers needed */ |
| 2246 | |
| 2247 | return 0; |
| 2248 | } |
| 2249 | |
| 2250 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2253 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2254 | * @HashResultPointer: pointer to an array as hash table. |
| 2255 | * |
| 2256 | * This routine sets up the initial values to the array of hash table entries |
| 2257 | * for the LC HBAs. |
| 2258 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | static void |
| 2260 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2261 | { |
| 2262 | HashResultPointer[0] = 0x67452301; |
| 2263 | HashResultPointer[1] = 0xEFCDAB89; |
| 2264 | HashResultPointer[2] = 0x98BADCFE; |
| 2265 | HashResultPointer[3] = 0x10325476; |
| 2266 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2267 | } |
| 2268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2270 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2271 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2272 | * @HashWorkingPointer: pointer to an working hash table. |
| 2273 | * |
| 2274 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2275 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2276 | * The results are putting back to the initial hash table, returned through |
| 2277 | * the @HashResultPointer as the result hash table. |
| 2278 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | static void |
| 2280 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2281 | { |
| 2282 | int t; |
| 2283 | uint32_t TEMP; |
| 2284 | uint32_t A, B, C, D, E; |
| 2285 | t = 16; |
| 2286 | do { |
| 2287 | HashWorkingPointer[t] = |
| 2288 | S(1, |
| 2289 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2290 | 8] ^ |
| 2291 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2292 | } while (++t <= 79); |
| 2293 | t = 0; |
| 2294 | A = HashResultPointer[0]; |
| 2295 | B = HashResultPointer[1]; |
| 2296 | C = HashResultPointer[2]; |
| 2297 | D = HashResultPointer[3]; |
| 2298 | E = HashResultPointer[4]; |
| 2299 | |
| 2300 | do { |
| 2301 | if (t < 20) { |
| 2302 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2303 | } else if (t < 40) { |
| 2304 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2305 | } else if (t < 60) { |
| 2306 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2307 | } else { |
| 2308 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2309 | } |
| 2310 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2311 | E = D; |
| 2312 | D = C; |
| 2313 | C = S(30, B); |
| 2314 | B = A; |
| 2315 | A = TEMP; |
| 2316 | } while (++t <= 79); |
| 2317 | |
| 2318 | HashResultPointer[0] += A; |
| 2319 | HashResultPointer[1] += B; |
| 2320 | HashResultPointer[2] += C; |
| 2321 | HashResultPointer[3] += D; |
| 2322 | HashResultPointer[4] += E; |
| 2323 | |
| 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_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2328 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2329 | * @HashWorking: pointer to the entry of the working hash array. |
| 2330 | * |
| 2331 | * This routine calculates the working hash array referred by @HashWorking |
| 2332 | * from the challenge random numbers associated with the host, referred by |
| 2333 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2334 | * array and returned by reference through @HashWorking. |
| 2335 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | static void |
| 2337 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2338 | { |
| 2339 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2340 | } |
| 2341 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2342 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2343 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2344 | * @phba: pointer to lpfc hba data structure. |
| 2345 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2346 | * |
| 2347 | * This routine performs the special handling for LC HBA initialization. |
| 2348 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | void |
| 2350 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2351 | { |
| 2352 | int t; |
| 2353 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2354 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2356 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | if (!HashWorking) |
| 2358 | return; |
| 2359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2361 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2362 | |
| 2363 | for (t = 0; t < 7; t++) |
| 2364 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2365 | |
| 2366 | lpfc_sha_init(hbainit); |
| 2367 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2368 | kfree(HashWorking); |
| 2369 | } |
| 2370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2372 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2373 | * @vport: pointer to a virtual N_Port data structure. |
| 2374 | * |
| 2375 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2376 | * It invokes the discovery state machine to perform necessary state |
| 2377 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2378 | * the physical port is treated as @vport 0. |
| 2379 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2380 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2381 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2382 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2383 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2385 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2387 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2388 | lpfc_port_link_failure(vport); |
| 2389 | |
| 2390 | 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] | 2391 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2392 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2393 | NLP_STE_UNUSED_NODE); |
| 2394 | if (!ndlp) |
| 2395 | continue; |
| 2396 | spin_lock_irq(&phba->ndlp_lock); |
| 2397 | NLP_SET_FREE_REQ(ndlp); |
| 2398 | spin_unlock_irq(&phba->ndlp_lock); |
| 2399 | /* Trigger the release of the ndlp memory */ |
| 2400 | lpfc_nlp_put(ndlp); |
| 2401 | continue; |
| 2402 | } |
| 2403 | spin_lock_irq(&phba->ndlp_lock); |
| 2404 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2405 | /* The ndlp should not be in memory free mode already */ |
| 2406 | spin_unlock_irq(&phba->ndlp_lock); |
| 2407 | continue; |
| 2408 | } else |
| 2409 | /* Indicate request for freeing ndlp memory */ |
| 2410 | NLP_SET_FREE_REQ(ndlp); |
| 2411 | spin_unlock_irq(&phba->ndlp_lock); |
| 2412 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2413 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2414 | ndlp->nlp_DID == Fabric_DID) { |
| 2415 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2416 | lpfc_nlp_put(ndlp); |
| 2417 | continue; |
| 2418 | } |
| 2419 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2420 | /* take care of nodes in unused state before the state |
| 2421 | * machine taking action. |
| 2422 | */ |
| 2423 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2424 | lpfc_nlp_put(ndlp); |
| 2425 | continue; |
| 2426 | } |
| 2427 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2428 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2429 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2430 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2431 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2432 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2433 | NLP_EVT_DEVICE_RM); |
| 2434 | } |
| 2435 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2436 | /* At this point, ALL ndlp's should be gone |
| 2437 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2438 | * Lets wait for this to happen, if needed. |
| 2439 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2440 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2441 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2442 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2443 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2444 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2445 | &vport->fc_nodes, nlp_listp) { |
| 2446 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2447 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2448 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2449 | "usgmap:x%x refcnt:%d\n", |
| 2450 | ndlp->nlp_DID, (void *)ndlp, |
| 2451 | ndlp->nlp_usg_map, |
| 2452 | atomic_read( |
| 2453 | &ndlp->kref.refcount)); |
| 2454 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2455 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2456 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2457 | |
| 2458 | /* Wait for any activity on ndlps to settle */ |
| 2459 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2460 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2461 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2462 | } |
| 2463 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2464 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2465 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2466 | * @vport: pointer to a virtual N_Port data structure. |
| 2467 | * |
| 2468 | * This routine stops all the timers associated with a @vport. This function |
| 2469 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2470 | * port is treated as @vport 0. |
| 2471 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2472 | void |
| 2473 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2474 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2475 | del_timer_sync(&vport->els_tmofunc); |
| 2476 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2477 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2478 | lpfc_can_disctmo(vport); |
| 2479 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | } |
| 2481 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2482 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2483 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2484 | * @phba: pointer to lpfc hba data structure. |
| 2485 | * |
| 2486 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2487 | * caller of this routine should already hold the host lock. |
| 2488 | **/ |
| 2489 | void |
| 2490 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2491 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2492 | /* Clear pending FCF rediscovery wait flag */ |
| 2493 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2494 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2495 | /* Now, try to stop the timer */ |
| 2496 | del_timer(&phba->fcf.redisc_wait); |
| 2497 | } |
| 2498 | |
| 2499 | /** |
| 2500 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2501 | * @phba: pointer to lpfc hba data structure. |
| 2502 | * |
| 2503 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2504 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2505 | * lock held before proceeding with disabling the timer and clearing the |
| 2506 | * wait timer pendig flag. |
| 2507 | **/ |
| 2508 | void |
| 2509 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2510 | { |
| 2511 | spin_lock_irq(&phba->hbalock); |
| 2512 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2513 | /* FCF rediscovery timer already fired or stopped */ |
| 2514 | spin_unlock_irq(&phba->hbalock); |
| 2515 | return; |
| 2516 | } |
| 2517 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2518 | /* Clear failover in progress flags */ |
| 2519 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2520 | spin_unlock_irq(&phba->hbalock); |
| 2521 | } |
| 2522 | |
| 2523 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2524 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2525 | * @phba: pointer to lpfc hba data structure. |
| 2526 | * |
| 2527 | * This routine stops all the timers associated with a HBA. This function is |
| 2528 | * invoked before either putting a HBA offline or unloading the driver. |
| 2529 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2530 | void |
| 2531 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2532 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2533 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2534 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2535 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2536 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2537 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2538 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2539 | del_timer_sync(&phba->rrq_tmr); |
| 2540 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2541 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2542 | phba->hb_outstanding = 0; |
| 2543 | |
| 2544 | switch (phba->pci_dev_grp) { |
| 2545 | case LPFC_PCI_DEV_LP: |
| 2546 | /* Stop any LightPulse device specific driver timers */ |
| 2547 | del_timer_sync(&phba->fcp_poll_timer); |
| 2548 | break; |
| 2549 | case LPFC_PCI_DEV_OC: |
| 2550 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2551 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2552 | break; |
| 2553 | default: |
| 2554 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2555 | "0297 Invalid device group (x%x)\n", |
| 2556 | phba->pci_dev_grp); |
| 2557 | break; |
| 2558 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2559 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | } |
| 2561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2563 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2564 | * @phba: pointer to lpfc hba data structure. |
| 2565 | * |
| 2566 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2567 | * management interface is marked as blocked, all the user space access to |
| 2568 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2569 | * all be blocked. The HBA is set to block the management interface when the |
| 2570 | * driver prepares the HBA interface for online or offline. |
| 2571 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2572 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2573 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2574 | { |
| 2575 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2576 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2577 | unsigned long timeout; |
| 2578 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2579 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2580 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2582 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2583 | return; |
| 2584 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2585 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2586 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2587 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2588 | /* Determine how long we might wait for the active mailbox |
| 2589 | * command to be gracefully completed by firmware. |
| 2590 | */ |
| 2591 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2592 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2593 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2594 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2595 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2596 | /* Wait for the outstnading mailbox command to complete */ |
| 2597 | while (phba->sli.mbox_active) { |
| 2598 | /* Check active mailbox complete status every 2ms */ |
| 2599 | msleep(2); |
| 2600 | if (time_after(jiffies, timeout)) { |
| 2601 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2602 | "2813 Mgmt IO is Blocked %x " |
| 2603 | "- mbox cmd %x still active\n", |
| 2604 | phba->sli.sli_flag, actcmd); |
| 2605 | break; |
| 2606 | } |
| 2607 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2608 | } |
| 2609 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2610 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2611 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2612 | * @phba: pointer to lpfc hba data structure. |
| 2613 | * |
| 2614 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2615 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2616 | * is to fixup the temporary rpi assignments. |
| 2617 | **/ |
| 2618 | void |
| 2619 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2620 | { |
| 2621 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2622 | struct lpfc_vport **vports; |
| 2623 | int i; |
| 2624 | |
| 2625 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2626 | return; |
| 2627 | |
| 2628 | vports = lpfc_create_vport_work_array(phba); |
| 2629 | if (vports != NULL) { |
| 2630 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2631 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2632 | continue; |
| 2633 | |
| 2634 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2635 | &vports[i]->fc_nodes, |
| 2636 | nlp_listp) { |
| 2637 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2638 | ndlp->nlp_rpi = |
| 2639 | lpfc_sli4_alloc_rpi(phba); |
| 2640 | } |
| 2641 | } |
| 2642 | } |
| 2643 | lpfc_destroy_vport_work_array(phba, vports); |
| 2644 | } |
| 2645 | |
| 2646 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2647 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2648 | * @phba: pointer to lpfc hba data structure. |
| 2649 | * |
| 2650 | * This routine initializes the HBA and brings a HBA online. During this |
| 2651 | * process, the management interface is blocked to prevent user space access |
| 2652 | * to the HBA interfering with the driver initialization. |
| 2653 | * |
| 2654 | * Return codes |
| 2655 | * 0 - successful |
| 2656 | * 1 - failed |
| 2657 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2659 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2661 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2662 | struct lpfc_vport **vports; |
| 2663 | int i; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2664 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | if (!phba) |
| 2667 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2668 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | return 0; |
| 2672 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2673 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2674 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2676 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2678 | if (!lpfc_sli_queue_setup(phba)) { |
| 2679 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2683 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2684 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2685 | lpfc_unblock_mgmt_io(phba); |
| 2686 | return 1; |
| 2687 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2688 | spin_lock_irq(&phba->hbalock); |
| 2689 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 2690 | vpis_cleared = true; |
| 2691 | spin_unlock_irq(&phba->hbalock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2692 | } else { |
| 2693 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2694 | lpfc_unblock_mgmt_io(phba); |
| 2695 | return 1; |
| 2696 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2697 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2699 | vports = lpfc_create_vport_work_array(phba); |
| 2700 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2701 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2702 | struct Scsi_Host *shost; |
| 2703 | shost = lpfc_shost_from_vport(vports[i]); |
| 2704 | spin_lock_irq(shost->host_lock); |
| 2705 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2706 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2707 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2708 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2709 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2710 | if ((vpis_cleared) && |
| 2711 | (vports[i]->port_type != |
| 2712 | LPFC_PHYSICAL_PORT)) |
| 2713 | vports[i]->vpi = 0; |
| 2714 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2715 | spin_unlock_irq(shost->host_lock); |
| 2716 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2717 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2719 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | return 0; |
| 2721 | } |
| 2722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2723 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2724 | * 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] | 2725 | * @phba: pointer to lpfc hba data structure. |
| 2726 | * |
| 2727 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2728 | * HBA's management interface is marked as not blocked, all the user space |
| 2729 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2730 | * interface will be allowed. The HBA is set to block the management interface |
| 2731 | * when the driver prepares the HBA interface for online or offline and then |
| 2732 | * set to unblock the management interface afterwards. |
| 2733 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2734 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2735 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2736 | { |
| 2737 | unsigned long iflag; |
| 2738 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2739 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2740 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2741 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2742 | } |
| 2743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2745 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2746 | * @phba: pointer to lpfc hba data structure. |
| 2747 | * |
| 2748 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2749 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2750 | * queue to make it ready to be brought offline. |
| 2751 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2752 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2753 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2754 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2755 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2756 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2757 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2758 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2759 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2761 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2762 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2764 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | |
| 2766 | lpfc_linkdown(phba); |
| 2767 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2768 | /* Issue an unreg_login to all nodes on all vports */ |
| 2769 | vports = lpfc_create_vport_work_array(phba); |
| 2770 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2771 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2772 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2773 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2774 | shost = lpfc_shost_from_vport(vports[i]); |
| 2775 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2776 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2777 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2778 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2779 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2780 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2781 | shost = lpfc_shost_from_vport(vports[i]); |
| 2782 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2783 | &vports[i]->fc_nodes, |
| 2784 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2785 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2786 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2787 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2788 | continue; |
| 2789 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2790 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2791 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2792 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2793 | NULL, NLP_EVT_DEVICE_RM); |
| 2794 | } |
| 2795 | spin_lock_irq(shost->host_lock); |
| 2796 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2797 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2798 | /* |
| 2799 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2800 | * RPI. Get a new RPI when the adapter port |
| 2801 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2802 | */ |
| 2803 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2804 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2805 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2806 | } |
| 2807 | } |
| 2808 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2809 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2810 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2811 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2814 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2815 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2816 | * @phba: pointer to lpfc hba data structure. |
| 2817 | * |
| 2818 | * This routine actually brings a HBA offline. It stops all the timers |
| 2819 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2820 | * marks the HBA as in offline state for the upper layer protocol. |
| 2821 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2822 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2824 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2825 | struct Scsi_Host *shost; |
| 2826 | struct lpfc_vport **vports; |
| 2827 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2828 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2829 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2830 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2831 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2832 | /* stop port and all timers associated with this hba */ |
| 2833 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2834 | vports = lpfc_create_vport_work_array(phba); |
| 2835 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2836 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2837 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2838 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2839 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2840 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2842 | now. */ |
| 2843 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2844 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2845 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2846 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2847 | vports = lpfc_create_vport_work_array(phba); |
| 2848 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2849 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2850 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2851 | spin_lock_irq(shost->host_lock); |
| 2852 | vports[i]->work_port_events = 0; |
| 2853 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2854 | spin_unlock_irq(shost->host_lock); |
| 2855 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2856 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | } |
| 2858 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2859 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2860 | * 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] | 2861 | * @phba: pointer to lpfc hba data structure. |
| 2862 | * |
| 2863 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2864 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2865 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2866 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2867 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2868 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | { |
| 2870 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2871 | struct lpfc_iocbq *io, *io_next; |
| 2872 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2873 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2874 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2876 | |
| 2877 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 2878 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 2879 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | list_del(&sb->list); |
| 2881 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2882 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2883 | kfree(sb); |
| 2884 | phba->total_scsi_bufs--; |
| 2885 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2886 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 2887 | |
| 2888 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 2889 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 2890 | list) { |
| 2891 | list_del(&sb->list); |
| 2892 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
| 2893 | sb->dma_handle); |
| 2894 | kfree(sb); |
| 2895 | phba->total_scsi_bufs--; |
| 2896 | } |
| 2897 | spin_unlock(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2898 | |
| 2899 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2900 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2901 | list_del(&io->list); |
| 2902 | kfree(io); |
| 2903 | phba->total_iocbq_bufs--; |
| 2904 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2905 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2906 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | /** |
| 2910 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 2911 | * @phba: pointer to lpfc hba data structure. |
| 2912 | * |
| 2913 | * This routine first calculates the sizes of the current els and allocated |
| 2914 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 2915 | * XRIs assigned due to port function reset. During port initialization, the |
| 2916 | * current els and allocated scsi sgl lists are 0s. |
| 2917 | * |
| 2918 | * Return codes |
| 2919 | * 0 - successful (for now, it always returns 0) |
| 2920 | **/ |
| 2921 | int |
| 2922 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 2923 | { |
| 2924 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 2925 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 2926 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 2927 | LIST_HEAD(els_sgl_list); |
| 2928 | LIST_HEAD(scsi_sgl_list); |
| 2929 | int rc; |
| 2930 | |
| 2931 | /* |
| 2932 | * update on pci function's els xri-sgl list |
| 2933 | */ |
| 2934 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 2935 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 2936 | /* els xri-sgl expanded */ |
| 2937 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 2938 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2939 | "3157 ELS xri-sgl count increased from " |
| 2940 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2941 | els_xri_cnt); |
| 2942 | /* allocate the additional els sgls */ |
| 2943 | for (i = 0; i < xri_cnt; i++) { |
| 2944 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 2945 | GFP_KERNEL); |
| 2946 | if (sglq_entry == NULL) { |
| 2947 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2948 | "2562 Failure to allocate an " |
| 2949 | "ELS sgl entry:%d\n", i); |
| 2950 | rc = -ENOMEM; |
| 2951 | goto out_free_mem; |
| 2952 | } |
| 2953 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 2954 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 2955 | &sglq_entry->phys); |
| 2956 | if (sglq_entry->virt == NULL) { |
| 2957 | kfree(sglq_entry); |
| 2958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2959 | "2563 Failure to allocate an " |
| 2960 | "ELS mbuf:%d\n", i); |
| 2961 | rc = -ENOMEM; |
| 2962 | goto out_free_mem; |
| 2963 | } |
| 2964 | sglq_entry->sgl = sglq_entry->virt; |
| 2965 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 2966 | sglq_entry->state = SGL_FREED; |
| 2967 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 2968 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 2969 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2970 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 2971 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2972 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 2973 | /* els xri-sgl shrinked */ |
| 2974 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 2975 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2976 | "3158 ELS xri-sgl count decreased from " |
| 2977 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2978 | els_xri_cnt); |
| 2979 | spin_lock_irq(&phba->hbalock); |
| 2980 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
| 2981 | spin_unlock_irq(&phba->hbalock); |
| 2982 | /* release extra els sgls from list */ |
| 2983 | for (i = 0; i < xri_cnt; i++) { |
| 2984 | list_remove_head(&els_sgl_list, |
| 2985 | sglq_entry, struct lpfc_sglq, list); |
| 2986 | if (sglq_entry) { |
| 2987 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 2988 | sglq_entry->phys); |
| 2989 | kfree(sglq_entry); |
| 2990 | } |
| 2991 | } |
| 2992 | spin_lock_irq(&phba->hbalock); |
| 2993 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2994 | spin_unlock_irq(&phba->hbalock); |
| 2995 | } else |
| 2996 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2997 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 2998 | els_xri_cnt); |
| 2999 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3000 | |
| 3001 | /* update xris to els sgls on the list */ |
| 3002 | sglq_entry = NULL; |
| 3003 | sglq_entry_next = NULL; |
| 3004 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3005 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 3006 | lxri = lpfc_sli4_next_xritag(phba); |
| 3007 | if (lxri == NO_XRI) { |
| 3008 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3009 | "2400 Failed to allocate xri for " |
| 3010 | "ELS sgl\n"); |
| 3011 | rc = -ENOMEM; |
| 3012 | goto out_free_mem; |
| 3013 | } |
| 3014 | sglq_entry->sli4_lxritag = lxri; |
| 3015 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3016 | } |
| 3017 | |
| 3018 | /* |
| 3019 | * update on pci function's allocated scsi xri-sgl list |
| 3020 | */ |
| 3021 | phba->total_scsi_bufs = 0; |
| 3022 | |
| 3023 | /* maximum number of xris available for scsi buffers */ |
| 3024 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3025 | els_xri_cnt; |
| 3026 | |
| 3027 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3028 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 3029 | "maximum SCSI xri count:%d\n", |
| 3030 | phba->sli4_hba.scsi_xri_cnt, |
| 3031 | phba->sli4_hba.scsi_xri_max); |
| 3032 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3033 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
| 3034 | spin_lock_irq(&phba->scsi_buf_list_put_lock); |
| 3035 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3036 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
| 3037 | spin_unlock_irq(&phba->scsi_buf_list_put_lock); |
| 3038 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3039 | |
| 3040 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3041 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3042 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3043 | phba->sli4_hba.scsi_xri_max; |
| 3044 | /* release the extra allocated scsi buffers */ |
| 3045 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3046 | list_remove_head(&scsi_sgl_list, psb, |
| 3047 | struct lpfc_scsi_buf, list); |
| 3048 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, |
| 3049 | psb->dma_handle); |
| 3050 | kfree(psb); |
| 3051 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3052 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3053 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3054 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | /* update xris associated to remaining allocated scsi buffers */ |
| 3058 | psb = NULL; |
| 3059 | psb_next = NULL; |
| 3060 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3061 | lxri = lpfc_sli4_next_xritag(phba); |
| 3062 | if (lxri == NO_XRI) { |
| 3063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3064 | "2560 Failed to allocate xri for " |
| 3065 | "scsi buffer\n"); |
| 3066 | rc = -ENOMEM; |
| 3067 | goto out_free_mem; |
| 3068 | } |
| 3069 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3070 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3071 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3072 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
| 3073 | spin_lock_irq(&phba->scsi_buf_list_put_lock); |
| 3074 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3075 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 3076 | spin_unlock_irq(&phba->scsi_buf_list_put_lock); |
| 3077 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3078 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3080 | |
| 3081 | out_free_mem: |
| 3082 | lpfc_free_els_sgl_list(phba); |
| 3083 | lpfc_scsi_free(phba); |
| 3084 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | } |
| 3086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3088 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3089 | * @phba: pointer to lpfc hba data structure. |
| 3090 | * @instance: a unique integer ID to this FC port. |
| 3091 | * @dev: pointer to the device data structure. |
| 3092 | * |
| 3093 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3094 | * can be created on top of either a physical port or a virtual port provided |
| 3095 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3096 | * and associates the FC port created before adding the shost into the SCSI |
| 3097 | * layer. |
| 3098 | * |
| 3099 | * Return codes |
| 3100 | * @vport - pointer to the virtual N_Port data structure. |
| 3101 | * NULL - port create failed. |
| 3102 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3104 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3105 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3106 | struct lpfc_vport *vport; |
| 3107 | struct Scsi_Host *shost; |
| 3108 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3109 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3110 | if (dev != &phba->pcidev->dev) |
| 3111 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3112 | sizeof(struct lpfc_vport)); |
| 3113 | else |
| 3114 | shost = scsi_host_alloc(&lpfc_template, |
| 3115 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | if (!shost) |
| 3117 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3118 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3119 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3120 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3122 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3123 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3124 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3125 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3126 | shost->unique_id = instance; |
| 3127 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3128 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3129 | shost->this_id = -1; |
| 3130 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3131 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3132 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3133 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3134 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3135 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3136 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3137 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3138 | * Set initial can_queue value since 0 is no longer supported and |
| 3139 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3140 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3141 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3142 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3143 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3144 | shost->transportt = lpfc_vport_transport_template; |
| 3145 | vport->port_type = LPFC_NPIV_PORT; |
| 3146 | } else { |
| 3147 | shost->transportt = lpfc_transport_template; |
| 3148 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3149 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3150 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3151 | /* Initialize all internally managed lists. */ |
| 3152 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3153 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3154 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3155 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3156 | init_timer(&vport->fc_disctmo); |
| 3157 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3158 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3159 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | init_timer(&vport->fc_fdmitmo); |
| 3161 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3162 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | init_timer(&vport->els_tmofunc); |
| 3165 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3166 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3167 | |
| 3168 | init_timer(&vport->delayed_disc_tmo); |
| 3169 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3170 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3171 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3172 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3173 | if (error) |
| 3174 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3175 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3176 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3178 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3179 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3180 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | out_put_shost: |
| 3182 | scsi_host_put(shost); |
| 3183 | out: |
| 3184 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3185 | } |
| 3186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3188 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3189 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3190 | * |
| 3191 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3192 | * resources associated with the port are released. |
| 3193 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3194 | void |
| 3195 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3196 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3197 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3198 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3199 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3200 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3201 | fc_remove_host(shost); |
| 3202 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3203 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3204 | spin_lock_irq(&phba->hbalock); |
| 3205 | list_del_init(&vport->listentry); |
| 3206 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3207 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3208 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3209 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3210 | } |
| 3211 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3212 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3213 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3214 | * |
| 3215 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3216 | * uses the kernel idr facility to perform the task. |
| 3217 | * |
| 3218 | * Return codes: |
| 3219 | * instance - a unique integer ID allocated as the new instance. |
| 3220 | * -1 - lpfc get instance failed. |
| 3221 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3222 | int |
| 3223 | lpfc_get_instance(void) |
| 3224 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3225 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3226 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3227 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 3228 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3229 | } |
| 3230 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3231 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3232 | * 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] | 3233 | * @shost: pointer to SCSI host data structure. |
| 3234 | * @time: elapsed time of the scan in jiffies. |
| 3235 | * |
| 3236 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3237 | * whether the scan host is finished. |
| 3238 | * |
| 3239 | * Note: there is no scan_start function as adapter initialization will have |
| 3240 | * asynchronously kicked off the link initialization. |
| 3241 | * |
| 3242 | * Return codes |
| 3243 | * 0 - SCSI host scan is not over yet. |
| 3244 | * 1 - SCSI host scan is over. |
| 3245 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3246 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3247 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3248 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3249 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3250 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3251 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3252 | spin_lock_irq(shost->host_lock); |
| 3253 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3254 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3255 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3256 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3257 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3258 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3260 | "0461 Scanning longer than 30 " |
| 3261 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3262 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3263 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3265 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 3266 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3267 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3268 | "0465 Link down longer than 15 " |
| 3269 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3270 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3271 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3272 | } |
| 3273 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3274 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3275 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3276 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3277 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3278 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3279 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3280 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3281 | goto finished; |
| 3282 | |
| 3283 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3284 | |
| 3285 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3286 | spin_unlock_irq(shost->host_lock); |
| 3287 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3288 | } |
| 3289 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3291 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3292 | * @shost: pointer to SCSI host data structure. |
| 3293 | * |
| 3294 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3295 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3296 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3297 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3298 | { |
| 3299 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3300 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3301 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3302 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3303 | */ |
| 3304 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3305 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3306 | 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] | 3307 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3308 | |
| 3309 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3310 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3311 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3312 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3313 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3314 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3315 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3316 | |
| 3317 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3318 | if (phba->lmt & LMT_16Gb) |
| 3319 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3320 | if (phba->lmt & LMT_10Gb) |
| 3321 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3322 | if (phba->lmt & LMT_8Gb) |
| 3323 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3324 | if (phba->lmt & LMT_4Gb) |
| 3325 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3326 | if (phba->lmt & LMT_2Gb) |
| 3327 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3328 | if (phba->lmt & LMT_1Gb) |
| 3329 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3330 | |
| 3331 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3332 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3333 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3334 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3335 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3336 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3337 | /* This value is also unchanging */ |
| 3338 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3340 | fc_host_active_fc4s(shost)[2] = 1; |
| 3341 | fc_host_active_fc4s(shost)[7] = 1; |
| 3342 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3343 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3344 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3345 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3346 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3349 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3350 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3351 | * @phba: pointer to lpfc hba data structure. |
| 3352 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3353 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3354 | * from generating interrupts and stops the device driver's timers for the |
| 3355 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3356 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3357 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3358 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3359 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3360 | /* Clear all interrupt enable conditions */ |
| 3361 | writel(0, phba->HCregaddr); |
| 3362 | readl(phba->HCregaddr); /* flush */ |
| 3363 | /* Clear all pending interrupts */ |
| 3364 | writel(0xffffffff, phba->HAregaddr); |
| 3365 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3366 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3367 | /* Reset some HBA SLI setup states */ |
| 3368 | lpfc_stop_hba_timers(phba); |
| 3369 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3370 | } |
| 3371 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3372 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3373 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3374 | * @phba: pointer to lpfc hba data structure. |
| 3375 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3376 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3377 | * from generating interrupts and stops the device driver's timers for the |
| 3378 | * device. |
| 3379 | **/ |
| 3380 | static void |
| 3381 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3382 | { |
| 3383 | /* Reset some HBA SLI4 setup states */ |
| 3384 | lpfc_stop_hba_timers(phba); |
| 3385 | phba->pport->work_port_events = 0; |
| 3386 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | /** |
| 3390 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3391 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3392 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3393 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3394 | * the API jump table function pointer from the lpfc_hba struct. |
| 3395 | **/ |
| 3396 | void |
| 3397 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3398 | { |
| 3399 | phba->lpfc_stop_port(phba); |
| 3400 | } |
| 3401 | |
| 3402 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3403 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3404 | * @phba: Pointer to hba for which this call is being executed. |
| 3405 | * |
| 3406 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3407 | **/ |
| 3408 | void |
| 3409 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3410 | { |
| 3411 | unsigned long fcf_redisc_wait_tmo = |
| 3412 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3413 | /* Start fcf rediscovery wait period timer */ |
| 3414 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3415 | spin_lock_irq(&phba->hbalock); |
| 3416 | /* Allow action to new fcf asynchronous event */ |
| 3417 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3418 | /* Mark the FCF rediscovery pending state */ |
| 3419 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3420 | spin_unlock_irq(&phba->hbalock); |
| 3421 | } |
| 3422 | |
| 3423 | /** |
| 3424 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3425 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3426 | * |
| 3427 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3428 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3429 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3430 | * list, and then worker thread shall be waked up for processing from the |
| 3431 | * worker thread context. |
| 3432 | **/ |
| 3433 | void |
| 3434 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3435 | { |
| 3436 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3437 | |
| 3438 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3439 | spin_lock_irq(&phba->hbalock); |
| 3440 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3441 | spin_unlock_irq(&phba->hbalock); |
| 3442 | return; |
| 3443 | } |
| 3444 | /* Clear FCF rediscovery timer pending flag */ |
| 3445 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3446 | /* FCF rediscovery event to worker thread */ |
| 3447 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3448 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3449 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3450 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3451 | /* wake up worker thread */ |
| 3452 | lpfc_worker_wake_up(phba); |
| 3453 | } |
| 3454 | |
| 3455 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3456 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3457 | * @phba: pointer to lpfc hba data structure. |
| 3458 | * @acqe_link: pointer to the async link completion queue entry. |
| 3459 | * |
| 3460 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3461 | * translate it into the base driver's read link attention mailbox command |
| 3462 | * status. |
| 3463 | * |
| 3464 | * Return: Link-attention status in terms of base driver's coding. |
| 3465 | **/ |
| 3466 | static uint16_t |
| 3467 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3468 | struct lpfc_acqe_link *acqe_link) |
| 3469 | { |
| 3470 | uint16_t latt_fault; |
| 3471 | |
| 3472 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3473 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3474 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3475 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3476 | latt_fault = 0; |
| 3477 | break; |
| 3478 | default: |
| 3479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3480 | "0398 Invalid link fault code: x%x\n", |
| 3481 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3482 | latt_fault = MBXERR_ERROR; |
| 3483 | break; |
| 3484 | } |
| 3485 | return latt_fault; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3490 | * @phba: pointer to lpfc hba data structure. |
| 3491 | * @acqe_link: pointer to the async link completion queue entry. |
| 3492 | * |
| 3493 | * This routine is to parse the SLI4 link attention type and translate it |
| 3494 | * into the base driver's link attention type coding. |
| 3495 | * |
| 3496 | * Return: Link attention type in terms of base driver's coding. |
| 3497 | **/ |
| 3498 | static uint8_t |
| 3499 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3500 | struct lpfc_acqe_link *acqe_link) |
| 3501 | { |
| 3502 | uint8_t att_type; |
| 3503 | |
| 3504 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3505 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3506 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3507 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3508 | break; |
| 3509 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3510 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3511 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3512 | break; |
| 3513 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3514 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3515 | break; |
| 3516 | default: |
| 3517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3518 | "0399 Invalid link attention type: x%x\n", |
| 3519 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3520 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3521 | break; |
| 3522 | } |
| 3523 | return att_type; |
| 3524 | } |
| 3525 | |
| 3526 | /** |
| 3527 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3528 | * @phba: pointer to lpfc hba data structure. |
| 3529 | * @acqe_link: pointer to the async link completion queue entry. |
| 3530 | * |
| 3531 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3532 | * it into the base driver's link-attention link speed coding. |
| 3533 | * |
| 3534 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3535 | **/ |
| 3536 | static uint8_t |
| 3537 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3538 | struct lpfc_acqe_link *acqe_link) |
| 3539 | { |
| 3540 | uint8_t link_speed; |
| 3541 | |
| 3542 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3543 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3544 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3545 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3546 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3547 | break; |
| 3548 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3549 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3550 | break; |
| 3551 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3552 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3553 | break; |
| 3554 | default: |
| 3555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3556 | "0483 Invalid link-attention link speed: x%x\n", |
| 3557 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3558 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3559 | break; |
| 3560 | } |
| 3561 | return link_speed; |
| 3562 | } |
| 3563 | |
| 3564 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3565 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 3566 | * @phba: pointer to lpfc hba data structure. |
| 3567 | * |
| 3568 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 3569 | * |
| 3570 | * Return: link speed in terms of Mbps. |
| 3571 | **/ |
| 3572 | uint32_t |
| 3573 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 3574 | { |
| 3575 | uint32_t link_speed; |
| 3576 | |
| 3577 | if (!lpfc_is_link_up(phba)) |
| 3578 | return 0; |
| 3579 | |
| 3580 | switch (phba->fc_linkspeed) { |
| 3581 | case LPFC_LINK_SPEED_1GHZ: |
| 3582 | link_speed = 1000; |
| 3583 | break; |
| 3584 | case LPFC_LINK_SPEED_2GHZ: |
| 3585 | link_speed = 2000; |
| 3586 | break; |
| 3587 | case LPFC_LINK_SPEED_4GHZ: |
| 3588 | link_speed = 4000; |
| 3589 | break; |
| 3590 | case LPFC_LINK_SPEED_8GHZ: |
| 3591 | link_speed = 8000; |
| 3592 | break; |
| 3593 | case LPFC_LINK_SPEED_10GHZ: |
| 3594 | link_speed = 10000; |
| 3595 | break; |
| 3596 | case LPFC_LINK_SPEED_16GHZ: |
| 3597 | link_speed = 16000; |
| 3598 | break; |
| 3599 | default: |
| 3600 | link_speed = 0; |
| 3601 | } |
| 3602 | return link_speed; |
| 3603 | } |
| 3604 | |
| 3605 | /** |
| 3606 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 3607 | * @phba: pointer to lpfc hba data structure. |
| 3608 | * @evt_code: asynchronous event code. |
| 3609 | * @speed_code: asynchronous event link speed code. |
| 3610 | * |
| 3611 | * This routine is to parse the giving SLI4 async event link speed code into |
| 3612 | * value of Mbps for the link speed. |
| 3613 | * |
| 3614 | * Return: link speed in terms of Mbps. |
| 3615 | **/ |
| 3616 | static uint32_t |
| 3617 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 3618 | uint8_t speed_code) |
| 3619 | { |
| 3620 | uint32_t port_speed; |
| 3621 | |
| 3622 | switch (evt_code) { |
| 3623 | case LPFC_TRAILER_CODE_LINK: |
| 3624 | switch (speed_code) { |
| 3625 | case LPFC_EVT_CODE_LINK_NO_LINK: |
| 3626 | port_speed = 0; |
| 3627 | break; |
| 3628 | case LPFC_EVT_CODE_LINK_10_MBIT: |
| 3629 | port_speed = 10; |
| 3630 | break; |
| 3631 | case LPFC_EVT_CODE_LINK_100_MBIT: |
| 3632 | port_speed = 100; |
| 3633 | break; |
| 3634 | case LPFC_EVT_CODE_LINK_1_GBIT: |
| 3635 | port_speed = 1000; |
| 3636 | break; |
| 3637 | case LPFC_EVT_CODE_LINK_10_GBIT: |
| 3638 | port_speed = 10000; |
| 3639 | break; |
| 3640 | default: |
| 3641 | port_speed = 0; |
| 3642 | } |
| 3643 | break; |
| 3644 | case LPFC_TRAILER_CODE_FC: |
| 3645 | switch (speed_code) { |
| 3646 | case LPFC_EVT_CODE_FC_NO_LINK: |
| 3647 | port_speed = 0; |
| 3648 | break; |
| 3649 | case LPFC_EVT_CODE_FC_1_GBAUD: |
| 3650 | port_speed = 1000; |
| 3651 | break; |
| 3652 | case LPFC_EVT_CODE_FC_2_GBAUD: |
| 3653 | port_speed = 2000; |
| 3654 | break; |
| 3655 | case LPFC_EVT_CODE_FC_4_GBAUD: |
| 3656 | port_speed = 4000; |
| 3657 | break; |
| 3658 | case LPFC_EVT_CODE_FC_8_GBAUD: |
| 3659 | port_speed = 8000; |
| 3660 | break; |
| 3661 | case LPFC_EVT_CODE_FC_10_GBAUD: |
| 3662 | port_speed = 10000; |
| 3663 | break; |
| 3664 | case LPFC_EVT_CODE_FC_16_GBAUD: |
| 3665 | port_speed = 16000; |
| 3666 | break; |
| 3667 | default: |
| 3668 | port_speed = 0; |
| 3669 | } |
| 3670 | break; |
| 3671 | default: |
| 3672 | port_speed = 0; |
| 3673 | } |
| 3674 | return port_speed; |
| 3675 | } |
| 3676 | |
| 3677 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3678 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3679 | * @phba: pointer to lpfc hba data structure. |
| 3680 | * @acqe_link: pointer to the async link completion queue entry. |
| 3681 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3682 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3683 | **/ |
| 3684 | static void |
| 3685 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3686 | struct lpfc_acqe_link *acqe_link) |
| 3687 | { |
| 3688 | struct lpfc_dmabuf *mp; |
| 3689 | LPFC_MBOXQ_t *pmb; |
| 3690 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3691 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3692 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3693 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3694 | |
| 3695 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3696 | 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] | 3697 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3698 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3699 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3700 | if (!pmb) { |
| 3701 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3702 | "0395 The mboxq allocation failed\n"); |
| 3703 | return; |
| 3704 | } |
| 3705 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3706 | if (!mp) { |
| 3707 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3708 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3709 | goto out_free_pmb; |
| 3710 | } |
| 3711 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3712 | if (!mp->virt) { |
| 3713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3714 | "0397 The mbuf allocation failed\n"); |
| 3715 | goto out_free_dmabuf; |
| 3716 | } |
| 3717 | |
| 3718 | /* Cleanup any outstanding ELS commands */ |
| 3719 | lpfc_els_flush_all_cmd(phba); |
| 3720 | |
| 3721 | /* Block ELS IOCBs until we have done process link event */ |
| 3722 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3723 | |
| 3724 | /* Update link event statistics */ |
| 3725 | phba->sli.slistat.link_event++; |
| 3726 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3727 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3728 | lpfc_read_topology(phba, pmb, mp); |
| 3729 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3730 | pmb->vport = phba->pport; |
| 3731 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3732 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3733 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3734 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 3735 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3736 | phba->sli4_hba.link_state.duplex = |
| 3737 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3738 | phba->sli4_hba.link_state.status = |
| 3739 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3740 | phba->sli4_hba.link_state.type = |
| 3741 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3742 | phba->sli4_hba.link_state.number = |
| 3743 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3744 | phba->sli4_hba.link_state.fault = |
| 3745 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3746 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3747 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 3748 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3749 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3750 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3751 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3752 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3753 | phba->sli4_hba.link_state.speed, |
| 3754 | phba->sli4_hba.link_state.topology, |
| 3755 | phba->sli4_hba.link_state.status, |
| 3756 | phba->sli4_hba.link_state.type, |
| 3757 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3758 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3759 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3760 | /* |
| 3761 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3762 | * topology info. Note: Optional for non FC-AL ports. |
| 3763 | */ |
| 3764 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3765 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3766 | if (rc == MBX_NOT_FINISHED) |
| 3767 | goto out_free_dmabuf; |
| 3768 | return; |
| 3769 | } |
| 3770 | /* |
| 3771 | * For FCoE Mode: fill in all the topology information we need and call |
| 3772 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3773 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3774 | */ |
| 3775 | /* Parse and translate status field */ |
| 3776 | mb = &pmb->u.mb; |
| 3777 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3778 | |
| 3779 | /* Parse and translate link attention fields */ |
| 3780 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3781 | la->eventTag = acqe_link->event_tag; |
| 3782 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3783 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3784 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3785 | |
| 3786 | /* Fake the the following irrelvant fields */ |
| 3787 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3788 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3789 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3790 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3791 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3792 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3793 | |
| 3794 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3795 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3796 | |
| 3797 | return; |
| 3798 | |
| 3799 | out_free_dmabuf: |
| 3800 | kfree(mp); |
| 3801 | out_free_pmb: |
| 3802 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3803 | } |
| 3804 | |
| 3805 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3806 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3807 | * @phba: pointer to lpfc hba data structure. |
| 3808 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3809 | * |
| 3810 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3811 | * that the event was received and then issue a read_topology mailbox command so |
| 3812 | * that the rest of the driver will treat it the same as SLI3. |
| 3813 | **/ |
| 3814 | static void |
| 3815 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3816 | { |
| 3817 | struct lpfc_dmabuf *mp; |
| 3818 | LPFC_MBOXQ_t *pmb; |
| 3819 | int rc; |
| 3820 | |
| 3821 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3822 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3823 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3824 | "2895 Non FC link Event detected.(%d)\n", |
| 3825 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3826 | return; |
| 3827 | } |
| 3828 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3829 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3830 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 3831 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3832 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3833 | phba->sli4_hba.link_state.topology = |
| 3834 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3835 | phba->sli4_hba.link_state.status = |
| 3836 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3837 | phba->sli4_hba.link_state.type = |
| 3838 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3839 | phba->sli4_hba.link_state.number = |
| 3840 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3841 | phba->sli4_hba.link_state.fault = |
| 3842 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3843 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3844 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3845 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3846 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3847 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3848 | "%dMbps Fault:%d\n", |
| 3849 | phba->sli4_hba.link_state.speed, |
| 3850 | phba->sli4_hba.link_state.topology, |
| 3851 | phba->sli4_hba.link_state.status, |
| 3852 | phba->sli4_hba.link_state.type, |
| 3853 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3854 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3855 | phba->sli4_hba.link_state.fault); |
| 3856 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3857 | if (!pmb) { |
| 3858 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3859 | "2897 The mboxq allocation failed\n"); |
| 3860 | return; |
| 3861 | } |
| 3862 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3863 | if (!mp) { |
| 3864 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3865 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3866 | goto out_free_pmb; |
| 3867 | } |
| 3868 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3869 | if (!mp->virt) { |
| 3870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3871 | "2899 The mbuf allocation failed\n"); |
| 3872 | goto out_free_dmabuf; |
| 3873 | } |
| 3874 | |
| 3875 | /* Cleanup any outstanding ELS commands */ |
| 3876 | lpfc_els_flush_all_cmd(phba); |
| 3877 | |
| 3878 | /* Block ELS IOCBs until we have done process link event */ |
| 3879 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3880 | |
| 3881 | /* Update link event statistics */ |
| 3882 | phba->sli.slistat.link_event++; |
| 3883 | |
| 3884 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3885 | lpfc_read_topology(phba, pmb, mp); |
| 3886 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3887 | pmb->vport = phba->pport; |
| 3888 | |
| 3889 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3890 | if (rc == MBX_NOT_FINISHED) |
| 3891 | goto out_free_dmabuf; |
| 3892 | return; |
| 3893 | |
| 3894 | out_free_dmabuf: |
| 3895 | kfree(mp); |
| 3896 | out_free_pmb: |
| 3897 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3898 | } |
| 3899 | |
| 3900 | /** |
| 3901 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3902 | * @phba: pointer to lpfc hba data structure. |
| 3903 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3904 | * |
| 3905 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3906 | **/ |
| 3907 | static void |
| 3908 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3909 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3910 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 3911 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3912 | uint8_t status; |
| 3913 | struct lpfc_acqe_misconfigured_event *misconfigured; |
| 3914 | |
| 3915 | /* special case misconfigured event as it contains data for all ports */ |
| 3916 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3917 | LPFC_SLI_INTF_IF_TYPE_2) || |
| 3918 | (bf_get(lpfc_trailer_type, acqe_sli) != |
| 3919 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { |
| 3920 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3921 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3922 | "x%08x SLI Event Type:%d\n", |
| 3923 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3924 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3925 | return; |
| 3926 | } |
| 3927 | |
| 3928 | port_name = phba->Port[0]; |
| 3929 | if (port_name == 0x00) |
| 3930 | port_name = '?'; /* get port name is empty */ |
| 3931 | |
| 3932 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
| 3933 | &acqe_sli->event_data1; |
| 3934 | |
| 3935 | /* fetch the status for this port */ |
| 3936 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 3937 | case LPFC_LINK_NUMBER_0: |
| 3938 | status = bf_get(lpfc_sli_misconfigured_port0, |
| 3939 | &misconfigured->theEvent); |
| 3940 | break; |
| 3941 | case LPFC_LINK_NUMBER_1: |
| 3942 | status = bf_get(lpfc_sli_misconfigured_port1, |
| 3943 | &misconfigured->theEvent); |
| 3944 | break; |
| 3945 | case LPFC_LINK_NUMBER_2: |
| 3946 | status = bf_get(lpfc_sli_misconfigured_port2, |
| 3947 | &misconfigured->theEvent); |
| 3948 | break; |
| 3949 | case LPFC_LINK_NUMBER_3: |
| 3950 | status = bf_get(lpfc_sli_misconfigured_port3, |
| 3951 | &misconfigured->theEvent); |
| 3952 | break; |
| 3953 | default: |
| 3954 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 3955 | break; |
| 3956 | } |
| 3957 | |
| 3958 | switch (status) { |
| 3959 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 3960 | return; /* no message if the sfp is okay */ |
| 3961 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3962 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
| 3963 | "installed - Reseat optics, if issue not " |
| 3964 | "resolved, replace."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3965 | break; |
| 3966 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 3967 | sprintf(message, |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3968 | "Optics of two types installed - Remove one optic or " \ |
| 3969 | "install matching pair of optics."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3970 | break; |
| 3971 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3972 | sprintf(message, "Incompatible optics - Replace with " \ |
| 3973 | "compatible optics for card to function."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3974 | break; |
| 3975 | default: |
| 3976 | /* firmware is reporting a status we don't know about */ |
| 3977 | sprintf(message, "Unknown event status x%02x", status); |
| 3978 | break; |
| 3979 | } |
| 3980 | |
| 3981 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3982 | "3176 Misconfigured Physical Port - " |
| 3983 | "Port Name %c %s\n", port_name, message); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3987 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 3988 | * @vport: pointer to vport data structure. |
| 3989 | * |
| 3990 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 3991 | * response to a CVL event. |
| 3992 | * |
| 3993 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 3994 | * return NULL. |
| 3995 | **/ |
| 3996 | static struct lpfc_nodelist * |
| 3997 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 3998 | { |
| 3999 | struct lpfc_nodelist *ndlp; |
| 4000 | struct Scsi_Host *shost; |
| 4001 | struct lpfc_hba *phba; |
| 4002 | |
| 4003 | if (!vport) |
| 4004 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4005 | phba = vport->phba; |
| 4006 | if (!phba) |
| 4007 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4008 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4009 | if (!ndlp) { |
| 4010 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 4011 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4012 | if (!ndlp) |
| 4013 | return 0; |
| 4014 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 4015 | /* Set the node type */ |
| 4016 | ndlp->nlp_type |= NLP_FABRIC; |
| 4017 | /* Put ndlp onto node list */ |
| 4018 | lpfc_enqueue_node(vport, ndlp); |
| 4019 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4020 | /* re-setup ndlp without removing from node list */ |
| 4021 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4022 | if (!ndlp) |
| 4023 | return 0; |
| 4024 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4025 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4026 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4027 | return NULL; |
| 4028 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4029 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4030 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4031 | return NULL; |
| 4032 | shost = lpfc_shost_from_vport(vport); |
| 4033 | if (!shost) |
| 4034 | return NULL; |
| 4035 | lpfc_linkdown_port(vport); |
| 4036 | lpfc_cleanup_pending_mbox(vport); |
| 4037 | spin_lock_irq(shost->host_lock); |
| 4038 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4039 | spin_unlock_irq(shost->host_lock); |
| 4040 | |
| 4041 | return ndlp; |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4046 | * @vport: pointer to lpfc hba data structure. |
| 4047 | * |
| 4048 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4049 | * response to a FCF dead event. |
| 4050 | **/ |
| 4051 | static void |
| 4052 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4053 | { |
| 4054 | struct lpfc_vport **vports; |
| 4055 | int i; |
| 4056 | |
| 4057 | vports = lpfc_create_vport_work_array(phba); |
| 4058 | if (vports) |
| 4059 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4060 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4061 | lpfc_destroy_vport_work_array(phba, vports); |
| 4062 | } |
| 4063 | |
| 4064 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4065 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4066 | * @phba: pointer to lpfc hba data structure. |
| 4067 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4068 | * |
| 4069 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4070 | **/ |
| 4071 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4072 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4073 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4074 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4075 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4076 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4077 | struct lpfc_vport *vport; |
| 4078 | struct lpfc_nodelist *ndlp; |
| 4079 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4080 | int active_vlink_present; |
| 4081 | struct lpfc_vport **vports; |
| 4082 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4083 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4084 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4085 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4086 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4087 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4088 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4089 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4090 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4091 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4092 | "2546 New FCF event, evt_tag:x%x, " |
| 4093 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4094 | acqe_fip->event_tag, |
| 4095 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4096 | else |
| 4097 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4098 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4099 | "2788 FCF param modified event, " |
| 4100 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4101 | acqe_fip->event_tag, |
| 4102 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4103 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4104 | /* |
| 4105 | * During period of FCF discovery, read the FCF |
| 4106 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4107 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4108 | */ |
| 4109 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4110 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4111 | "2779 Read FCF (x%x) for updating " |
| 4112 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4113 | acqe_fip->index); |
| 4114 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4115 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4116 | |
| 4117 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4118 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4119 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4120 | spin_unlock_irq(&phba->hbalock); |
| 4121 | break; |
| 4122 | } |
| 4123 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 4124 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 4125 | spin_unlock_irq(&phba->hbalock); |
| 4126 | break; |
| 4127 | } |
| 4128 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4129 | /* If the FCF has been in discovered state, do nothing. */ |
| 4130 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4131 | spin_unlock_irq(&phba->hbalock); |
| 4132 | break; |
| 4133 | } |
| 4134 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4135 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4136 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 4137 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4138 | "2770 Start FCF table scan per async FCF " |
| 4139 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4140 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4141 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 4142 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4143 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4144 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4145 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4146 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4147 | break; |
| 4148 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4149 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4150 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4151 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4152 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 4153 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4154 | break; |
| 4155 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4156 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4157 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4158 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4159 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4160 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4161 | /* |
| 4162 | * If we are in the middle of FCF failover process, clear |
| 4163 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4164 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4165 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4166 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4167 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4168 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4169 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4170 | break; |
| 4171 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4172 | spin_unlock_irq(&phba->hbalock); |
| 4173 | |
| 4174 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4175 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4176 | break; |
| 4177 | |
| 4178 | /* |
| 4179 | * Otherwise, request the port to rediscover the entire FCF |
| 4180 | * table for a fast recovery from case that the current FCF |
| 4181 | * is no longer valid as we are not in the middle of FCF |
| 4182 | * failover process already. |
| 4183 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 4184 | spin_lock_irq(&phba->hbalock); |
| 4185 | /* Mark the fast failover process in progress */ |
| 4186 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 4187 | spin_unlock_irq(&phba->hbalock); |
| 4188 | |
| 4189 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4190 | "2771 Start FCF fast failover process due to " |
| 4191 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 4192 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 4193 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4194 | if (rc) { |
| 4195 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4196 | LOG_DISCOVERY, |
| 4197 | "2772 Issue FCF rediscover mabilbox " |
| 4198 | "command failed, fail through to FCF " |
| 4199 | "dead event\n"); |
| 4200 | spin_lock_irq(&phba->hbalock); |
| 4201 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 4202 | spin_unlock_irq(&phba->hbalock); |
| 4203 | /* |
| 4204 | * Last resort will fail over by treating this |
| 4205 | * as a link down to FCF registration. |
| 4206 | */ |
| 4207 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 4208 | } else { |
| 4209 | /* Reset FCF roundrobin bmask for new discovery */ |
| 4210 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 4211 | /* |
| 4212 | * Handling fast FCF failover to a DEAD FCF event is |
| 4213 | * considered equalivant to receiving CVL to all vports. |
| 4214 | */ |
| 4215 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 4216 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4217 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4218 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4219 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4220 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4221 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4222 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4223 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4224 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4225 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4226 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4227 | if (!ndlp) |
| 4228 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4229 | active_vlink_present = 0; |
| 4230 | |
| 4231 | vports = lpfc_create_vport_work_array(phba); |
| 4232 | if (vports) { |
| 4233 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4234 | i++) { |
| 4235 | if ((!(vports[i]->fc_flag & |
| 4236 | FC_VPORT_CVL_RCVD)) && |
| 4237 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4238 | active_vlink_present = 1; |
| 4239 | break; |
| 4240 | } |
| 4241 | } |
| 4242 | lpfc_destroy_vport_work_array(phba, vports); |
| 4243 | } |
| 4244 | |
| 4245 | if (active_vlink_present) { |
| 4246 | /* |
| 4247 | * If there are other active VLinks present, |
| 4248 | * re-instantiate the Vlink using FDISC. |
| 4249 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4250 | mod_timer(&ndlp->nlp_delayfunc, |
| 4251 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4252 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4253 | spin_lock_irq(shost->host_lock); |
| 4254 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4255 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4256 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4257 | vport->port_state = LPFC_FDISC; |
| 4258 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4259 | /* |
| 4260 | * Otherwise, we request port to rediscover |
| 4261 | * the entire FCF table for a fast recovery |
| 4262 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4263 | * is no longer valid if we are not already |
| 4264 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4265 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4266 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4267 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4268 | spin_unlock_irq(&phba->hbalock); |
| 4269 | break; |
| 4270 | } |
| 4271 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4272 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4273 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4274 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4275 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4276 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4277 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4278 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4279 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4280 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4281 | LOG_DISCOVERY, |
| 4282 | "2774 Issue FCF rediscover " |
| 4283 | "mabilbox command failed, " |
| 4284 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4285 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4286 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4287 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4288 | /* |
| 4289 | * Last resort will be re-try on the |
| 4290 | * the current registered FCF entry. |
| 4291 | */ |
| 4292 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4293 | } else |
| 4294 | /* |
| 4295 | * Reset FCF roundrobin bmask for new |
| 4296 | * discovery. |
| 4297 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4298 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4299 | } |
| 4300 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4301 | default: |
| 4302 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4303 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4304 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4305 | break; |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | /** |
| 4310 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4311 | * @phba: pointer to lpfc hba data structure. |
| 4312 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4313 | * |
| 4314 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4315 | **/ |
| 4316 | static void |
| 4317 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4318 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4319 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4320 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4321 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4322 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4323 | "handled yet\n"); |
| 4324 | } |
| 4325 | |
| 4326 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4327 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4328 | * @phba: pointer to lpfc hba data structure. |
| 4329 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4330 | * |
| 4331 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4332 | * is an asynchronous notified of a logical link speed change. The Port |
| 4333 | * reports the logical link speed in units of 10Mbps. |
| 4334 | **/ |
| 4335 | static void |
| 4336 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4337 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4338 | { |
| 4339 | uint16_t prev_ll_spd; |
| 4340 | |
| 4341 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4342 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4343 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4344 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4345 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4346 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4347 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4348 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 4349 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4353 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4354 | * @phba: pointer to lpfc hba data structure. |
| 4355 | * |
| 4356 | * This routine is invoked by the worker thread to process all the pending |
| 4357 | * SLI4 asynchronous events. |
| 4358 | **/ |
| 4359 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4360 | { |
| 4361 | struct lpfc_cq_event *cq_event; |
| 4362 | |
| 4363 | /* First, declare the async event has been handled */ |
| 4364 | spin_lock_irq(&phba->hbalock); |
| 4365 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4366 | spin_unlock_irq(&phba->hbalock); |
| 4367 | /* Now, handle all the async events */ |
| 4368 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4369 | /* Get the first event from the head of the event queue */ |
| 4370 | spin_lock_irq(&phba->hbalock); |
| 4371 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4372 | cq_event, struct lpfc_cq_event, list); |
| 4373 | spin_unlock_irq(&phba->hbalock); |
| 4374 | /* Process the asynchronous event */ |
| 4375 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4376 | case LPFC_TRAILER_CODE_LINK: |
| 4377 | lpfc_sli4_async_link_evt(phba, |
| 4378 | &cq_event->cqe.acqe_link); |
| 4379 | break; |
| 4380 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4381 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4382 | break; |
| 4383 | case LPFC_TRAILER_CODE_DCBX: |
| 4384 | lpfc_sli4_async_dcbx_evt(phba, |
| 4385 | &cq_event->cqe.acqe_dcbx); |
| 4386 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4387 | case LPFC_TRAILER_CODE_GRP5: |
| 4388 | lpfc_sli4_async_grp5_evt(phba, |
| 4389 | &cq_event->cqe.acqe_grp5); |
| 4390 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4391 | case LPFC_TRAILER_CODE_FC: |
| 4392 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4393 | break; |
| 4394 | case LPFC_TRAILER_CODE_SLI: |
| 4395 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4396 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4397 | default: |
| 4398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4399 | "1804 Invalid asynchrous event code: " |
| 4400 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4401 | &cq_event->cqe.mcqe_cmpl)); |
| 4402 | break; |
| 4403 | } |
| 4404 | /* Free the completion event processed to the free pool */ |
| 4405 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4410 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4411 | * @phba: pointer to lpfc hba data structure. |
| 4412 | * |
| 4413 | * This routine is invoked by the worker thread to process FCF table |
| 4414 | * rediscovery pending completion event. |
| 4415 | **/ |
| 4416 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4417 | { |
| 4418 | int rc; |
| 4419 | |
| 4420 | spin_lock_irq(&phba->hbalock); |
| 4421 | /* Clear FCF rediscovery timeout event */ |
| 4422 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4423 | /* Clear driver fast failover FCF record flag */ |
| 4424 | phba->fcf.failover_rec.flag = 0; |
| 4425 | /* Set state for FCF fast failover */ |
| 4426 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4427 | spin_unlock_irq(&phba->hbalock); |
| 4428 | |
| 4429 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4430 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4431 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4432 | 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] | 4433 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4434 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4435 | "2747 Issue FCF scan read FCF mailbox " |
| 4436 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4440 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4441 | * @phba: pointer to lpfc hba data structure. |
| 4442 | * @dev_grp: The HBA PCI-Device group number. |
| 4443 | * |
| 4444 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4445 | * API jump table entries. |
| 4446 | * |
| 4447 | * Return: 0 if success, otherwise -ENODEV |
| 4448 | **/ |
| 4449 | int |
| 4450 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4451 | { |
| 4452 | int rc; |
| 4453 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4454 | /* Set up lpfc PCI-device group */ |
| 4455 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4456 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4457 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4458 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4459 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4460 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4461 | /* Set up device INIT API function jump table */ |
| 4462 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4463 | if (rc) |
| 4464 | return -ENODEV; |
| 4465 | /* Set up SCSI API function jump table */ |
| 4466 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4467 | if (rc) |
| 4468 | return -ENODEV; |
| 4469 | /* Set up SLI API function jump table */ |
| 4470 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4471 | if (rc) |
| 4472 | return -ENODEV; |
| 4473 | /* Set up MBOX API function jump table */ |
| 4474 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4475 | if (rc) |
| 4476 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4477 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4478 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4482 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4483 | * @phba: pointer to lpfc hba data structure. |
| 4484 | * @intr_mode: active interrupt mode adopted. |
| 4485 | * |
| 4486 | * This routine it invoked to log the currently used active interrupt mode |
| 4487 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4488 | **/ |
| 4489 | 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] | 4490 | { |
| 4491 | switch (intr_mode) { |
| 4492 | case 0: |
| 4493 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4494 | "0470 Enable INTx interrupt mode.\n"); |
| 4495 | break; |
| 4496 | case 1: |
| 4497 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4498 | "0481 Enabled MSI interrupt mode.\n"); |
| 4499 | break; |
| 4500 | case 2: |
| 4501 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4502 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4503 | break; |
| 4504 | default: |
| 4505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4506 | "0482 Illegal interrupt mode.\n"); |
| 4507 | break; |
| 4508 | } |
| 4509 | return; |
| 4510 | } |
| 4511 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4512 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4513 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4514 | * @phba: pointer to lpfc hba data structure. |
| 4515 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4516 | * This routine is invoked to enable the PCI device that is common to all |
| 4517 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4518 | * |
| 4519 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4520 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4521 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4522 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4523 | static int |
| 4524 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4525 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4526 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4527 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4528 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4529 | /* Obtain PCI device reference */ |
| 4530 | if (!phba->pcidev) |
| 4531 | goto out_error; |
| 4532 | else |
| 4533 | pdev = phba->pcidev; |
| 4534 | /* Select PCI BARs */ |
| 4535 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4536 | /* Enable PCI device */ |
| 4537 | if (pci_enable_device_mem(pdev)) |
| 4538 | goto out_error; |
| 4539 | /* Request PCI resource for the device */ |
| 4540 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4541 | goto out_disable_device; |
| 4542 | /* Set up device as PCI master and save state for EEH */ |
| 4543 | pci_set_master(pdev); |
| 4544 | pci_try_set_mwi(pdev); |
| 4545 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4546 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4547 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
| 4548 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) |
| 4549 | pdev->needs_freset = 1; |
| 4550 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4551 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4552 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4553 | out_disable_device: |
| 4554 | pci_disable_device(pdev); |
| 4555 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4557 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4558 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4562 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4563 | * @phba: pointer to lpfc hba data structure. |
| 4564 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4565 | * This routine is invoked to disable the PCI device that is common to all |
| 4566 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4567 | **/ |
| 4568 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4569 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4570 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4571 | struct pci_dev *pdev; |
| 4572 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4573 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4574 | /* Obtain PCI device reference */ |
| 4575 | if (!phba->pcidev) |
| 4576 | return; |
| 4577 | else |
| 4578 | pdev = phba->pcidev; |
| 4579 | /* Select PCI BARs */ |
| 4580 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4581 | /* Release PCI resource and disable PCI device */ |
| 4582 | pci_release_selected_regions(pdev, bars); |
| 4583 | pci_disable_device(pdev); |
| 4584 | /* Null out PCI private reference to driver */ |
| 4585 | pci_set_drvdata(pdev, NULL); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4586 | |
| 4587 | return; |
| 4588 | } |
| 4589 | |
| 4590 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4591 | * lpfc_reset_hba - Reset a hba |
| 4592 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4593 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4594 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4595 | * offline, performs a board restart, and then brings the board back |
| 4596 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4597 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4598 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4599 | void |
| 4600 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4601 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4602 | /* If resets are disabled then set error state and return. */ |
| 4603 | if (!phba->cfg_enable_hba_reset) { |
| 4604 | phba->link_state = LPFC_HBA_ERROR; |
| 4605 | return; |
| 4606 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 4607 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4608 | lpfc_offline(phba); |
| 4609 | lpfc_sli_brdrestart(phba); |
| 4610 | lpfc_online(phba); |
| 4611 | lpfc_unblock_mgmt_io(phba); |
| 4612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4613 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4614 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4615 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4616 | * @phba: pointer to lpfc hba data structure. |
| 4617 | * |
| 4618 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4619 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4620 | * enable the number of virtual functions to the physical function. As |
| 4621 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4622 | * API call does not considered as an error condition for most of the device. |
| 4623 | **/ |
| 4624 | uint16_t |
| 4625 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4626 | { |
| 4627 | struct pci_dev *pdev = phba->pcidev; |
| 4628 | uint16_t nr_virtfn; |
| 4629 | int pos; |
| 4630 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4631 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4632 | if (pos == 0) |
| 4633 | return 0; |
| 4634 | |
| 4635 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4636 | return nr_virtfn; |
| 4637 | } |
| 4638 | |
| 4639 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4640 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4641 | * @phba: pointer to lpfc hba data structure. |
| 4642 | * @nr_vfn: number of virtual functions to be enabled. |
| 4643 | * |
| 4644 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4645 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4646 | * enable the number of virtual functions to the physical function. As |
| 4647 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4648 | * API call does not considered as an error condition for most of the device. |
| 4649 | **/ |
| 4650 | int |
| 4651 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4652 | { |
| 4653 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4654 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4655 | int rc; |
| 4656 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4657 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4658 | if (nr_vfn > max_nr_vfn) { |
| 4659 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4660 | "3057 Requested vfs (%d) greater than " |
| 4661 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4662 | return -EINVAL; |
| 4663 | } |
| 4664 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4665 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4666 | if (rc) { |
| 4667 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4668 | "2806 Failed to enable sriov on this device " |
| 4669 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4670 | nr_vfn, rc); |
| 4671 | } else |
| 4672 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4673 | "2807 Successful enable sriov on this device " |
| 4674 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4675 | return rc; |
| 4676 | } |
| 4677 | |
| 4678 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4679 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4680 | * @phba: pointer to lpfc hba data structure. |
| 4681 | * |
| 4682 | * This routine is invoked to set up the driver internal resources specific to |
| 4683 | * support the SLI-3 HBA device it attached to. |
| 4684 | * |
| 4685 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4686 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4687 | * other values - error |
| 4688 | **/ |
| 4689 | static int |
| 4690 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4691 | { |
| 4692 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4693 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4695 | /* |
| 4696 | * Initialize timers used by driver |
| 4697 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4698 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4699 | /* Heartbeat timer */ |
| 4700 | init_timer(&phba->hb_tmofunc); |
| 4701 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4702 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4703 | |
| 4704 | psli = &phba->sli; |
| 4705 | /* MBOX heartbeat timer */ |
| 4706 | init_timer(&psli->mbox_tmo); |
| 4707 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4708 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4709 | /* FCP polling mode timer */ |
| 4710 | init_timer(&phba->fcp_poll_timer); |
| 4711 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4712 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4713 | /* Fabric block timer */ |
| 4714 | init_timer(&phba->fabric_block_timer); |
| 4715 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4716 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4717 | /* EA polling mode timer */ |
| 4718 | init_timer(&phba->eratt_poll); |
| 4719 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4720 | phba->eratt_poll.data = (unsigned long) phba; |
| 4721 | |
| 4722 | /* Host attention work mask setup */ |
| 4723 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4724 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4725 | |
| 4726 | /* Get all the module params for configuring this host */ |
| 4727 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4728 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4729 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4730 | /* check for menlo minimum sg count */ |
| 4731 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4732 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4733 | } |
| 4734 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4735 | if (!phba->sli.ring) |
| 4736 | phba->sli.ring = (struct lpfc_sli_ring *) |
| 4737 | kzalloc(LPFC_SLI3_MAX_RING * |
| 4738 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4739 | if (!phba->sli.ring) |
| 4740 | return -ENOMEM; |
| 4741 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4742 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4743 | * 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] | 4744 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4745 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4746 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4747 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4748 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4749 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4750 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4751 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 4752 | if (phba->cfg_enable_bg) { |
| 4753 | /* |
| 4754 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 4755 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 4756 | * over how many protection data segments the SCSI Layer |
| 4757 | * will hand us (ie: there could be one for every block |
| 4758 | * in the IO), we just allocate enough BDEs to accomidate |
| 4759 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 4760 | * minimize the risk of running out. |
| 4761 | */ |
| 4762 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4763 | sizeof(struct fcp_rsp) + |
| 4764 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 4765 | |
| 4766 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 4767 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 4768 | |
| 4769 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 4770 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4771 | } else { |
| 4772 | /* |
| 4773 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 4774 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 4775 | * cfg_sg_seg_cnt data segments. |
| 4776 | */ |
| 4777 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4778 | sizeof(struct fcp_rsp) + |
| 4779 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4780 | |
| 4781 | /* Total BDEs in BPL for scsi_sg_list */ |
| 4782 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 4783 | } |
| 4784 | |
| 4785 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4786 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 4787 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 4788 | phba->cfg_total_seg_cnt); |
| 4789 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4790 | phba->max_vpi = LPFC_MAX_VPI; |
| 4791 | /* This will be set to correct value after config_port mbox */ |
| 4792 | phba->max_vports = 0; |
| 4793 | |
| 4794 | /* |
| 4795 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4796 | */ |
| 4797 | lpfc_sli_setup(phba); |
| 4798 | lpfc_sli_queue_setup(phba); |
| 4799 | |
| 4800 | /* Allocate device driver memory */ |
| 4801 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4802 | return -ENOMEM; |
| 4803 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4804 | /* |
| 4805 | * Enable sr-iov virtual functions if supported and configured |
| 4806 | * through the module parameter. |
| 4807 | */ |
| 4808 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4809 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4810 | phba->cfg_sriov_nr_virtfn); |
| 4811 | if (rc) { |
| 4812 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4813 | "2808 Requested number of SR-IOV " |
| 4814 | "virtual functions (%d) is not " |
| 4815 | "supported\n", |
| 4816 | phba->cfg_sriov_nr_virtfn); |
| 4817 | phba->cfg_sriov_nr_virtfn = 0; |
| 4818 | } |
| 4819 | } |
| 4820 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4821 | return 0; |
| 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4826 | * @phba: pointer to lpfc hba data structure. |
| 4827 | * |
| 4828 | * This routine is invoked to unset the driver internal resources set up |
| 4829 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4830 | **/ |
| 4831 | static void |
| 4832 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4833 | { |
| 4834 | /* Free device driver memory allocated */ |
| 4835 | lpfc_mem_free_all(phba); |
| 4836 | |
| 4837 | return; |
| 4838 | } |
| 4839 | |
| 4840 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4841 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4842 | * @phba: pointer to lpfc hba data structure. |
| 4843 | * |
| 4844 | * This routine is invoked to set up the driver internal resources specific to |
| 4845 | * support the SLI-4 HBA device it attached to. |
| 4846 | * |
| 4847 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4848 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4849 | * other values - error |
| 4850 | **/ |
| 4851 | static int |
| 4852 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4853 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 4854 | struct lpfc_vector_map_info *cpup; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4855 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4856 | LPFC_MBOXQ_t *mboxq; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4857 | int rc, i, hbq_count, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4858 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4859 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4860 | int longs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4861 | |
| 4862 | /* Before proceed, wait for POST done and device ready */ |
| 4863 | rc = lpfc_sli4_post_status_check(phba); |
| 4864 | if (rc) |
| 4865 | return -ENODEV; |
| 4866 | |
| 4867 | /* |
| 4868 | * Initialize timers used by driver |
| 4869 | */ |
| 4870 | |
| 4871 | /* Heartbeat timer */ |
| 4872 | init_timer(&phba->hb_tmofunc); |
| 4873 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4874 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4875 | init_timer(&phba->rrq_tmr); |
| 4876 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4877 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4878 | |
| 4879 | psli = &phba->sli; |
| 4880 | /* MBOX heartbeat timer */ |
| 4881 | init_timer(&psli->mbox_tmo); |
| 4882 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4883 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4884 | /* Fabric block timer */ |
| 4885 | init_timer(&phba->fabric_block_timer); |
| 4886 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4887 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4888 | /* EA polling mode timer */ |
| 4889 | init_timer(&phba->eratt_poll); |
| 4890 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4891 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4892 | /* FCF rediscover timer */ |
| 4893 | init_timer(&phba->fcf.redisc_wait); |
| 4894 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4895 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4896 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4897 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4898 | * Control structure for handling external multi-buffer mailbox |
| 4899 | * command pass-through. |
| 4900 | */ |
| 4901 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4902 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4903 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4904 | |
| 4905 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4906 | * We need to do a READ_CONFIG mailbox command here before |
| 4907 | * calling lpfc_get_cfgparam. For VFs this will report the |
| 4908 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. |
| 4909 | * All of the resources allocated |
| 4910 | * for this Port are tied to these values. |
| 4911 | */ |
| 4912 | /* Get all the module params for configuring this host */ |
| 4913 | lpfc_get_cfgparam(phba); |
| 4914 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4915 | |
| 4916 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 4917 | phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count; |
| 4918 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4919 | /* This will be set to correct value after the read_config mbox */ |
| 4920 | phba->max_vports = 0; |
| 4921 | |
| 4922 | /* Program the default value of vlan_id and fc_map */ |
| 4923 | phba->valid_vlan = 0; |
| 4924 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4925 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4926 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4927 | |
| 4928 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4929 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 4930 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 4931 | */ |
| 4932 | if (!phba->sli.ring) |
| 4933 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4934 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4935 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4936 | if (!phba->sli.ring) |
| 4937 | return -ENOMEM; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4938 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4939 | /* |
| 4940 | * It doesn't matter what family our adapter is in, we are |
| 4941 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 4942 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 4943 | */ |
| 4944 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 4945 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) |
| 4946 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4947 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4948 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4949 | * 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] | 4950 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4951 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4952 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4953 | if (phba->cfg_enable_bg) { |
| 4954 | /* |
| 4955 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 4956 | * the FCP rsp, and a SGE for each. Sice we have no control |
| 4957 | * over how many protection data segments the SCSI Layer |
| 4958 | * will hand us (ie: there could be one for every block |
| 4959 | * in the IO), we just allocate enough SGEs to accomidate |
| 4960 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 4961 | * minimize the risk of running out. |
| 4962 | */ |
| 4963 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4964 | sizeof(struct fcp_rsp) + max_buf_size; |
| 4965 | |
| 4966 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 4967 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 4968 | |
| 4969 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
| 4970 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
| 4971 | } else { |
| 4972 | /* |
| 4973 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 4974 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 4975 | * cfg_sg_seg_cnt data segments. |
| 4976 | */ |
| 4977 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4978 | sizeof(struct fcp_rsp) + |
| 4979 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); |
| 4980 | |
| 4981 | /* Total SGEs for scsi_sg_list */ |
| 4982 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 4983 | /* |
| 4984 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need |
| 4985 | * to post 1 page for the SGL. |
| 4986 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4987 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4988 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4989 | /* Initialize the host templates with the updated values. */ |
| 4990 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4991 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4992 | |
| 4993 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 4994 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 4995 | else |
| 4996 | phba->cfg_sg_dma_buf_size = |
| 4997 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 4998 | |
| 4999 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5000 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5001 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5002 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5003 | |
| 5004 | /* Initialize buffer queue management fields */ |
| 5005 | hbq_count = lpfc_sli_hbq_count(); |
| 5006 | for (i = 0; i < hbq_count; ++i) |
| 5007 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5008 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5009 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5010 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5011 | |
| 5012 | /* |
| 5013 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5014 | */ |
| 5015 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5016 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5017 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5018 | /* This abort list used by worker thread */ |
| 5019 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 5020 | |
| 5021 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5022 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5023 | */ |
| 5024 | |
| 5025 | /* Driver internel slow-path CQ Event pool */ |
| 5026 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5027 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5028 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5029 | /* Asynchronous event CQ Event work queue list */ |
| 5030 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5031 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5032 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5033 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5034 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5035 | /* Receive queue CQ Event work queue list */ |
| 5036 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5037 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5038 | /* Initialize extent block lists. */ |
| 5039 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 5040 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 5041 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 5042 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 5043 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5044 | /* Initialize the driver internal SLI layer lists. */ |
| 5045 | lpfc_sli_setup(phba); |
| 5046 | lpfc_sli_queue_setup(phba); |
| 5047 | |
| 5048 | /* Allocate device driver memory */ |
| 5049 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 5050 | if (rc) |
| 5051 | return -ENOMEM; |
| 5052 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5053 | /* IF Type 2 ports get initialized now. */ |
| 5054 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5055 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 5056 | rc = lpfc_pci_function_reset(phba); |
| 5057 | if (unlikely(rc)) |
| 5058 | return -ENODEV; |
| 5059 | } |
| 5060 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5061 | /* Create the bootstrap mailbox command */ |
| 5062 | rc = lpfc_create_bootstrap_mbox(phba); |
| 5063 | if (unlikely(rc)) |
| 5064 | goto out_free_mem; |
| 5065 | |
| 5066 | /* Set up the host's endian order with the device. */ |
| 5067 | rc = lpfc_setup_endian_order(phba); |
| 5068 | if (unlikely(rc)) |
| 5069 | goto out_free_bsmbx; |
| 5070 | |
| 5071 | /* Set up the hba's configuration parameters. */ |
| 5072 | rc = lpfc_sli4_read_config(phba); |
| 5073 | if (unlikely(rc)) |
| 5074 | goto out_free_bsmbx; |
| 5075 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5076 | /* IF Type 0 ports get initialized now. */ |
| 5077 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5078 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 5079 | rc = lpfc_pci_function_reset(phba); |
| 5080 | if (unlikely(rc)) |
| 5081 | goto out_free_bsmbx; |
| 5082 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5083 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5084 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 5085 | GFP_KERNEL); |
| 5086 | if (!mboxq) { |
| 5087 | rc = -ENOMEM; |
| 5088 | goto out_free_bsmbx; |
| 5089 | } |
| 5090 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5091 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5092 | lpfc_supported_pages(mboxq); |
| 5093 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5094 | if (!rc) { |
| 5095 | mqe = &mboxq->u.mqe; |
| 5096 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 5097 | LPFC_MAX_SUPPORTED_PAGES); |
| 5098 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 5099 | switch (pn_page[i]) { |
| 5100 | case LPFC_SLI4_PARAMETERS: |
| 5101 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 5102 | break; |
| 5103 | default: |
| 5104 | break; |
| 5105 | } |
| 5106 | } |
| 5107 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 5108 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 5109 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 5110 | if (rc) { |
| 5111 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5112 | rc = -EIO; |
| 5113 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5114 | } |
| 5115 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5116 | /* |
| 5117 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5118 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 5119 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5120 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5121 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 5122 | if (rc) { |
| 5123 | if (phba->sli4_hba.extents_in_use && |
| 5124 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 5125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5126 | "2999 Unsupported SLI4 Parameters " |
| 5127 | "Extents and RPI headers enabled.\n"); |
| 5128 | goto out_free_bsmbx; |
| 5129 | } |
| 5130 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5131 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5132 | /* Verify all the SLI4 queues */ |
| 5133 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5134 | if (rc) |
| 5135 | goto out_free_bsmbx; |
| 5136 | |
| 5137 | /* Create driver internal CQE event pool */ |
| 5138 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 5139 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5140 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5141 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5142 | /* Initialize sgl lists per host */ |
| 5143 | lpfc_init_sgl_list(phba); |
| 5144 | |
| 5145 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5146 | rc = lpfc_init_active_sgl_array(phba); |
| 5147 | if (rc) { |
| 5148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5149 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5150 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5151 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5152 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 5153 | if (rc) { |
| 5154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5155 | "1432 Failed to initialize rpi headers.\n"); |
| 5156 | goto out_free_active_sgl; |
| 5157 | } |
| 5158 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5159 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5160 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 5161 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 5162 | GFP_KERNEL); |
| 5163 | if (!phba->fcf.fcf_rr_bmask) { |
| 5164 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5165 | "2759 Failed allocate memory for FCF round " |
| 5166 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5167 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5168 | goto out_remove_rpi_hdrs; |
| 5169 | } |
| 5170 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5171 | phba->sli4_hba.fcp_eq_hdl = |
| 5172 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
| 5173 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 5174 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 5175 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5176 | "2572 Failed allocate memory for " |
| 5177 | "fast-path per-EQ handle array\n"); |
| 5178 | rc = -ENOMEM; |
| 5179 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 5183 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5184 | if (!phba->sli4_hba.msix_entries) { |
| 5185 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5186 | "2573 Failed allocate memory for msi-x " |
| 5187 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5188 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5189 | goto out_free_fcp_eq_hdl; |
| 5190 | } |
| 5191 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5192 | phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) * |
| 5193 | phba->sli4_hba.num_present_cpu), |
| 5194 | GFP_KERNEL); |
| 5195 | if (!phba->sli4_hba.cpu_map) { |
| 5196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5197 | "3327 Failed allocate memory for msi-x " |
| 5198 | "interrupt vector mapping\n"); |
| 5199 | rc = -ENOMEM; |
| 5200 | goto out_free_msix; |
| 5201 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 5202 | if (lpfc_used_cpu == NULL) { |
| 5203 | lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu), |
| 5204 | GFP_KERNEL); |
| 5205 | if (!lpfc_used_cpu) { |
| 5206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5207 | "3335 Failed allocate memory for msi-x " |
| 5208 | "interrupt vector mapping\n"); |
| 5209 | kfree(phba->sli4_hba.cpu_map); |
| 5210 | rc = -ENOMEM; |
| 5211 | goto out_free_msix; |
| 5212 | } |
| 5213 | for (i = 0; i < lpfc_present_cpu; i++) |
| 5214 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 5215 | } |
| 5216 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5217 | /* Initialize io channels for round robin */ |
| 5218 | cpup = phba->sli4_hba.cpu_map; |
| 5219 | rc = 0; |
| 5220 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 5221 | cpup->channel_id = rc; |
| 5222 | rc++; |
| 5223 | if (rc >= phba->cfg_fcp_io_channel) |
| 5224 | rc = 0; |
| 5225 | } |
| 5226 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5227 | /* |
| 5228 | * Enable sr-iov virtual functions if supported and configured |
| 5229 | * through the module parameter. |
| 5230 | */ |
| 5231 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5232 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5233 | phba->cfg_sriov_nr_virtfn); |
| 5234 | if (rc) { |
| 5235 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5236 | "3020 Requested number of SR-IOV " |
| 5237 | "virtual functions (%d) is not " |
| 5238 | "supported\n", |
| 5239 | phba->cfg_sriov_nr_virtfn); |
| 5240 | phba->cfg_sriov_nr_virtfn = 0; |
| 5241 | } |
| 5242 | } |
| 5243 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5244 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5245 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5246 | out_free_msix: |
| 5247 | kfree(phba->sli4_hba.msix_entries); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5248 | out_free_fcp_eq_hdl: |
| 5249 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5250 | out_free_fcf_rr_bmask: |
| 5251 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5252 | out_remove_rpi_hdrs: |
| 5253 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 5254 | out_free_active_sgl: |
| 5255 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5256 | out_destroy_cq_event_pool: |
| 5257 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5258 | out_free_bsmbx: |
| 5259 | lpfc_destroy_bootstrap_mbox(phba); |
| 5260 | out_free_mem: |
| 5261 | lpfc_mem_free(phba); |
| 5262 | return rc; |
| 5263 | } |
| 5264 | |
| 5265 | /** |
| 5266 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5267 | * @phba: pointer to lpfc hba data structure. |
| 5268 | * |
| 5269 | * This routine is invoked to unset the driver internal resources set up |
| 5270 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5271 | **/ |
| 5272 | static void |
| 5273 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5274 | { |
| 5275 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5276 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 5277 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 5278 | kfree(phba->sli4_hba.cpu_map); |
| 5279 | phba->sli4_hba.num_present_cpu = 0; |
| 5280 | phba->sli4_hba.num_online_cpu = 0; |
| 5281 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5282 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5283 | kfree(phba->sli4_hba.msix_entries); |
| 5284 | |
| 5285 | /* Free memory allocated for fast-path work queue handles */ |
| 5286 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5287 | |
| 5288 | /* Free the allocated rpi headers. */ |
| 5289 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5290 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5291 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5292 | /* Free eligible FCF index bmask */ |
| 5293 | kfree(phba->fcf.fcf_rr_bmask); |
| 5294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5295 | /* Free the ELS sgl list */ |
| 5296 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5297 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5298 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5299 | /* Free the completion queue EQ event pool */ |
| 5300 | lpfc_sli4_cq_event_release_all(phba); |
| 5301 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5302 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5303 | /* Release resource identifiers. */ |
| 5304 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5305 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5306 | /* Free the bsmbx region. */ |
| 5307 | lpfc_destroy_bootstrap_mbox(phba); |
| 5308 | |
| 5309 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5310 | lpfc_mem_free_all(phba); |
| 5311 | |
| 5312 | /* Free the current connect table */ |
| 5313 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5314 | &phba->fcf_conn_rec_list, list) { |
| 5315 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5316 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5317 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5318 | |
| 5319 | return; |
| 5320 | } |
| 5321 | |
| 5322 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5323 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5324 | * @phba: The hba struct for which this call is being executed. |
| 5325 | * @dev_grp: The HBA PCI-Device group number. |
| 5326 | * |
| 5327 | * This routine sets up the device INIT interface API function jump table |
| 5328 | * in @phba struct. |
| 5329 | * |
| 5330 | * Returns: 0 - success, -ENODEV - failure. |
| 5331 | **/ |
| 5332 | int |
| 5333 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5334 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5335 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5336 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5337 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5338 | switch (dev_grp) { |
| 5339 | case LPFC_PCI_DEV_LP: |
| 5340 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5341 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5342 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5343 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5344 | case LPFC_PCI_DEV_OC: |
| 5345 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5346 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5347 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5348 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5349 | default: |
| 5350 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5351 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5352 | dev_grp); |
| 5353 | return -ENODEV; |
| 5354 | break; |
| 5355 | } |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
| 5359 | /** |
| 5360 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5361 | * @phba: pointer to lpfc hba data structure. |
| 5362 | * |
| 5363 | * This routine is invoked to set up the driver internal resources before the |
| 5364 | * device specific resource setup to support the HBA device it attached to. |
| 5365 | * |
| 5366 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5367 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5368 | * other values - error |
| 5369 | **/ |
| 5370 | static int |
| 5371 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5372 | { |
| 5373 | /* |
| 5374 | * Driver resources common to all SLI revisions |
| 5375 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5376 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5377 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5378 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5379 | /* Initialize ndlp management spinlock */ |
| 5380 | spin_lock_init(&phba->ndlp_lock); |
| 5381 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5382 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5383 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5384 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5385 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5386 | /* Initialize the wait queue head for the kernel thread */ |
| 5387 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5388 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5389 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 5390 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5391 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5392 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5393 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5394 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5395 | /* Initialize the fabric iocb list */ |
| 5396 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5397 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5398 | /* Initialize list to save ELS buffers */ |
| 5399 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5400 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5401 | /* Initialize FCF connection rec list */ |
| 5402 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5403 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5404 | return 0; |
| 5405 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5406 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5407 | /** |
| 5408 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5409 | * @phba: pointer to lpfc hba data structure. |
| 5410 | * |
| 5411 | * This routine is invoked to set up the driver internal resources after the |
| 5412 | * device specific resource setup to support the HBA device it attached to. |
| 5413 | * |
| 5414 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5415 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5416 | * other values - error |
| 5417 | **/ |
| 5418 | static int |
| 5419 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5420 | { |
| 5421 | int error; |
| 5422 | |
| 5423 | /* Startup the kernel thread for this host adapter. */ |
| 5424 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5425 | "lpfc_worker_%d", phba->brd_no); |
| 5426 | if (IS_ERR(phba->worker_thread)) { |
| 5427 | error = PTR_ERR(phba->worker_thread); |
| 5428 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5429 | } |
| 5430 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5431 | return 0; |
| 5432 | } |
| 5433 | |
| 5434 | /** |
| 5435 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5436 | * @phba: pointer to lpfc hba data structure. |
| 5437 | * |
| 5438 | * This routine is invoked to unset the driver internal resources set up after |
| 5439 | * the device specific resource setup for supporting the HBA device it |
| 5440 | * attached to. |
| 5441 | **/ |
| 5442 | static void |
| 5443 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5444 | { |
| 5445 | /* Stop kernel worker thread */ |
| 5446 | kthread_stop(phba->worker_thread); |
| 5447 | } |
| 5448 | |
| 5449 | /** |
| 5450 | * lpfc_free_iocb_list - Free iocb list. |
| 5451 | * @phba: pointer to lpfc hba data structure. |
| 5452 | * |
| 5453 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5454 | **/ |
| 5455 | static void |
| 5456 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5457 | { |
| 5458 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5459 | |
| 5460 | spin_lock_irq(&phba->hbalock); |
| 5461 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5462 | &phba->lpfc_iocb_list, list) { |
| 5463 | list_del(&iocbq_entry->list); |
| 5464 | kfree(iocbq_entry); |
| 5465 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5466 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5467 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5468 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5469 | return; |
| 5470 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5471 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5472 | /** |
| 5473 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5474 | * @phba: pointer to lpfc hba data structure. |
| 5475 | * |
| 5476 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5477 | * list and set up the IOCB tag array accordingly. |
| 5478 | * |
| 5479 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5480 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5481 | * other values - error |
| 5482 | **/ |
| 5483 | static int |
| 5484 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5485 | { |
| 5486 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5487 | uint16_t iotag; |
| 5488 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5489 | |
| 5490 | /* Initialize and populate the iocb list per host. */ |
| 5491 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5492 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5493 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5494 | if (iocbq_entry == NULL) { |
| 5495 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5496 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5497 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5498 | goto out_free_iocbq; |
| 5499 | } |
| 5500 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5501 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5502 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5503 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5504 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5505 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5506 | goto out_free_iocbq; |
| 5507 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5508 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5509 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5510 | |
| 5511 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5512 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5513 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5514 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5515 | } |
| 5516 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5517 | return 0; |
| 5518 | |
| 5519 | out_free_iocbq: |
| 5520 | lpfc_free_iocb_list(phba); |
| 5521 | |
| 5522 | return -ENOMEM; |
| 5523 | } |
| 5524 | |
| 5525 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5526 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5527 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5528 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5529 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5530 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5531 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5532 | void |
| 5533 | 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] | 5534 | { |
| 5535 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5536 | |
| 5537 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5538 | list_del(&sglq_entry->list); |
| 5539 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5540 | kfree(sglq_entry); |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | /** |
| 5545 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5546 | * @phba: pointer to lpfc hba data structure. |
| 5547 | * |
| 5548 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5549 | **/ |
| 5550 | static void |
| 5551 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5552 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5553 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5554 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5555 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5556 | spin_lock_irq(&phba->hbalock); |
| 5557 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5558 | spin_unlock_irq(&phba->hbalock); |
| 5559 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5560 | /* Now free the sgl list */ |
| 5561 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5566 | * @phba: pointer to lpfc hba data structure. |
| 5567 | * |
| 5568 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5569 | * This array will hold the sglq_entry's for active IOs. |
| 5570 | **/ |
| 5571 | static int |
| 5572 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5573 | { |
| 5574 | int size; |
| 5575 | size = sizeof(struct lpfc_sglq *); |
| 5576 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5577 | |
| 5578 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5579 | kzalloc(size, GFP_KERNEL); |
| 5580 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5581 | return -ENOMEM; |
| 5582 | return 0; |
| 5583 | } |
| 5584 | |
| 5585 | /** |
| 5586 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5587 | * @phba: pointer to lpfc hba data structure. |
| 5588 | * |
| 5589 | * This routine is invoked to walk through the array of active sglq entries |
| 5590 | * and free all of the resources. |
| 5591 | * This is just a place holder for now. |
| 5592 | **/ |
| 5593 | static void |
| 5594 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5595 | { |
| 5596 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5597 | } |
| 5598 | |
| 5599 | /** |
| 5600 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5601 | * @phba: pointer to lpfc hba data structure. |
| 5602 | * |
| 5603 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5604 | * list and set up the sgl xritag tag array accordingly. |
| 5605 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5606 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5607 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5608 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5609 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5610 | /* Initialize and populate the sglq list per host/VF. */ |
| 5611 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5612 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5613 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5614 | /* els xri-sgl book keeping */ |
| 5615 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5616 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5617 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5618 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | /** |
| 5622 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5623 | * @phba: pointer to lpfc hba data structure. |
| 5624 | * |
| 5625 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5626 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5627 | * 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] | 5628 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5629 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5630 | * |
| 5631 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5632 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5633 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5634 | **/ |
| 5635 | int |
| 5636 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5637 | { |
| 5638 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5639 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5640 | |
| 5641 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5642 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5643 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5644 | if (phba->sli4_hba.extents_in_use) |
| 5645 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5646 | |
| 5647 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5648 | if (!rpi_hdr) { |
| 5649 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5650 | "0391 Error during rpi post operation\n"); |
| 5651 | lpfc_sli4_remove_rpis(phba); |
| 5652 | rc = -ENODEV; |
| 5653 | } |
| 5654 | |
| 5655 | return rc; |
| 5656 | } |
| 5657 | |
| 5658 | /** |
| 5659 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5660 | * @phba: pointer to lpfc hba data structure. |
| 5661 | * |
| 5662 | * This routine is invoked to allocate a single 4KB memory region to |
| 5663 | * support rpis and stores them in the phba. This single region |
| 5664 | * provides support for up to 64 rpis. The region is used globally |
| 5665 | * by the device. |
| 5666 | * |
| 5667 | * Returns: |
| 5668 | * A valid rpi hdr on success. |
| 5669 | * A NULL pointer on any failure. |
| 5670 | **/ |
| 5671 | struct lpfc_rpi_hdr * |
| 5672 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5673 | { |
| 5674 | uint16_t rpi_limit, curr_rpi_range; |
| 5675 | struct lpfc_dmabuf *dmabuf; |
| 5676 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5677 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5678 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5679 | /* |
| 5680 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5681 | * required. Set the expected maximum count and let the actual value |
| 5682 | * get set when extents are fully allocated. |
| 5683 | */ |
| 5684 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5685 | return NULL; |
| 5686 | if (phba->sli4_hba.extents_in_use) |
| 5687 | return NULL; |
| 5688 | |
| 5689 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5690 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5691 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5692 | |
| 5693 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5694 | /* |
| 5695 | * Establish the starting RPI in this header block. The starting |
| 5696 | * rpi is normalized to a zero base because the physical rpi is |
| 5697 | * port based. |
| 5698 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5699 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5700 | spin_unlock_irq(&phba->hbalock); |
| 5701 | |
| 5702 | /* |
| 5703 | * The port has a limited number of rpis. The increment here |
| 5704 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5705 | * and to allow the full max_rpi range per port. |
| 5706 | */ |
| 5707 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5708 | rpi_count = rpi_limit - curr_rpi_range; |
| 5709 | else |
| 5710 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5711 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5712 | if (!rpi_count) |
| 5713 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5714 | /* |
| 5715 | * First allocate the protocol header region for the port. The |
| 5716 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5717 | */ |
| 5718 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5719 | if (!dmabuf) |
| 5720 | return NULL; |
| 5721 | |
| 5722 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5723 | LPFC_HDR_TEMPLATE_SIZE, |
| 5724 | &dmabuf->phys, |
| 5725 | GFP_KERNEL); |
| 5726 | if (!dmabuf->virt) { |
| 5727 | rpi_hdr = NULL; |
| 5728 | goto err_free_dmabuf; |
| 5729 | } |
| 5730 | |
| 5731 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5732 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5733 | rpi_hdr = NULL; |
| 5734 | goto err_free_coherent; |
| 5735 | } |
| 5736 | |
| 5737 | /* Save the rpi header data for cleanup later. */ |
| 5738 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5739 | if (!rpi_hdr) |
| 5740 | goto err_free_coherent; |
| 5741 | |
| 5742 | rpi_hdr->dmabuf = dmabuf; |
| 5743 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5744 | rpi_hdr->page_count = 1; |
| 5745 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5746 | |
| 5747 | /* The rpi_hdr stores the logical index only. */ |
| 5748 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5749 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5750 | |
| 5751 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5752 | * The next_rpi stores the next logical module-64 rpi value used |
| 5753 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5754 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5755 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5756 | spin_unlock_irq(&phba->hbalock); |
| 5757 | return rpi_hdr; |
| 5758 | |
| 5759 | err_free_coherent: |
| 5760 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5761 | dmabuf->virt, dmabuf->phys); |
| 5762 | err_free_dmabuf: |
| 5763 | kfree(dmabuf); |
| 5764 | return NULL; |
| 5765 | } |
| 5766 | |
| 5767 | /** |
| 5768 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5769 | * @phba: pointer to lpfc hba data structure. |
| 5770 | * |
| 5771 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5772 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5773 | * presumes the caller has released all rpis consumed by fabric or port |
| 5774 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5775 | **/ |
| 5776 | void |
| 5777 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5778 | { |
| 5779 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5780 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5781 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5782 | goto exit; |
| 5783 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5784 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5785 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5786 | list_del(&rpi_hdr->list); |
| 5787 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5788 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5789 | kfree(rpi_hdr->dmabuf); |
| 5790 | kfree(rpi_hdr); |
| 5791 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5792 | exit: |
| 5793 | /* There are no rpis available to the port now. */ |
| 5794 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5798 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5799 | * @pdev: pointer to pci device data structure. |
| 5800 | * |
| 5801 | * This routine is invoked to allocate the driver hba data structure for an |
| 5802 | * HBA device. If the allocation is successful, the phba reference to the |
| 5803 | * PCI device data structure is set. |
| 5804 | * |
| 5805 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5806 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5807 | * NULL - error |
| 5808 | **/ |
| 5809 | static struct lpfc_hba * |
| 5810 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5811 | { |
| 5812 | struct lpfc_hba *phba; |
| 5813 | |
| 5814 | /* Allocate memory for HBA structure */ |
| 5815 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5816 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5817 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5818 | return NULL; |
| 5819 | } |
| 5820 | |
| 5821 | /* Set reference to PCI device in HBA structure */ |
| 5822 | phba->pcidev = pdev; |
| 5823 | |
| 5824 | /* Assign an unused board number */ |
| 5825 | phba->brd_no = lpfc_get_instance(); |
| 5826 | if (phba->brd_no < 0) { |
| 5827 | kfree(phba); |
| 5828 | return NULL; |
| 5829 | } |
| 5830 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5831 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5832 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5833 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5834 | return phba; |
| 5835 | } |
| 5836 | |
| 5837 | /** |
| 5838 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5839 | * @phba: pointer to lpfc hba data structure. |
| 5840 | * |
| 5841 | * This routine is invoked to free the driver hba data structure with an |
| 5842 | * HBA device. |
| 5843 | **/ |
| 5844 | static void |
| 5845 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5846 | { |
| 5847 | /* Release the driver assigned board number */ |
| 5848 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5849 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5850 | /* Free memory allocated with sli rings */ |
| 5851 | kfree(phba->sli.ring); |
| 5852 | phba->sli.ring = NULL; |
| 5853 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5854 | kfree(phba); |
| 5855 | return; |
| 5856 | } |
| 5857 | |
| 5858 | /** |
| 5859 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5860 | * @phba: pointer to lpfc hba data structure. |
| 5861 | * |
| 5862 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5863 | * host with it. |
| 5864 | * |
| 5865 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5866 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5867 | * other values - error |
| 5868 | **/ |
| 5869 | static int |
| 5870 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5871 | { |
| 5872 | struct lpfc_vport *vport; |
| 5873 | struct Scsi_Host *shost; |
| 5874 | |
| 5875 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5876 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5877 | phba->fc_ratov = FF_DEF_RATOV; |
| 5878 | phba->fc_altov = FF_DEF_ALTOV; |
| 5879 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5880 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5881 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5882 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5883 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5884 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5885 | |
| 5886 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5887 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5888 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5889 | /* Put reference to SCSI host to driver's device private data */ |
| 5890 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5891 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5892 | return 0; |
| 5893 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5894 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5895 | /** |
| 5896 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5897 | * @phba: pointer to lpfc hba data structure. |
| 5898 | * |
| 5899 | * This routine is invoked to destroy HBA physical port and the associated |
| 5900 | * SCSI host. |
| 5901 | **/ |
| 5902 | static void |
| 5903 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5904 | { |
| 5905 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5906 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5907 | /* Destroy physical port that associated with the SCSI host */ |
| 5908 | destroy_port(vport); |
| 5909 | |
| 5910 | return; |
| 5911 | } |
| 5912 | |
| 5913 | /** |
| 5914 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5915 | * @phba: pointer to lpfc hba data structure. |
| 5916 | * @shost: the shost to be used to detect Block guard settings. |
| 5917 | * |
| 5918 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5919 | * This routine also allocates memory for debugging bg buffers. |
| 5920 | **/ |
| 5921 | static void |
| 5922 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5923 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5924 | uint32_t old_mask; |
| 5925 | uint32_t old_guard; |
| 5926 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5927 | int pagecnt = 10; |
| 5928 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5929 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5930 | "1478 Registering BlockGuard with the " |
| 5931 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5932 | |
| 5933 | old_mask = lpfc_prot_mask; |
| 5934 | old_guard = lpfc_prot_guard; |
| 5935 | |
| 5936 | /* Only allow supported values */ |
| 5937 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 5938 | SHOST_DIX_TYPE0_PROTECTION | |
| 5939 | SHOST_DIX_TYPE1_PROTECTION); |
| 5940 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 5941 | |
| 5942 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 5943 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 5944 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 5945 | |
| 5946 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5947 | if ((old_mask != lpfc_prot_mask) || |
| 5948 | (old_guard != lpfc_prot_guard)) |
| 5949 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5950 | "1475 Registering BlockGuard with the " |
| 5951 | "SCSI layer: mask %d guard %d\n", |
| 5952 | lpfc_prot_mask, lpfc_prot_guard); |
| 5953 | |
| 5954 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 5955 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 5956 | } else |
| 5957 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5958 | "1479 Not Registering BlockGuard with the SCSI " |
| 5959 | "layer, Bad protection parameters: %d %d\n", |
| 5960 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5961 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5962 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5963 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5964 | while (pagecnt) { |
| 5965 | spin_lock_init(&_dump_buf_lock); |
| 5966 | _dump_buf_data = |
| 5967 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5968 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5969 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5970 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5971 | "_dump_buf_data at 0x%p\n", |
| 5972 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5973 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5974 | memset(_dump_buf_data, 0, |
| 5975 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5976 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5977 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5978 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5979 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5980 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5981 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5982 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5983 | "memory for hexdump\n"); |
| 5984 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5985 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5986 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5987 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5988 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5989 | while (pagecnt) { |
| 5990 | _dump_buf_dif = |
| 5991 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5992 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5993 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5994 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5995 | "_dump_buf_dif at 0x%p\n", |
| 5996 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5997 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5998 | memset(_dump_buf_dif, 0, |
| 5999 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6000 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6001 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6002 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6003 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 6004 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6005 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6006 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6007 | "memory for hexdump\n"); |
| 6008 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6009 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 6010 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6011 | _dump_buf_dif); |
| 6012 | } |
| 6013 | |
| 6014 | /** |
| 6015 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 6016 | * @phba: pointer to lpfc hba data structure. |
| 6017 | * |
| 6018 | * This routine is invoked to perform all the necessary post initialization |
| 6019 | * setup for the device. |
| 6020 | **/ |
| 6021 | static void |
| 6022 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 6023 | { |
| 6024 | struct Scsi_Host *shost; |
| 6025 | struct lpfc_adapter_event_header adapter_event; |
| 6026 | |
| 6027 | /* Get the default values for Model Name and Description */ |
| 6028 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 6029 | |
| 6030 | /* |
| 6031 | * hba setup may have changed the hba_queue_depth so we need to |
| 6032 | * adjust the value of can_queue. |
| 6033 | */ |
| 6034 | shost = pci_get_drvdata(phba->pcidev); |
| 6035 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 6036 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 6037 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6038 | |
| 6039 | lpfc_host_attrib_init(shost); |
| 6040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6041 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6042 | spin_lock_irq(shost->host_lock); |
| 6043 | lpfc_poll_start_timer(phba); |
| 6044 | spin_unlock_irq(shost->host_lock); |
| 6045 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 6046 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6047 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6048 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6049 | /* Send board arrival event to upper layer */ |
| 6050 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 6051 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 6052 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6053 | sizeof(adapter_event), |
| 6054 | (char *) &adapter_event, |
| 6055 | LPFC_NL_VENDOR_ID); |
| 6056 | return; |
| 6057 | } |
| 6058 | |
| 6059 | /** |
| 6060 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 6061 | * @phba: pointer to lpfc hba data structure. |
| 6062 | * |
| 6063 | * This routine is invoked to set up the PCI device memory space for device |
| 6064 | * with SLI-3 interface spec. |
| 6065 | * |
| 6066 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6067 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6068 | * other values - error |
| 6069 | **/ |
| 6070 | static int |
| 6071 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 6072 | { |
| 6073 | struct pci_dev *pdev; |
| 6074 | unsigned long bar0map_len, bar2map_len; |
| 6075 | int i, hbq_count; |
| 6076 | void *ptr; |
| 6077 | int error = -ENODEV; |
| 6078 | |
| 6079 | /* Obtain PCI device reference */ |
| 6080 | if (!phba->pcidev) |
| 6081 | return error; |
| 6082 | else |
| 6083 | pdev = phba->pcidev; |
| 6084 | |
| 6085 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6086 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 6087 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 6088 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 6089 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6090 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6091 | } |
| 6092 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6093 | |
| 6094 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 6095 | * required by each mapping. |
| 6096 | */ |
| 6097 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 6098 | bar0map_len = pci_resource_len(pdev, 0); |
| 6099 | |
| 6100 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 6101 | bar2map_len = pci_resource_len(pdev, 2); |
| 6102 | |
| 6103 | /* Map HBA SLIM to a kernel virtual address. */ |
| 6104 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 6105 | if (!phba->slim_memmap_p) { |
| 6106 | dev_printk(KERN_ERR, &pdev->dev, |
| 6107 | "ioremap failed for SLIM memory.\n"); |
| 6108 | goto out; |
| 6109 | } |
| 6110 | |
| 6111 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 6112 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 6113 | if (!phba->ctrl_regs_memmap_p) { |
| 6114 | dev_printk(KERN_ERR, &pdev->dev, |
| 6115 | "ioremap failed for HBA control registers.\n"); |
| 6116 | goto out_iounmap_slim; |
| 6117 | } |
| 6118 | |
| 6119 | /* Allocate memory for SLI-2 structures */ |
| 6120 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 6121 | SLI2_SLIM_SIZE, |
| 6122 | &phba->slim2p.phys, |
| 6123 | GFP_KERNEL); |
| 6124 | if (!phba->slim2p.virt) |
| 6125 | goto out_iounmap; |
| 6126 | |
| 6127 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 6128 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6129 | phba->mbox_ext = (phba->slim2p.virt + |
| 6130 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6131 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 6132 | phba->IOCBs = (phba->slim2p.virt + |
| 6133 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 6134 | |
| 6135 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 6136 | lpfc_sli_hbq_size(), |
| 6137 | &phba->hbqslimp.phys, |
| 6138 | GFP_KERNEL); |
| 6139 | if (!phba->hbqslimp.virt) |
| 6140 | goto out_free_slim; |
| 6141 | |
| 6142 | hbq_count = lpfc_sli_hbq_count(); |
| 6143 | ptr = phba->hbqslimp.virt; |
| 6144 | for (i = 0; i < hbq_count; ++i) { |
| 6145 | phba->hbqs[i].hbq_virt = ptr; |
| 6146 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 6147 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 6148 | sizeof(struct lpfc_hbq_entry)); |
| 6149 | } |
| 6150 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 6151 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 6152 | |
| 6153 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 6154 | |
| 6155 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 6156 | |
| 6157 | phba->MBslimaddr = phba->slim_memmap_p; |
| 6158 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 6159 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 6160 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 6161 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6162 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6163 | return 0; |
| 6164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6165 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6166 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6167 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6168 | out_iounmap: |
| 6169 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6170 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6171 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6172 | out: |
| 6173 | return error; |
| 6174 | } |
| 6175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6176 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6177 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 6178 | * @phba: pointer to lpfc hba data structure. |
| 6179 | * |
| 6180 | * This routine is invoked to unset the PCI device memory space for device |
| 6181 | * with SLI-3 interface spec. |
| 6182 | **/ |
| 6183 | static void |
| 6184 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 6185 | { |
| 6186 | struct pci_dev *pdev; |
| 6187 | |
| 6188 | /* Obtain PCI device reference */ |
| 6189 | if (!phba->pcidev) |
| 6190 | return; |
| 6191 | else |
| 6192 | pdev = phba->pcidev; |
| 6193 | |
| 6194 | /* Free coherent DMA memory allocated */ |
| 6195 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 6196 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 6197 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6198 | phba->slim2p.virt, phba->slim2p.phys); |
| 6199 | |
| 6200 | /* I/O memory unmap */ |
| 6201 | iounmap(phba->ctrl_regs_memmap_p); |
| 6202 | iounmap(phba->slim_memmap_p); |
| 6203 | |
| 6204 | return; |
| 6205 | } |
| 6206 | |
| 6207 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6208 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 6209 | * @phba: pointer to lpfc hba data structure. |
| 6210 | * |
| 6211 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 6212 | * done and check status. |
| 6213 | * |
| 6214 | * Return 0 if successful, otherwise -ENODEV. |
| 6215 | **/ |
| 6216 | int |
| 6217 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 6218 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6219 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 6220 | struct lpfc_register reg_data; |
| 6221 | int i, port_error = 0; |
| 6222 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6223 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6224 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 6225 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6226 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6227 | return -ENODEV; |
| 6228 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6229 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 6230 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6231 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 6232 | &portsmphr_reg.word0) || |
| 6233 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6234 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6235 | port_error = -ENODEV; |
| 6236 | break; |
| 6237 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6238 | if (LPFC_POST_STAGE_PORT_READY == |
| 6239 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6240 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6241 | msleep(10); |
| 6242 | } |
| 6243 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6244 | /* |
| 6245 | * If there was a port error during POST, then don't proceed with |
| 6246 | * other register reads as the data may not be valid. Just exit. |
| 6247 | */ |
| 6248 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6249 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6250 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 6251 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 6252 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 6253 | portsmphr_reg.word0, |
| 6254 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 6255 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 6256 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 6257 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 6258 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 6259 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 6260 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 6261 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 6262 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6263 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6264 | "2534 Device Info: SLIFamily=0x%x, " |
| 6265 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 6266 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6267 | bf_get(lpfc_sli_intf_sli_family, |
| 6268 | &phba->sli4_hba.sli_intf), |
| 6269 | bf_get(lpfc_sli_intf_slirev, |
| 6270 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6271 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6272 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6273 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6274 | &phba->sli4_hba.sli_intf), |
| 6275 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6276 | &phba->sli4_hba.sli_intf), |
| 6277 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6278 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6279 | /* |
| 6280 | * Check for other Port errors during the initialization |
| 6281 | * process. Fail the load if the port did not come up |
| 6282 | * correctly. |
| 6283 | */ |
| 6284 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6285 | &phba->sli4_hba.sli_intf); |
| 6286 | switch (if_type) { |
| 6287 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6288 | phba->sli4_hba.ue_mask_lo = |
| 6289 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6290 | phba->sli4_hba.ue_mask_hi = |
| 6291 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6292 | uerrlo_reg.word0 = |
| 6293 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6294 | uerrhi_reg.word0 = |
| 6295 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6296 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6297 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6298 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6299 | "1422 Unrecoverable Error " |
| 6300 | "Detected during POST " |
| 6301 | "uerr_lo_reg=0x%x, " |
| 6302 | "uerr_hi_reg=0x%x, " |
| 6303 | "ue_mask_lo_reg=0x%x, " |
| 6304 | "ue_mask_hi_reg=0x%x\n", |
| 6305 | uerrlo_reg.word0, |
| 6306 | uerrhi_reg.word0, |
| 6307 | phba->sli4_hba.ue_mask_lo, |
| 6308 | phba->sli4_hba.ue_mask_hi); |
| 6309 | port_error = -ENODEV; |
| 6310 | } |
| 6311 | break; |
| 6312 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6313 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6314 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6315 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6316 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6317 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6318 | phba->work_status[0] = |
| 6319 | readl(phba->sli4_hba.u.if_type2. |
| 6320 | ERR1regaddr); |
| 6321 | phba->work_status[1] = |
| 6322 | readl(phba->sli4_hba.u.if_type2. |
| 6323 | ERR2regaddr); |
| 6324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6325 | "2888 Unrecoverable port error " |
| 6326 | "following POST: port status reg " |
| 6327 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6328 | "error 1=0x%x, error 2=0x%x\n", |
| 6329 | reg_data.word0, |
| 6330 | portsmphr_reg.word0, |
| 6331 | phba->work_status[0], |
| 6332 | phba->work_status[1]); |
| 6333 | port_error = -ENODEV; |
| 6334 | } |
| 6335 | break; |
| 6336 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6337 | default: |
| 6338 | break; |
| 6339 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6340 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6341 | return port_error; |
| 6342 | } |
| 6343 | |
| 6344 | /** |
| 6345 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6346 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6347 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6348 | * |
| 6349 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6350 | * memory map. |
| 6351 | **/ |
| 6352 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6353 | 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] | 6354 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6355 | switch (if_type) { |
| 6356 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6357 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6358 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6359 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6360 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6361 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6362 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6363 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6364 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6365 | phba->sli4_hba.SLIINTFregaddr = |
| 6366 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6367 | break; |
| 6368 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6369 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6370 | phba->sli4_hba.conf_regs_memmap_p + |
| 6371 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6372 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6373 | phba->sli4_hba.conf_regs_memmap_p + |
| 6374 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6375 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6376 | phba->sli4_hba.conf_regs_memmap_p + |
| 6377 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6378 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6379 | phba->sli4_hba.conf_regs_memmap_p + |
| 6380 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6381 | phba->sli4_hba.SLIINTFregaddr = |
| 6382 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6383 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6384 | phba->sli4_hba.conf_regs_memmap_p + |
| 6385 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6386 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6387 | phba->sli4_hba.conf_regs_memmap_p + |
| 6388 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6389 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6390 | phba->sli4_hba.conf_regs_memmap_p + |
| 6391 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6392 | phba->sli4_hba.EQCQDBregaddr = |
| 6393 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6394 | phba->sli4_hba.MQDBregaddr = |
| 6395 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6396 | phba->sli4_hba.BMBXregaddr = |
| 6397 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6398 | break; |
| 6399 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6400 | default: |
| 6401 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6402 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6403 | if_type); |
| 6404 | break; |
| 6405 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | /** |
| 6409 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6410 | * @phba: pointer to lpfc hba data structure. |
| 6411 | * |
| 6412 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6413 | * memory map. |
| 6414 | **/ |
| 6415 | static void |
| 6416 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6417 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6418 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6419 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6420 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6421 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6422 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6423 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6424 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6425 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | /** |
| 6429 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6430 | * @phba: pointer to lpfc hba data structure. |
| 6431 | * @vf: virtual function number |
| 6432 | * |
| 6433 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6434 | * based on the given viftual function number, @vf. |
| 6435 | * |
| 6436 | * Return 0 if successful, otherwise -ENODEV. |
| 6437 | **/ |
| 6438 | static int |
| 6439 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6440 | { |
| 6441 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6442 | return -ENODEV; |
| 6443 | |
| 6444 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6445 | vf * LPFC_VFR_PAGE_SIZE + |
| 6446 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6447 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6448 | vf * LPFC_VFR_PAGE_SIZE + |
| 6449 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6450 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6451 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6452 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6453 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6454 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6455 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6456 | return 0; |
| 6457 | } |
| 6458 | |
| 6459 | /** |
| 6460 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6461 | * @phba: pointer to lpfc hba data structure. |
| 6462 | * |
| 6463 | * This routine is invoked to create the bootstrap mailbox |
| 6464 | * region consistent with the SLI-4 interface spec. This |
| 6465 | * routine allocates all memory necessary to communicate |
| 6466 | * mailbox commands to the port and sets up all alignment |
| 6467 | * needs. No locks are expected to be held when calling |
| 6468 | * this routine. |
| 6469 | * |
| 6470 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6471 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6472 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6473 | **/ |
| 6474 | static int |
| 6475 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6476 | { |
| 6477 | uint32_t bmbx_size; |
| 6478 | struct lpfc_dmabuf *dmabuf; |
| 6479 | struct dma_address *dma_address; |
| 6480 | uint32_t pa_addr; |
| 6481 | uint64_t phys_addr; |
| 6482 | |
| 6483 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6484 | if (!dmabuf) |
| 6485 | return -ENOMEM; |
| 6486 | |
| 6487 | /* |
| 6488 | * The bootstrap mailbox region is comprised of 2 parts |
| 6489 | * plus an alignment restriction of 16 bytes. |
| 6490 | */ |
| 6491 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 6492 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6493 | bmbx_size, |
| 6494 | &dmabuf->phys, |
| 6495 | GFP_KERNEL); |
| 6496 | if (!dmabuf->virt) { |
| 6497 | kfree(dmabuf); |
| 6498 | return -ENOMEM; |
| 6499 | } |
| 6500 | memset(dmabuf->virt, 0, bmbx_size); |
| 6501 | |
| 6502 | /* |
| 6503 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6504 | * operations are simple later. The mailbox dma address is required |
| 6505 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6506 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6507 | * command to the port. |
| 6508 | */ |
| 6509 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6510 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6511 | |
| 6512 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6513 | LPFC_ALIGN_16_BYTE); |
| 6514 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6515 | LPFC_ALIGN_16_BYTE); |
| 6516 | |
| 6517 | /* |
| 6518 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6519 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6520 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6521 | * the 30-bit address is the high or low address. |
| 6522 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6523 | * clean on 32 bit machines. |
| 6524 | */ |
| 6525 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6526 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6527 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6528 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6529 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6530 | |
| 6531 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6532 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6533 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6534 | return 0; |
| 6535 | } |
| 6536 | |
| 6537 | /** |
| 6538 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6539 | * @phba: pointer to lpfc hba data structure. |
| 6540 | * |
| 6541 | * This routine is invoked to teardown the bootstrap mailbox |
| 6542 | * region and release all host resources. This routine requires |
| 6543 | * the caller to ensure all mailbox commands recovered, no |
| 6544 | * additional mailbox comands are sent, and interrupts are disabled |
| 6545 | * before calling this routine. |
| 6546 | * |
| 6547 | **/ |
| 6548 | static void |
| 6549 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6550 | { |
| 6551 | dma_free_coherent(&phba->pcidev->dev, |
| 6552 | phba->sli4_hba.bmbx.bmbx_size, |
| 6553 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6554 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6555 | |
| 6556 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6557 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6558 | } |
| 6559 | |
| 6560 | /** |
| 6561 | * lpfc_sli4_read_config - Get the config parameters. |
| 6562 | * @phba: pointer to lpfc hba data structure. |
| 6563 | * |
| 6564 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6565 | * The configuration parameters are used to set the base and maximum values |
| 6566 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6567 | * allocation for the port. |
| 6568 | * |
| 6569 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6570 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6571 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6572 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6573 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6574 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6575 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6576 | { |
| 6577 | LPFC_MBOXQ_t *pmb; |
| 6578 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6579 | union lpfc_sli4_cfg_shdr *shdr; |
| 6580 | uint32_t shdr_status, shdr_add_status; |
| 6581 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6582 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6583 | char *pdesc_0; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6584 | uint32_t desc_count; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6585 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6586 | |
| 6587 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6588 | if (!pmb) { |
| 6589 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6590 | "2011 Unable to allocate memory for issuing " |
| 6591 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6592 | return -ENOMEM; |
| 6593 | } |
| 6594 | |
| 6595 | lpfc_read_config(phba, pmb); |
| 6596 | |
| 6597 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6598 | if (rc != MBX_SUCCESS) { |
| 6599 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6600 | "2012 Mailbox failed , mbxCmd x%x " |
| 6601 | "READ_CONFIG, mbxStatus x%x\n", |
| 6602 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6603 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6604 | rc = -EIO; |
| 6605 | } else { |
| 6606 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6607 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6608 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6609 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6610 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6611 | phba->sli4_hba.lnk_info.lnk_no = |
| 6612 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6613 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6614 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6615 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6616 | phba->sli4_hba.lnk_info.lnk_no); |
| 6617 | } else |
| 6618 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6619 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6620 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6621 | phba->sli4_hba.extents_in_use = |
| 6622 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6623 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6624 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6625 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6626 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6627 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6628 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6629 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6630 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6631 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6632 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6633 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6634 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6635 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6636 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6637 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6638 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6639 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6640 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6641 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6642 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6643 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6644 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6645 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6646 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6647 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6648 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6649 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6650 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6651 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6652 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6653 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6654 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6655 | phba->max_vports = phba->max_vpi; |
| 6656 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6657 | "2003 cfg params Extents? %d " |
| 6658 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6659 | "VPI(B:%d M:%d) " |
| 6660 | "VFI(B:%d M:%d) " |
| 6661 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6662 | "FCFI(Count:%d)\n", |
| 6663 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6664 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6665 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6666 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6667 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6668 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6669 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6670 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6671 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6672 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6673 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6674 | |
| 6675 | if (rc) |
| 6676 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6677 | |
| 6678 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6679 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 6680 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 6681 | if (phba->cfg_hba_queue_depth > length) { |
| 6682 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6683 | "3361 HBA queue depth changed from %d to %d\n", |
| 6684 | phba->cfg_hba_queue_depth, length); |
| 6685 | phba->cfg_hba_queue_depth = length; |
| 6686 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6687 | |
| 6688 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6689 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6690 | goto read_cfg_out; |
| 6691 | |
| 6692 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6693 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6694 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6695 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6696 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6697 | length, LPFC_SLI4_MBX_EMBED); |
| 6698 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6699 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6700 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6701 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6702 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6703 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6704 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6705 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6706 | "3026 Mailbox failed , mbxCmd x%x " |
| 6707 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6708 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6709 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6710 | goto read_cfg_out; |
| 6711 | } |
| 6712 | |
| 6713 | /* search for fc_fcoe resrouce descriptor */ |
| 6714 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6715 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6716 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6717 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6718 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6719 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6720 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6721 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6722 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6723 | goto read_cfg_out; |
| 6724 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6725 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6726 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6727 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6728 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6729 | phba->sli4_hba.iov.pf_number = |
| 6730 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6731 | phba->sli4_hba.iov.vf_number = |
| 6732 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6733 | break; |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6738 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6739 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6740 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6741 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6742 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6743 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6744 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6745 | "Resrouce Descriptor:x%x\n", |
| 6746 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6747 | |
| 6748 | read_cfg_out: |
| 6749 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6750 | return rc; |
| 6751 | } |
| 6752 | |
| 6753 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6754 | * 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] | 6755 | * @phba: pointer to lpfc hba data structure. |
| 6756 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6757 | * This routine is invoked to setup the port-side endian order when |
| 6758 | * the port if_type is 0. This routine has no function for other |
| 6759 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6760 | * |
| 6761 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6762 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6763 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6764 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6765 | **/ |
| 6766 | static int |
| 6767 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6768 | { |
| 6769 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6770 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6771 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6772 | HOST_ENDIAN_HIGH_WORD1}; |
| 6773 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6774 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6775 | switch (if_type) { |
| 6776 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6777 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6778 | GFP_KERNEL); |
| 6779 | if (!mboxq) { |
| 6780 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6781 | "0492 Unable to allocate memory for " |
| 6782 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6783 | "command\n"); |
| 6784 | return -ENOMEM; |
| 6785 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6786 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6787 | /* |
| 6788 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6789 | * two words to contain special data values and no other data. |
| 6790 | */ |
| 6791 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6792 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6793 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6794 | if (rc != MBX_SUCCESS) { |
| 6795 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6796 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6797 | "failed with status x%x\n", |
| 6798 | rc); |
| 6799 | rc = -EIO; |
| 6800 | } |
| 6801 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6802 | break; |
| 6803 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6804 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6805 | default: |
| 6806 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6807 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6808 | return rc; |
| 6809 | } |
| 6810 | |
| 6811 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6812 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6813 | * @phba: pointer to lpfc hba data structure. |
| 6814 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6815 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6816 | * CQs. after this routine is called the counts will be set to valid values that |
| 6817 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6818 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6819 | * |
| 6820 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6821 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6822 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6823 | **/ |
| 6824 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6825 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6826 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6827 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6828 | uint32_t cpu; |
| 6829 | uint32_t i = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6830 | |
| 6831 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6832 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6833 | * device parameters |
| 6834 | */ |
| 6835 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6836 | /* Sanity check on HBA EQ parameters */ |
| 6837 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6838 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6839 | /* It doesn't make sense to have more io channels then online CPUs */ |
| 6840 | for_each_present_cpu(cpu) { |
| 6841 | if (cpu_online(cpu)) |
| 6842 | i++; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6843 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6844 | phba->sli4_hba.num_online_cpu = i; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6845 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6846 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6847 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6848 | lpfc_printf_log(phba, |
| 6849 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6850 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6851 | "online CPUs: from %d to %d\n", |
| 6852 | cfg_fcp_io_channel, i); |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6853 | cfg_fcp_io_channel = i; |
| 6854 | } |
| 6855 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6856 | if (cfg_fcp_io_channel > |
| 6857 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6858 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 6859 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6860 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6861 | "2574 Not enough EQs (%d) from the " |
| 6862 | "pci function for supporting FCP " |
| 6863 | "EQs (%d)\n", |
| 6864 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6865 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6866 | goto out_error; |
| 6867 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6868 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6869 | "2575 Reducing IO channels to match number of " |
| 6870 | "available EQs: from %d to %d\n", |
| 6871 | cfg_fcp_io_channel, |
| 6872 | phba->sli4_hba.max_cfg_param.max_eq); |
| 6873 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6874 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6875 | |
| 6876 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 6877 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6878 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6879 | phba->cfg_fcp_eq_count = cfg_fcp_io_channel; |
| 6880 | phba->cfg_fcp_wq_count = cfg_fcp_io_channel; |
| 6881 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6882 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6883 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6884 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6885 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6886 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6887 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6888 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6889 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6890 | |
| 6891 | return 0; |
| 6892 | out_error: |
| 6893 | return -ENOMEM; |
| 6894 | } |
| 6895 | |
| 6896 | /** |
| 6897 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6898 | * @phba: pointer to lpfc hba data structure. |
| 6899 | * |
| 6900 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6901 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6902 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6903 | * we just use some constant number as place holder. |
| 6904 | * |
| 6905 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 6906 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6907 | * -ENOMEM - No availble memory |
| 6908 | * -EIO - The mailbox failed to complete successfully. |
| 6909 | **/ |
| 6910 | int |
| 6911 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6912 | { |
| 6913 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6914 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6915 | |
| 6916 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6917 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6918 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6919 | if (!phba->cfg_fcp_io_channel) |
| 6920 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6921 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6922 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6923 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6924 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6925 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6926 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6927 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6928 | |
| 6929 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6930 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6931 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6932 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6933 | "2576 Failed allocate memory for " |
| 6934 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6935 | goto out_error; |
| 6936 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6937 | |
| 6938 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6939 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6940 | if (!phba->sli4_hba.fcp_cq) { |
| 6941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6942 | "2577 Failed allocate memory for fast-path " |
| 6943 | "CQ record array\n"); |
| 6944 | goto out_error; |
| 6945 | } |
| 6946 | |
| 6947 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6948 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6949 | if (!phba->sli4_hba.fcp_wq) { |
| 6950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6951 | "2578 Failed allocate memory for fast-path " |
| 6952 | "WQ record array\n"); |
| 6953 | goto out_error; |
| 6954 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6955 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6956 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6957 | * Since the first EQ can have multiple CQs associated with it, |
| 6958 | * this array is used to quickly see if we have a FCP fast-path |
| 6959 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6960 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6961 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 6962 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6963 | if (!phba->sli4_hba.fcp_cq_map) { |
| 6964 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6965 | "2545 Failed allocate memory for fast-path " |
| 6966 | "CQ map\n"); |
| 6967 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6968 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6969 | |
| 6970 | /* |
| 6971 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 6972 | * how many EQs to create. |
| 6973 | */ |
| 6974 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6975 | |
| 6976 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6977 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6978 | phba->sli4_hba.eq_ecount); |
| 6979 | if (!qdesc) { |
| 6980 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6981 | "0497 Failed allocate EQ (%d)\n", idx); |
| 6982 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6983 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6984 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 6985 | |
| 6986 | /* Create Fast Path FCP CQs */ |
| 6987 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6988 | phba->sli4_hba.cq_ecount); |
| 6989 | if (!qdesc) { |
| 6990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6991 | "0499 Failed allocate fast-path FCP " |
| 6992 | "CQ (%d)\n", idx); |
| 6993 | goto out_error; |
| 6994 | } |
| 6995 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 6996 | |
| 6997 | /* Create Fast Path FCP WQs */ |
| 6998 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6999 | phba->sli4_hba.wq_ecount); |
| 7000 | if (!qdesc) { |
| 7001 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7002 | "0503 Failed allocate fast-path FCP " |
| 7003 | "WQ (%d)\n", idx); |
| 7004 | goto out_error; |
| 7005 | } |
| 7006 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7007 | } |
| 7008 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7009 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7010 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7011 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7012 | */ |
| 7013 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7014 | /* Create slow-path Mailbox Command Complete Queue */ |
| 7015 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7016 | phba->sli4_hba.cq_ecount); |
| 7017 | if (!qdesc) { |
| 7018 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7019 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7020 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7021 | } |
| 7022 | phba->sli4_hba.mbx_cq = qdesc; |
| 7023 | |
| 7024 | /* Create slow-path ELS Complete Queue */ |
| 7025 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 7026 | phba->sli4_hba.cq_ecount); |
| 7027 | if (!qdesc) { |
| 7028 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7029 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7030 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7031 | } |
| 7032 | phba->sli4_hba.els_cq = qdesc; |
| 7033 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7034 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7035 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7036 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7037 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7038 | |
| 7039 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7040 | |
| 7041 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 7042 | phba->sli4_hba.mq_ecount); |
| 7043 | if (!qdesc) { |
| 7044 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7045 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7046 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7047 | } |
| 7048 | phba->sli4_hba.mbx_wq = qdesc; |
| 7049 | |
| 7050 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7051 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7052 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7053 | |
| 7054 | /* Create slow-path ELS Work Queue */ |
| 7055 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7056 | phba->sli4_hba.wq_ecount); |
| 7057 | if (!qdesc) { |
| 7058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7059 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7060 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7061 | } |
| 7062 | phba->sli4_hba.els_wq = qdesc; |
| 7063 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7064 | /* |
| 7065 | * Create Receive Queue (RQ) |
| 7066 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7067 | |
| 7068 | /* Create Receive Queue for header */ |
| 7069 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7070 | phba->sli4_hba.rq_ecount); |
| 7071 | if (!qdesc) { |
| 7072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7073 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7074 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7075 | } |
| 7076 | phba->sli4_hba.hdr_rq = qdesc; |
| 7077 | |
| 7078 | /* Create Receive Queue for data */ |
| 7079 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7080 | phba->sli4_hba.rq_ecount); |
| 7081 | if (!qdesc) { |
| 7082 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7083 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7084 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7085 | } |
| 7086 | phba->sli4_hba.dat_rq = qdesc; |
| 7087 | |
| 7088 | return 0; |
| 7089 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7090 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7091 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7092 | return -ENOMEM; |
| 7093 | } |
| 7094 | |
| 7095 | /** |
| 7096 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 7097 | * @phba: pointer to lpfc hba data structure. |
| 7098 | * |
| 7099 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 7100 | * operation. |
| 7101 | * |
| 7102 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7103 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7104 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7105 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7106 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7107 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7108 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 7109 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7110 | int idx; |
| 7111 | |
| 7112 | if (phba->sli4_hba.hba_eq != NULL) { |
| 7113 | /* Release HBA event queue */ |
| 7114 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7115 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 7116 | lpfc_sli4_queue_free( |
| 7117 | phba->sli4_hba.hba_eq[idx]); |
| 7118 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 7119 | } |
| 7120 | } |
| 7121 | kfree(phba->sli4_hba.hba_eq); |
| 7122 | phba->sli4_hba.hba_eq = NULL; |
| 7123 | } |
| 7124 | |
| 7125 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 7126 | /* Release FCP completion queue */ |
| 7127 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7128 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 7129 | lpfc_sli4_queue_free( |
| 7130 | phba->sli4_hba.fcp_cq[idx]); |
| 7131 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 7132 | } |
| 7133 | } |
| 7134 | kfree(phba->sli4_hba.fcp_cq); |
| 7135 | phba->sli4_hba.fcp_cq = NULL; |
| 7136 | } |
| 7137 | |
| 7138 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 7139 | /* Release FCP work queue */ |
| 7140 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7141 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 7142 | lpfc_sli4_queue_free( |
| 7143 | phba->sli4_hba.fcp_wq[idx]); |
| 7144 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 7145 | } |
| 7146 | } |
| 7147 | kfree(phba->sli4_hba.fcp_wq); |
| 7148 | phba->sli4_hba.fcp_wq = NULL; |
| 7149 | } |
| 7150 | |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7151 | if (phba->pci_bar0_memmap_p) { |
| 7152 | iounmap(phba->pci_bar0_memmap_p); |
| 7153 | phba->pci_bar0_memmap_p = NULL; |
| 7154 | } |
| 7155 | if (phba->pci_bar2_memmap_p) { |
| 7156 | iounmap(phba->pci_bar2_memmap_p); |
| 7157 | phba->pci_bar2_memmap_p = NULL; |
| 7158 | } |
| 7159 | if (phba->pci_bar4_memmap_p) { |
| 7160 | iounmap(phba->pci_bar4_memmap_p); |
| 7161 | phba->pci_bar4_memmap_p = NULL; |
| 7162 | } |
| 7163 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7164 | /* Release FCP CQ mapping array */ |
| 7165 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 7166 | kfree(phba->sli4_hba.fcp_cq_map); |
| 7167 | phba->sli4_hba.fcp_cq_map = NULL; |
| 7168 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7169 | |
| 7170 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7171 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 7172 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 7173 | phba->sli4_hba.mbx_wq = NULL; |
| 7174 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7175 | |
| 7176 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7177 | if (phba->sli4_hba.els_wq != NULL) { |
| 7178 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 7179 | phba->sli4_hba.els_wq = NULL; |
| 7180 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7181 | |
| 7182 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7183 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 7184 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 7185 | phba->sli4_hba.hdr_rq = NULL; |
| 7186 | } |
| 7187 | if (phba->sli4_hba.dat_rq != NULL) { |
| 7188 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 7189 | phba->sli4_hba.dat_rq = NULL; |
| 7190 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7191 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7192 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7193 | if (phba->sli4_hba.els_cq != NULL) { |
| 7194 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 7195 | phba->sli4_hba.els_cq = NULL; |
| 7196 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7197 | |
| 7198 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7199 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 7200 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 7201 | phba->sli4_hba.mbx_cq = NULL; |
| 7202 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7203 | |
| 7204 | return; |
| 7205 | } |
| 7206 | |
| 7207 | /** |
| 7208 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 7209 | * @phba: pointer to lpfc hba data structure. |
| 7210 | * |
| 7211 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 7212 | * operation. |
| 7213 | * |
| 7214 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7215 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7216 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7217 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7218 | **/ |
| 7219 | int |
| 7220 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 7221 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7222 | struct lpfc_sli *psli = &phba->sli; |
| 7223 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7224 | int rc = -ENOMEM; |
| 7225 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 7226 | int fcp_cq_index = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7227 | uint32_t shdr_status, shdr_add_status; |
| 7228 | union lpfc_sli4_cfg_shdr *shdr; |
| 7229 | LPFC_MBOXQ_t *mboxq; |
| 7230 | uint32_t length; |
| 7231 | |
| 7232 | /* Check for dual-ULP support */ |
| 7233 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7234 | if (!mboxq) { |
| 7235 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7236 | "3249 Unable to allocate memory for " |
| 7237 | "QUERY_FW_CFG mailbox command\n"); |
| 7238 | return -ENOMEM; |
| 7239 | } |
| 7240 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 7241 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7242 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7243 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 7244 | length, LPFC_SLI4_MBX_EMBED); |
| 7245 | |
| 7246 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7247 | |
| 7248 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7249 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7250 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7252 | if (shdr_status || shdr_add_status || rc) { |
| 7253 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7254 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 7255 | "x%x add_status x%x, mbx status x%x\n", |
| 7256 | shdr_status, shdr_add_status, rc); |
| 7257 | if (rc != MBX_TIMEOUT) |
| 7258 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7259 | rc = -ENXIO; |
| 7260 | goto out_error; |
| 7261 | } |
| 7262 | |
| 7263 | phba->sli4_hba.fw_func_mode = |
| 7264 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 7265 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 7266 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; |
| 7267 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7268 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 7269 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 7270 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 7271 | |
| 7272 | if (rc != MBX_TIMEOUT) |
| 7273 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7274 | |
| 7275 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7276 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7277 | */ |
| 7278 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7279 | /* Set up HBA event queue */ |
| 7280 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7282 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7283 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7284 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7285 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7286 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 7287 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7288 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7289 | "0522 Fast-path EQ (%d) not " |
| 7290 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7291 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7292 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7293 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7294 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 7295 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7296 | if (rc) { |
| 7297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7298 | "0523 Failed setup of fast-path EQ " |
| 7299 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7300 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7301 | } |
| 7302 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7303 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7304 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7305 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7306 | } |
| 7307 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7308 | /* Set up fast-path FCP Response Complete Queue */ |
| 7309 | if (!phba->sli4_hba.fcp_cq) { |
| 7310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7311 | "3148 Fast-path FCP CQ array not " |
| 7312 | "allocated\n"); |
| 7313 | rc = -ENOMEM; |
| 7314 | goto out_destroy_hba_eq; |
| 7315 | } |
| 7316 | |
| 7317 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 7318 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 7319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7320 | "0526 Fast-path FCP CQ (%d) not " |
| 7321 | "allocated\n", fcp_cqidx); |
| 7322 | rc = -ENOMEM; |
| 7323 | goto out_destroy_fcp_cq; |
| 7324 | } |
| 7325 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 7326 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 7327 | if (rc) { |
| 7328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7329 | "0527 Failed setup of fast-path FCP " |
| 7330 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 7331 | goto out_destroy_fcp_cq; |
| 7332 | } |
| 7333 | |
| 7334 | /* Setup fcp_cq_map for fast lookup */ |
| 7335 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 7336 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7337 | |
| 7338 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7339 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7340 | "parent seq[%d]-id=%d\n", |
| 7341 | fcp_cqidx, |
| 7342 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7343 | fcp_cqidx, |
| 7344 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7345 | } |
| 7346 | |
| 7347 | /* Set up fast-path FCP Work Queue */ |
| 7348 | if (!phba->sli4_hba.fcp_wq) { |
| 7349 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7350 | "3149 Fast-path FCP WQ array not " |
| 7351 | "allocated\n"); |
| 7352 | rc = -ENOMEM; |
| 7353 | goto out_destroy_fcp_cq; |
| 7354 | } |
| 7355 | |
| 7356 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7357 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7359 | "0534 Fast-path FCP WQ (%d) not " |
| 7360 | "allocated\n", fcp_wqidx); |
| 7361 | rc = -ENOMEM; |
| 7362 | goto out_destroy_fcp_wq; |
| 7363 | } |
| 7364 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7365 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7366 | LPFC_FCP); |
| 7367 | if (rc) { |
| 7368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7369 | "0535 Failed setup of fast-path FCP " |
| 7370 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 7371 | goto out_destroy_fcp_wq; |
| 7372 | } |
| 7373 | |
| 7374 | /* Bind this WQ to the next FCP ring */ |
| 7375 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7376 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7377 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7378 | |
| 7379 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7380 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7381 | "parent cq[%d]-id=%d\n", |
| 7382 | fcp_wqidx, |
| 7383 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7384 | fcp_cq_index, |
| 7385 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7386 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7387 | /* |
| 7388 | * Set up Complete Queues (CQs) |
| 7389 | */ |
| 7390 | |
| 7391 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7392 | if (!phba->sli4_hba.mbx_cq) { |
| 7393 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7394 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7395 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7396 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7397 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7398 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7399 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7400 | if (rc) { |
| 7401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7402 | "0529 Failed setup of slow-path mailbox CQ: " |
| 7403 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7404 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7405 | } |
| 7406 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7407 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7408 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7409 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7410 | |
| 7411 | /* Set up slow-path ELS Complete Queue */ |
| 7412 | if (!phba->sli4_hba.els_cq) { |
| 7413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7414 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7415 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7416 | goto out_destroy_mbx_cq; |
| 7417 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7418 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7419 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7420 | if (rc) { |
| 7421 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7422 | "0531 Failed setup of slow-path ELS CQ: " |
| 7423 | "rc = 0x%x\n", rc); |
| 7424 | goto out_destroy_mbx_cq; |
| 7425 | } |
| 7426 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7427 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7428 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7429 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7430 | |
| 7431 | /* |
| 7432 | * Set up all the Work Queues (WQs) |
| 7433 | */ |
| 7434 | |
| 7435 | /* Set up Mailbox Command Queue */ |
| 7436 | if (!phba->sli4_hba.mbx_wq) { |
| 7437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7438 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7439 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7440 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7441 | } |
| 7442 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7443 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7444 | if (rc) { |
| 7445 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7446 | "0539 Failed setup of slow-path MQ: " |
| 7447 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7448 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7449 | } |
| 7450 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7451 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7452 | phba->sli4_hba.mbx_wq->queue_id, |
| 7453 | phba->sli4_hba.mbx_cq->queue_id); |
| 7454 | |
| 7455 | /* Set up slow-path ELS Work Queue */ |
| 7456 | if (!phba->sli4_hba.els_wq) { |
| 7457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7458 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7459 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7460 | goto out_destroy_mbx_wq; |
| 7461 | } |
| 7462 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7463 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7464 | if (rc) { |
| 7465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7466 | "0537 Failed setup of slow-path ELS WQ: " |
| 7467 | "rc = 0x%x\n", rc); |
| 7468 | goto out_destroy_mbx_wq; |
| 7469 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7470 | |
| 7471 | /* Bind this WQ to the ELS ring */ |
| 7472 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7473 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7474 | phba->sli4_hba.els_cq->pring = pring; |
| 7475 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7476 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7477 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7478 | phba->sli4_hba.els_wq->queue_id, |
| 7479 | phba->sli4_hba.els_cq->queue_id); |
| 7480 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7481 | /* |
| 7482 | * Create Receive Queue (RQ) |
| 7483 | */ |
| 7484 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7486 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7487 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7488 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7489 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7490 | |
| 7491 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7492 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7493 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7494 | 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] | 7495 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7496 | if (rc) { |
| 7497 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7498 | "0541 Failed setup of Receive Queue: " |
| 7499 | "rc = 0x%x\n", rc); |
| 7500 | goto out_destroy_fcp_wq; |
| 7501 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7502 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7503 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7504 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7505 | "parent cq-id=%d\n", |
| 7506 | phba->sli4_hba.hdr_rq->queue_id, |
| 7507 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7508 | phba->sli4_hba.els_cq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7509 | return 0; |
| 7510 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7511 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7512 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7513 | out_destroy_mbx_wq: |
| 7514 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7515 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7516 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7517 | out_destroy_mbx_cq: |
| 7518 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7519 | out_destroy_fcp_wq: |
| 7520 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7521 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7522 | out_destroy_fcp_cq: |
| 7523 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7524 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7525 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7526 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7527 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7528 | out_error: |
| 7529 | return rc; |
| 7530 | } |
| 7531 | |
| 7532 | /** |
| 7533 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7534 | * @phba: pointer to lpfc hba data structure. |
| 7535 | * |
| 7536 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7537 | * operation. |
| 7538 | * |
| 7539 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7540 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7541 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7542 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7543 | **/ |
| 7544 | void |
| 7545 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7546 | { |
| 7547 | int fcp_qidx; |
| 7548 | |
| 7549 | /* Unset mailbox command work queue */ |
| 7550 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7551 | /* Unset ELS work queue */ |
| 7552 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7553 | /* Unset unsolicited receive queue */ |
| 7554 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7555 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7556 | if (phba->sli4_hba.fcp_wq) { |
| 7557 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7558 | fcp_qidx++) |
| 7559 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7560 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7561 | /* Unset mailbox command complete queue */ |
| 7562 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7563 | /* Unset ELS complete queue */ |
| 7564 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7565 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7566 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7567 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7568 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7569 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7570 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7571 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7572 | if (phba->sli4_hba.hba_eq) { |
| 7573 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7574 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7575 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7576 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
| 7580 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7581 | * @phba: pointer to lpfc hba data structure. |
| 7582 | * |
| 7583 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7584 | * events. The body of the completion queue event is a completion queue entry |
| 7585 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7586 | * the following HBA completion queue events for the worker thread to process: |
| 7587 | * - Mailbox asynchronous events |
| 7588 | * - Receive queue completion unsolicited events |
| 7589 | * Later, this can be used for all the slow-path events. |
| 7590 | * |
| 7591 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7592 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7593 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7594 | **/ |
| 7595 | static int |
| 7596 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7597 | { |
| 7598 | struct lpfc_cq_event *cq_event; |
| 7599 | int i; |
| 7600 | |
| 7601 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7602 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7603 | if (!cq_event) |
| 7604 | goto out_pool_create_fail; |
| 7605 | list_add_tail(&cq_event->list, |
| 7606 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7607 | } |
| 7608 | return 0; |
| 7609 | |
| 7610 | out_pool_create_fail: |
| 7611 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7612 | return -ENOMEM; |
| 7613 | } |
| 7614 | |
| 7615 | /** |
| 7616 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7617 | * @phba: pointer to lpfc hba data structure. |
| 7618 | * |
| 7619 | * This routine is invoked to free the pool of completion queue events at |
| 7620 | * driver unload time. Note that, it is the responsibility of the driver |
| 7621 | * cleanup routine to free all the outstanding completion-queue events |
| 7622 | * allocated from this pool back into the pool before invoking this routine |
| 7623 | * to destroy the pool. |
| 7624 | **/ |
| 7625 | static void |
| 7626 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7627 | { |
| 7628 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7629 | |
| 7630 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7631 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7632 | list_del(&cq_event->list); |
| 7633 | kfree(cq_event); |
| 7634 | } |
| 7635 | } |
| 7636 | |
| 7637 | /** |
| 7638 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7639 | * @phba: pointer to lpfc hba data structure. |
| 7640 | * |
| 7641 | * This routine is the lock free version of the API invoked to allocate a |
| 7642 | * completion-queue event from the free pool. |
| 7643 | * |
| 7644 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7645 | * NULL otherwise. |
| 7646 | **/ |
| 7647 | struct lpfc_cq_event * |
| 7648 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7649 | { |
| 7650 | struct lpfc_cq_event *cq_event = NULL; |
| 7651 | |
| 7652 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7653 | struct lpfc_cq_event, list); |
| 7654 | return cq_event; |
| 7655 | } |
| 7656 | |
| 7657 | /** |
| 7658 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7659 | * @phba: pointer to lpfc hba data structure. |
| 7660 | * |
| 7661 | * This routine is the lock version of the API invoked to allocate a |
| 7662 | * completion-queue event from the free pool. |
| 7663 | * |
| 7664 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7665 | * NULL otherwise. |
| 7666 | **/ |
| 7667 | struct lpfc_cq_event * |
| 7668 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7669 | { |
| 7670 | struct lpfc_cq_event *cq_event; |
| 7671 | unsigned long iflags; |
| 7672 | |
| 7673 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7674 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7675 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7676 | return cq_event; |
| 7677 | } |
| 7678 | |
| 7679 | /** |
| 7680 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7681 | * @phba: pointer to lpfc hba data structure. |
| 7682 | * @cq_event: pointer to the completion queue event to be freed. |
| 7683 | * |
| 7684 | * This routine is the lock free version of the API invoked to release a |
| 7685 | * completion-queue event back into the free pool. |
| 7686 | **/ |
| 7687 | void |
| 7688 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7689 | struct lpfc_cq_event *cq_event) |
| 7690 | { |
| 7691 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7692 | } |
| 7693 | |
| 7694 | /** |
| 7695 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7696 | * @phba: pointer to lpfc hba data structure. |
| 7697 | * @cq_event: pointer to the completion queue event to be freed. |
| 7698 | * |
| 7699 | * This routine is the lock version of the API invoked to release a |
| 7700 | * completion-queue event back into the free pool. |
| 7701 | **/ |
| 7702 | void |
| 7703 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7704 | struct lpfc_cq_event *cq_event) |
| 7705 | { |
| 7706 | unsigned long iflags; |
| 7707 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7708 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7709 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7710 | } |
| 7711 | |
| 7712 | /** |
| 7713 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7714 | * @phba: pointer to lpfc hba data structure. |
| 7715 | * |
| 7716 | * This routine is to free all the pending completion-queue events to the |
| 7717 | * back into the free pool for device reset. |
| 7718 | **/ |
| 7719 | static void |
| 7720 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7721 | { |
| 7722 | LIST_HEAD(cqelist); |
| 7723 | struct lpfc_cq_event *cqe; |
| 7724 | unsigned long iflags; |
| 7725 | |
| 7726 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7727 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7728 | /* Pending FCP XRI abort events */ |
| 7729 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7730 | &cqelist); |
| 7731 | /* Pending ELS XRI abort events */ |
| 7732 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7733 | &cqelist); |
| 7734 | /* Pending asynnc events */ |
| 7735 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7736 | &cqelist); |
| 7737 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7738 | |
| 7739 | while (!list_empty(&cqelist)) { |
| 7740 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7741 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7742 | } |
| 7743 | } |
| 7744 | |
| 7745 | /** |
| 7746 | * lpfc_pci_function_reset - Reset pci function. |
| 7747 | * @phba: pointer to lpfc hba data structure. |
| 7748 | * |
| 7749 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7750 | * all resources assigned to the PCI function which originates this request. |
| 7751 | * |
| 7752 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7753 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7754 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7755 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7756 | **/ |
| 7757 | int |
| 7758 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7759 | { |
| 7760 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7761 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7762 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7763 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7764 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7765 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7766 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7767 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7768 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7769 | switch (if_type) { |
| 7770 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7771 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7772 | GFP_KERNEL); |
| 7773 | if (!mboxq) { |
| 7774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7775 | "0494 Unable to allocate memory for " |
| 7776 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7777 | "command\n"); |
| 7778 | return -ENOMEM; |
| 7779 | } |
| 7780 | |
| 7781 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7782 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7783 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7784 | LPFC_SLI4_MBX_EMBED); |
| 7785 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7786 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7787 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7788 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7789 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7790 | &shdr->response); |
| 7791 | if (rc != MBX_TIMEOUT) |
| 7792 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7793 | if (shdr_status || shdr_add_status || rc) { |
| 7794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7795 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7796 | "failed with status x%x add_status x%x," |
| 7797 | " mbx status x%x\n", |
| 7798 | shdr_status, shdr_add_status, rc); |
| 7799 | rc = -ENXIO; |
| 7800 | } |
| 7801 | break; |
| 7802 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7803 | for (num_resets = 0; |
| 7804 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7805 | num_resets++) { |
| 7806 | reg_data.word0 = 0; |
| 7807 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7808 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7809 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7810 | LPFC_SLIPORT_INIT_PORT); |
| 7811 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7812 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7813 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7814 | pci_read_config_word(phba->pcidev, |
| 7815 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7816 | /* |
| 7817 | * Poll the Port Status Register and wait for RDY for |
| 7818 | * up to 10 seconds. If the port doesn't respond, treat |
| 7819 | * it as an error. If the port responds with RN, start |
| 7820 | * the loop again. |
| 7821 | */ |
| 7822 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7823 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7824 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7825 | STATUSregaddr, ®_data.word0)) { |
| 7826 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7827 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7828 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7829 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7830 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7831 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7832 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | /* |
| 7836 | * If the port responds to the init request with |
| 7837 | * reset needed, delay for a bit and restart the loop. |
| 7838 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7839 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7840 | msleep(10); |
| 7841 | reset_again = 0; |
| 7842 | continue; |
| 7843 | } |
| 7844 | |
| 7845 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7846 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7847 | (rdy_chk >= 1000)) { |
| 7848 | phba->work_status[0] = readl( |
| 7849 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7850 | phba->work_status[1] = readl( |
| 7851 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7852 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7853 | "2890 Port error detected during port " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7854 | "reset(%d): wait_tmo:%d ms, " |
| 7855 | "port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7856 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7857 | num_resets, rdy_chk*10, |
| 7858 | reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7859 | phba->work_status[0], |
| 7860 | phba->work_status[1]); |
| 7861 | rc = -ENODEV; |
| 7862 | } |
| 7863 | |
| 7864 | /* |
| 7865 | * Terminate the outer loop provided the Port indicated |
| 7866 | * ready within 10 seconds. |
| 7867 | */ |
| 7868 | if (rdy_chk < 1000) |
| 7869 | break; |
| 7870 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7871 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7872 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7873 | break; |
| 7874 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7875 | default: |
| 7876 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7877 | } |
| 7878 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7879 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7880 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7881 | if (num_resets >= MAX_IF_TYPE_2_RESETS) { |
| 7882 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7883 | "3317 HBA not functional: IP Reset Failed " |
| 7884 | "after (%d) retries, try: " |
| 7885 | "echo fw_reset > board_mode\n", num_resets); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7886 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7887 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7888 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7889 | return rc; |
| 7890 | } |
| 7891 | |
| 7892 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7893 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7894 | * @phba: pointer to lpfc hba data structure. |
| 7895 | * |
| 7896 | * This routine is invoked to set up the PCI device memory space for device |
| 7897 | * with SLI-4 interface spec. |
| 7898 | * |
| 7899 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7900 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7901 | * other values - error |
| 7902 | **/ |
| 7903 | static int |
| 7904 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7905 | { |
| 7906 | struct pci_dev *pdev; |
| 7907 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7908 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7909 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7910 | |
| 7911 | /* Obtain PCI device reference */ |
| 7912 | if (!phba->pcidev) |
| 7913 | return error; |
| 7914 | else |
| 7915 | pdev = phba->pcidev; |
| 7916 | |
| 7917 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7918 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7919 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7920 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7921 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7922 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7923 | } |
| 7924 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7925 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7926 | /* |
| 7927 | * The BARs and register set definitions and offset locations are |
| 7928 | * dependent on the if_type. |
| 7929 | */ |
| 7930 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 7931 | &phba->sli4_hba.sli_intf.word0)) { |
| 7932 | return error; |
| 7933 | } |
| 7934 | |
| 7935 | /* There is no SLI3 failback for SLI4 devices. */ |
| 7936 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 7937 | LPFC_SLI_INTF_VALID) { |
| 7938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7939 | "2894 SLI_INTF reg contents invalid " |
| 7940 | "sli_intf reg 0x%x\n", |
| 7941 | phba->sli4_hba.sli_intf.word0); |
| 7942 | return error; |
| 7943 | } |
| 7944 | |
| 7945 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7946 | /* |
| 7947 | * Get the bus address of SLI4 device Bar regions and the |
| 7948 | * number of bytes required by each mapping. The mapping of the |
| 7949 | * particular PCI BARs regions is dependent on the type of |
| 7950 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7951 | */ |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7952 | if (pci_resource_start(pdev, 0)) { |
| 7953 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7954 | bar0map_len = pci_resource_len(pdev, 0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7955 | |
| 7956 | /* |
| 7957 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 7958 | * addr |
| 7959 | */ |
| 7960 | phba->sli4_hba.conf_regs_memmap_p = |
| 7961 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 7962 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7963 | dev_printk(KERN_ERR, &pdev->dev, |
| 7964 | "ioremap failed for SLI4 PCI config " |
| 7965 | "registers.\n"); |
| 7966 | goto out; |
| 7967 | } |
| 7968 | /* Set up BAR0 PCI config space register memory map */ |
| 7969 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7970 | } else { |
| 7971 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 7972 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7973 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7974 | dev_printk(KERN_ERR, &pdev->dev, |
| 7975 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 7976 | goto out; |
| 7977 | } |
| 7978 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7979 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7980 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7981 | dev_printk(KERN_ERR, &pdev->dev, |
| 7982 | "ioremap failed for SLI4 PCI config " |
| 7983 | "registers.\n"); |
| 7984 | goto out; |
| 7985 | } |
| 7986 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7987 | } |
| 7988 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7989 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7990 | (pci_resource_start(pdev, 2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7991 | /* |
| 7992 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 7993 | * virtual address and setup the registers. |
| 7994 | */ |
| 7995 | phba->pci_bar1_map = pci_resource_start(pdev, 2); |
| 7996 | bar1map_len = pci_resource_len(pdev, 2); |
| 7997 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7998 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7999 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 8000 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8001 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8002 | goto out_iounmap_conf; |
| 8003 | } |
| 8004 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8005 | } |
| 8006 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8007 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 8008 | (pci_resource_start(pdev, 4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8009 | /* |
| 8010 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 8011 | * virtual address and setup the registers. |
| 8012 | */ |
| 8013 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
| 8014 | bar2map_len = pci_resource_len(pdev, 4); |
| 8015 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8016 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8017 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 8018 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8019 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8020 | goto out_iounmap_ctrl; |
| 8021 | } |
| 8022 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 8023 | if (error) |
| 8024 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8025 | } |
| 8026 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8027 | return 0; |
| 8028 | |
| 8029 | out_iounmap_all: |
| 8030 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8031 | out_iounmap_ctrl: |
| 8032 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8033 | out_iounmap_conf: |
| 8034 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8035 | out: |
| 8036 | return error; |
| 8037 | } |
| 8038 | |
| 8039 | /** |
| 8040 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 8041 | * @phba: pointer to lpfc hba data structure. |
| 8042 | * |
| 8043 | * This routine is invoked to unset the PCI device memory space for device |
| 8044 | * with SLI-4 interface spec. |
| 8045 | **/ |
| 8046 | static void |
| 8047 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 8048 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8049 | uint32_t if_type; |
| 8050 | 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] | 8051 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8052 | switch (if_type) { |
| 8053 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8054 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8055 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8056 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8057 | break; |
| 8058 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8059 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8060 | break; |
| 8061 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8062 | default: |
| 8063 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8064 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8065 | if_type); |
| 8066 | break; |
| 8067 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8068 | } |
| 8069 | |
| 8070 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8071 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 8072 | * @phba: pointer to lpfc hba data structure. |
| 8073 | * |
| 8074 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8075 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 8076 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 8077 | * invoked, enables either all or nothing, depending on the current |
| 8078 | * availability of PCI vector resources. The device driver is responsible |
| 8079 | * for calling the individual request_irq() to register each MSI-X vector |
| 8080 | * with a interrupt handler, which is done in this function. Note that |
| 8081 | * later when device is unloading, the driver should always call free_irq() |
| 8082 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8083 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8084 | * will be left with MSI-X enabled and leaks its vectors. |
| 8085 | * |
| 8086 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8087 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8088 | * other values - error |
| 8089 | **/ |
| 8090 | static int |
| 8091 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 8092 | { |
| 8093 | int rc, i; |
| 8094 | LPFC_MBOXQ_t *pmb; |
| 8095 | |
| 8096 | /* Set up MSI-X multi-message vectors */ |
| 8097 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8098 | phba->msix_entries[i].entry = i; |
| 8099 | |
| 8100 | /* Configure MSI-X capability structure */ |
| 8101 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 8102 | ARRAY_SIZE(phba->msix_entries)); |
| 8103 | if (rc) { |
| 8104 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8105 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 8106 | goto msi_fail_out; |
| 8107 | } |
| 8108 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8109 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8110 | "0477 MSI-X entry[%d]: vector=x%x " |
| 8111 | "message=%d\n", i, |
| 8112 | phba->msix_entries[i].vector, |
| 8113 | phba->msix_entries[i].entry); |
| 8114 | /* |
| 8115 | * Assign MSI-X vectors to interrupt handlers |
| 8116 | */ |
| 8117 | |
| 8118 | /* vector-0 is associated to slow-path handler */ |
| 8119 | rc = request_irq(phba->msix_entries[0].vector, |
| 8120 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 8121 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 8122 | if (rc) { |
| 8123 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8124 | "0421 MSI-X slow-path request_irq failed " |
| 8125 | "(%d)\n", rc); |
| 8126 | goto msi_fail_out; |
| 8127 | } |
| 8128 | |
| 8129 | /* vector-1 is associated to fast-path handler */ |
| 8130 | rc = request_irq(phba->msix_entries[1].vector, |
| 8131 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 8132 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 8133 | |
| 8134 | if (rc) { |
| 8135 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8136 | "0429 MSI-X fast-path request_irq failed " |
| 8137 | "(%d)\n", rc); |
| 8138 | goto irq_fail_out; |
| 8139 | } |
| 8140 | |
| 8141 | /* |
| 8142 | * Configure HBA MSI-X attention conditions to messages |
| 8143 | */ |
| 8144 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8145 | |
| 8146 | if (!pmb) { |
| 8147 | rc = -ENOMEM; |
| 8148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8149 | "0474 Unable to allocate memory for issuing " |
| 8150 | "MBOX_CONFIG_MSI command\n"); |
| 8151 | goto mem_fail_out; |
| 8152 | } |
| 8153 | rc = lpfc_config_msi(phba, pmb); |
| 8154 | if (rc) |
| 8155 | goto mbx_fail_out; |
| 8156 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8157 | if (rc != MBX_SUCCESS) { |
| 8158 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 8159 | "0351 Config MSI mailbox command failed, " |
| 8160 | "mbxCmd x%x, mbxStatus x%x\n", |
| 8161 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 8162 | goto mbx_fail_out; |
| 8163 | } |
| 8164 | |
| 8165 | /* Free memory allocated for mailbox command */ |
| 8166 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8167 | return rc; |
| 8168 | |
| 8169 | mbx_fail_out: |
| 8170 | /* Free memory allocated for mailbox command */ |
| 8171 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8172 | |
| 8173 | mem_fail_out: |
| 8174 | /* free the irq already requested */ |
| 8175 | free_irq(phba->msix_entries[1].vector, phba); |
| 8176 | |
| 8177 | irq_fail_out: |
| 8178 | /* free the irq already requested */ |
| 8179 | free_irq(phba->msix_entries[0].vector, phba); |
| 8180 | |
| 8181 | msi_fail_out: |
| 8182 | /* Unconfigure MSI-X capability structure */ |
| 8183 | pci_disable_msix(phba->pcidev); |
| 8184 | return rc; |
| 8185 | } |
| 8186 | |
| 8187 | /** |
| 8188 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 8189 | * @phba: pointer to lpfc hba data structure. |
| 8190 | * |
| 8191 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8192 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 8193 | **/ |
| 8194 | static void |
| 8195 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 8196 | { |
| 8197 | int i; |
| 8198 | |
| 8199 | /* Free up MSI-X multi-message vectors */ |
| 8200 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8201 | free_irq(phba->msix_entries[i].vector, phba); |
| 8202 | /* Disable MSI-X */ |
| 8203 | pci_disable_msix(phba->pcidev); |
| 8204 | |
| 8205 | return; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
| 8209 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 8210 | * @phba: pointer to lpfc hba data structure. |
| 8211 | * |
| 8212 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8213 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 8214 | * enable the MSI vector. The device driver is responsible for calling the |
| 8215 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 8216 | * is done in this function. |
| 8217 | * |
| 8218 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8219 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8220 | * other values - error |
| 8221 | */ |
| 8222 | static int |
| 8223 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 8224 | { |
| 8225 | int rc; |
| 8226 | |
| 8227 | rc = pci_enable_msi(phba->pcidev); |
| 8228 | if (!rc) |
| 8229 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8230 | "0462 PCI enable MSI mode success.\n"); |
| 8231 | else { |
| 8232 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8233 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 8234 | return rc; |
| 8235 | } |
| 8236 | |
| 8237 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8238 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8239 | if (rc) { |
| 8240 | pci_disable_msi(phba->pcidev); |
| 8241 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8242 | "0478 MSI request_irq failed (%d)\n", rc); |
| 8243 | } |
| 8244 | return rc; |
| 8245 | } |
| 8246 | |
| 8247 | /** |
| 8248 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 8249 | * @phba: pointer to lpfc hba data structure. |
| 8250 | * |
| 8251 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8252 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 8253 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8254 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8255 | * its vector. |
| 8256 | */ |
| 8257 | static void |
| 8258 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 8259 | { |
| 8260 | free_irq(phba->pcidev->irq, phba); |
| 8261 | pci_disable_msi(phba->pcidev); |
| 8262 | return; |
| 8263 | } |
| 8264 | |
| 8265 | /** |
| 8266 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 8267 | * @phba: pointer to lpfc hba data structure. |
| 8268 | * |
| 8269 | * This routine is invoked to enable device interrupt and associate driver's |
| 8270 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8271 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8272 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8273 | * mode which is supported by the platform, kernel, and device in the order |
| 8274 | * of: |
| 8275 | * MSI-X -> MSI -> IRQ. |
| 8276 | * |
| 8277 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8278 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8279 | * other values - error |
| 8280 | **/ |
| 8281 | static uint32_t |
| 8282 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8283 | { |
| 8284 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8285 | int retval; |
| 8286 | |
| 8287 | if (cfg_mode == 2) { |
| 8288 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8289 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8290 | if (!retval) { |
| 8291 | /* Now, try to enable MSI-X interrupt mode */ |
| 8292 | retval = lpfc_sli_enable_msix(phba); |
| 8293 | if (!retval) { |
| 8294 | /* Indicate initialization to MSI-X mode */ |
| 8295 | phba->intr_type = MSIX; |
| 8296 | intr_mode = 2; |
| 8297 | } |
| 8298 | } |
| 8299 | } |
| 8300 | |
| 8301 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8302 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8303 | retval = lpfc_sli_enable_msi(phba); |
| 8304 | if (!retval) { |
| 8305 | /* Indicate initialization to MSI mode */ |
| 8306 | phba->intr_type = MSI; |
| 8307 | intr_mode = 1; |
| 8308 | } |
| 8309 | } |
| 8310 | |
| 8311 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8312 | if (phba->intr_type == NONE) { |
| 8313 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8314 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8315 | if (!retval) { |
| 8316 | /* Indicate initialization to INTx mode */ |
| 8317 | phba->intr_type = INTx; |
| 8318 | intr_mode = 0; |
| 8319 | } |
| 8320 | } |
| 8321 | return intr_mode; |
| 8322 | } |
| 8323 | |
| 8324 | /** |
| 8325 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8326 | * @phba: pointer to lpfc hba data structure. |
| 8327 | * |
| 8328 | * This routine is invoked to disable device interrupt and disassociate the |
| 8329 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8330 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8331 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8332 | **/ |
| 8333 | static void |
| 8334 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8335 | { |
| 8336 | /* Disable the currently initialized interrupt mode */ |
| 8337 | if (phba->intr_type == MSIX) |
| 8338 | lpfc_sli_disable_msix(phba); |
| 8339 | else if (phba->intr_type == MSI) |
| 8340 | lpfc_sli_disable_msi(phba); |
| 8341 | else if (phba->intr_type == INTx) |
| 8342 | free_irq(phba->pcidev->irq, phba); |
| 8343 | |
| 8344 | /* Reset interrupt management states */ |
| 8345 | phba->intr_type = NONE; |
| 8346 | phba->sli.slistat.sli_intr = 0; |
| 8347 | |
| 8348 | return; |
| 8349 | } |
| 8350 | |
| 8351 | /** |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8352 | * lpfc_find_next_cpu - Find next available CPU that matches the phys_id |
| 8353 | * @phba: pointer to lpfc hba data structure. |
| 8354 | * |
| 8355 | * Find next available CPU to use for IRQ to CPU affinity. |
| 8356 | */ |
| 8357 | static int |
| 8358 | lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id) |
| 8359 | { |
| 8360 | struct lpfc_vector_map_info *cpup; |
| 8361 | int cpu; |
| 8362 | |
| 8363 | cpup = phba->sli4_hba.cpu_map; |
| 8364 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8365 | /* CPU must be online */ |
| 8366 | if (cpu_online(cpu)) { |
| 8367 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8368 | (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) && |
| 8369 | (cpup->phys_id == phys_id)) { |
| 8370 | return cpu; |
| 8371 | } |
| 8372 | } |
| 8373 | cpup++; |
| 8374 | } |
| 8375 | |
| 8376 | /* |
| 8377 | * If we get here, we have used ALL CPUs for the specific |
| 8378 | * phys_id. Now we need to clear out lpfc_used_cpu and start |
| 8379 | * reusing CPUs. |
| 8380 | */ |
| 8381 | |
| 8382 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8383 | if (lpfc_used_cpu[cpu] == phys_id) |
| 8384 | lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY; |
| 8385 | } |
| 8386 | |
| 8387 | cpup = phba->sli4_hba.cpu_map; |
| 8388 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8389 | /* CPU must be online */ |
| 8390 | if (cpu_online(cpu)) { |
| 8391 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && |
| 8392 | (cpup->phys_id == phys_id)) { |
| 8393 | return cpu; |
| 8394 | } |
| 8395 | } |
| 8396 | cpup++; |
| 8397 | } |
| 8398 | return LPFC_VECTOR_MAP_EMPTY; |
| 8399 | } |
| 8400 | |
| 8401 | /** |
| 8402 | * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors |
| 8403 | * @phba: pointer to lpfc hba data structure. |
| 8404 | * @vectors: number of HBA vectors |
| 8405 | * |
| 8406 | * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector |
| 8407 | * affinization across multple physical CPUs (numa nodes). |
| 8408 | * In addition, this routine will assign an IO channel for each CPU |
| 8409 | * to use when issuing I/Os. |
| 8410 | */ |
| 8411 | static int |
| 8412 | lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors) |
| 8413 | { |
| 8414 | int i, idx, saved_chann, used_chann, cpu, phys_id; |
| 8415 | int max_phys_id, num_io_channel, first_cpu; |
| 8416 | struct lpfc_vector_map_info *cpup; |
| 8417 | #ifdef CONFIG_X86 |
| 8418 | struct cpuinfo_x86 *cpuinfo; |
| 8419 | #endif |
| 8420 | struct cpumask *mask; |
| 8421 | uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1]; |
| 8422 | |
| 8423 | /* If there is no mapping, just return */ |
| 8424 | if (!phba->cfg_fcp_cpu_map) |
| 8425 | return 1; |
| 8426 | |
| 8427 | /* Init cpu_map array */ |
| 8428 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 8429 | (sizeof(struct lpfc_vector_map_info) * |
| 8430 | phba->sli4_hba.num_present_cpu)); |
| 8431 | |
| 8432 | max_phys_id = 0; |
| 8433 | phys_id = 0; |
| 8434 | num_io_channel = 0; |
| 8435 | first_cpu = LPFC_VECTOR_MAP_EMPTY; |
| 8436 | |
| 8437 | /* Update CPU map with physical id and core id of each CPU */ |
| 8438 | cpup = phba->sli4_hba.cpu_map; |
| 8439 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 8440 | #ifdef CONFIG_X86 |
| 8441 | cpuinfo = &cpu_data(cpu); |
| 8442 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 8443 | cpup->core_id = cpuinfo->cpu_core_id; |
| 8444 | #else |
| 8445 | /* No distinction between CPUs for other platforms */ |
| 8446 | cpup->phys_id = 0; |
| 8447 | cpup->core_id = 0; |
| 8448 | #endif |
| 8449 | |
| 8450 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8451 | "3328 CPU physid %d coreid %d\n", |
| 8452 | cpup->phys_id, cpup->core_id); |
| 8453 | |
| 8454 | if (cpup->phys_id > max_phys_id) |
| 8455 | max_phys_id = cpup->phys_id; |
| 8456 | cpup++; |
| 8457 | } |
| 8458 | |
| 8459 | /* Now associate the HBA vectors with specific CPUs */ |
| 8460 | for (idx = 0; idx < vectors; idx++) { |
| 8461 | cpup = phba->sli4_hba.cpu_map; |
| 8462 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8463 | if (cpu == LPFC_VECTOR_MAP_EMPTY) { |
| 8464 | |
| 8465 | /* Try for all phys_id's */ |
| 8466 | for (i = 1; i < max_phys_id; i++) { |
| 8467 | phys_id++; |
| 8468 | if (phys_id > max_phys_id) |
| 8469 | phys_id = 0; |
| 8470 | cpu = lpfc_find_next_cpu(phba, phys_id); |
| 8471 | if (cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8472 | continue; |
| 8473 | goto found; |
| 8474 | } |
| 8475 | |
| 8476 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8477 | "3329 Cannot set affinity:" |
| 8478 | "Error mapping vector %d (%d)\n", |
| 8479 | idx, vectors); |
| 8480 | return 0; |
| 8481 | } |
| 8482 | found: |
| 8483 | cpup += cpu; |
| 8484 | if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP) |
| 8485 | lpfc_used_cpu[cpu] = phys_id; |
| 8486 | |
| 8487 | /* Associate vector with selected CPU */ |
| 8488 | cpup->irq = phba->sli4_hba.msix_entries[idx].vector; |
| 8489 | |
| 8490 | /* Associate IO channel with selected CPU */ |
| 8491 | cpup->channel_id = idx; |
| 8492 | num_io_channel++; |
| 8493 | |
| 8494 | if (first_cpu == LPFC_VECTOR_MAP_EMPTY) |
| 8495 | first_cpu = cpu; |
| 8496 | |
| 8497 | /* Now affinitize to the selected CPU */ |
| 8498 | mask = &cpup->maskbits; |
| 8499 | cpumask_clear(mask); |
| 8500 | cpumask_set_cpu(cpu, mask); |
| 8501 | i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx]. |
| 8502 | vector, mask); |
| 8503 | |
| 8504 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8505 | "3330 Set Affinity: CPU %d channel %d " |
| 8506 | "irq %d (%x)\n", |
| 8507 | cpu, cpup->channel_id, |
| 8508 | phba->sli4_hba.msix_entries[idx].vector, i); |
| 8509 | |
| 8510 | /* Spread vector mapping across multple physical CPU nodes */ |
| 8511 | phys_id++; |
| 8512 | if (phys_id > max_phys_id) |
| 8513 | phys_id = 0; |
| 8514 | } |
| 8515 | |
| 8516 | /* |
| 8517 | * Finally fill in the IO channel for any remaining CPUs. |
| 8518 | * At this point, all IO channels have been assigned to a specific |
| 8519 | * MSIx vector, mapped to a specific CPU. |
| 8520 | * Base the remaining IO channel assigned, to IO channels already |
| 8521 | * assigned to other CPUs on the same phys_id. |
| 8522 | */ |
| 8523 | for (i = 0; i <= max_phys_id; i++) { |
| 8524 | /* |
| 8525 | * If there are no io channels already mapped to |
| 8526 | * this phys_id, just round robin thru the io_channels. |
| 8527 | * Setup chann[] for round robin. |
| 8528 | */ |
| 8529 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8530 | chann[idx] = idx; |
| 8531 | |
| 8532 | saved_chann = 0; |
| 8533 | used_chann = 0; |
| 8534 | |
| 8535 | /* |
| 8536 | * First build a list of IO channels already assigned |
| 8537 | * to this phys_id before reassigning the same IO |
| 8538 | * channels to the remaining CPUs. |
| 8539 | */ |
| 8540 | cpup = phba->sli4_hba.cpu_map; |
| 8541 | cpu = first_cpu; |
| 8542 | cpup += cpu; |
| 8543 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; |
| 8544 | idx++) { |
| 8545 | if (cpup->phys_id == i) { |
| 8546 | /* |
| 8547 | * Save any IO channels that are |
| 8548 | * already mapped to this phys_id. |
| 8549 | */ |
| 8550 | if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) { |
| 8551 | chann[saved_chann] = |
| 8552 | cpup->channel_id; |
| 8553 | saved_chann++; |
| 8554 | goto out; |
| 8555 | } |
| 8556 | |
| 8557 | /* See if we are using round-robin */ |
| 8558 | if (saved_chann == 0) |
| 8559 | saved_chann = |
| 8560 | phba->cfg_fcp_io_channel; |
| 8561 | |
| 8562 | /* Associate next IO channel with CPU */ |
| 8563 | cpup->channel_id = chann[used_chann]; |
| 8564 | num_io_channel++; |
| 8565 | used_chann++; |
| 8566 | if (used_chann == saved_chann) |
| 8567 | used_chann = 0; |
| 8568 | |
| 8569 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8570 | "3331 Set IO_CHANN " |
| 8571 | "CPU %d channel %d\n", |
| 8572 | idx, cpup->channel_id); |
| 8573 | } |
| 8574 | out: |
| 8575 | cpu++; |
| 8576 | if (cpu >= phba->sli4_hba.num_present_cpu) { |
| 8577 | cpup = phba->sli4_hba.cpu_map; |
| 8578 | cpu = 0; |
| 8579 | } else { |
| 8580 | cpup++; |
| 8581 | } |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) { |
| 8586 | cpup = phba->sli4_hba.cpu_map; |
| 8587 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) { |
| 8588 | if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) { |
| 8589 | cpup->channel_id = 0; |
| 8590 | num_io_channel++; |
| 8591 | |
| 8592 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8593 | "3332 Assign IO_CHANN " |
| 8594 | "CPU %d channel %d\n", |
| 8595 | idx, cpup->channel_id); |
| 8596 | } |
| 8597 | cpup++; |
| 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | /* Sanity check */ |
| 8602 | if (num_io_channel != phba->sli4_hba.num_present_cpu) |
| 8603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8604 | "3333 Set affinity mismatch:" |
| 8605 | "%d chann != %d cpus: %d vactors\n", |
| 8606 | num_io_channel, phba->sli4_hba.num_present_cpu, |
| 8607 | vectors); |
| 8608 | |
| 8609 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU; |
| 8610 | return 1; |
| 8611 | } |
| 8612 | |
| 8613 | |
| 8614 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8615 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8616 | * @phba: pointer to lpfc hba data structure. |
| 8617 | * |
| 8618 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8619 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 8620 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 8621 | * enables either all or nothing, depending on the current availability of |
| 8622 | * PCI vector resources. The device driver is responsible for calling the |
| 8623 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 8624 | * handler, which is done in this function. Note that later when device is |
| 8625 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 8626 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 8627 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 8628 | * enabled and leaks its vectors. |
| 8629 | * |
| 8630 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8631 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8632 | * other values - error |
| 8633 | **/ |
| 8634 | static int |
| 8635 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8636 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8637 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8638 | |
| 8639 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8640 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8641 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8642 | |
| 8643 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8644 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8645 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8646 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8647 | vectors); |
| 8648 | if (rc > 1) { |
| 8649 | vectors = rc; |
| 8650 | goto enable_msix_vectors; |
| 8651 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8652 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8653 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 8654 | goto msi_fail_out; |
| 8655 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8656 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8657 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8658 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8659 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8660 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8661 | "message=%d\n", index, |
| 8662 | phba->sli4_hba.msix_entries[index].vector, |
| 8663 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8664 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8665 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8666 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8667 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
| 8668 | sprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8669 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8670 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8671 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8672 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8673 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8674 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8675 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8676 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8677 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8678 | if (rc) { |
| 8679 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8680 | "0486 MSI-X fast-path (%d) " |
| 8681 | "request_irq failed (%d)\n", index, rc); |
| 8682 | goto cfg_fail_out; |
| 8683 | } |
| 8684 | } |
| 8685 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8686 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8688 | "3238 Reducing IO channels to match number of " |
| 8689 | "MSI-X vectors, requested %d got %d\n", |
| 8690 | phba->cfg_fcp_io_channel, vectors); |
| 8691 | phba->cfg_fcp_io_channel = vectors; |
| 8692 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8693 | |
| 8694 | lpfc_sli4_set_affinity(phba, vectors); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8695 | return rc; |
| 8696 | |
| 8697 | cfg_fail_out: |
| 8698 | /* free the irq already requested */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8699 | for (--index; index >= 0; index--) |
| 8700 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8701 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8702 | |
| 8703 | msi_fail_out: |
| 8704 | /* Unconfigure MSI-X capability structure */ |
| 8705 | pci_disable_msix(phba->pcidev); |
| 8706 | return rc; |
| 8707 | } |
| 8708 | |
| 8709 | /** |
| 8710 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 8711 | * @phba: pointer to lpfc hba data structure. |
| 8712 | * |
| 8713 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8714 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 8715 | **/ |
| 8716 | static void |
| 8717 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 8718 | { |
| 8719 | int index; |
| 8720 | |
| 8721 | /* Free up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8722 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8723 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8724 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8725 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8726 | /* Disable MSI-X */ |
| 8727 | pci_disable_msix(phba->pcidev); |
| 8728 | |
| 8729 | return; |
| 8730 | } |
| 8731 | |
| 8732 | /** |
| 8733 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8734 | * @phba: pointer to lpfc hba data structure. |
| 8735 | * |
| 8736 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8737 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8738 | * to enable the MSI vector. The device driver is responsible for calling |
| 8739 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8740 | * which is done in this function. |
| 8741 | * |
| 8742 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8743 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8744 | * other values - error |
| 8745 | **/ |
| 8746 | static int |
| 8747 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8748 | { |
| 8749 | int rc, index; |
| 8750 | |
| 8751 | rc = pci_enable_msi(phba->pcidev); |
| 8752 | if (!rc) |
| 8753 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8754 | "0487 PCI enable MSI mode success.\n"); |
| 8755 | else { |
| 8756 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8757 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8758 | return rc; |
| 8759 | } |
| 8760 | |
| 8761 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8762 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8763 | if (rc) { |
| 8764 | pci_disable_msi(phba->pcidev); |
| 8765 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8766 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8767 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8768 | } |
| 8769 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8770 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8771 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8772 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8773 | } |
| 8774 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8775 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8776 | } |
| 8777 | |
| 8778 | /** |
| 8779 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8780 | * @phba: pointer to lpfc hba data structure. |
| 8781 | * |
| 8782 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8783 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8784 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8785 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8786 | * its vector. |
| 8787 | **/ |
| 8788 | static void |
| 8789 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8790 | { |
| 8791 | free_irq(phba->pcidev->irq, phba); |
| 8792 | pci_disable_msi(phba->pcidev); |
| 8793 | return; |
| 8794 | } |
| 8795 | |
| 8796 | /** |
| 8797 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8798 | * @phba: pointer to lpfc hba data structure. |
| 8799 | * |
| 8800 | * This routine is invoked to enable device interrupt and associate driver's |
| 8801 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8802 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8803 | * the driver will try to fallback from the configured interrupt mode to an |
| 8804 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8805 | * the order of: |
| 8806 | * MSI-X -> MSI -> IRQ. |
| 8807 | * |
| 8808 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8809 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8810 | * other values - error |
| 8811 | **/ |
| 8812 | static uint32_t |
| 8813 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8814 | { |
| 8815 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8816 | int retval, index; |
| 8817 | |
| 8818 | if (cfg_mode == 2) { |
| 8819 | /* Preparation before conf_msi mbox cmd */ |
| 8820 | retval = 0; |
| 8821 | if (!retval) { |
| 8822 | /* Now, try to enable MSI-X interrupt mode */ |
| 8823 | retval = lpfc_sli4_enable_msix(phba); |
| 8824 | if (!retval) { |
| 8825 | /* Indicate initialization to MSI-X mode */ |
| 8826 | phba->intr_type = MSIX; |
| 8827 | intr_mode = 2; |
| 8828 | } |
| 8829 | } |
| 8830 | } |
| 8831 | |
| 8832 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8833 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8834 | retval = lpfc_sli4_enable_msi(phba); |
| 8835 | if (!retval) { |
| 8836 | /* Indicate initialization to MSI mode */ |
| 8837 | phba->intr_type = MSI; |
| 8838 | intr_mode = 1; |
| 8839 | } |
| 8840 | } |
| 8841 | |
| 8842 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8843 | if (phba->intr_type == NONE) { |
| 8844 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8845 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8846 | if (!retval) { |
| 8847 | /* Indicate initialization to INTx mode */ |
| 8848 | phba->intr_type = INTx; |
| 8849 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8850 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8851 | index++) { |
| 8852 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8853 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8854 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8855 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8856 | } |
| 8857 | } |
| 8858 | } |
| 8859 | return intr_mode; |
| 8860 | } |
| 8861 | |
| 8862 | /** |
| 8863 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8864 | * @phba: pointer to lpfc hba data structure. |
| 8865 | * |
| 8866 | * This routine is invoked to disable device interrupt and disassociate |
| 8867 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8868 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8869 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8870 | **/ |
| 8871 | static void |
| 8872 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 8873 | { |
| 8874 | /* Disable the currently initialized interrupt mode */ |
| 8875 | if (phba->intr_type == MSIX) |
| 8876 | lpfc_sli4_disable_msix(phba); |
| 8877 | else if (phba->intr_type == MSI) |
| 8878 | lpfc_sli4_disable_msi(phba); |
| 8879 | else if (phba->intr_type == INTx) |
| 8880 | free_irq(phba->pcidev->irq, phba); |
| 8881 | |
| 8882 | /* Reset interrupt management states */ |
| 8883 | phba->intr_type = NONE; |
| 8884 | phba->sli.slistat.sli_intr = 0; |
| 8885 | |
| 8886 | return; |
| 8887 | } |
| 8888 | |
| 8889 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8890 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 8891 | * @phba: pointer to lpfc hba data structure. |
| 8892 | * |
| 8893 | * This routine is invoked to unset the HBA device initialization steps to |
| 8894 | * a device with SLI-3 interface spec. |
| 8895 | **/ |
| 8896 | static void |
| 8897 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 8898 | { |
| 8899 | struct lpfc_vport *vport = phba->pport; |
| 8900 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8901 | |
| 8902 | spin_lock_irq(shost->host_lock); |
| 8903 | vport->load_flag |= FC_UNLOADING; |
| 8904 | spin_unlock_irq(shost->host_lock); |
| 8905 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8906 | kfree(phba->vpi_bmask); |
| 8907 | kfree(phba->vpi_ids); |
| 8908 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8909 | lpfc_stop_hba_timers(phba); |
| 8910 | |
| 8911 | phba->pport->work_port_events = 0; |
| 8912 | |
| 8913 | lpfc_sli_hba_down(phba); |
| 8914 | |
| 8915 | lpfc_sli_brdrestart(phba); |
| 8916 | |
| 8917 | lpfc_sli_disable_intr(phba); |
| 8918 | |
| 8919 | return; |
| 8920 | } |
| 8921 | |
| 8922 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8923 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 8924 | * @phba: Pointer to HBA context object. |
| 8925 | * |
| 8926 | * This function is called in the SLI4 code path to wait for completion |
| 8927 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 8928 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 8929 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 8930 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 8931 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 8932 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 8933 | * the rest of the driver unload resource release. |
| 8934 | **/ |
| 8935 | static void |
| 8936 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 8937 | { |
| 8938 | int wait_time = 0; |
| 8939 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8940 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8941 | |
| 8942 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 8943 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 8944 | if (!fcp_xri_cmpl) |
| 8945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8946 | "2877 FCP XRI exchange busy " |
| 8947 | "wait time: %d seconds.\n", |
| 8948 | wait_time/1000); |
| 8949 | if (!els_xri_cmpl) |
| 8950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8951 | "2878 ELS XRI exchange busy " |
| 8952 | "wait time: %d seconds.\n", |
| 8953 | wait_time/1000); |
| 8954 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 8955 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 8956 | } else { |
| 8957 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 8958 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 8959 | } |
| 8960 | fcp_xri_cmpl = |
| 8961 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8962 | els_xri_cmpl = |
| 8963 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8964 | } |
| 8965 | } |
| 8966 | |
| 8967 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8968 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 8969 | * @phba: Pointer to HBA context object. |
| 8970 | * |
| 8971 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 8972 | * function. The caller is not required to hold any lock. This routine |
| 8973 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 8974 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 8975 | * free any pending commands. |
| 8976 | **/ |
| 8977 | static void |
| 8978 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 8979 | { |
| 8980 | int wait_cnt = 0; |
| 8981 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8982 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8983 | |
| 8984 | lpfc_stop_hba_timers(phba); |
| 8985 | phba->sli4_hba.intr_enable = 0; |
| 8986 | |
| 8987 | /* |
| 8988 | * Gracefully wait out the potential current outstanding asynchronous |
| 8989 | * mailbox command. |
| 8990 | */ |
| 8991 | |
| 8992 | /* First, block any pending async mailbox command from posted */ |
| 8993 | spin_lock_irq(&phba->hbalock); |
| 8994 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 8995 | spin_unlock_irq(&phba->hbalock); |
| 8996 | /* Now, trying to wait it out if we can */ |
| 8997 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8998 | msleep(10); |
| 8999 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 9000 | break; |
| 9001 | } |
| 9002 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 9003 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 9004 | spin_lock_irq(&phba->hbalock); |
| 9005 | mboxq = phba->sli.mbox_active; |
| 9006 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 9007 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 9008 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 9009 | phba->sli.mbox_active = NULL; |
| 9010 | spin_unlock_irq(&phba->hbalock); |
| 9011 | } |
| 9012 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 9013 | /* Abort all iocbs associated with the hba */ |
| 9014 | lpfc_sli_hba_iocb_abort(phba); |
| 9015 | |
| 9016 | /* Wait for completion of device XRI exchange busy */ |
| 9017 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 9018 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9019 | /* Disable PCI subsystem interrupt */ |
| 9020 | lpfc_sli4_disable_intr(phba); |
| 9021 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9022 | /* Disable SR-IOV if enabled */ |
| 9023 | if (phba->cfg_sriov_nr_virtfn) |
| 9024 | pci_disable_sriov(pdev); |
| 9025 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9026 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9027 | kthread_stop(phba->worker_thread); |
| 9028 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9029 | /* Reset SLI4 HBA FCoE function */ |
| 9030 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9031 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9032 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9033 | /* Stop the SLI4 device port */ |
| 9034 | phba->pport->work_port_events = 0; |
| 9035 | } |
| 9036 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9037 | /** |
| 9038 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 9039 | * @phba: Pointer to HBA context object. |
| 9040 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9041 | * |
| 9042 | * This function is called in the SLI4 code path to read the port's |
| 9043 | * sli4 capabilities. |
| 9044 | * |
| 9045 | * This function may be be called from any context that can block-wait |
| 9046 | * for the completion. The expectation is that this routine is called |
| 9047 | * typically from probe_one or from the online routine. |
| 9048 | **/ |
| 9049 | int |
| 9050 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9051 | { |
| 9052 | int rc; |
| 9053 | struct lpfc_mqe *mqe; |
| 9054 | struct lpfc_pc_sli4_params *sli4_params; |
| 9055 | uint32_t mbox_tmo; |
| 9056 | |
| 9057 | rc = 0; |
| 9058 | mqe = &mboxq->u.mqe; |
| 9059 | |
| 9060 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9061 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9062 | if (!phba->sli4_hba.intr_enable) |
| 9063 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9064 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9065 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9066 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9067 | } |
| 9068 | |
| 9069 | if (unlikely(rc)) |
| 9070 | return 1; |
| 9071 | |
| 9072 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9073 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 9074 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 9075 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 9076 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 9077 | &mqe->un.sli4_params); |
| 9078 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 9079 | &mqe->un.sli4_params); |
| 9080 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 9081 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 9082 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 9083 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 9084 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 9085 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 9086 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 9087 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 9088 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 9089 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 9090 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 9091 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 9092 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 9093 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 9094 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 9095 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 9096 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 9097 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 9098 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 9099 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 9100 | 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] | 9101 | |
| 9102 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9103 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9104 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9105 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9106 | return rc; |
| 9107 | } |
| 9108 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9109 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9110 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 9111 | * @phba: Pointer to HBA context object. |
| 9112 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 9113 | * |
| 9114 | * This function is called in the SLI4 code path to read the port's |
| 9115 | * sli4 capabilities. |
| 9116 | * |
| 9117 | * This function may be be called from any context that can block-wait |
| 9118 | * for the completion. The expectation is that this routine is called |
| 9119 | * typically from probe_one or from the online routine. |
| 9120 | **/ |
| 9121 | int |
| 9122 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 9123 | { |
| 9124 | int rc; |
| 9125 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 9126 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9127 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9128 | int length; |
| 9129 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 9130 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9131 | /* |
| 9132 | * By default, the driver assumes the SLI4 port requires RPI |
| 9133 | * header postings. The SLI4_PARAM response will correct this |
| 9134 | * assumption. |
| 9135 | */ |
| 9136 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 9137 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9138 | /* Read the port's SLI4 Config Parameters */ |
| 9139 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 9140 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9141 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9142 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 9143 | length, LPFC_SLI4_MBX_EMBED); |
| 9144 | if (!phba->sli4_hba.intr_enable) |
| 9145 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 9146 | else { |
| 9147 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 9148 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 9149 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9150 | if (unlikely(rc)) |
| 9151 | return rc; |
| 9152 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 9153 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 9154 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 9155 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 9156 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 9157 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 9158 | mbx_sli4_parameters); |
| 9159 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 9160 | mbx_sli4_parameters); |
| 9161 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 9162 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 9163 | else |
| 9164 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 9165 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 9166 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
| 9167 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 9168 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 9169 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 9170 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame^] | 9171 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9172 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 9173 | mbx_sli4_parameters); |
| 9174 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 9175 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9176 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 9177 | 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] | 9178 | |
| 9179 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 9180 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 9181 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 9182 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 9183 | return 0; |
| 9184 | } |
| 9185 | |
| 9186 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9187 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 9188 | * @pdev: pointer to PCI device |
| 9189 | * @pid: pointer to PCI device identifier |
| 9190 | * |
| 9191 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 9192 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9193 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9194 | * information of the device and driver to see if the driver state that it can |
| 9195 | * support this kind of device. If the match is successful, the driver core |
| 9196 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 9197 | * does all the initialization that it needs to do to handle the HBA properly. |
| 9198 | * |
| 9199 | * Return code |
| 9200 | * 0 - driver can claim the device |
| 9201 | * negative value - driver can not claim the device |
| 9202 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9203 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9204 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9205 | { |
| 9206 | struct lpfc_hba *phba; |
| 9207 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9208 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9209 | int error; |
| 9210 | uint32_t cfg_mode, intr_mode; |
| 9211 | |
| 9212 | /* Allocate memory for HBA structure */ |
| 9213 | phba = lpfc_hba_alloc(pdev); |
| 9214 | if (!phba) |
| 9215 | return -ENOMEM; |
| 9216 | |
| 9217 | /* Perform generic PCI device enabling operation */ |
| 9218 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9219 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9220 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9221 | |
| 9222 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 9223 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 9224 | if (error) |
| 9225 | goto out_disable_pci_dev; |
| 9226 | |
| 9227 | /* Set up SLI-3 specific device PCI memory space */ |
| 9228 | error = lpfc_sli_pci_mem_setup(phba); |
| 9229 | if (error) { |
| 9230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9231 | "1402 Failed to set up pci memory space.\n"); |
| 9232 | goto out_disable_pci_dev; |
| 9233 | } |
| 9234 | |
| 9235 | /* Set up phase-1 common device driver resources */ |
| 9236 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9237 | if (error) { |
| 9238 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9239 | "1403 Failed to set up driver resource.\n"); |
| 9240 | goto out_unset_pci_mem_s3; |
| 9241 | } |
| 9242 | |
| 9243 | /* Set up SLI-3 specific device driver resources */ |
| 9244 | error = lpfc_sli_driver_resource_setup(phba); |
| 9245 | if (error) { |
| 9246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9247 | "1404 Failed to set up driver resource.\n"); |
| 9248 | goto out_unset_pci_mem_s3; |
| 9249 | } |
| 9250 | |
| 9251 | /* Initialize and populate the iocb list per host */ |
| 9252 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 9253 | if (error) { |
| 9254 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9255 | "1405 Failed to initialize iocb list.\n"); |
| 9256 | goto out_unset_driver_resource_s3; |
| 9257 | } |
| 9258 | |
| 9259 | /* Set up common device driver resources */ |
| 9260 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9261 | if (error) { |
| 9262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9263 | "1406 Failed to set up driver resource.\n"); |
| 9264 | goto out_free_iocb_list; |
| 9265 | } |
| 9266 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9267 | /* Get the default values for Model Name and Description */ |
| 9268 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9269 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9270 | /* Create SCSI host to the physical port */ |
| 9271 | error = lpfc_create_shost(phba); |
| 9272 | if (error) { |
| 9273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9274 | "1407 Failed to create scsi host.\n"); |
| 9275 | goto out_unset_driver_resource; |
| 9276 | } |
| 9277 | |
| 9278 | /* Configure sysfs attributes */ |
| 9279 | vport = phba->pport; |
| 9280 | error = lpfc_alloc_sysfs_attr(vport); |
| 9281 | if (error) { |
| 9282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9283 | "1476 Failed to allocate sysfs attr\n"); |
| 9284 | goto out_destroy_shost; |
| 9285 | } |
| 9286 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9287 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9288 | /* Now, trying to enable interrupt and bring up the device */ |
| 9289 | cfg_mode = phba->cfg_use_msi; |
| 9290 | while (true) { |
| 9291 | /* Put device to a known state before enabling interrupt */ |
| 9292 | lpfc_stop_port(phba); |
| 9293 | /* Configure and enable interrupt */ |
| 9294 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 9295 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9296 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9297 | "0431 Failed to enable interrupt.\n"); |
| 9298 | error = -ENODEV; |
| 9299 | goto out_free_sysfs_attr; |
| 9300 | } |
| 9301 | /* SLI-3 HBA setup */ |
| 9302 | if (lpfc_sli_hba_setup(phba)) { |
| 9303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9304 | "1477 Failed to set up hba\n"); |
| 9305 | error = -ENODEV; |
| 9306 | goto out_remove_device; |
| 9307 | } |
| 9308 | |
| 9309 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 9310 | msleep(50); |
| 9311 | /* Check active interrupts on message signaled interrupts */ |
| 9312 | if (intr_mode == 0 || |
| 9313 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 9314 | /* Log the current active interrupt mode */ |
| 9315 | phba->intr_mode = intr_mode; |
| 9316 | lpfc_log_intr_mode(phba, intr_mode); |
| 9317 | break; |
| 9318 | } else { |
| 9319 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9320 | "0447 Configure interrupt mode (%d) " |
| 9321 | "failed active interrupt test.\n", |
| 9322 | intr_mode); |
| 9323 | /* Disable the current interrupt mode */ |
| 9324 | lpfc_sli_disable_intr(phba); |
| 9325 | /* Try next level of interrupt mode */ |
| 9326 | cfg_mode = --intr_mode; |
| 9327 | } |
| 9328 | } |
| 9329 | |
| 9330 | /* Perform post initialization setup */ |
| 9331 | lpfc_post_init_setup(phba); |
| 9332 | |
| 9333 | /* Check if there are static vports to be created. */ |
| 9334 | lpfc_create_static_vport(phba); |
| 9335 | |
| 9336 | return 0; |
| 9337 | |
| 9338 | out_remove_device: |
| 9339 | lpfc_unset_hba(phba); |
| 9340 | out_free_sysfs_attr: |
| 9341 | lpfc_free_sysfs_attr(vport); |
| 9342 | out_destroy_shost: |
| 9343 | lpfc_destroy_shost(phba); |
| 9344 | out_unset_driver_resource: |
| 9345 | lpfc_unset_driver_resource_phase2(phba); |
| 9346 | out_free_iocb_list: |
| 9347 | lpfc_free_iocb_list(phba); |
| 9348 | out_unset_driver_resource_s3: |
| 9349 | lpfc_sli_driver_resource_unset(phba); |
| 9350 | out_unset_pci_mem_s3: |
| 9351 | lpfc_sli_pci_mem_unset(phba); |
| 9352 | out_disable_pci_dev: |
| 9353 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9354 | if (shost) |
| 9355 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9356 | out_free_phba: |
| 9357 | lpfc_hba_free(phba); |
| 9358 | return error; |
| 9359 | } |
| 9360 | |
| 9361 | /** |
| 9362 | * 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] | 9363 | * @pdev: pointer to PCI device |
| 9364 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9365 | * This routine is to be called to disattach a device with SLI-3 interface |
| 9366 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9367 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9368 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9369 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9370 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9371 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9372 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9373 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9374 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9375 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9376 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9377 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9378 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 9379 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9380 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9381 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9382 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9383 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9384 | lpfc_free_sysfs_attr(vport); |
| 9385 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9386 | /* Release all the vports against this physical port */ |
| 9387 | vports = lpfc_create_vport_work_array(phba); |
| 9388 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9389 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9390 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9391 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9392 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9393 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9394 | lpfc_destroy_vport_work_array(phba, vports); |
| 9395 | |
| 9396 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9397 | fc_remove_host(shost); |
| 9398 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 9399 | lpfc_cleanup(vport); |
| 9400 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9401 | /* |
| 9402 | * Bring down the SLI Layer. This step disable all interrupts, |
| 9403 | * clears the rings, discards all mailbox commands, and resets |
| 9404 | * the HBA. |
| 9405 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9406 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 9407 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9408 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9409 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9410 | kthread_stop(phba->worker_thread); |
| 9411 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9412 | lpfc_sli_brdrestart(phba); |
| 9413 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9414 | kfree(phba->vpi_bmask); |
| 9415 | kfree(phba->vpi_ids); |
| 9416 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9417 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9418 | spin_lock_irq(&phba->hbalock); |
| 9419 | list_del_init(&vport->listentry); |
| 9420 | spin_unlock_irq(&phba->hbalock); |
| 9421 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9422 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9423 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9424 | /* Disable SR-IOV if enabled */ |
| 9425 | if (phba->cfg_sriov_nr_virtfn) |
| 9426 | pci_disable_sriov(pdev); |
| 9427 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9428 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9429 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9430 | |
| 9431 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9432 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9433 | |
| 9434 | /* |
| 9435 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 9436 | * corresponding pools here. |
| 9437 | */ |
| 9438 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9439 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9440 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9441 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9442 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9444 | /* Free resources associated with SLI2 interface */ |
| 9445 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9446 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9447 | |
| 9448 | /* unmap adapter SLIM and Control Registers */ |
| 9449 | iounmap(phba->ctrl_regs_memmap_p); |
| 9450 | iounmap(phba->slim_memmap_p); |
| 9451 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9452 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9453 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9454 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9455 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9456 | } |
| 9457 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9458 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9459 | * 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] | 9460 | * @pdev: pointer to PCI device |
| 9461 | * @msg: power management message |
| 9462 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9463 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9464 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 9465 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 9466 | * worker thread for the device, turning off device's interrupt and DMA, |
| 9467 | * and bring the device offline. Note that as the driver implements the |
| 9468 | * minimum PM requirements to a power-aware driver's PM support for the |
| 9469 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9470 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 9471 | * fully reinitialize its device during resume() method call, the driver will |
| 9472 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 9473 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9474 | * |
| 9475 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9476 | * 0 - driver suspended the device |
| 9477 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9478 | **/ |
| 9479 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9480 | 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] | 9481 | { |
| 9482 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9483 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9484 | |
| 9485 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9486 | "0473 PCI device Power Management suspend.\n"); |
| 9487 | |
| 9488 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9489 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9490 | lpfc_offline(phba); |
| 9491 | kthread_stop(phba->worker_thread); |
| 9492 | |
| 9493 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9494 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9495 | |
| 9496 | /* Save device state to PCI config space */ |
| 9497 | pci_save_state(pdev); |
| 9498 | pci_set_power_state(pdev, PCI_D3hot); |
| 9499 | |
| 9500 | return 0; |
| 9501 | } |
| 9502 | |
| 9503 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9504 | * 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] | 9505 | * @pdev: pointer to PCI device |
| 9506 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9507 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9508 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9509 | * invokes this method, it restores the device's PCI config space state and |
| 9510 | * fully reinitializes the device and brings it online. Note that as the |
| 9511 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9512 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9513 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9514 | * driver will fully reinitialize its device during resume() method call, |
| 9515 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9516 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9517 | * |
| 9518 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9519 | * 0 - driver suspended the device |
| 9520 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9521 | **/ |
| 9522 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9523 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9524 | { |
| 9525 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9526 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9527 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9528 | int error; |
| 9529 | |
| 9530 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9531 | "0452 PCI device Power Management resume.\n"); |
| 9532 | |
| 9533 | /* Restore device state from PCI config space */ |
| 9534 | pci_set_power_state(pdev, PCI_D0); |
| 9535 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9536 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9537 | /* |
| 9538 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9539 | * device saved_state flag, need to save the restored state again. |
| 9540 | */ |
| 9541 | pci_save_state(pdev); |
| 9542 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9543 | if (pdev->is_busmaster) |
| 9544 | pci_set_master(pdev); |
| 9545 | |
| 9546 | /* Startup the kernel thread for this host adapter. */ |
| 9547 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9548 | "lpfc_worker_%d", phba->brd_no); |
| 9549 | if (IS_ERR(phba->worker_thread)) { |
| 9550 | error = PTR_ERR(phba->worker_thread); |
| 9551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9552 | "0434 PM resume failed to start worker " |
| 9553 | "thread: error=x%x.\n", error); |
| 9554 | return error; |
| 9555 | } |
| 9556 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9557 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9558 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9559 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9560 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9561 | "0430 PM resume Failed to enable interrupt\n"); |
| 9562 | return -EIO; |
| 9563 | } else |
| 9564 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9565 | |
| 9566 | /* Restart HBA and bring it online */ |
| 9567 | lpfc_sli_brdrestart(phba); |
| 9568 | lpfc_online(phba); |
| 9569 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9570 | /* Log the current active interrupt mode */ |
| 9571 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9572 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9573 | return 0; |
| 9574 | } |
| 9575 | |
| 9576 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9577 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9578 | * @phba: pointer to lpfc hba data structure. |
| 9579 | * |
| 9580 | * 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] | 9581 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9582 | **/ |
| 9583 | static void |
| 9584 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9585 | { |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9586 | struct lpfc_sli *psli = &phba->sli; |
| 9587 | struct lpfc_sli_ring *pring; |
| 9588 | |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9590 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9591 | |
| 9592 | /* |
| 9593 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9594 | * and let the SCSI mid-layer to retry them to recover. |
| 9595 | */ |
| 9596 | pring = &psli->ring[psli->fcp_ring]; |
| 9597 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9598 | } |
| 9599 | |
| 9600 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9601 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9602 | * @phba: pointer to lpfc hba data structure. |
| 9603 | * |
| 9604 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9605 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9606 | * pending I/Os. |
| 9607 | **/ |
| 9608 | static void |
| 9609 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9610 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9611 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9612 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9613 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9614 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9615 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9616 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9617 | /* Block all SCSI devices' I/Os on the host */ |
| 9618 | lpfc_scsi_dev_block(phba); |
| 9619 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 9620 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9621 | lpfc_sli_flush_fcp_rings(phba); |
| 9622 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9623 | /* stop all timers */ |
| 9624 | lpfc_stop_hba_timers(phba); |
| 9625 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9626 | /* Disable interrupt and pci device */ |
| 9627 | lpfc_sli_disable_intr(phba); |
| 9628 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9629 | } |
| 9630 | |
| 9631 | /** |
| 9632 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9633 | * @phba: pointer to lpfc hba data structure. |
| 9634 | * |
| 9635 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9636 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9637 | * pending I/Os. |
| 9638 | **/ |
| 9639 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9640 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9641 | { |
| 9642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9643 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9644 | /* Block all SCSI devices' I/Os on the host */ |
| 9645 | lpfc_scsi_dev_block(phba); |
| 9646 | |
| 9647 | /* stop all timers */ |
| 9648 | lpfc_stop_hba_timers(phba); |
| 9649 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9650 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9651 | lpfc_sli_flush_fcp_rings(phba); |
| 9652 | } |
| 9653 | |
| 9654 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9655 | * 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] | 9656 | * @pdev: pointer to PCI device. |
| 9657 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9658 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9659 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9660 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9661 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9662 | * When this function is invoked, it will need to stop all the I/Os and |
| 9663 | * interrupt(s) to the device. Once that is done, it will return |
| 9664 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9665 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9666 | * |
| 9667 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9668 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9669 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9670 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9671 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9672 | static pci_ers_result_t |
| 9673 | 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] | 9674 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9675 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9676 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9677 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9678 | switch (state) { |
| 9679 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9680 | /* Non-fatal error, prepare for recovery */ |
| 9681 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9682 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9683 | case pci_channel_io_frozen: |
| 9684 | /* Fatal error, prepare for slot reset */ |
| 9685 | lpfc_sli_prep_dev_for_reset(phba); |
| 9686 | return PCI_ERS_RESULT_NEED_RESET; |
| 9687 | case pci_channel_io_perm_failure: |
| 9688 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9689 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9690 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9691 | default: |
| 9692 | /* Unknown state, prepare and request slot reset */ |
| 9693 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9694 | "0472 Unknown PCI error state: x%x\n", state); |
| 9695 | lpfc_sli_prep_dev_for_reset(phba); |
| 9696 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9697 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9698 | } |
| 9699 | |
| 9700 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9701 | * 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] | 9702 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9703 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9704 | * This routine is called from the PCI subsystem for error handling to |
| 9705 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9706 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9707 | * During the PCI subsystem error recovery, after driver returns |
| 9708 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9709 | * recovery and then call this routine before calling the .resume method |
| 9710 | * to recover the device. This function will initialize the HBA device, |
| 9711 | * enable the interrupt, but it will just put the HBA to offline state |
| 9712 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9713 | * |
| 9714 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9715 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9716 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9717 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9718 | static pci_ers_result_t |
| 9719 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9720 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9721 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9722 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9723 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9724 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9725 | |
| 9726 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9727 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9728 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9729 | "PCI device after reset.\n"); |
| 9730 | return PCI_ERS_RESULT_DISCONNECT; |
| 9731 | } |
| 9732 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9733 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9734 | |
| 9735 | /* |
| 9736 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9737 | * device saved_state flag, need to save the restored state again. |
| 9738 | */ |
| 9739 | pci_save_state(pdev); |
| 9740 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9741 | if (pdev->is_busmaster) |
| 9742 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9743 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9744 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9745 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9746 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9747 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9748 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9749 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9750 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9752 | "0427 Cannot re-enable interrupt after " |
| 9753 | "slot reset.\n"); |
| 9754 | return PCI_ERS_RESULT_DISCONNECT; |
| 9755 | } else |
| 9756 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9757 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9758 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9759 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9760 | lpfc_offline(phba); |
| 9761 | lpfc_sli_brdrestart(phba); |
| 9762 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9763 | /* Log the current active interrupt mode */ |
| 9764 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9765 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9766 | return PCI_ERS_RESULT_RECOVERED; |
| 9767 | } |
| 9768 | |
| 9769 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9770 | * 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] | 9771 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9772 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9773 | * This routine is called from the PCI subsystem for error handling to device |
| 9774 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9775 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9776 | * error recovery. After this call, traffic can start to flow from this device |
| 9777 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9778 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9779 | static void |
| 9780 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9781 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9782 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9783 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9784 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9785 | /* 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] | 9786 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9787 | |
| 9788 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9789 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9790 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9791 | } |
| 9792 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9793 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9794 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9795 | * @phba: pointer to lpfc hba data structure. |
| 9796 | * |
| 9797 | * returns the number of ELS/CT IOCBs to reserve |
| 9798 | **/ |
| 9799 | int |
| 9800 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9801 | { |
| 9802 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9803 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9804 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9805 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9806 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9807 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9808 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9809 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9810 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9811 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9812 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9813 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9814 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9815 | else if (max_xri <= 2048) |
| 9816 | return 200; |
| 9817 | else |
| 9818 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9819 | } else |
| 9820 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9821 | } |
| 9822 | |
| 9823 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9824 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9825 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9826 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9827 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9828 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9829 | static void |
| 9830 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9831 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9832 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9833 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9834 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9835 | struct list_head dma_buffer_list; |
| 9836 | int i, rc = 0; |
| 9837 | struct lpfc_dmabuf *dmabuf, *next; |
| 9838 | uint32_t offset = 0, temp_offset = 0; |
| 9839 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9840 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9841 | if (!fw) { |
| 9842 | rc = -ENXIO; |
| 9843 | goto out; |
| 9844 | } |
| 9845 | image = (struct lpfc_grp_hdr *)fw->data; |
| 9846 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9847 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9848 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9849 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9850 | LPFC_FILE_TYPE_GROUP) || |
| 9851 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9852 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9853 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9854 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9855 | "Magic:%x Type:%x ID:%x\n", |
| 9856 | be32_to_cpu(image->magic_number), |
| 9857 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9858 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9859 | rc = -EINVAL; |
| 9860 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9861 | } |
| 9862 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9863 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9864 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9865 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9866 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9867 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9868 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9869 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9870 | GFP_KERNEL); |
| 9871 | if (!dmabuf) { |
| 9872 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9873 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9874 | } |
| 9875 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 9876 | SLI4_PAGE_SIZE, |
| 9877 | &dmabuf->phys, |
| 9878 | GFP_KERNEL); |
| 9879 | if (!dmabuf->virt) { |
| 9880 | kfree(dmabuf); |
| 9881 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9882 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9883 | } |
| 9884 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 9885 | } |
| 9886 | while (offset < fw->size) { |
| 9887 | temp_offset = offset; |
| 9888 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9889 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9890 | memcpy(dmabuf->virt, |
| 9891 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9892 | fw->size - temp_offset); |
| 9893 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9894 | break; |
| 9895 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9896 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 9897 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9898 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9899 | } |
| 9900 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 9901 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9902 | if (rc) |
| 9903 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9904 | } |
| 9905 | rc = offset; |
| 9906 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9907 | |
| 9908 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9909 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 9910 | list_del(&dmabuf->list); |
| 9911 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 9912 | dmabuf->virt, dmabuf->phys); |
| 9913 | kfree(dmabuf); |
| 9914 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9915 | release_firmware(fw); |
| 9916 | out: |
| 9917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9918 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9919 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9920 | } |
| 9921 | |
| 9922 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9923 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 9924 | * @phba: pointer to lpfc hba data structure. |
| 9925 | * |
| 9926 | * This routine is called to perform Linux generic firmware upgrade on device |
| 9927 | * that supports such feature. |
| 9928 | **/ |
| 9929 | int |
| 9930 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 9931 | { |
| 9932 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 9933 | int ret; |
| 9934 | const struct firmware *fw; |
| 9935 | |
| 9936 | /* Only supported on SLI4 interface type 2 for now */ |
| 9937 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 9938 | LPFC_SLI_INTF_IF_TYPE_2) |
| 9939 | return -EPERM; |
| 9940 | |
| 9941 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 9942 | |
| 9943 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 9944 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 9945 | file_name, &phba->pcidev->dev, |
| 9946 | GFP_KERNEL, (void *)phba, |
| 9947 | lpfc_write_firmware); |
| 9948 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 9949 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 9950 | if (!ret) |
| 9951 | lpfc_write_firmware(fw, (void *)phba); |
| 9952 | } else { |
| 9953 | ret = -EINVAL; |
| 9954 | } |
| 9955 | |
| 9956 | return ret; |
| 9957 | } |
| 9958 | |
| 9959 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9960 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 9961 | * @pdev: pointer to PCI device |
| 9962 | * @pid: pointer to PCI device identifier |
| 9963 | * |
| 9964 | * This routine is called from the kernel's PCI subsystem to device with |
| 9965 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9966 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9967 | * information of the device and driver to see if the driver state that it |
| 9968 | * can support this kind of device. If the match is successful, the driver |
| 9969 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 9970 | * it does all the initialization that it needs to do to handle the HBA |
| 9971 | * properly. |
| 9972 | * |
| 9973 | * Return code |
| 9974 | * 0 - driver can claim the device |
| 9975 | * negative value - driver can not claim the device |
| 9976 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9977 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9978 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9979 | { |
| 9980 | struct lpfc_hba *phba; |
| 9981 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9982 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9983 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9984 | uint32_t cfg_mode, intr_mode; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9985 | int adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9986 | |
| 9987 | /* Allocate memory for HBA structure */ |
| 9988 | phba = lpfc_hba_alloc(pdev); |
| 9989 | if (!phba) |
| 9990 | return -ENOMEM; |
| 9991 | |
| 9992 | /* Perform generic PCI device enabling operation */ |
| 9993 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9994 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9995 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9996 | |
| 9997 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 9998 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 9999 | if (error) |
| 10000 | goto out_disable_pci_dev; |
| 10001 | |
| 10002 | /* Set up SLI-4 specific device PCI memory space */ |
| 10003 | error = lpfc_sli4_pci_mem_setup(phba); |
| 10004 | if (error) { |
| 10005 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10006 | "1410 Failed to set up pci memory space.\n"); |
| 10007 | goto out_disable_pci_dev; |
| 10008 | } |
| 10009 | |
| 10010 | /* Set up phase-1 common device driver resources */ |
| 10011 | error = lpfc_setup_driver_resource_phase1(phba); |
| 10012 | if (error) { |
| 10013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10014 | "1411 Failed to set up driver resource.\n"); |
| 10015 | goto out_unset_pci_mem_s4; |
| 10016 | } |
| 10017 | |
| 10018 | /* Set up SLI-4 Specific device driver resources */ |
| 10019 | error = lpfc_sli4_driver_resource_setup(phba); |
| 10020 | if (error) { |
| 10021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10022 | "1412 Failed to set up driver resource.\n"); |
| 10023 | goto out_unset_pci_mem_s4; |
| 10024 | } |
| 10025 | |
| 10026 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10027 | |
| 10028 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10029 | "2821 initialize iocb list %d.\n", |
| 10030 | phba->cfg_iocb_cnt*1024); |
| 10031 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 10032 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10033 | if (error) { |
| 10034 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10035 | "1413 Failed to initialize iocb list.\n"); |
| 10036 | goto out_unset_driver_resource_s4; |
| 10037 | } |
| 10038 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10039 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 10040 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 10041 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10042 | /* Set up common device driver resources */ |
| 10043 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10044 | if (error) { |
| 10045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10046 | "1414 Failed to set up driver resource.\n"); |
| 10047 | goto out_free_iocb_list; |
| 10048 | } |
| 10049 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10050 | /* Get the default values for Model Name and Description */ |
| 10051 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10052 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10053 | /* Create SCSI host to the physical port */ |
| 10054 | error = lpfc_create_shost(phba); |
| 10055 | if (error) { |
| 10056 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10057 | "1415 Failed to create scsi host.\n"); |
| 10058 | goto out_unset_driver_resource; |
| 10059 | } |
| 10060 | |
| 10061 | /* Configure sysfs attributes */ |
| 10062 | vport = phba->pport; |
| 10063 | error = lpfc_alloc_sysfs_attr(vport); |
| 10064 | if (error) { |
| 10065 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10066 | "1416 Failed to allocate sysfs attr\n"); |
| 10067 | goto out_destroy_shost; |
| 10068 | } |
| 10069 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10070 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10071 | /* Now, trying to enable interrupt and bring up the device */ |
| 10072 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10073 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10074 | /* Put device to a known state before enabling interrupt */ |
| 10075 | lpfc_stop_port(phba); |
| 10076 | /* Configure and enable interrupt */ |
| 10077 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 10078 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10080 | "0426 Failed to enable interrupt.\n"); |
| 10081 | error = -ENODEV; |
| 10082 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10083 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 10084 | /* Default to single EQ for non-MSI-X */ |
| 10085 | if (phba->intr_type != MSIX) |
| 10086 | adjusted_fcp_io_channel = 1; |
| 10087 | else |
| 10088 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 10089 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
| 10090 | /* Set up SLI-4 HBA */ |
| 10091 | if (lpfc_sli4_hba_setup(phba)) { |
| 10092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10093 | "1421 Failed to set up hba\n"); |
| 10094 | error = -ENODEV; |
| 10095 | goto out_disable_intr; |
| 10096 | } |
| 10097 | |
| 10098 | /* Log the current active interrupt mode */ |
| 10099 | phba->intr_mode = intr_mode; |
| 10100 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10101 | |
| 10102 | /* Perform post initialization setup */ |
| 10103 | lpfc_post_init_setup(phba); |
| 10104 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 10105 | /* check for firmware upgrade or downgrade */ |
| 10106 | if (phba->cfg_request_firmware_upgrade) |
| 10107 | ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 10108 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 10109 | /* Check if there are static vports to be created. */ |
| 10110 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10111 | return 0; |
| 10112 | |
| 10113 | out_disable_intr: |
| 10114 | lpfc_sli4_disable_intr(phba); |
| 10115 | out_free_sysfs_attr: |
| 10116 | lpfc_free_sysfs_attr(vport); |
| 10117 | out_destroy_shost: |
| 10118 | lpfc_destroy_shost(phba); |
| 10119 | out_unset_driver_resource: |
| 10120 | lpfc_unset_driver_resource_phase2(phba); |
| 10121 | out_free_iocb_list: |
| 10122 | lpfc_free_iocb_list(phba); |
| 10123 | out_unset_driver_resource_s4: |
| 10124 | lpfc_sli4_driver_resource_unset(phba); |
| 10125 | out_unset_pci_mem_s4: |
| 10126 | lpfc_sli4_pci_mem_unset(phba); |
| 10127 | out_disable_pci_dev: |
| 10128 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10129 | if (shost) |
| 10130 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10131 | out_free_phba: |
| 10132 | lpfc_hba_free(phba); |
| 10133 | return error; |
| 10134 | } |
| 10135 | |
| 10136 | /** |
| 10137 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 10138 | * @pdev: pointer to PCI device |
| 10139 | * |
| 10140 | * This routine is called from the kernel's PCI subsystem to device with |
| 10141 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 10142 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10143 | * device to be removed from the PCI subsystem properly. |
| 10144 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10145 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10146 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 10147 | { |
| 10148 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10149 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 10150 | struct lpfc_vport **vports; |
| 10151 | struct lpfc_hba *phba = vport->phba; |
| 10152 | int i; |
| 10153 | |
| 10154 | /* Mark the device unloading flag */ |
| 10155 | spin_lock_irq(&phba->hbalock); |
| 10156 | vport->load_flag |= FC_UNLOADING; |
| 10157 | spin_unlock_irq(&phba->hbalock); |
| 10158 | |
| 10159 | /* Free the HBA sysfs attributes */ |
| 10160 | lpfc_free_sysfs_attr(vport); |
| 10161 | |
| 10162 | /* Release all the vports against this physical port */ |
| 10163 | vports = lpfc_create_vport_work_array(phba); |
| 10164 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10165 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10166 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10167 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10168 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10169 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10170 | lpfc_destroy_vport_work_array(phba, vports); |
| 10171 | |
| 10172 | /* Remove FC host and then SCSI host with the physical port */ |
| 10173 | fc_remove_host(shost); |
| 10174 | scsi_remove_host(shost); |
| 10175 | |
| 10176 | /* Perform cleanup on the physical port */ |
| 10177 | lpfc_cleanup(vport); |
| 10178 | |
| 10179 | /* |
| 10180 | * Bring down the SLI Layer. This step disables all interrupts, |
| 10181 | * clears the rings, discards all mailbox commands, and resets |
| 10182 | * the HBA FCoE function. |
| 10183 | */ |
| 10184 | lpfc_debugfs_terminate(vport); |
| 10185 | lpfc_sli4_hba_unset(phba); |
| 10186 | |
| 10187 | spin_lock_irq(&phba->hbalock); |
| 10188 | list_del_init(&vport->listentry); |
| 10189 | spin_unlock_irq(&phba->hbalock); |
| 10190 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10191 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10192 | * buffers are released to their corresponding pools here. |
| 10193 | */ |
| 10194 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10195 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10196 | lpfc_sli4_driver_resource_unset(phba); |
| 10197 | |
| 10198 | /* Unmap adapter Control and Doorbell registers */ |
| 10199 | lpfc_sli4_pci_mem_unset(phba); |
| 10200 | |
| 10201 | /* Release PCI resources and disable device's PCI function */ |
| 10202 | scsi_host_put(shost); |
| 10203 | lpfc_disable_pci_dev(phba); |
| 10204 | |
| 10205 | /* Finally, free the driver's device data structure */ |
| 10206 | lpfc_hba_free(phba); |
| 10207 | |
| 10208 | return; |
| 10209 | } |
| 10210 | |
| 10211 | /** |
| 10212 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 10213 | * @pdev: pointer to PCI device |
| 10214 | * @msg: power management message |
| 10215 | * |
| 10216 | * This routine is called from the kernel's PCI subsystem to support system |
| 10217 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 10218 | * this method, it quiesces the device by stopping the driver's worker |
| 10219 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 10220 | * the device offline. Note that as the driver implements the minimum PM |
| 10221 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 10222 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 10223 | * method call will be treated as SUSPEND and the driver will fully |
| 10224 | * reinitialize its device during resume() method call, the driver will set |
| 10225 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 10226 | * according to the @msg provided by the PM. |
| 10227 | * |
| 10228 | * Return code |
| 10229 | * 0 - driver suspended the device |
| 10230 | * Error otherwise |
| 10231 | **/ |
| 10232 | static int |
| 10233 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 10234 | { |
| 10235 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10236 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10237 | |
| 10238 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10239 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10240 | |
| 10241 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10242 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10243 | lpfc_offline(phba); |
| 10244 | kthread_stop(phba->worker_thread); |
| 10245 | |
| 10246 | /* Disable interrupt from device */ |
| 10247 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10248 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10249 | |
| 10250 | /* Save device state to PCI config space */ |
| 10251 | pci_save_state(pdev); |
| 10252 | pci_set_power_state(pdev, PCI_D3hot); |
| 10253 | |
| 10254 | return 0; |
| 10255 | } |
| 10256 | |
| 10257 | /** |
| 10258 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 10259 | * @pdev: pointer to PCI device |
| 10260 | * |
| 10261 | * This routine is called from the kernel's PCI subsystem to support system |
| 10262 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 10263 | * this method, it restores the device's PCI config space state and fully |
| 10264 | * reinitializes the device and brings it online. Note that as the driver |
| 10265 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 10266 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 10267 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 10268 | * will fully reinitialize its device during resume() method call, the device |
| 10269 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 10270 | * state. |
| 10271 | * |
| 10272 | * Return code |
| 10273 | * 0 - driver suspended the device |
| 10274 | * Error otherwise |
| 10275 | **/ |
| 10276 | static int |
| 10277 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 10278 | { |
| 10279 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10280 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10281 | uint32_t intr_mode; |
| 10282 | int error; |
| 10283 | |
| 10284 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10285 | "0292 PCI device Power Management resume.\n"); |
| 10286 | |
| 10287 | /* Restore device state from PCI config space */ |
| 10288 | pci_set_power_state(pdev, PCI_D0); |
| 10289 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10290 | |
| 10291 | /* |
| 10292 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10293 | * device saved_state flag, need to save the restored state again. |
| 10294 | */ |
| 10295 | pci_save_state(pdev); |
| 10296 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10297 | if (pdev->is_busmaster) |
| 10298 | pci_set_master(pdev); |
| 10299 | |
| 10300 | /* Startup the kernel thread for this host adapter. */ |
| 10301 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 10302 | "lpfc_worker_%d", phba->brd_no); |
| 10303 | if (IS_ERR(phba->worker_thread)) { |
| 10304 | error = PTR_ERR(phba->worker_thread); |
| 10305 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10306 | "0293 PM resume failed to start worker " |
| 10307 | "thread: error=x%x.\n", error); |
| 10308 | return error; |
| 10309 | } |
| 10310 | |
| 10311 | /* Configure and enable interrupt */ |
| 10312 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10313 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10315 | "0294 PM resume Failed to enable interrupt\n"); |
| 10316 | return -EIO; |
| 10317 | } else |
| 10318 | phba->intr_mode = intr_mode; |
| 10319 | |
| 10320 | /* Restart HBA and bring it online */ |
| 10321 | lpfc_sli_brdrestart(phba); |
| 10322 | lpfc_online(phba); |
| 10323 | |
| 10324 | /* Log the current active interrupt mode */ |
| 10325 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10326 | |
| 10327 | return 0; |
| 10328 | } |
| 10329 | |
| 10330 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10331 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 10332 | * @phba: pointer to lpfc hba data structure. |
| 10333 | * |
| 10334 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 10335 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 10336 | **/ |
| 10337 | static void |
| 10338 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10339 | { |
| 10340 | struct lpfc_sli *psli = &phba->sli; |
| 10341 | struct lpfc_sli_ring *pring; |
| 10342 | |
| 10343 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10344 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 10345 | /* |
| 10346 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10347 | * and let the SCSI mid-layer to retry them to recover. |
| 10348 | */ |
| 10349 | pring = &psli->ring[psli->fcp_ring]; |
| 10350 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 10351 | } |
| 10352 | |
| 10353 | /** |
| 10354 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 10355 | * @phba: pointer to lpfc hba data structure. |
| 10356 | * |
| 10357 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 10358 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10359 | * pending I/Os. |
| 10360 | **/ |
| 10361 | static void |
| 10362 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10363 | { |
| 10364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10365 | "2826 PCI channel disable preparing for reset\n"); |
| 10366 | |
| 10367 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10368 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10369 | |
| 10370 | /* Block all SCSI devices' I/Os on the host */ |
| 10371 | lpfc_scsi_dev_block(phba); |
| 10372 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10373 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10374 | lpfc_sli_flush_fcp_rings(phba); |
| 10375 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10376 | /* stop all timers */ |
| 10377 | lpfc_stop_hba_timers(phba); |
| 10378 | |
| 10379 | /* Disable interrupt and pci device */ |
| 10380 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10381 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10382 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10383 | } |
| 10384 | |
| 10385 | /** |
| 10386 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 10387 | * @phba: pointer to lpfc hba data structure. |
| 10388 | * |
| 10389 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 10390 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10391 | * pending I/Os. |
| 10392 | **/ |
| 10393 | static void |
| 10394 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 10395 | { |
| 10396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10397 | "2827 PCI channel permanent disable for failure\n"); |
| 10398 | |
| 10399 | /* Block all SCSI devices' I/Os on the host */ |
| 10400 | lpfc_scsi_dev_block(phba); |
| 10401 | |
| 10402 | /* stop all timers */ |
| 10403 | lpfc_stop_hba_timers(phba); |
| 10404 | |
| 10405 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10406 | lpfc_sli_flush_fcp_rings(phba); |
| 10407 | } |
| 10408 | |
| 10409 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10410 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 10411 | * @pdev: pointer to PCI device. |
| 10412 | * @state: the current PCI connection state. |
| 10413 | * |
| 10414 | * This routine is called from the PCI subsystem for error handling to device |
| 10415 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 10416 | * after a PCI bus error affecting this device has been detected. When this |
| 10417 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 10418 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 10419 | * for the PCI subsystem to perform proper recovery as desired. |
| 10420 | * |
| 10421 | * Return codes |
| 10422 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10423 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10424 | **/ |
| 10425 | static pci_ers_result_t |
| 10426 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 10427 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10428 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10429 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10430 | |
| 10431 | switch (state) { |
| 10432 | case pci_channel_io_normal: |
| 10433 | /* Non-fatal error, prepare for recovery */ |
| 10434 | lpfc_sli4_prep_dev_for_recover(phba); |
| 10435 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10436 | case pci_channel_io_frozen: |
| 10437 | /* Fatal error, prepare for slot reset */ |
| 10438 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10439 | return PCI_ERS_RESULT_NEED_RESET; |
| 10440 | case pci_channel_io_perm_failure: |
| 10441 | /* Permanent failure, prepare for device down */ |
| 10442 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 10443 | return PCI_ERS_RESULT_DISCONNECT; |
| 10444 | default: |
| 10445 | /* Unknown state, prepare and request slot reset */ |
| 10446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10447 | "2825 Unknown PCI error state: x%x\n", state); |
| 10448 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10449 | return PCI_ERS_RESULT_NEED_RESET; |
| 10450 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10451 | } |
| 10452 | |
| 10453 | /** |
| 10454 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 10455 | * @pdev: pointer to PCI device. |
| 10456 | * |
| 10457 | * This routine is called from the PCI subsystem for error handling to device |
| 10458 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 10459 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 10460 | * PCI subsystem error recovery, after the driver returns |
| 10461 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10462 | * recovery and then call this routine before calling the .resume method to |
| 10463 | * recover the device. This function will initialize the HBA device, enable |
| 10464 | * the interrupt, but it will just put the HBA to offline state without |
| 10465 | * passing any I/O traffic. |
| 10466 | * |
| 10467 | * Return codes |
| 10468 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10469 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10470 | */ |
| 10471 | static pci_ers_result_t |
| 10472 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 10473 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10474 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10475 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10476 | struct lpfc_sli *psli = &phba->sli; |
| 10477 | uint32_t intr_mode; |
| 10478 | |
| 10479 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 10480 | if (pci_enable_device_mem(pdev)) { |
| 10481 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10482 | "PCI device after reset.\n"); |
| 10483 | return PCI_ERS_RESULT_DISCONNECT; |
| 10484 | } |
| 10485 | |
| 10486 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 10487 | |
| 10488 | /* |
| 10489 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10490 | * device saved_state flag, need to save the restored state again. |
| 10491 | */ |
| 10492 | pci_save_state(pdev); |
| 10493 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10494 | if (pdev->is_busmaster) |
| 10495 | pci_set_master(pdev); |
| 10496 | |
| 10497 | spin_lock_irq(&phba->hbalock); |
| 10498 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 10499 | spin_unlock_irq(&phba->hbalock); |
| 10500 | |
| 10501 | /* Configure and enable interrupt */ |
| 10502 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10503 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10505 | "2824 Cannot re-enable interrupt after " |
| 10506 | "slot reset.\n"); |
| 10507 | return PCI_ERS_RESULT_DISCONNECT; |
| 10508 | } else |
| 10509 | phba->intr_mode = intr_mode; |
| 10510 | |
| 10511 | /* Log the current active interrupt mode */ |
| 10512 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10513 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10514 | return PCI_ERS_RESULT_RECOVERED; |
| 10515 | } |
| 10516 | |
| 10517 | /** |
| 10518 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10519 | * @pdev: pointer to PCI device |
| 10520 | * |
| 10521 | * This routine is called from the PCI subsystem for error handling to device |
| 10522 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10523 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10524 | * error recovery. After this call, traffic can start to flow from this device |
| 10525 | * again. |
| 10526 | **/ |
| 10527 | static void |
| 10528 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10529 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10530 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10531 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10532 | |
| 10533 | /* |
| 10534 | * In case of slot reset, as function reset is performed through |
| 10535 | * mailbox command which needs DMA to be enabled, this operation |
| 10536 | * has to be moved to the io resume phase. Taking device offline |
| 10537 | * will perform the necessary cleanup. |
| 10538 | */ |
| 10539 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10540 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10541 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10542 | lpfc_offline(phba); |
| 10543 | lpfc_sli_brdrestart(phba); |
| 10544 | /* Bring the device back online */ |
| 10545 | lpfc_online(phba); |
| 10546 | } |
| 10547 | |
| 10548 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10549 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10550 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10551 | } |
| 10552 | |
| 10553 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10554 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10555 | * @pdev: pointer to PCI device |
| 10556 | * @pid: pointer to PCI device identifier |
| 10557 | * |
| 10558 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10559 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10560 | * at PCI device-specific information of the device and driver to see if the |
| 10561 | * driver state that it can support this kind of device. If the match is |
| 10562 | * successful, the driver core invokes this routine. This routine dispatches |
| 10563 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10564 | * do all the initialization that it needs to do to handle the HBA device |
| 10565 | * properly. |
| 10566 | * |
| 10567 | * Return code |
| 10568 | * 0 - driver can claim the device |
| 10569 | * negative value - driver can not claim the device |
| 10570 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10571 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10572 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10573 | { |
| 10574 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10575 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10576 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10577 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10578 | return -ENODEV; |
| 10579 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10580 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10581 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10582 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10583 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10584 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10585 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10586 | return rc; |
| 10587 | } |
| 10588 | |
| 10589 | /** |
| 10590 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10591 | * @pdev: pointer to PCI device |
| 10592 | * |
| 10593 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10594 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10595 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10596 | * remove routine, which will perform all the necessary cleanup for the |
| 10597 | * device to be removed from the PCI subsystem properly. |
| 10598 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10599 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10600 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10601 | { |
| 10602 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10603 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10604 | |
| 10605 | switch (phba->pci_dev_grp) { |
| 10606 | case LPFC_PCI_DEV_LP: |
| 10607 | lpfc_pci_remove_one_s3(pdev); |
| 10608 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10609 | case LPFC_PCI_DEV_OC: |
| 10610 | lpfc_pci_remove_one_s4(pdev); |
| 10611 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10612 | default: |
| 10613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10614 | "1424 Invalid PCI device group: 0x%x\n", |
| 10615 | phba->pci_dev_grp); |
| 10616 | break; |
| 10617 | } |
| 10618 | return; |
| 10619 | } |
| 10620 | |
| 10621 | /** |
| 10622 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10623 | * @pdev: pointer to PCI device |
| 10624 | * @msg: power management message |
| 10625 | * |
| 10626 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10627 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10628 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10629 | * suspend the device. |
| 10630 | * |
| 10631 | * Return code |
| 10632 | * 0 - driver suspended the device |
| 10633 | * Error otherwise |
| 10634 | **/ |
| 10635 | static int |
| 10636 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10637 | { |
| 10638 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10639 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10640 | int rc = -ENODEV; |
| 10641 | |
| 10642 | switch (phba->pci_dev_grp) { |
| 10643 | case LPFC_PCI_DEV_LP: |
| 10644 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10645 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10646 | case LPFC_PCI_DEV_OC: |
| 10647 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10648 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10649 | default: |
| 10650 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10651 | "1425 Invalid PCI device group: 0x%x\n", |
| 10652 | phba->pci_dev_grp); |
| 10653 | break; |
| 10654 | } |
| 10655 | return rc; |
| 10656 | } |
| 10657 | |
| 10658 | /** |
| 10659 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10660 | * @pdev: pointer to PCI device |
| 10661 | * |
| 10662 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10663 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10664 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10665 | * resume the device. |
| 10666 | * |
| 10667 | * Return code |
| 10668 | * 0 - driver suspended the device |
| 10669 | * Error otherwise |
| 10670 | **/ |
| 10671 | static int |
| 10672 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10673 | { |
| 10674 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10675 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10676 | int rc = -ENODEV; |
| 10677 | |
| 10678 | switch (phba->pci_dev_grp) { |
| 10679 | case LPFC_PCI_DEV_LP: |
| 10680 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10681 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10682 | case LPFC_PCI_DEV_OC: |
| 10683 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10684 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10685 | default: |
| 10686 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10687 | "1426 Invalid PCI device group: 0x%x\n", |
| 10688 | phba->pci_dev_grp); |
| 10689 | break; |
| 10690 | } |
| 10691 | return rc; |
| 10692 | } |
| 10693 | |
| 10694 | /** |
| 10695 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10696 | * @pdev: pointer to PCI device. |
| 10697 | * @state: the current PCI connection state. |
| 10698 | * |
| 10699 | * This routine is registered to the PCI subsystem for error handling. This |
| 10700 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10701 | * this device has been detected. When this routine is invoked, it dispatches |
| 10702 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 10703 | * routine, which will perform the proper error detected operation. |
| 10704 | * |
| 10705 | * Return codes |
| 10706 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10707 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10708 | **/ |
| 10709 | static pci_ers_result_t |
| 10710 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 10711 | { |
| 10712 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10713 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10714 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10715 | |
| 10716 | switch (phba->pci_dev_grp) { |
| 10717 | case LPFC_PCI_DEV_LP: |
| 10718 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10719 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10720 | case LPFC_PCI_DEV_OC: |
| 10721 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10722 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10723 | default: |
| 10724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10725 | "1427 Invalid PCI device group: 0x%x\n", |
| 10726 | phba->pci_dev_grp); |
| 10727 | break; |
| 10728 | } |
| 10729 | return rc; |
| 10730 | } |
| 10731 | |
| 10732 | /** |
| 10733 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10734 | * @pdev: pointer to PCI device. |
| 10735 | * |
| 10736 | * This routine is registered to the PCI subsystem for error handling. This |
| 10737 | * function is called after PCI bus has been reset to restart the PCI card |
| 10738 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10739 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10740 | * routine, which will perform the proper device reset. |
| 10741 | * |
| 10742 | * Return codes |
| 10743 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10744 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10745 | **/ |
| 10746 | static pci_ers_result_t |
| 10747 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10748 | { |
| 10749 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10750 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10751 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10752 | |
| 10753 | switch (phba->pci_dev_grp) { |
| 10754 | case LPFC_PCI_DEV_LP: |
| 10755 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10756 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10757 | case LPFC_PCI_DEV_OC: |
| 10758 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10759 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10760 | default: |
| 10761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10762 | "1428 Invalid PCI device group: 0x%x\n", |
| 10763 | phba->pci_dev_grp); |
| 10764 | break; |
| 10765 | } |
| 10766 | return rc; |
| 10767 | } |
| 10768 | |
| 10769 | /** |
| 10770 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10771 | * @pdev: pointer to PCI device |
| 10772 | * |
| 10773 | * This routine is registered to the PCI subsystem for error handling. It |
| 10774 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10775 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10776 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10777 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10778 | **/ |
| 10779 | static void |
| 10780 | lpfc_io_resume(struct pci_dev *pdev) |
| 10781 | { |
| 10782 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10783 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10784 | |
| 10785 | switch (phba->pci_dev_grp) { |
| 10786 | case LPFC_PCI_DEV_LP: |
| 10787 | lpfc_io_resume_s3(pdev); |
| 10788 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10789 | case LPFC_PCI_DEV_OC: |
| 10790 | lpfc_io_resume_s4(pdev); |
| 10791 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10792 | default: |
| 10793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10794 | "1429 Invalid PCI device group: 0x%x\n", |
| 10795 | phba->pci_dev_grp); |
| 10796 | break; |
| 10797 | } |
| 10798 | return; |
| 10799 | } |
| 10800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10801 | static struct pci_device_id lpfc_id_table[] = { |
| 10802 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 10803 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 10804 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 10805 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10806 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 10807 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10808 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 10809 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10810 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 10811 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10812 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 10813 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10814 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 10815 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10816 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 10817 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10818 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 10819 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10820 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 10821 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10822 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 10823 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10824 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 10825 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10826 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 10827 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10828 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 10829 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10830 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 10831 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10832 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 10833 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10834 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 10835 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10836 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 10837 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10838 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 10839 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10840 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 10841 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10842 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 10843 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10844 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 10845 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10846 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 10847 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10848 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 10849 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10850 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 10851 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10852 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 10853 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10854 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 10855 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10856 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 10857 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 10858 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 10859 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10860 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 10861 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10862 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 10863 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10864 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 10865 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10866 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 10867 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10868 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 10869 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10870 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 10871 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10872 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 10873 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10874 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 10875 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10876 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 10877 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10878 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 10879 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10880 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10881 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 10882 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 10883 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 10884 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 10885 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10886 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 10887 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 10888 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 10889 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10890 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 10891 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 10892 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 10893 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10894 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 10895 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10896 | { 0 } |
| 10897 | }; |
| 10898 | |
| 10899 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 10900 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 10901 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10902 | .error_detected = lpfc_io_error_detected, |
| 10903 | .slot_reset = lpfc_io_slot_reset, |
| 10904 | .resume = lpfc_io_resume, |
| 10905 | }; |
| 10906 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10907 | static struct pci_driver lpfc_driver = { |
| 10908 | .name = LPFC_DRIVER_NAME, |
| 10909 | .id_table = lpfc_id_table, |
| 10910 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10911 | .remove = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10912 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10913 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10914 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10915 | }; |
| 10916 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10917 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 10918 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10919 | }; |
| 10920 | |
| 10921 | static struct miscdevice lpfc_mgmt_dev = { |
| 10922 | .minor = MISC_DYNAMIC_MINOR, |
| 10923 | .name = "lpfcmgmt", |
| 10924 | .fops = &lpfc_mgmt_fop, |
| 10925 | }; |
| 10926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10927 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10928 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10929 | * |
| 10930 | * This routine is to be invoked when the lpfc module is loaded into the |
| 10931 | * kernel. The special kernel macro module_init() is used to indicate the |
| 10932 | * role of this routine to the kernel as lpfc module entry point. |
| 10933 | * |
| 10934 | * Return codes |
| 10935 | * 0 - successful |
| 10936 | * -ENOMEM - FC attach transport failed |
| 10937 | * all others - failed |
| 10938 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10939 | static int __init |
| 10940 | lpfc_init(void) |
| 10941 | { |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10942 | int cpu; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10943 | int error = 0; |
| 10944 | |
| 10945 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10946 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10947 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10948 | error = misc_register(&lpfc_mgmt_dev); |
| 10949 | if (error) |
| 10950 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 10951 | "misc_register returned with status %d", error); |
| 10952 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10953 | if (lpfc_enable_npiv) { |
| 10954 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 10955 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 10956 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10957 | lpfc_transport_template = |
| 10958 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10959 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10960 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10961 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10962 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10963 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 10964 | if (lpfc_vport_transport_template == NULL) { |
| 10965 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10966 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10967 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10968 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10969 | |
| 10970 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 10971 | lpfc_used_cpu = NULL; |
| 10972 | lpfc_present_cpu = 0; |
| 10973 | for_each_present_cpu(cpu) |
| 10974 | lpfc_present_cpu++; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10976 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10977 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10978 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10979 | if (lpfc_enable_npiv) |
| 10980 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10981 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10982 | |
| 10983 | return error; |
| 10984 | } |
| 10985 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10987 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10988 | * |
| 10989 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 10990 | * The special kernel macro module_exit() is used to indicate the role of |
| 10991 | * this routine to the kernel as lpfc module exit point. |
| 10992 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10993 | static void __exit |
| 10994 | lpfc_exit(void) |
| 10995 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10996 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10997 | pci_unregister_driver(&lpfc_driver); |
| 10998 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10999 | if (lpfc_enable_npiv) |
| 11000 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11001 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11002 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 11003 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11004 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 11005 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 11006 | } |
| 11007 | |
| 11008 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11009 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 11010 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 11011 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 11012 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 11013 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 11014 | kfree(lpfc_used_cpu); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11015 | } |
| 11016 | |
| 11017 | module_init(lpfc_init); |
| 11018 | module_exit(lpfc_exit); |
| 11019 | MODULE_LICENSE("GPL"); |
| 11020 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 11021 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 11022 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |