| 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 | d4379ac | 2012-03-01 22:37:07 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2012 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> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 37 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | #include <scsi/scsi_device.h> |
| 39 | #include <scsi/scsi_host.h> |
| 40 | #include <scsi/scsi_transport_fc.h> |
| 41 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 42 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_hw.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 46 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc_disc.h" |
| 48 | #include "lpfc_scsi.h" |
| 49 | #include "lpfc.h" |
| 50 | #include "lpfc_logmsg.h" |
| 51 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | #include "lpfc_version.h" |
| 54 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 55 | char *_dump_buf_data; |
| 56 | unsigned long _dump_buf_data_order; |
| 57 | char *_dump_buf_dif; |
| 58 | unsigned long _dump_buf_dif_order; |
| 59 | spinlock_t _dump_buf_lock; |
| 60 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 62 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 63 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 64 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 65 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 66 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 67 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
| 68 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 69 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 70 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 71 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 72 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 73 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 74 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 75 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 76 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 77 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | |
| 79 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 80 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 81 | static DEFINE_IDR(lpfc_hba_index); |
| 82 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 83 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 84 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 85 | * @phba: pointer to lpfc hba data structure. |
| 86 | * |
| 87 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 88 | * mailbox command. It retrieves the revision information from the HBA and |
| 89 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 90 | * configuration of the HBA. |
| 91 | * |
| 92 | * Return codes: |
| 93 | * 0 - success. |
| 94 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 95 | * Any other value - indicates an error. |
| 96 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 97 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 98 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | { |
| 100 | lpfc_vpd_t *vp = &phba->vpd; |
| 101 | int i = 0, rc; |
| 102 | LPFC_MBOXQ_t *pmb; |
| 103 | MAILBOX_t *mb; |
| 104 | char *lpfc_vpd_data = NULL; |
| 105 | uint16_t offset = 0; |
| 106 | static char licensed[56] = |
| 107 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 108 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 109 | |
| 110 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 111 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 112 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | return -ENOMEM; |
| 114 | } |
| 115 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 116 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 117 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | |
| 119 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 120 | if (init_key) { |
| 121 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 123 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 124 | *ptext = cpu_to_be32(*ptext); |
| 125 | init_key = 0; |
| 126 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 127 | |
| 128 | lpfc_read_nv(phba, pmb); |
| 129 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 130 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 131 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 132 | sizeof (licensed)); |
| 133 | |
| 134 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 135 | |
| 136 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 137 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 138 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 139 | "error, mbxCmd x%x READ_NVPARM, " |
| 140 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | mb->mbxCommand, mb->mbxStatus); |
| 142 | mempool_free(pmb, phba->mbox_mem_pool); |
| 143 | return -ERESTART; |
| 144 | } |
| 145 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 146 | sizeof(phba->wwnn)); |
| 147 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 148 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | } |
| 150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 151 | phba->sli3_options = 0x0; |
| 152 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | /* Setup and issue mailbox READ REV command */ |
| 154 | lpfc_read_rev(phba, pmb); |
| 155 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 156 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 158 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | mb->mbxCommand, mb->mbxStatus); |
| 161 | mempool_free( pmb, phba->mbox_mem_pool); |
| 162 | return -ERESTART; |
| 163 | } |
| 164 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 165 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 166 | /* |
| 167 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 168 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 170 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 171 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 173 | "0440 Adapter failed to init, READ_REV has " |
| 174 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 175 | mempool_free(pmb, phba->mbox_mem_pool); |
| 176 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | } |
| 178 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 179 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 180 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 181 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 182 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 183 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 185 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 186 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 187 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 188 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 189 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 190 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 191 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 192 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 193 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 194 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 195 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 196 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 197 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 198 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 199 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 200 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 201 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 202 | /* If the sli feature level is less then 9, we must |
| 203 | * tear down all RPIs and VPIs on link down if NPIV |
| 204 | * is enabled. |
| 205 | */ |
| 206 | if (vp->rev.feaLevelHigh < 9) |
| 207 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 208 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 210 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 211 | sizeof (phba->RandomData)); |
| 212 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 215 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 216 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 218 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 220 | |
| 221 | if (rc != MBX_SUCCESS) { |
| 222 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 223 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 224 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 226 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 227 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 228 | /* dump mem may return a zero when finished or we got a |
| 229 | * mailbox error, either way we are done. |
| 230 | */ |
| 231 | if (mb->un.varDmp.word_cnt == 0) |
| 232 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 233 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 234 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 235 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 236 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 239 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 240 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | |
| 242 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | out_free_mbox: |
| 244 | mempool_free(pmb, phba->mbox_mem_pool); |
| 245 | return 0; |
| 246 | } |
| 247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 249 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 250 | * @phba: pointer to lpfc hba data structure. |
| 251 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 252 | * |
| 253 | * This is the completion handler for driver's configuring asynchronous event |
| 254 | * mailbox command to the device. If the mailbox command returns successfully, |
| 255 | * it will set internal async event support flag to 1; otherwise, it will |
| 256 | * set internal async event support flag to 0. |
| 257 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 258 | static void |
| 259 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 260 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 261 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 262 | phba->temp_sensor_support = 1; |
| 263 | else |
| 264 | phba->temp_sensor_support = 0; |
| 265 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 266 | return; |
| 267 | } |
| 268 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 269 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 270 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 271 | * @phba: pointer to lpfc hba data structure. |
| 272 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 273 | * |
| 274 | * This is the completion handler for dump mailbox command for getting |
| 275 | * wake up parameters. When this command complete, the response contain |
| 276 | * Option rom version of the HBA. This function translate the version number |
| 277 | * into a human readable string and store it in OptionROMVersion. |
| 278 | **/ |
| 279 | static void |
| 280 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 281 | { |
| 282 | struct prog_id *prg; |
| 283 | uint32_t prog_id_word; |
| 284 | char dist = ' '; |
| 285 | /* character array used for decoding dist type. */ |
| 286 | char dist_char[] = "nabx"; |
| 287 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 288 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 289 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 290 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 291 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 292 | |
| 293 | prg = (struct prog_id *) &prog_id_word; |
| 294 | |
| 295 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 296 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 297 | |
| 298 | /* Decode the Option rom version word to a readable string */ |
| 299 | if (prg->dist < 4) |
| 300 | dist = dist_char[prg->dist]; |
| 301 | |
| 302 | if ((prg->dist == 3) && (prg->num == 0)) |
| 303 | sprintf(phba->OptionROMVersion, "%d.%d%d", |
| 304 | prg->ver, prg->rev, prg->lev); |
| 305 | else |
| 306 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", |
| 307 | prg->ver, prg->rev, prg->lev, |
| 308 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 309 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
| 313 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 314 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 315 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 316 | * @vport: pointer to lpfc vport data structure. |
| 317 | * |
| 318 | * |
| 319 | * Return codes |
| 320 | * None. |
| 321 | **/ |
| 322 | void |
| 323 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 324 | { |
| 325 | /* If the soft name exists then update it using the service params */ |
| 326 | if (vport->phba->cfg_soft_wwnn) |
| 327 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 328 | vport->fc_sparam.nodeName.u.wwn); |
| 329 | if (vport->phba->cfg_soft_wwpn) |
| 330 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 331 | vport->fc_sparam.portName.u.wwn); |
| 332 | |
| 333 | /* |
| 334 | * If the name is empty or there exists a soft name |
| 335 | * then copy the service params name, otherwise use the fc name |
| 336 | */ |
| 337 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 338 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 339 | sizeof(struct lpfc_name)); |
| 340 | else |
| 341 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 342 | sizeof(struct lpfc_name)); |
| 343 | |
| 344 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) |
| 345 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 346 | sizeof(struct lpfc_name)); |
| 347 | else |
| 348 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 349 | sizeof(struct lpfc_name)); |
| 350 | } |
| 351 | |
| 352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 353 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 354 | * @phba: pointer to lpfc hba data structure. |
| 355 | * |
| 356 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 357 | * command call. It performs all internal resource and state setups on the |
| 358 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 359 | * ELS ring timers, etc. |
| 360 | * |
| 361 | * Return codes |
| 362 | * 0 - success. |
| 363 | * Any other value - error. |
| 364 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 365 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 366 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 367 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 368 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 369 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 370 | LPFC_MBOXQ_t *pmb; |
| 371 | MAILBOX_t *mb; |
| 372 | struct lpfc_dmabuf *mp; |
| 373 | struct lpfc_sli *psli = &phba->sli; |
| 374 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 375 | int i, j; |
| 376 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 377 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 378 | spin_lock_irq(&phba->hbalock); |
| 379 | /* |
| 380 | * If the Config port completed correctly the HBA is not |
| 381 | * over heated any more. |
| 382 | */ |
| 383 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 384 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 385 | spin_unlock_irq(&phba->hbalock); |
| 386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 388 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 389 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | return -ENOMEM; |
| 391 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 392 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 393 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 394 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 395 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 396 | if (rc) { |
| 397 | mempool_free(pmb, phba->mbox_mem_pool); |
| 398 | return -ENOMEM; |
| 399 | } |
| 400 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 401 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 402 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 404 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 407 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 409 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 411 | kfree(mp); |
| 412 | return -EIO; |
| 413 | } |
| 414 | |
| 415 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 416 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 417 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 418 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 419 | kfree(mp); |
| 420 | pmb->context1 = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 421 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 422 | |
| 423 | /* Update the fc_host data structures with new wwn. */ |
| 424 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 425 | 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] | 426 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 429 | /* This should be consolidated into parse_vpd ? - mr */ |
| 430 | if (phba->SerialNumber[0] == 0) { |
| 431 | uint8_t *outptr; |
| 432 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 433 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | for (i = 0; i < 12; i++) { |
| 435 | status = *outptr++; |
| 436 | j = ((status & 0xf0) >> 4); |
| 437 | if (j <= 9) |
| 438 | phba->SerialNumber[i] = |
| 439 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 440 | else |
| 441 | phba->SerialNumber[i] = |
| 442 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 443 | i++; |
| 444 | j = (status & 0xf); |
| 445 | if (j <= 9) |
| 446 | phba->SerialNumber[i] = |
| 447 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 448 | else |
| 449 | phba->SerialNumber[i] = |
| 450 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 451 | } |
| 452 | } |
| 453 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 454 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 455 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 458 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 459 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | mempool_free( pmb, phba->mbox_mem_pool); |
| 463 | return -EIO; |
| 464 | } |
| 465 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 466 | /* Check if the port is disabled */ |
| 467 | lpfc_sli_read_link_ste(phba); |
| 468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 469 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 470 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 471 | phba->cfg_hba_queue_depth = |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 472 | (mb->un.varRdConfig.max_xri + 1) - |
| 473 | lpfc_sli4_get_els_iocb_cnt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | |
| 475 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 476 | |
| 477 | /* Get the default values for Model Name and Description */ |
| 478 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 479 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 480 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 481 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 482 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 483 | if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr) |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 484 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 485 | if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 487 | if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 489 | |
| 490 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 491 | if (phba->sli_rev != 3) |
| 492 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 494 | /* |
| 495 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 496 | */ |
| 497 | if (phba->intr_type == MSIX) { |
| 498 | rc = lpfc_config_msi(phba, pmb); |
| 499 | if (rc) { |
| 500 | mempool_free(pmb, phba->mbox_mem_pool); |
| 501 | return -EIO; |
| 502 | } |
| 503 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 504 | if (rc != MBX_SUCCESS) { |
| 505 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 506 | "0352 Config MSI mailbox command " |
| 507 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 508 | pmb->u.mb.mbxCommand, |
| 509 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 510 | mempool_free(pmb, phba->mbox_mem_pool); |
| 511 | return -EIO; |
| 512 | } |
| 513 | } |
| 514 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 515 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 516 | /* Initialize ERATT handling flag */ |
| 517 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 518 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 519 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 520 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 521 | spin_unlock_irq(&phba->hbalock); |
| 522 | return -EIO; |
| 523 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 525 | if (psli->num_rings > 0) |
| 526 | status |= HC_R0INT_ENA; |
| 527 | if (psli->num_rings > 1) |
| 528 | status |= HC_R1INT_ENA; |
| 529 | if (psli->num_rings > 2) |
| 530 | status |= HC_R2INT_ENA; |
| 531 | if (psli->num_rings > 3) |
| 532 | status |= HC_R3INT_ENA; |
| 533 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 534 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 535 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 536 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 537 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | writel(status, phba->HCregaddr); |
| 539 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 540 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 542 | /* Set up ring-0 (ELS) timer */ |
| 543 | timeout = phba->fc_ratov * 2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 544 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 545 | /* Set up heart beat (HB) timer */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 546 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 547 | phba->hb_outstanding = 0; |
| 548 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 549 | /* Set up error attention (ERATT) polling timer */ |
| 550 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 551 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 552 | if (phba->hba_flag & LINK_DISABLED) { |
| 553 | lpfc_printf_log(phba, |
| 554 | KERN_ERR, LOG_INIT, |
| 555 | "2598 Adapter Link is disabled.\n"); |
| 556 | lpfc_down_link(phba, pmb); |
| 557 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 558 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 559 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 560 | lpfc_printf_log(phba, |
| 561 | KERN_ERR, LOG_INIT, |
| 562 | "2599 Adapter failed to issue DOWN_LINK" |
| 563 | " mbox command rc 0x%x\n", rc); |
| 564 | |
| 565 | mempool_free(pmb, phba->mbox_mem_pool); |
| 566 | return -EIO; |
| 567 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 568 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 569 | mempool_free(pmb, phba->mbox_mem_pool); |
| 570 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 571 | if (rc) |
| 572 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 573 | } |
| 574 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 575 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 576 | if (!pmb) { |
| 577 | phba->link_state = LPFC_HBA_ERROR; |
| 578 | return -ENOMEM; |
| 579 | } |
| 580 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 581 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 582 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 583 | pmb->vport = phba->pport; |
| 584 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 585 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 586 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 587 | lpfc_printf_log(phba, |
| 588 | KERN_ERR, |
| 589 | LOG_INIT, |
| 590 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 591 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 592 | rc); |
| 593 | mempool_free(pmb, phba->mbox_mem_pool); |
| 594 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 595 | |
| 596 | /* Get Option rom version */ |
| 597 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 598 | if (!pmb) { |
| 599 | phba->link_state = LPFC_HBA_ERROR; |
| 600 | return -ENOMEM; |
| 601 | } |
| 602 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 603 | lpfc_dump_wakeup_param(phba, pmb); |
| 604 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 605 | pmb->vport = phba->pport; |
| 606 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 607 | |
| 608 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 610 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 611 | mempool_free(pmb, phba->mbox_mem_pool); |
| 612 | } |
| 613 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 614 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 615 | } |
| 616 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 617 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 618 | * lpfc_hba_init_link - Initialize the FC link |
| 619 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 620 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 621 | * |
| 622 | * This routine will issue the INIT_LINK mailbox command call. |
| 623 | * It is available to other drivers through the lpfc_hba data |
| 624 | * structure for use as a delayed link up mechanism with the |
| 625 | * module parameter lpfc_suppress_link_up. |
| 626 | * |
| 627 | * Return code |
| 628 | * 0 - success |
| 629 | * Any other value - error |
| 630 | **/ |
| 631 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 632 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 633 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 634 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 639 | * @phba: pointer to lpfc hba data structure. |
| 640 | * @fc_topology: desired fc topology. |
| 641 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 642 | * |
| 643 | * This routine will issue the INIT_LINK mailbox command call. |
| 644 | * It is available to other drivers through the lpfc_hba data |
| 645 | * structure for use as a delayed link up mechanism with the |
| 646 | * module parameter lpfc_suppress_link_up. |
| 647 | * |
| 648 | * Return code |
| 649 | * 0 - success |
| 650 | * Any other value - error |
| 651 | **/ |
| 652 | int |
| 653 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 654 | uint32_t flag) |
| 655 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 656 | struct lpfc_vport *vport = phba->pport; |
| 657 | LPFC_MBOXQ_t *pmb; |
| 658 | MAILBOX_t *mb; |
| 659 | int rc; |
| 660 | |
| 661 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 662 | if (!pmb) { |
| 663 | phba->link_state = LPFC_HBA_ERROR; |
| 664 | return -ENOMEM; |
| 665 | } |
| 666 | mb = &pmb->u.mb; |
| 667 | pmb->vport = vport; |
| 668 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 669 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 670 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 671 | !(phba->lmt & LMT_1Gb)) || |
| 672 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 673 | !(phba->lmt & LMT_2Gb)) || |
| 674 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 675 | !(phba->lmt & LMT_4Gb)) || |
| 676 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 677 | !(phba->lmt & LMT_8Gb)) || |
| 678 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 679 | !(phba->lmt & LMT_10Gb)) || |
| 680 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
| 681 | !(phba->lmt & LMT_16Gb))) { |
| 682 | /* Reset link speed to auto */ |
| 683 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 684 | "1302 Invalid speed for this board:%d " |
| 685 | "Reset link speed to auto.\n", |
| 686 | phba->cfg_link_speed); |
| 687 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 688 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 689 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 690 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 691 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 692 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 693 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 694 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 696 | "0498 Adapter failed to init, mbxCmd x%x " |
| 697 | "INIT_LINK, mbxStatus x%x\n", |
| 698 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 699 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 700 | /* Clear all interrupt enable conditions */ |
| 701 | writel(0, phba->HCregaddr); |
| 702 | readl(phba->HCregaddr); /* flush */ |
| 703 | /* Clear all pending interrupts */ |
| 704 | writel(0xffffffff, phba->HAregaddr); |
| 705 | readl(phba->HAregaddr); /* flush */ |
| 706 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 707 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 708 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 709 | mempool_free(pmb, phba->mbox_mem_pool); |
| 710 | return -EIO; |
| 711 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 712 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 713 | if (flag == MBX_POLL) |
| 714 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 721 | * @phba: pointer to lpfc hba data structure. |
| 722 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 723 | * |
| 724 | * This routine will issue the DOWN_LINK mailbox command call. |
| 725 | * It is available to other drivers through the lpfc_hba data |
| 726 | * structure for use to stop the link. |
| 727 | * |
| 728 | * Return code |
| 729 | * 0 - success |
| 730 | * Any other value - error |
| 731 | **/ |
| 732 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 733 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 734 | { |
| 735 | LPFC_MBOXQ_t *pmb; |
| 736 | int rc; |
| 737 | |
| 738 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 739 | if (!pmb) { |
| 740 | phba->link_state = LPFC_HBA_ERROR; |
| 741 | return -ENOMEM; |
| 742 | } |
| 743 | |
| 744 | lpfc_printf_log(phba, |
| 745 | KERN_ERR, LOG_INIT, |
| 746 | "0491 Adapter Link is disabled.\n"); |
| 747 | lpfc_down_link(phba, pmb); |
| 748 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 749 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 750 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 751 | lpfc_printf_log(phba, |
| 752 | KERN_ERR, LOG_INIT, |
| 753 | "2522 Adapter failed to issue DOWN_LINK" |
| 754 | " mbox command rc 0x%x\n", rc); |
| 755 | |
| 756 | mempool_free(pmb, phba->mbox_mem_pool); |
| 757 | return -EIO; |
| 758 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 759 | if (flag == MBX_POLL) |
| 760 | mempool_free(pmb, phba->mbox_mem_pool); |
| 761 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 766 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 767 | * @phba: pointer to lpfc HBA data structure. |
| 768 | * |
| 769 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 770 | * bringing down the SLI Layer. |
| 771 | * |
| 772 | * Return codes |
| 773 | * 0 - success. |
| 774 | * Any other value - error. |
| 775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 779 | struct lpfc_vport **vports; |
| 780 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 781 | |
| 782 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 783 | /* Disable interrupts */ |
| 784 | writel(0, phba->HCregaddr); |
| 785 | readl(phba->HCregaddr); /* flush */ |
| 786 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 787 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 788 | if (phba->pport->load_flag & FC_UNLOADING) |
| 789 | lpfc_cleanup_discovery_resources(phba->pport); |
| 790 | else { |
| 791 | vports = lpfc_create_vport_work_array(phba); |
| 792 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 793 | for (i = 0; i <= phba->max_vports && |
| 794 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 795 | lpfc_cleanup_discovery_resources(vports[i]); |
| 796 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 797 | } |
| 798 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | } |
| 800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 801 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 802 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 803 | * @phba: pointer to lpfc HBA data structure. |
| 804 | * |
| 805 | * This routine will do uninitialization after the HBA is reset when bring |
| 806 | * down the SLI Layer. |
| 807 | * |
| 808 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 809 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 810 | * Any other value - error. |
| 811 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 812 | static int |
| 813 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 814 | { |
| 815 | struct lpfc_sli *psli = &phba->sli; |
| 816 | struct lpfc_sli_ring *pring; |
| 817 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 818 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 819 | int i; |
| 820 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 821 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 822 | lpfc_sli_hbqbuf_free_all(phba); |
| 823 | else { |
| 824 | /* Cleanup preposted buffers on the ELS ring */ |
| 825 | pring = &psli->ring[LPFC_ELS_RING]; |
| 826 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 827 | list_del(&mp->list); |
| 828 | pring->postbufq_cnt--; |
| 829 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 830 | kfree(mp); |
| 831 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 832 | } |
| 833 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 834 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 835 | for (i = 0; i < psli->num_rings; i++) { |
| 836 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 837 | |
| 838 | /* At this point in time the HBA is either reset or DOA. Either |
| 839 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 840 | */ |
| 841 | list_splice_init(&pring->txcmplq, &completions); |
| 842 | pring->txcmplq_cnt = 0; |
| 843 | spin_unlock_irq(&phba->hbalock); |
| 844 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 845 | /* Cancel all the IOCBs from the completions list */ |
| 846 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 847 | IOERR_SLI_ABORTED); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 848 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 849 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 850 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 851 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 852 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 853 | |
| 854 | return 0; |
| 855 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 856 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 857 | /** |
| 858 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 859 | * @phba: pointer to lpfc HBA data structure. |
| 860 | * |
| 861 | * This routine will do uninitialization after the HBA is reset when bring |
| 862 | * down the SLI Layer. |
| 863 | * |
| 864 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 865 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 866 | * Any other value - error. |
| 867 | **/ |
| 868 | static int |
| 869 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 870 | { |
| 871 | struct lpfc_scsi_buf *psb, *psb_next; |
| 872 | LIST_HEAD(aborts); |
| 873 | int ret; |
| 874 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 875 | struct lpfc_sglq *sglq_entry = NULL; |
| 876 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 877 | ret = lpfc_hba_down_post_s3(phba); |
| 878 | if (ret) |
| 879 | return ret; |
| 880 | /* At this point in time the HBA is either reset or DOA. Either |
| 881 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 882 | * on the lpfc_sgl_list so that it can either be freed if the |
| 883 | * driver is unloading or reposted if the driver is restarting |
| 884 | * the port. |
| 885 | */ |
| 886 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 887 | /* scsl_buf_list */ |
| 888 | /* abts_sgl_list_lock required because worker thread uses this |
| 889 | * list. |
| 890 | */ |
| 891 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 892 | list_for_each_entry(sglq_entry, |
| 893 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 894 | sglq_entry->state = SGL_FREED; |
| 895 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 896 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 897 | &phba->sli4_hba.lpfc_sgl_list); |
| 898 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 899 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 900 | * list. |
| 901 | */ |
| 902 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 903 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 904 | &aborts); |
| 905 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 906 | spin_unlock_irq(&phba->hbalock); |
| 907 | |
| 908 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 909 | psb->pCmd = NULL; |
| 910 | psb->status = IOSTAT_SUCCESS; |
| 911 | } |
| 912 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
| 913 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); |
| 914 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 920 | * @phba: pointer to lpfc HBA data structure. |
| 921 | * |
| 922 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 923 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 924 | * |
| 925 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 926 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 927 | * Any other value - error. |
| 928 | **/ |
| 929 | int |
| 930 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 931 | { |
| 932 | return (*phba->lpfc_hba_down_post)(phba); |
| 933 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 934 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 935 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 936 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 937 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 938 | * |
| 939 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 940 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 941 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 942 | * event will be used by the worker thread to invoke the actual timeout |
| 943 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 944 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 945 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 946 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 947 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 948 | lpfc_hb_timeout(unsigned long ptr) |
| 949 | { |
| 950 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 951 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 952 | unsigned long iflag; |
| 953 | |
| 954 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 955 | |
| 956 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 957 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 958 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 959 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 960 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 961 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 962 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 963 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 964 | if (!tmo_posted) |
| 965 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 966 | return; |
| 967 | } |
| 968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 969 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 970 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 971 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 972 | * |
| 973 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 974 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 975 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 976 | * event will be used by the worker thread to invoke the actual timeout |
| 977 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 978 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 979 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 980 | **/ |
| 981 | static void |
| 982 | lpfc_rrq_timeout(unsigned long ptr) |
| 983 | { |
| 984 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 985 | unsigned long iflag; |
| 986 | |
| 987 | phba = (struct lpfc_hba *)ptr; |
| 988 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 989 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 990 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 991 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 995 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 996 | * @phba: pointer to lpfc hba data structure. |
| 997 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 998 | * |
| 999 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1000 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1001 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1002 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1003 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1004 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1005 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1006 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1007 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1008 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1009 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1010 | static void |
| 1011 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1012 | { |
| 1013 | unsigned long drvr_flag; |
| 1014 | |
| 1015 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1016 | phba->hb_outstanding = 0; |
| 1017 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1018 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1019 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1020 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1021 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1022 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1023 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1024 | mod_timer(&phba->hb_tmofunc, |
| 1025 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 1026 | return; |
| 1027 | } |
| 1028 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1029 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1030 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1031 | * @phba: pointer to lpfc hba data structure. |
| 1032 | * |
| 1033 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1034 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1035 | * handler performs any periodic operations needed for the device. If such |
| 1036 | * periodic event has already been attended to either in the interrupt handler |
| 1037 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1038 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1039 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1040 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1041 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1042 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1043 | * to offline. |
| 1044 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1045 | void |
| 1046 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1047 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1048 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1049 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1050 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1051 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1052 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1053 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1054 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1055 | vports = lpfc_create_vport_work_array(phba); |
| 1056 | if (vports != NULL) |
| 1057 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1058 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1059 | lpfc_destroy_vport_work_array(phba, vports); |
| 1060 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1061 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1062 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1063 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1064 | return; |
| 1065 | |
| 1066 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1067 | |
| 1068 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 1069 | jiffies)) { |
| 1070 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1071 | if (!phba->hb_outstanding) |
| 1072 | mod_timer(&phba->hb_tmofunc, |
| 1073 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 1074 | else |
| 1075 | mod_timer(&phba->hb_tmofunc, |
| 1076 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 1077 | return; |
| 1078 | } |
| 1079 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1080 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1081 | if (phba->elsbuf_cnt && |
| 1082 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1083 | spin_lock_irq(&phba->hbalock); |
| 1084 | list_splice_init(&phba->elsbuf, &completions); |
| 1085 | phba->elsbuf_cnt = 0; |
| 1086 | phba->elsbuf_prev_cnt = 0; |
| 1087 | spin_unlock_irq(&phba->hbalock); |
| 1088 | |
| 1089 | while (!list_empty(&completions)) { |
| 1090 | list_remove_head(&completions, buf_ptr, |
| 1091 | struct lpfc_dmabuf, list); |
| 1092 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1093 | kfree(buf_ptr); |
| 1094 | } |
| 1095 | } |
| 1096 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1097 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1098 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1099 | if (phba->cfg_enable_hba_heartbeat) { |
| 1100 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1101 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1102 | (list_empty(&psli->mboxq))) { |
| 1103 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1104 | GFP_KERNEL); |
| 1105 | if (!pmboxq) { |
| 1106 | mod_timer(&phba->hb_tmofunc, |
| 1107 | jiffies + |
| 1108 | HZ * LPFC_HB_MBOX_INTERVAL); |
| 1109 | return; |
| 1110 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1111 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1112 | lpfc_heart_beat(phba, pmboxq); |
| 1113 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1114 | pmboxq->vport = phba->pport; |
| 1115 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1116 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1117 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1118 | if (retval != MBX_BUSY && |
| 1119 | retval != MBX_SUCCESS) { |
| 1120 | mempool_free(pmboxq, |
| 1121 | phba->mbox_mem_pool); |
| 1122 | mod_timer(&phba->hb_tmofunc, |
| 1123 | jiffies + |
| 1124 | HZ * LPFC_HB_MBOX_INTERVAL); |
| 1125 | return; |
| 1126 | } |
| 1127 | phba->skipped_hb = 0; |
| 1128 | phba->hb_outstanding = 1; |
| 1129 | } else if (time_before_eq(phba->last_completion_time, |
| 1130 | phba->skipped_hb)) { |
| 1131 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1132 | "2857 Last completion time not " |
| 1133 | " updated in %d ms\n", |
| 1134 | jiffies_to_msecs(jiffies |
| 1135 | - phba->last_completion_time)); |
| 1136 | } else |
| 1137 | phba->skipped_hb = jiffies; |
| 1138 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1139 | mod_timer(&phba->hb_tmofunc, |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1140 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1141 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1142 | } else { |
| 1143 | /* |
| 1144 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1145 | * we need to give the hb mailbox cmd a chance to |
| 1146 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1147 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1148 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1149 | "0459 Adapter heartbeat still out" |
| 1150 | "standing:last compl time was %d ms.\n", |
| 1151 | jiffies_to_msecs(jiffies |
| 1152 | - phba->last_completion_time)); |
| 1153 | mod_timer(&phba->hb_tmofunc, |
| 1154 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1155 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1160 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1161 | * @phba: pointer to lpfc hba data structure. |
| 1162 | * |
| 1163 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1164 | * other than Port Error 6 has been detected. |
| 1165 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1166 | static void |
| 1167 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1168 | { |
| 1169 | struct lpfc_sli *psli = &phba->sli; |
| 1170 | |
| 1171 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1172 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1173 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1174 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1175 | |
| 1176 | lpfc_offline(phba); |
| 1177 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1178 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1179 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1180 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1181 | lpfc_hba_down_post(phba); |
| 1182 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1183 | lpfc_unblock_mgmt_io(phba); |
| 1184 | phba->link_state = LPFC_HBA_ERROR; |
| 1185 | return; |
| 1186 | } |
| 1187 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1189 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1190 | * @phba: pointer to lpfc hba data structure. |
| 1191 | * |
| 1192 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1193 | * other than Port Error 6 has been detected. |
| 1194 | **/ |
| 1195 | static void |
| 1196 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1197 | { |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1198 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1199 | lpfc_offline(phba); |
| 1200 | lpfc_sli4_brdreset(phba); |
| 1201 | lpfc_hba_down_post(phba); |
| 1202 | lpfc_sli4_post_status_check(phba); |
| 1203 | lpfc_unblock_mgmt_io(phba); |
| 1204 | phba->link_state = LPFC_HBA_ERROR; |
| 1205 | } |
| 1206 | |
| 1207 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1208 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1209 | * @phba: pointer to lpfc hba data structure. |
| 1210 | * |
| 1211 | * This routine is invoked to handle the deferred HBA hardware error |
| 1212 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1213 | * and another ER bit in the host status register. The driver will |
| 1214 | * wait until the ER1 bit clears before handling the error condition. |
| 1215 | **/ |
| 1216 | static void |
| 1217 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1218 | { |
| 1219 | uint32_t old_host_status = phba->work_hs; |
| 1220 | struct lpfc_sli_ring *pring; |
| 1221 | struct lpfc_sli *psli = &phba->sli; |
| 1222 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1223 | /* If the pci channel is offline, ignore possible errors, |
| 1224 | * since we cannot communicate with the pci card anyway. |
| 1225 | */ |
| 1226 | if (pci_channel_offline(phba->pcidev)) { |
| 1227 | spin_lock_irq(&phba->hbalock); |
| 1228 | phba->hba_flag &= ~DEFER_ERATT; |
| 1229 | spin_unlock_irq(&phba->hbalock); |
| 1230 | return; |
| 1231 | } |
| 1232 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1234 | "0479 Deferred Adapter Hardware Error " |
| 1235 | "Data: x%x x%x x%x\n", |
| 1236 | phba->work_hs, |
| 1237 | phba->work_status[0], phba->work_status[1]); |
| 1238 | |
| 1239 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1240 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1241 | spin_unlock_irq(&phba->hbalock); |
| 1242 | |
| 1243 | |
| 1244 | /* |
| 1245 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1246 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1247 | * SCSI layer retry it after re-establishing link. |
| 1248 | */ |
| 1249 | pring = &psli->ring[psli->fcp_ring]; |
| 1250 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1251 | |
| 1252 | /* |
| 1253 | * There was a firmware error. Take the hba offline and then |
| 1254 | * attempt to restart it. |
| 1255 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1256 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1257 | lpfc_offline(phba); |
| 1258 | |
| 1259 | /* Wait for the ER1 bit to clear.*/ |
| 1260 | while (phba->work_hs & HS_FFER1) { |
| 1261 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1262 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1263 | phba->work_hs = UNPLUG_ERR ; |
| 1264 | break; |
| 1265 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1266 | /* If driver is unloading let the worker thread continue */ |
| 1267 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1268 | phba->work_hs = 0; |
| 1269 | break; |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | /* |
| 1274 | * This is to ptrotect against a race condition in which |
| 1275 | * first write to the host attention register clear the |
| 1276 | * host status register. |
| 1277 | */ |
| 1278 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1279 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1280 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1281 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1282 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1283 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1284 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1285 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1286 | } |
| 1287 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1288 | static void |
| 1289 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1290 | { |
| 1291 | struct lpfc_board_event_header board_event; |
| 1292 | struct Scsi_Host *shost; |
| 1293 | |
| 1294 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1295 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1296 | shost = lpfc_shost_from_vport(phba->pport); |
| 1297 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1298 | sizeof(board_event), |
| 1299 | (char *) &board_event, |
| 1300 | LPFC_NL_VENDOR_ID); |
| 1301 | } |
| 1302 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1303 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1304 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1305 | * @phba: pointer to lpfc hba data structure. |
| 1306 | * |
| 1307 | * This routine is invoked to handle the following HBA hardware error |
| 1308 | * conditions: |
| 1309 | * 1 - HBA error attention interrupt |
| 1310 | * 2 - DMA ring index out of range |
| 1311 | * 3 - Mailbox command came back as unknown |
| 1312 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1313 | static void |
| 1314 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1315 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1316 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1317 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1319 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1320 | unsigned long temperature; |
| 1321 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1322 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1323 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1324 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1325 | * since we cannot communicate with the pci card anyway. |
| 1326 | */ |
| 1327 | if (pci_channel_offline(phba->pcidev)) { |
| 1328 | spin_lock_irq(&phba->hbalock); |
| 1329 | phba->hba_flag &= ~DEFER_ERATT; |
| 1330 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1331 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1334 | /* If resets are disabled then leave the HBA alone and return */ |
| 1335 | if (!phba->cfg_enable_hba_reset) |
| 1336 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1338 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1339 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1340 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1341 | if (phba->hba_flag & DEFER_ERATT) |
| 1342 | lpfc_handle_deferred_eratt(phba); |
| 1343 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1344 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1345 | if (phba->work_hs & HS_FFER6) |
| 1346 | /* Re-establishing Link */ |
| 1347 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1348 | "1301 Re-establishing Link " |
| 1349 | "Data: x%x x%x x%x\n", |
| 1350 | phba->work_hs, phba->work_status[0], |
| 1351 | phba->work_status[1]); |
| 1352 | if (phba->work_hs & HS_FFER8) |
| 1353 | /* Device Zeroization */ |
| 1354 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1355 | "2861 Host Authentication device " |
| 1356 | "zeroization Data:x%x x%x x%x\n", |
| 1357 | phba->work_hs, phba->work_status[0], |
| 1358 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1359 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1360 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1361 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1362 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | |
| 1364 | /* |
| 1365 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1366 | * That could cause the I/Os dropped by the firmware. |
| 1367 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1368 | * retry it after re-establishing link. |
| 1369 | */ |
| 1370 | pring = &psli->ring[psli->fcp_ring]; |
| 1371 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1372 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | /* |
| 1374 | * There was a firmware error. Take the hba offline and then |
| 1375 | * attempt to restart it. |
| 1376 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1377 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1379 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1381 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | return; |
| 1383 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1384 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1385 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1386 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1387 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1388 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1389 | temp_event_data.data = (uint32_t)temperature; |
| 1390 | |
| 1391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1392 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1393 | "(%ld), taking this port offline " |
| 1394 | "Data: x%x x%x x%x\n", |
| 1395 | temperature, phba->work_hs, |
| 1396 | phba->work_status[0], phba->work_status[1]); |
| 1397 | |
| 1398 | shost = lpfc_shost_from_vport(phba->pport); |
| 1399 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1400 | sizeof(temp_event_data), |
| 1401 | (char *) &temp_event_data, |
| 1402 | SCSI_NL_VID_TYPE_PCI |
| 1403 | | PCI_VENDOR_ID_EMULEX); |
| 1404 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1405 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1406 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1407 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1408 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1409 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | } else { |
| 1411 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1412 | * failure is a value other than FFER6. Do not call the offline |
| 1413 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | */ |
| 1415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1416 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1418 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | phba->work_status[0], phba->work_status[1]); |
| 1420 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1421 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1422 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1424 | sizeof(event_data), (char *) &event_data, |
| 1425 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1426 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1427 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1429 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | } |
| 1431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1432 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1433 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1434 | * @phba: pointer to lpfc hba data structure. |
| 1435 | * @mbx_action: flag for mailbox shutdown action. |
| 1436 | * |
| 1437 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1438 | * response to port status register polling attention. It waits for port |
| 1439 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1440 | * During this process, interrupt vectors are freed and later requested |
| 1441 | * for handling possible port resource change. |
| 1442 | **/ |
| 1443 | static int |
| 1444 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action) |
| 1445 | { |
| 1446 | int rc; |
| 1447 | uint32_t intr_mode; |
| 1448 | |
| 1449 | /* |
| 1450 | * On error status condition, driver need to wait for port |
| 1451 | * ready before performing reset. |
| 1452 | */ |
| 1453 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1454 | if (!rc) { |
| 1455 | /* need reset: attempt for port recovery */ |
| 1456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1457 | "2887 Reset Needed: Attempting Port " |
| 1458 | "Recovery...\n"); |
| 1459 | lpfc_offline_prep(phba, mbx_action); |
| 1460 | lpfc_offline(phba); |
| 1461 | /* release interrupt for possible resource change */ |
| 1462 | lpfc_sli4_disable_intr(phba); |
| 1463 | lpfc_sli_brdrestart(phba); |
| 1464 | /* request and enable interrupt */ |
| 1465 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1466 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1468 | "3175 Failed to enable interrupt\n"); |
| 1469 | return -EIO; |
| 1470 | } else { |
| 1471 | phba->intr_mode = intr_mode; |
| 1472 | } |
| 1473 | rc = lpfc_online(phba); |
| 1474 | if (rc == 0) |
| 1475 | lpfc_unblock_mgmt_io(phba); |
| 1476 | } |
| 1477 | return rc; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1481 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1482 | * @phba: pointer to lpfc hba data structure. |
| 1483 | * |
| 1484 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1485 | * conditions. |
| 1486 | **/ |
| 1487 | static void |
| 1488 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1489 | { |
| 1490 | struct lpfc_vport *vport = phba->pport; |
| 1491 | uint32_t event_data; |
| 1492 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1493 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1494 | struct lpfc_register portstat_reg = {0}; |
| 1495 | uint32_t reg_err1, reg_err2; |
| 1496 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1497 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1498 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1499 | |
| 1500 | /* If the pci channel is offline, ignore possible errors, since |
| 1501 | * we cannot communicate with the pci card anyway. |
| 1502 | */ |
| 1503 | if (pci_channel_offline(phba->pcidev)) |
| 1504 | return; |
| 1505 | /* If resets are disabled then leave the HBA alone and return */ |
| 1506 | if (!phba->cfg_enable_hba_reset) |
| 1507 | return; |
| 1508 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1509 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1510 | switch (if_type) { |
| 1511 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1512 | pci_rd_rc1 = lpfc_readl( |
| 1513 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1514 | &uerrlo_reg); |
| 1515 | pci_rd_rc2 = lpfc_readl( |
| 1516 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1517 | &uemasklo_reg); |
| 1518 | /* consider PCI bus read error as pci_channel_offline */ |
| 1519 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1520 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1521 | lpfc_sli4_offline_eratt(phba); |
| 1522 | break; |
| 1523 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1524 | pci_rd_rc1 = lpfc_readl( |
| 1525 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1526 | &portstat_reg.word0); |
| 1527 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1528 | if (pci_rd_rc1 == -EIO) { |
| 1529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1530 | "3151 PCI bus read access failure: x%x\n", |
| 1531 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1532 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1533 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1534 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1535 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1536 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
| 1537 | /* TODO: Register for Overtemp async events. */ |
| 1538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1539 | "2889 Port Overtemperature event, " |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 1540 | "taking port offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1541 | spin_lock_irq(&phba->hbalock); |
| 1542 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1543 | spin_unlock_irq(&phba->hbalock); |
| 1544 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1545 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1546 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1547 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1548 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) |
| 1549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1550 | "3143 Port Down: Firmware Restarted\n"); |
| 1551 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1552 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1554 | "3144 Port Down: Debug Dump\n"); |
| 1555 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1556 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1558 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1559 | |
| 1560 | /* Check port status register for function reset */ |
| 1561 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT); |
| 1562 | if (rc == 0) { |
| 1563 | /* don't report event on forced debug dump */ |
| 1564 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1565 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1566 | return; |
| 1567 | else |
| 1568 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1569 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1570 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1572 | "3152 Unrecoverable error, bring the port " |
| 1573 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1574 | lpfc_sli4_offline_eratt(phba); |
| 1575 | break; |
| 1576 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1577 | default: |
| 1578 | break; |
| 1579 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1580 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1581 | "3123 Report dump event to upper layer\n"); |
| 1582 | /* Send an internal error event to mgmt application */ |
| 1583 | lpfc_board_errevt_to_mgmt(phba); |
| 1584 | |
| 1585 | event_data = FC_REG_DUMP_EVENT; |
| 1586 | shost = lpfc_shost_from_vport(vport); |
| 1587 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1588 | sizeof(event_data), (char *) &event_data, |
| 1589 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /** |
| 1593 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1594 | * @phba: pointer to lpfc HBA data structure. |
| 1595 | * |
| 1596 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1597 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1598 | * |
| 1599 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1600 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1601 | * Any other value - error. |
| 1602 | **/ |
| 1603 | void |
| 1604 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1605 | { |
| 1606 | (*phba->lpfc_handle_eratt)(phba); |
| 1607 | } |
| 1608 | |
| 1609 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1610 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1611 | * @phba: pointer to lpfc hba data structure. |
| 1612 | * |
| 1613 | * This routine is invoked from the worker thread to handle a HBA host |
| 1614 | * attention link event. |
| 1615 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1617 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | struct lpfc_vport *vport = phba->pport; |
| 1620 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | LPFC_MBOXQ_t *pmb; |
| 1622 | volatile uint32_t control; |
| 1623 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1624 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | |
| 1626 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1627 | if (!pmb) { |
| 1628 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1630 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | |
| 1632 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1633 | if (!mp) { |
| 1634 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1636 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | |
| 1638 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1639 | if (!mp->virt) { |
| 1640 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1642 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1644 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1645 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | |
| 1647 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1648 | lpfc_read_topology(phba, pmb, mp); |
| 1649 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1651 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1652 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1653 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1654 | if (rc == MBX_NOT_FINISHED) { |
| 1655 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1656 | goto lpfc_handle_latt_free_mbuf; |
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 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1660 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1661 | writel(HA_LATT, phba->HAregaddr); |
| 1662 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1663 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | |
| 1665 | return; |
| 1666 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1667 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1668 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1669 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | lpfc_handle_latt_free_mp: |
| 1671 | kfree(mp); |
| 1672 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1673 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | lpfc_handle_latt_err_exit: |
| 1675 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1678 | control = readl(phba->HCregaddr); |
| 1679 | control |= HC_LAINT_ENA; |
| 1680 | writel(control, phba->HCregaddr); |
| 1681 | readl(phba->HCregaddr); /* flush */ |
| 1682 | |
| 1683 | /* Clear Link Attention in HA REG */ |
| 1684 | writel(HA_LATT, phba->HAregaddr); |
| 1685 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1690 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1691 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | |
| 1693 | return; |
| 1694 | } |
| 1695 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1697 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1698 | * @phba: pointer to lpfc hba data structure. |
| 1699 | * @vpd: pointer to the vital product data. |
| 1700 | * @len: length of the vital product data in bytes. |
| 1701 | * |
| 1702 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1703 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1704 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1705 | * |
| 1706 | * Return codes |
| 1707 | * 0 - pointer to the VPD passed in is NULL |
| 1708 | * 1 - success |
| 1709 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1710 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1711 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | { |
| 1713 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1714 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | int i, j; |
| 1716 | int finished = 0; |
| 1717 | int index = 0; |
| 1718 | |
| 1719 | if (!vpd) |
| 1720 | return 0; |
| 1721 | |
| 1722 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1723 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1724 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1726 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1727 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | switch (vpd[index]) { |
| 1729 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1730 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1731 | index += 1; |
| 1732 | lenlo = vpd[index]; |
| 1733 | index += 1; |
| 1734 | lenhi = vpd[index]; |
| 1735 | index += 1; |
| 1736 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1737 | index += i; |
| 1738 | break; |
| 1739 | case 0x90: |
| 1740 | index += 1; |
| 1741 | lenlo = vpd[index]; |
| 1742 | index += 1; |
| 1743 | lenhi = vpd[index]; |
| 1744 | index += 1; |
| 1745 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1746 | if (Length > len - index) |
| 1747 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | while (Length > 0) { |
| 1749 | /* Look for Serial Number */ |
| 1750 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1751 | index += 2; |
| 1752 | i = vpd[index]; |
| 1753 | index += 1; |
| 1754 | j = 0; |
| 1755 | Length -= (3+i); |
| 1756 | while(i--) { |
| 1757 | phba->SerialNumber[j++] = vpd[index++]; |
| 1758 | if (j == 31) |
| 1759 | break; |
| 1760 | } |
| 1761 | phba->SerialNumber[j] = 0; |
| 1762 | continue; |
| 1763 | } |
| 1764 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1765 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1766 | index += 2; |
| 1767 | i = vpd[index]; |
| 1768 | index += 1; |
| 1769 | j = 0; |
| 1770 | Length -= (3+i); |
| 1771 | while(i--) { |
| 1772 | phba->ModelDesc[j++] = vpd[index++]; |
| 1773 | if (j == 255) |
| 1774 | break; |
| 1775 | } |
| 1776 | phba->ModelDesc[j] = 0; |
| 1777 | continue; |
| 1778 | } |
| 1779 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1780 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1781 | index += 2; |
| 1782 | i = vpd[index]; |
| 1783 | index += 1; |
| 1784 | j = 0; |
| 1785 | Length -= (3+i); |
| 1786 | while(i--) { |
| 1787 | phba->ModelName[j++] = vpd[index++]; |
| 1788 | if (j == 79) |
| 1789 | break; |
| 1790 | } |
| 1791 | phba->ModelName[j] = 0; |
| 1792 | continue; |
| 1793 | } |
| 1794 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1795 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1796 | index += 2; |
| 1797 | i = vpd[index]; |
| 1798 | index += 1; |
| 1799 | j = 0; |
| 1800 | Length -= (3+i); |
| 1801 | while(i--) { |
| 1802 | phba->ProgramType[j++] = vpd[index++]; |
| 1803 | if (j == 255) |
| 1804 | break; |
| 1805 | } |
| 1806 | phba->ProgramType[j] = 0; |
| 1807 | continue; |
| 1808 | } |
| 1809 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1810 | phba->vpd_flag |= VPD_PORT; |
| 1811 | index += 2; |
| 1812 | i = vpd[index]; |
| 1813 | index += 1; |
| 1814 | j = 0; |
| 1815 | Length -= (3+i); |
| 1816 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1817 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1818 | (phba->sli4_hba.pport_name_sta == |
| 1819 | LPFC_SLI4_PPNAME_GET)) { |
| 1820 | j++; |
| 1821 | index++; |
| 1822 | } else |
| 1823 | phba->Port[j++] = vpd[index++]; |
| 1824 | if (j == 19) |
| 1825 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1827 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1828 | (phba->sli4_hba.pport_name_sta == |
| 1829 | LPFC_SLI4_PPNAME_NON)) |
| 1830 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | continue; |
| 1832 | } |
| 1833 | else { |
| 1834 | index += 2; |
| 1835 | i = vpd[index]; |
| 1836 | index += 1; |
| 1837 | index += i; |
| 1838 | Length -= (3 + i); |
| 1839 | } |
| 1840 | } |
| 1841 | finished = 0; |
| 1842 | break; |
| 1843 | case 0x78: |
| 1844 | finished = 1; |
| 1845 | break; |
| 1846 | default: |
| 1847 | index ++; |
| 1848 | break; |
| 1849 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1850 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | |
| 1852 | return(1); |
| 1853 | } |
| 1854 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1855 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1856 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1857 | * @phba: pointer to lpfc hba data structure. |
| 1858 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1859 | * @descp: pointer to the data structure to hold the derived description. |
| 1860 | * |
| 1861 | * This routine retrieves HBA's description based on its registered PCI device |
| 1862 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1863 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1864 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1865 | * function returns, the @mdp will be filled with the model name. |
| 1866 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1867 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | 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] | 1869 | { |
| 1870 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1871 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1872 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1873 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1874 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1875 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1876 | char *name; |
| 1877 | char *bus; |
| 1878 | char *function; |
| 1879 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1880 | |
| 1881 | if (mdp && mdp[0] != '\0' |
| 1882 | && descp && descp[0] != '\0') |
| 1883 | return; |
| 1884 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 1885 | if (phba->lmt & LMT_16Gb) |
| 1886 | max_speed = 16; |
| 1887 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1888 | max_speed = 10; |
| 1889 | else if (phba->lmt & LMT_8Gb) |
| 1890 | max_speed = 8; |
| 1891 | else if (phba->lmt & LMT_4Gb) |
| 1892 | max_speed = 4; |
| 1893 | else if (phba->lmt & LMT_2Gb) |
| 1894 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame^] | 1895 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1896 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame^] | 1897 | else |
| 1898 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | |
| 1900 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1902 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1903 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1904 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1905 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | case PCI_DEVICE_ID_SUPERFLY: |
| 1907 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1908 | m = (typeof(m)){"LP7000", "PCI", |
| 1909 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1911 | m = (typeof(m)){"LP7000E", "PCI", |
| 1912 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | break; |
| 1914 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1915 | m = (typeof(m)){"LP8000", "PCI", |
| 1916 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | break; |
| 1918 | case PCI_DEVICE_ID_CENTAUR: |
| 1919 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1920 | m = (typeof(m)){"LP9002", "PCI", |
| 1921 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1923 | m = (typeof(m)){"LP9000", "PCI", |
| 1924 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | break; |
| 1926 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1927 | m = (typeof(m)){"LP952", "PCI", |
| 1928 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1929 | break; |
| 1930 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1931 | m = (typeof(m)){"LP9802", "PCI-X", |
| 1932 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | break; |
| 1934 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1935 | m = (typeof(m)){"LP10000", "PCI-X", |
| 1936 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | break; |
| 1938 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1939 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 1940 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | break; |
| 1942 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1943 | m = (typeof(m)){"LP982", "PCI-X", |
| 1944 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | break; |
| 1946 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1947 | m = (typeof(m)){"LP1050", "PCI-X", |
| 1948 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | break; |
| 1950 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1951 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 1952 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1953 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1954 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1955 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 1956 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1957 | break; |
| 1958 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1959 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 1960 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1961 | break; |
| 1962 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1963 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1964 | break; |
| 1965 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1966 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1967 | break; |
| 1968 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1969 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1970 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1972 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1973 | break; |
| 1974 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1975 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | break; |
| 1977 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1978 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1979 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1980 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1981 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1982 | break; |
| 1983 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1984 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1985 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1986 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1988 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | break; |
| 1990 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1991 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1992 | break; |
| 1993 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1994 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1995 | break; |
| 1996 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1997 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1998 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1999 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2000 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2001 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2002 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2003 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2004 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2005 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2006 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2007 | break; |
| 2008 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2009 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2010 | break; |
| 2011 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2012 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2013 | break; |
| 2014 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2015 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2016 | break; |
| 2017 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2018 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2019 | break; |
| 2020 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2021 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2022 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2023 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2024 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2025 | GE = 1; |
| 2026 | break; |
| 2027 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2028 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2029 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2030 | break; |
| 2031 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2032 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2033 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2034 | break; |
| 2035 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2036 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 2037 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2038 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2039 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2040 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2041 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2042 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2043 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2044 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2045 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2046 | break; |
| 2047 | case PCI_DEVICE_ID_FALCON: |
| 2048 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2049 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2050 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2051 | case PCI_DEVICE_ID_BALIUS: |
| 2052 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2053 | "Fibre Channel Adapter"}; |
| 2054 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2055 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2056 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2057 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2058 | break; |
| 2059 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2060 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2061 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2062 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2063 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2064 | case PCI_DEVICE_ID_SKYHAWK: |
| 2065 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2066 | oneConnect = 1; |
| 2067 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2068 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2069 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2070 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2071 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2073 | |
| 2074 | if (mdp && mdp[0] == '\0') |
| 2075 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2076 | /* |
| 2077 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2078 | * and we put the port number on the end |
| 2079 | */ |
| 2080 | if (descp && descp[0] == '\0') { |
| 2081 | if (oneConnect) |
| 2082 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame^] | 2083 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2084 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2085 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame^] | 2086 | else if (max_speed == 0) |
| 2087 | snprintf(descp, 255, |
| 2088 | "Emulex %s %s %s ", |
| 2089 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2090 | else |
| 2091 | snprintf(descp, 255, |
| 2092 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2093 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2094 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2095 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2096 | } |
| 2097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2099 | * 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] | 2100 | * @phba: pointer to lpfc hba data structure. |
| 2101 | * @pring: pointer to a IOCB ring. |
| 2102 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2103 | * |
| 2104 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2105 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2106 | * |
| 2107 | * Return codes |
| 2108 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2109 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2110 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2111 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2112 | { |
| 2113 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2114 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | struct lpfc_dmabuf *mp1, *mp2; |
| 2116 | |
| 2117 | cnt += pring->missbufcnt; |
| 2118 | |
| 2119 | /* While there are buffers to post */ |
| 2120 | while (cnt > 0) { |
| 2121 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2122 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | if (iocb == NULL) { |
| 2124 | pring->missbufcnt = cnt; |
| 2125 | return cnt; |
| 2126 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2127 | icmd = &iocb->iocb; |
| 2128 | |
| 2129 | /* 2 buffers can be posted per command */ |
| 2130 | /* Allocate buffer to post */ |
| 2131 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2132 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2133 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2134 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2135 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2136 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | pring->missbufcnt = cnt; |
| 2138 | return cnt; |
| 2139 | } |
| 2140 | |
| 2141 | INIT_LIST_HEAD(&mp1->list); |
| 2142 | /* Allocate buffer to post */ |
| 2143 | if (cnt > 1) { |
| 2144 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2145 | if (mp2) |
| 2146 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2147 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2148 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2149 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2151 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2152 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2153 | pring->missbufcnt = cnt; |
| 2154 | return cnt; |
| 2155 | } |
| 2156 | |
| 2157 | INIT_LIST_HEAD(&mp2->list); |
| 2158 | } else { |
| 2159 | mp2 = NULL; |
| 2160 | } |
| 2161 | |
| 2162 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2163 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2164 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2165 | icmd->ulpBdeCount = 1; |
| 2166 | cnt--; |
| 2167 | if (mp2) { |
| 2168 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2169 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2170 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2171 | cnt--; |
| 2172 | icmd->ulpBdeCount = 2; |
| 2173 | } |
| 2174 | |
| 2175 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2176 | icmd->ulpLe = 1; |
| 2177 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2178 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2179 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2181 | kfree(mp1); |
| 2182 | cnt++; |
| 2183 | if (mp2) { |
| 2184 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2185 | kfree(mp2); |
| 2186 | cnt++; |
| 2187 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2188 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | return cnt; |
| 2191 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2192 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2194 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | } |
| 2196 | pring->missbufcnt = 0; |
| 2197 | return 0; |
| 2198 | } |
| 2199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2201 | * 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] | 2202 | * @phba: pointer to lpfc hba data structure. |
| 2203 | * |
| 2204 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2205 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2206 | * set to 64 IOCBs. |
| 2207 | * |
| 2208 | * Return codes |
| 2209 | * 0 - success (currently always success) |
| 2210 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2212 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2213 | { |
| 2214 | struct lpfc_sli *psli = &phba->sli; |
| 2215 | |
| 2216 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2217 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | /* Ring 2 - FCP no buffers needed */ |
| 2219 | |
| 2220 | return 0; |
| 2221 | } |
| 2222 | |
| 2223 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2226 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2227 | * @HashResultPointer: pointer to an array as hash table. |
| 2228 | * |
| 2229 | * This routine sets up the initial values to the array of hash table entries |
| 2230 | * for the LC HBAs. |
| 2231 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | static void |
| 2233 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2234 | { |
| 2235 | HashResultPointer[0] = 0x67452301; |
| 2236 | HashResultPointer[1] = 0xEFCDAB89; |
| 2237 | HashResultPointer[2] = 0x98BADCFE; |
| 2238 | HashResultPointer[3] = 0x10325476; |
| 2239 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2240 | } |
| 2241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2242 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2243 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2244 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2245 | * @HashWorkingPointer: pointer to an working hash table. |
| 2246 | * |
| 2247 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2248 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2249 | * The results are putting back to the initial hash table, returned through |
| 2250 | * the @HashResultPointer as the result hash table. |
| 2251 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | static void |
| 2253 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2254 | { |
| 2255 | int t; |
| 2256 | uint32_t TEMP; |
| 2257 | uint32_t A, B, C, D, E; |
| 2258 | t = 16; |
| 2259 | do { |
| 2260 | HashWorkingPointer[t] = |
| 2261 | S(1, |
| 2262 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2263 | 8] ^ |
| 2264 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2265 | } while (++t <= 79); |
| 2266 | t = 0; |
| 2267 | A = HashResultPointer[0]; |
| 2268 | B = HashResultPointer[1]; |
| 2269 | C = HashResultPointer[2]; |
| 2270 | D = HashResultPointer[3]; |
| 2271 | E = HashResultPointer[4]; |
| 2272 | |
| 2273 | do { |
| 2274 | if (t < 20) { |
| 2275 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2276 | } else if (t < 40) { |
| 2277 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2278 | } else if (t < 60) { |
| 2279 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2280 | } else { |
| 2281 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2282 | } |
| 2283 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2284 | E = D; |
| 2285 | D = C; |
| 2286 | C = S(30, B); |
| 2287 | B = A; |
| 2288 | A = TEMP; |
| 2289 | } while (++t <= 79); |
| 2290 | |
| 2291 | HashResultPointer[0] += A; |
| 2292 | HashResultPointer[1] += B; |
| 2293 | HashResultPointer[2] += C; |
| 2294 | HashResultPointer[3] += D; |
| 2295 | HashResultPointer[4] += E; |
| 2296 | |
| 2297 | } |
| 2298 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2299 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2300 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2301 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2302 | * @HashWorking: pointer to the entry of the working hash array. |
| 2303 | * |
| 2304 | * This routine calculates the working hash array referred by @HashWorking |
| 2305 | * from the challenge random numbers associated with the host, referred by |
| 2306 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2307 | * array and returned by reference through @HashWorking. |
| 2308 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | static void |
| 2310 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2311 | { |
| 2312 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2313 | } |
| 2314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2316 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2317 | * @phba: pointer to lpfc hba data structure. |
| 2318 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2319 | * |
| 2320 | * This routine performs the special handling for LC HBA initialization. |
| 2321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | void |
| 2323 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2324 | { |
| 2325 | int t; |
| 2326 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2327 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2329 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | if (!HashWorking) |
| 2331 | return; |
| 2332 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2334 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2335 | |
| 2336 | for (t = 0; t < 7; t++) |
| 2337 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2338 | |
| 2339 | lpfc_sha_init(hbainit); |
| 2340 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2341 | kfree(HashWorking); |
| 2342 | } |
| 2343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2344 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2345 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2346 | * @vport: pointer to a virtual N_Port data structure. |
| 2347 | * |
| 2348 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2349 | * It invokes the discovery state machine to perform necessary state |
| 2350 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2351 | * the physical port is treated as @vport 0. |
| 2352 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2353 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2354 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2356 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2357 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2358 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2360 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2361 | lpfc_port_link_failure(vport); |
| 2362 | |
| 2363 | 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] | 2364 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2365 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2366 | NLP_STE_UNUSED_NODE); |
| 2367 | if (!ndlp) |
| 2368 | continue; |
| 2369 | spin_lock_irq(&phba->ndlp_lock); |
| 2370 | NLP_SET_FREE_REQ(ndlp); |
| 2371 | spin_unlock_irq(&phba->ndlp_lock); |
| 2372 | /* Trigger the release of the ndlp memory */ |
| 2373 | lpfc_nlp_put(ndlp); |
| 2374 | continue; |
| 2375 | } |
| 2376 | spin_lock_irq(&phba->ndlp_lock); |
| 2377 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2378 | /* The ndlp should not be in memory free mode already */ |
| 2379 | spin_unlock_irq(&phba->ndlp_lock); |
| 2380 | continue; |
| 2381 | } else |
| 2382 | /* Indicate request for freeing ndlp memory */ |
| 2383 | NLP_SET_FREE_REQ(ndlp); |
| 2384 | spin_unlock_irq(&phba->ndlp_lock); |
| 2385 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2386 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2387 | ndlp->nlp_DID == Fabric_DID) { |
| 2388 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2389 | lpfc_nlp_put(ndlp); |
| 2390 | continue; |
| 2391 | } |
| 2392 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2393 | /* take care of nodes in unused state before the state |
| 2394 | * machine taking action. |
| 2395 | */ |
| 2396 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2397 | lpfc_nlp_put(ndlp); |
| 2398 | continue; |
| 2399 | } |
| 2400 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2401 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2402 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2403 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2404 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2405 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2406 | NLP_EVT_DEVICE_RM); |
| 2407 | } |
| 2408 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2409 | /* At this point, ALL ndlp's should be gone |
| 2410 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2411 | * Lets wait for this to happen, if needed. |
| 2412 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2413 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2414 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2415 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2416 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2417 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2418 | &vport->fc_nodes, nlp_listp) { |
| 2419 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2420 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2421 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2422 | "usgmap:x%x refcnt:%d\n", |
| 2423 | ndlp->nlp_DID, (void *)ndlp, |
| 2424 | ndlp->nlp_usg_map, |
| 2425 | atomic_read( |
| 2426 | &ndlp->kref.refcount)); |
| 2427 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2428 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2429 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2430 | |
| 2431 | /* Wait for any activity on ndlps to settle */ |
| 2432 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2433 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2434 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | } |
| 2436 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2437 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2438 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2439 | * @vport: pointer to a virtual N_Port data structure. |
| 2440 | * |
| 2441 | * This routine stops all the timers associated with a @vport. This function |
| 2442 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2443 | * port is treated as @vport 0. |
| 2444 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2445 | void |
| 2446 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2448 | del_timer_sync(&vport->els_tmofunc); |
| 2449 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2450 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2451 | lpfc_can_disctmo(vport); |
| 2452 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | } |
| 2454 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2455 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2456 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2457 | * @phba: pointer to lpfc hba data structure. |
| 2458 | * |
| 2459 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2460 | * caller of this routine should already hold the host lock. |
| 2461 | **/ |
| 2462 | void |
| 2463 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2464 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2465 | /* Clear pending FCF rediscovery wait flag */ |
| 2466 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2467 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2468 | /* Now, try to stop the timer */ |
| 2469 | del_timer(&phba->fcf.redisc_wait); |
| 2470 | } |
| 2471 | |
| 2472 | /** |
| 2473 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2474 | * @phba: pointer to lpfc hba data structure. |
| 2475 | * |
| 2476 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2477 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2478 | * lock held before proceeding with disabling the timer and clearing the |
| 2479 | * wait timer pendig flag. |
| 2480 | **/ |
| 2481 | void |
| 2482 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2483 | { |
| 2484 | spin_lock_irq(&phba->hbalock); |
| 2485 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2486 | /* FCF rediscovery timer already fired or stopped */ |
| 2487 | spin_unlock_irq(&phba->hbalock); |
| 2488 | return; |
| 2489 | } |
| 2490 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2491 | /* Clear failover in progress flags */ |
| 2492 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2493 | spin_unlock_irq(&phba->hbalock); |
| 2494 | } |
| 2495 | |
| 2496 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2497 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2498 | * @phba: pointer to lpfc hba data structure. |
| 2499 | * |
| 2500 | * This routine stops all the timers associated with a HBA. This function is |
| 2501 | * invoked before either putting a HBA offline or unloading the driver. |
| 2502 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2503 | void |
| 2504 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2506 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2507 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2508 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2509 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2510 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2511 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2512 | del_timer_sync(&phba->rrq_tmr); |
| 2513 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2514 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2515 | phba->hb_outstanding = 0; |
| 2516 | |
| 2517 | switch (phba->pci_dev_grp) { |
| 2518 | case LPFC_PCI_DEV_LP: |
| 2519 | /* Stop any LightPulse device specific driver timers */ |
| 2520 | del_timer_sync(&phba->fcp_poll_timer); |
| 2521 | break; |
| 2522 | case LPFC_PCI_DEV_OC: |
| 2523 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2524 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2525 | break; |
| 2526 | default: |
| 2527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2528 | "0297 Invalid device group (x%x)\n", |
| 2529 | phba->pci_dev_grp); |
| 2530 | break; |
| 2531 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2532 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2533 | } |
| 2534 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2535 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2536 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2537 | * @phba: pointer to lpfc hba data structure. |
| 2538 | * |
| 2539 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2540 | * management interface is marked as blocked, all the user space access to |
| 2541 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2542 | * all be blocked. The HBA is set to block the management interface when the |
| 2543 | * driver prepares the HBA interface for online or offline. |
| 2544 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2545 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2546 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2547 | { |
| 2548 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2549 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2550 | unsigned long timeout; |
| 2551 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2552 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2553 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2554 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2555 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2556 | return; |
| 2557 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2558 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2559 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2560 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2561 | /* Determine how long we might wait for the active mailbox |
| 2562 | * command to be gracefully completed by firmware. |
| 2563 | */ |
| 2564 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2565 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2566 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2567 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2568 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2569 | /* Wait for the outstnading mailbox command to complete */ |
| 2570 | while (phba->sli.mbox_active) { |
| 2571 | /* Check active mailbox complete status every 2ms */ |
| 2572 | msleep(2); |
| 2573 | if (time_after(jiffies, timeout)) { |
| 2574 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2575 | "2813 Mgmt IO is Blocked %x " |
| 2576 | "- mbox cmd %x still active\n", |
| 2577 | phba->sli.sli_flag, actcmd); |
| 2578 | break; |
| 2579 | } |
| 2580 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2581 | } |
| 2582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2583 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2584 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2585 | * @phba: pointer to lpfc hba data structure. |
| 2586 | * |
| 2587 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2588 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2589 | * is to fixup the temporary rpi assignments. |
| 2590 | **/ |
| 2591 | void |
| 2592 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2593 | { |
| 2594 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2595 | struct lpfc_vport **vports; |
| 2596 | int i; |
| 2597 | |
| 2598 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2599 | return; |
| 2600 | |
| 2601 | vports = lpfc_create_vport_work_array(phba); |
| 2602 | if (vports != NULL) { |
| 2603 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2604 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2605 | continue; |
| 2606 | |
| 2607 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2608 | &vports[i]->fc_nodes, |
| 2609 | nlp_listp) { |
| 2610 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2611 | ndlp->nlp_rpi = |
| 2612 | lpfc_sli4_alloc_rpi(phba); |
| 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | lpfc_destroy_vport_work_array(phba, vports); |
| 2617 | } |
| 2618 | |
| 2619 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2620 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2621 | * @phba: pointer to lpfc hba data structure. |
| 2622 | * |
| 2623 | * This routine initializes the HBA and brings a HBA online. During this |
| 2624 | * process, the management interface is blocked to prevent user space access |
| 2625 | * to the HBA interfering with the driver initialization. |
| 2626 | * |
| 2627 | * Return codes |
| 2628 | * 0 - successful |
| 2629 | * 1 - failed |
| 2630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2632 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2634 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2635 | struct lpfc_vport **vports; |
| 2636 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2637 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | if (!phba) |
| 2639 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2640 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | return 0; |
| 2644 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2645 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2646 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2647 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2648 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2650 | if (!lpfc_sli_queue_setup(phba)) { |
| 2651 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2655 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2656 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2657 | lpfc_unblock_mgmt_io(phba); |
| 2658 | return 1; |
| 2659 | } |
| 2660 | } else { |
| 2661 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2662 | lpfc_unblock_mgmt_io(phba); |
| 2663 | return 1; |
| 2664 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2665 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2667 | vports = lpfc_create_vport_work_array(phba); |
| 2668 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2669 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2670 | struct Scsi_Host *shost; |
| 2671 | shost = lpfc_shost_from_vport(vports[i]); |
| 2672 | spin_lock_irq(shost->host_lock); |
| 2673 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2674 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2675 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2676 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2677 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2678 | spin_unlock_irq(shost->host_lock); |
| 2679 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2680 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2682 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | return 0; |
| 2684 | } |
| 2685 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2686 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2687 | * 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] | 2688 | * @phba: pointer to lpfc hba data structure. |
| 2689 | * |
| 2690 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2691 | * HBA's management interface is marked as not blocked, all the user space |
| 2692 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2693 | * interface will be allowed. The HBA is set to block the management interface |
| 2694 | * when the driver prepares the HBA interface for online or offline and then |
| 2695 | * set to unblock the management interface afterwards. |
| 2696 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2697 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2698 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2699 | { |
| 2700 | unsigned long iflag; |
| 2701 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2702 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2703 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2704 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2705 | } |
| 2706 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2707 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2708 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2709 | * @phba: pointer to lpfc hba data structure. |
| 2710 | * |
| 2711 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2712 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2713 | * queue to make it ready to be brought offline. |
| 2714 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2715 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2716 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2717 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2718 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2719 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2720 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2721 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2722 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2724 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2725 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2726 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2727 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | |
| 2729 | lpfc_linkdown(phba); |
| 2730 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2731 | /* Issue an unreg_login to all nodes on all vports */ |
| 2732 | vports = lpfc_create_vport_work_array(phba); |
| 2733 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2734 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2735 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2736 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2737 | shost = lpfc_shost_from_vport(vports[i]); |
| 2738 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2739 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2740 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2741 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2742 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2743 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2744 | shost = lpfc_shost_from_vport(vports[i]); |
| 2745 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2746 | &vports[i]->fc_nodes, |
| 2747 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2748 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2749 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2750 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2751 | continue; |
| 2752 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2753 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2754 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2755 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2756 | NULL, NLP_EVT_DEVICE_RM); |
| 2757 | } |
| 2758 | spin_lock_irq(shost->host_lock); |
| 2759 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2760 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2761 | /* |
| 2762 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2763 | * RPI. Get a new RPI when the adapter port |
| 2764 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2765 | */ |
| 2766 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2767 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2768 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2769 | } |
| 2770 | } |
| 2771 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2772 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2774 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2775 | } |
| 2776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2778 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | * @phba: pointer to lpfc hba data structure. |
| 2780 | * |
| 2781 | * This routine actually brings a HBA offline. It stops all the timers |
| 2782 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2783 | * marks the HBA as in offline state for the upper layer protocol. |
| 2784 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2785 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2786 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2787 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2788 | struct Scsi_Host *shost; |
| 2789 | struct lpfc_vport **vports; |
| 2790 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2791 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2792 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2793 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2794 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2795 | /* stop port and all timers associated with this hba */ |
| 2796 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2797 | vports = lpfc_create_vport_work_array(phba); |
| 2798 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2799 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2800 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2801 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2802 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2803 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2804 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2805 | now. */ |
| 2806 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2807 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2808 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2809 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2810 | vports = lpfc_create_vport_work_array(phba); |
| 2811 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2812 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2813 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2814 | spin_lock_irq(shost->host_lock); |
| 2815 | vports[i]->work_port_events = 0; |
| 2816 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2817 | spin_unlock_irq(shost->host_lock); |
| 2818 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2819 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2820 | } |
| 2821 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2822 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2823 | * 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] | 2824 | * @phba: pointer to lpfc hba data structure. |
| 2825 | * |
| 2826 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2827 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2828 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2829 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2830 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2831 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | { |
| 2833 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2834 | struct lpfc_iocbq *io, *io_next; |
| 2835 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2836 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2837 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2838 | spin_lock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 2840 | list_del(&sb->list); |
| 2841 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2842 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2843 | kfree(sb); |
| 2844 | phba->total_scsi_bufs--; |
| 2845 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2846 | spin_unlock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2847 | |
| 2848 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2849 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2850 | list_del(&io->list); |
| 2851 | kfree(io); |
| 2852 | phba->total_iocbq_bufs--; |
| 2853 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2854 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2855 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | /** |
| 2859 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 2860 | * @phba: pointer to lpfc hba data structure. |
| 2861 | * |
| 2862 | * This routine first calculates the sizes of the current els and allocated |
| 2863 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 2864 | * XRIs assigned due to port function reset. During port initialization, the |
| 2865 | * current els and allocated scsi sgl lists are 0s. |
| 2866 | * |
| 2867 | * Return codes |
| 2868 | * 0 - successful (for now, it always returns 0) |
| 2869 | **/ |
| 2870 | int |
| 2871 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 2872 | { |
| 2873 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 2874 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 2875 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 2876 | LIST_HEAD(els_sgl_list); |
| 2877 | LIST_HEAD(scsi_sgl_list); |
| 2878 | int rc; |
| 2879 | |
| 2880 | /* |
| 2881 | * update on pci function's els xri-sgl list |
| 2882 | */ |
| 2883 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 2884 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 2885 | /* els xri-sgl expanded */ |
| 2886 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 2887 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2888 | "3157 ELS xri-sgl count increased from " |
| 2889 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2890 | els_xri_cnt); |
| 2891 | /* allocate the additional els sgls */ |
| 2892 | for (i = 0; i < xri_cnt; i++) { |
| 2893 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 2894 | GFP_KERNEL); |
| 2895 | if (sglq_entry == NULL) { |
| 2896 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2897 | "2562 Failure to allocate an " |
| 2898 | "ELS sgl entry:%d\n", i); |
| 2899 | rc = -ENOMEM; |
| 2900 | goto out_free_mem; |
| 2901 | } |
| 2902 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 2903 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 2904 | &sglq_entry->phys); |
| 2905 | if (sglq_entry->virt == NULL) { |
| 2906 | kfree(sglq_entry); |
| 2907 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2908 | "2563 Failure to allocate an " |
| 2909 | "ELS mbuf:%d\n", i); |
| 2910 | rc = -ENOMEM; |
| 2911 | goto out_free_mem; |
| 2912 | } |
| 2913 | sglq_entry->sgl = sglq_entry->virt; |
| 2914 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 2915 | sglq_entry->state = SGL_FREED; |
| 2916 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 2917 | } |
| 2918 | spin_lock(&phba->hbalock); |
| 2919 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2920 | spin_unlock(&phba->hbalock); |
| 2921 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 2922 | /* els xri-sgl shrinked */ |
| 2923 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 2924 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2925 | "3158 ELS xri-sgl count decreased from " |
| 2926 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2927 | els_xri_cnt); |
| 2928 | spin_lock_irq(&phba->hbalock); |
| 2929 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
| 2930 | spin_unlock_irq(&phba->hbalock); |
| 2931 | /* release extra els sgls from list */ |
| 2932 | for (i = 0; i < xri_cnt; i++) { |
| 2933 | list_remove_head(&els_sgl_list, |
| 2934 | sglq_entry, struct lpfc_sglq, list); |
| 2935 | if (sglq_entry) { |
| 2936 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 2937 | sglq_entry->phys); |
| 2938 | kfree(sglq_entry); |
| 2939 | } |
| 2940 | } |
| 2941 | spin_lock_irq(&phba->hbalock); |
| 2942 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2943 | spin_unlock_irq(&phba->hbalock); |
| 2944 | } else |
| 2945 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2946 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 2947 | els_xri_cnt); |
| 2948 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 2949 | |
| 2950 | /* update xris to els sgls on the list */ |
| 2951 | sglq_entry = NULL; |
| 2952 | sglq_entry_next = NULL; |
| 2953 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 2954 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 2955 | lxri = lpfc_sli4_next_xritag(phba); |
| 2956 | if (lxri == NO_XRI) { |
| 2957 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2958 | "2400 Failed to allocate xri for " |
| 2959 | "ELS sgl\n"); |
| 2960 | rc = -ENOMEM; |
| 2961 | goto out_free_mem; |
| 2962 | } |
| 2963 | sglq_entry->sli4_lxritag = lxri; |
| 2964 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 2965 | } |
| 2966 | |
| 2967 | /* |
| 2968 | * update on pci function's allocated scsi xri-sgl list |
| 2969 | */ |
| 2970 | phba->total_scsi_bufs = 0; |
| 2971 | |
| 2972 | /* maximum number of xris available for scsi buffers */ |
| 2973 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 2974 | els_xri_cnt; |
| 2975 | |
| 2976 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2977 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 2978 | "maximum SCSI xri count:%d\n", |
| 2979 | phba->sli4_hba.scsi_xri_cnt, |
| 2980 | phba->sli4_hba.scsi_xri_max); |
| 2981 | |
| 2982 | spin_lock_irq(&phba->scsi_buf_list_lock); |
| 2983 | list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list); |
| 2984 | spin_unlock_irq(&phba->scsi_buf_list_lock); |
| 2985 | |
| 2986 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 2987 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 2988 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 2989 | phba->sli4_hba.scsi_xri_max; |
| 2990 | /* release the extra allocated scsi buffers */ |
| 2991 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 2992 | list_remove_head(&scsi_sgl_list, psb, |
| 2993 | struct lpfc_scsi_buf, list); |
| 2994 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, |
| 2995 | psb->dma_handle); |
| 2996 | kfree(psb); |
| 2997 | } |
| 2998 | spin_lock_irq(&phba->scsi_buf_list_lock); |
| 2999 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
| 3000 | spin_unlock_irq(&phba->scsi_buf_list_lock); |
| 3001 | } |
| 3002 | |
| 3003 | /* update xris associated to remaining allocated scsi buffers */ |
| 3004 | psb = NULL; |
| 3005 | psb_next = NULL; |
| 3006 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3007 | lxri = lpfc_sli4_next_xritag(phba); |
| 3008 | if (lxri == NO_XRI) { |
| 3009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3010 | "2560 Failed to allocate xri for " |
| 3011 | "scsi buffer\n"); |
| 3012 | rc = -ENOMEM; |
| 3013 | goto out_free_mem; |
| 3014 | } |
| 3015 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3016 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3017 | } |
| 3018 | spin_lock(&phba->scsi_buf_list_lock); |
| 3019 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list); |
| 3020 | spin_unlock(&phba->scsi_buf_list_lock); |
| 3021 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3023 | |
| 3024 | out_free_mem: |
| 3025 | lpfc_free_els_sgl_list(phba); |
| 3026 | lpfc_scsi_free(phba); |
| 3027 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3028 | } |
| 3029 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3031 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3032 | * @phba: pointer to lpfc hba data structure. |
| 3033 | * @instance: a unique integer ID to this FC port. |
| 3034 | * @dev: pointer to the device data structure. |
| 3035 | * |
| 3036 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3037 | * can be created on top of either a physical port or a virtual port provided |
| 3038 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3039 | * and associates the FC port created before adding the shost into the SCSI |
| 3040 | * layer. |
| 3041 | * |
| 3042 | * Return codes |
| 3043 | * @vport - pointer to the virtual N_Port data structure. |
| 3044 | * NULL - port create failed. |
| 3045 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3046 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3047 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3048 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3049 | struct lpfc_vport *vport; |
| 3050 | struct Scsi_Host *shost; |
| 3051 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3052 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3053 | if (dev != &phba->pcidev->dev) |
| 3054 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3055 | sizeof(struct lpfc_vport)); |
| 3056 | else |
| 3057 | shost = scsi_host_alloc(&lpfc_template, |
| 3058 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3059 | if (!shost) |
| 3060 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3061 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3062 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3063 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3064 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3065 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3066 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3067 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3068 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3069 | shost->unique_id = instance; |
| 3070 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3071 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3072 | shost->this_id = -1; |
| 3073 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3074 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3075 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3076 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3077 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3078 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3079 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3080 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | * Set initial can_queue value since 0 is no longer supported and |
| 3082 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3083 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3084 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3085 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3086 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3087 | shost->transportt = lpfc_vport_transport_template; |
| 3088 | vport->port_type = LPFC_NPIV_PORT; |
| 3089 | } else { |
| 3090 | shost->transportt = lpfc_transport_template; |
| 3091 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3092 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3093 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | /* Initialize all internally managed lists. */ |
| 3095 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3096 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3097 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3098 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3099 | init_timer(&vport->fc_disctmo); |
| 3100 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3101 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3102 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3103 | init_timer(&vport->fc_fdmitmo); |
| 3104 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3105 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3106 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3107 | init_timer(&vport->els_tmofunc); |
| 3108 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3109 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3110 | |
| 3111 | init_timer(&vport->delayed_disc_tmo); |
| 3112 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3113 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3114 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3115 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | if (error) |
| 3117 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3118 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3119 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3120 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3121 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3122 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3123 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3124 | out_put_shost: |
| 3125 | scsi_host_put(shost); |
| 3126 | out: |
| 3127 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3128 | } |
| 3129 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3130 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3131 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3132 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3133 | * |
| 3134 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3135 | * resources associated with the port are released. |
| 3136 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3137 | void |
| 3138 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3139 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3140 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3141 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3142 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3143 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3144 | fc_remove_host(shost); |
| 3145 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3146 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3147 | spin_lock_irq(&phba->hbalock); |
| 3148 | list_del_init(&vport->listentry); |
| 3149 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3152 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3153 | } |
| 3154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3155 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3156 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3157 | * |
| 3158 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3159 | * uses the kernel idr facility to perform the task. |
| 3160 | * |
| 3161 | * Return codes: |
| 3162 | * instance - a unique integer ID allocated as the new instance. |
| 3163 | * -1 - lpfc get instance failed. |
| 3164 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3165 | int |
| 3166 | lpfc_get_instance(void) |
| 3167 | { |
| 3168 | int instance = 0; |
| 3169 | |
| 3170 | /* Assign an unused number */ |
| 3171 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 3172 | return -1; |
| 3173 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 3174 | return -1; |
| 3175 | return instance; |
| 3176 | } |
| 3177 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3178 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3179 | * 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] | 3180 | * @shost: pointer to SCSI host data structure. |
| 3181 | * @time: elapsed time of the scan in jiffies. |
| 3182 | * |
| 3183 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3184 | * whether the scan host is finished. |
| 3185 | * |
| 3186 | * Note: there is no scan_start function as adapter initialization will have |
| 3187 | * asynchronously kicked off the link initialization. |
| 3188 | * |
| 3189 | * Return codes |
| 3190 | * 0 - SCSI host scan is not over yet. |
| 3191 | * 1 - SCSI host scan is over. |
| 3192 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3193 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3194 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3195 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3196 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3197 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3198 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3199 | spin_lock_irq(shost->host_lock); |
| 3200 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3201 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3202 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3203 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3204 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | if (time >= 30 * HZ) { |
| 3206 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3207 | "0461 Scanning longer than 30 " |
| 3208 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3209 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3210 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3211 | } |
| 3212 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 3213 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3214 | "0465 Link down longer than 15 " |
| 3215 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3216 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3217 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3218 | } |
| 3219 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3220 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3221 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3222 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3223 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3224 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3225 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3226 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3227 | goto finished; |
| 3228 | |
| 3229 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3230 | |
| 3231 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3232 | spin_unlock_irq(shost->host_lock); |
| 3233 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3234 | } |
| 3235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3237 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3238 | * @shost: pointer to SCSI host data structure. |
| 3239 | * |
| 3240 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3241 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3242 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3243 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3244 | { |
| 3245 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3246 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3247 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3248 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3249 | */ |
| 3250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3251 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3252 | 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] | 3253 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3254 | |
| 3255 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3256 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3257 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3258 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3259 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3260 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3261 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3262 | |
| 3263 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3264 | if (phba->lmt & LMT_16Gb) |
| 3265 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3266 | if (phba->lmt & LMT_10Gb) |
| 3267 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3268 | if (phba->lmt & LMT_8Gb) |
| 3269 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3270 | if (phba->lmt & LMT_4Gb) |
| 3271 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3272 | if (phba->lmt & LMT_2Gb) |
| 3273 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3274 | if (phba->lmt & LMT_1Gb) |
| 3275 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3276 | |
| 3277 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3278 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3279 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3280 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3281 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3282 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3283 | /* This value is also unchanging */ |
| 3284 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3286 | fc_host_active_fc4s(shost)[2] = 1; |
| 3287 | fc_host_active_fc4s(shost)[7] = 1; |
| 3288 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3289 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3290 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3291 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3292 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3293 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3295 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3296 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3297 | * @phba: pointer to lpfc hba data structure. |
| 3298 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3299 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3300 | * from generating interrupts and stops the device driver's timers for the |
| 3301 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3302 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3303 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3304 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3305 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3306 | /* Clear all interrupt enable conditions */ |
| 3307 | writel(0, phba->HCregaddr); |
| 3308 | readl(phba->HCregaddr); /* flush */ |
| 3309 | /* Clear all pending interrupts */ |
| 3310 | writel(0xffffffff, phba->HAregaddr); |
| 3311 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3312 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3313 | /* Reset some HBA SLI setup states */ |
| 3314 | lpfc_stop_hba_timers(phba); |
| 3315 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3316 | } |
| 3317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3318 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3319 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3320 | * @phba: pointer to lpfc hba data structure. |
| 3321 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3322 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3323 | * from generating interrupts and stops the device driver's timers for the |
| 3324 | * device. |
| 3325 | **/ |
| 3326 | static void |
| 3327 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3328 | { |
| 3329 | /* Reset some HBA SLI4 setup states */ |
| 3330 | lpfc_stop_hba_timers(phba); |
| 3331 | phba->pport->work_port_events = 0; |
| 3332 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | /** |
| 3336 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3337 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3338 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3339 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3340 | * the API jump table function pointer from the lpfc_hba struct. |
| 3341 | **/ |
| 3342 | void |
| 3343 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3344 | { |
| 3345 | phba->lpfc_stop_port(phba); |
| 3346 | } |
| 3347 | |
| 3348 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3349 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3350 | * @phba: Pointer to hba for which this call is being executed. |
| 3351 | * |
| 3352 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3353 | **/ |
| 3354 | void |
| 3355 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3356 | { |
| 3357 | unsigned long fcf_redisc_wait_tmo = |
| 3358 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3359 | /* Start fcf rediscovery wait period timer */ |
| 3360 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3361 | spin_lock_irq(&phba->hbalock); |
| 3362 | /* Allow action to new fcf asynchronous event */ |
| 3363 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3364 | /* Mark the FCF rediscovery pending state */ |
| 3365 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3366 | spin_unlock_irq(&phba->hbalock); |
| 3367 | } |
| 3368 | |
| 3369 | /** |
| 3370 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3371 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3372 | * |
| 3373 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3374 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3375 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3376 | * list, and then worker thread shall be waked up for processing from the |
| 3377 | * worker thread context. |
| 3378 | **/ |
| 3379 | void |
| 3380 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3381 | { |
| 3382 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3383 | |
| 3384 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3385 | spin_lock_irq(&phba->hbalock); |
| 3386 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3387 | spin_unlock_irq(&phba->hbalock); |
| 3388 | return; |
| 3389 | } |
| 3390 | /* Clear FCF rediscovery timer pending flag */ |
| 3391 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3392 | /* FCF rediscovery event to worker thread */ |
| 3393 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3394 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3395 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3396 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3397 | /* wake up worker thread */ |
| 3398 | lpfc_worker_wake_up(phba); |
| 3399 | } |
| 3400 | |
| 3401 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3402 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3403 | * @phba: pointer to lpfc hba data structure. |
| 3404 | * @acqe_link: pointer to the async link completion queue entry. |
| 3405 | * |
| 3406 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3407 | * translate it into the base driver's read link attention mailbox command |
| 3408 | * status. |
| 3409 | * |
| 3410 | * Return: Link-attention status in terms of base driver's coding. |
| 3411 | **/ |
| 3412 | static uint16_t |
| 3413 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3414 | struct lpfc_acqe_link *acqe_link) |
| 3415 | { |
| 3416 | uint16_t latt_fault; |
| 3417 | |
| 3418 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3419 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3420 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3421 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3422 | latt_fault = 0; |
| 3423 | break; |
| 3424 | default: |
| 3425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3426 | "0398 Invalid link fault code: x%x\n", |
| 3427 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3428 | latt_fault = MBXERR_ERROR; |
| 3429 | break; |
| 3430 | } |
| 3431 | return latt_fault; |
| 3432 | } |
| 3433 | |
| 3434 | /** |
| 3435 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3436 | * @phba: pointer to lpfc hba data structure. |
| 3437 | * @acqe_link: pointer to the async link completion queue entry. |
| 3438 | * |
| 3439 | * This routine is to parse the SLI4 link attention type and translate it |
| 3440 | * into the base driver's link attention type coding. |
| 3441 | * |
| 3442 | * Return: Link attention type in terms of base driver's coding. |
| 3443 | **/ |
| 3444 | static uint8_t |
| 3445 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3446 | struct lpfc_acqe_link *acqe_link) |
| 3447 | { |
| 3448 | uint8_t att_type; |
| 3449 | |
| 3450 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3451 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3452 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3453 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3454 | break; |
| 3455 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3456 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3457 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3458 | break; |
| 3459 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3460 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3461 | break; |
| 3462 | default: |
| 3463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3464 | "0399 Invalid link attention type: x%x\n", |
| 3465 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3466 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3467 | break; |
| 3468 | } |
| 3469 | return att_type; |
| 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3474 | * @phba: pointer to lpfc hba data structure. |
| 3475 | * @acqe_link: pointer to the async link completion queue entry. |
| 3476 | * |
| 3477 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3478 | * it into the base driver's link-attention link speed coding. |
| 3479 | * |
| 3480 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3481 | **/ |
| 3482 | static uint8_t |
| 3483 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3484 | struct lpfc_acqe_link *acqe_link) |
| 3485 | { |
| 3486 | uint8_t link_speed; |
| 3487 | |
| 3488 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3489 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3490 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3491 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3492 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3493 | break; |
| 3494 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3495 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3496 | break; |
| 3497 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3498 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3499 | break; |
| 3500 | default: |
| 3501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3502 | "0483 Invalid link-attention link speed: x%x\n", |
| 3503 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3504 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3505 | break; |
| 3506 | } |
| 3507 | return link_speed; |
| 3508 | } |
| 3509 | |
| 3510 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3511 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3512 | * @phba: pointer to lpfc hba data structure. |
| 3513 | * @acqe_link: pointer to the async link completion queue entry. |
| 3514 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3515 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3516 | **/ |
| 3517 | static void |
| 3518 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3519 | struct lpfc_acqe_link *acqe_link) |
| 3520 | { |
| 3521 | struct lpfc_dmabuf *mp; |
| 3522 | LPFC_MBOXQ_t *pmb; |
| 3523 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3524 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3525 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3526 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3527 | |
| 3528 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3529 | 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] | 3530 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3531 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3532 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3533 | if (!pmb) { |
| 3534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3535 | "0395 The mboxq allocation failed\n"); |
| 3536 | return; |
| 3537 | } |
| 3538 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3539 | if (!mp) { |
| 3540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3541 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3542 | goto out_free_pmb; |
| 3543 | } |
| 3544 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3545 | if (!mp->virt) { |
| 3546 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3547 | "0397 The mbuf allocation failed\n"); |
| 3548 | goto out_free_dmabuf; |
| 3549 | } |
| 3550 | |
| 3551 | /* Cleanup any outstanding ELS commands */ |
| 3552 | lpfc_els_flush_all_cmd(phba); |
| 3553 | |
| 3554 | /* Block ELS IOCBs until we have done process link event */ |
| 3555 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3556 | |
| 3557 | /* Update link event statistics */ |
| 3558 | phba->sli.slistat.link_event++; |
| 3559 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3560 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3561 | lpfc_read_topology(phba, pmb, mp); |
| 3562 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3563 | pmb->vport = phba->pport; |
| 3564 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3565 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3566 | phba->sli4_hba.link_state.speed = |
| 3567 | bf_get(lpfc_acqe_link_speed, acqe_link); |
| 3568 | phba->sli4_hba.link_state.duplex = |
| 3569 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3570 | phba->sli4_hba.link_state.status = |
| 3571 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3572 | phba->sli4_hba.link_state.type = |
| 3573 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3574 | phba->sli4_hba.link_state.number = |
| 3575 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3576 | phba->sli4_hba.link_state.fault = |
| 3577 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3578 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3579 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
| 3580 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3581 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3582 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3583 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3584 | phba->sli4_hba.link_state.speed, |
| 3585 | phba->sli4_hba.link_state.topology, |
| 3586 | phba->sli4_hba.link_state.status, |
| 3587 | phba->sli4_hba.link_state.type, |
| 3588 | phba->sli4_hba.link_state.number, |
| 3589 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3590 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3591 | /* |
| 3592 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3593 | * topology info. Note: Optional for non FC-AL ports. |
| 3594 | */ |
| 3595 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3596 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3597 | if (rc == MBX_NOT_FINISHED) |
| 3598 | goto out_free_dmabuf; |
| 3599 | return; |
| 3600 | } |
| 3601 | /* |
| 3602 | * For FCoE Mode: fill in all the topology information we need and call |
| 3603 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3604 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3605 | */ |
| 3606 | /* Parse and translate status field */ |
| 3607 | mb = &pmb->u.mb; |
| 3608 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3609 | |
| 3610 | /* Parse and translate link attention fields */ |
| 3611 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3612 | la->eventTag = acqe_link->event_tag; |
| 3613 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3614 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3615 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3616 | |
| 3617 | /* Fake the the following irrelvant fields */ |
| 3618 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3619 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3620 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3621 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3622 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3623 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3624 | |
| 3625 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3626 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3627 | |
| 3628 | return; |
| 3629 | |
| 3630 | out_free_dmabuf: |
| 3631 | kfree(mp); |
| 3632 | out_free_pmb: |
| 3633 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3634 | } |
| 3635 | |
| 3636 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3637 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3638 | * @phba: pointer to lpfc hba data structure. |
| 3639 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3640 | * |
| 3641 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3642 | * that the event was received and then issue a read_topology mailbox command so |
| 3643 | * that the rest of the driver will treat it the same as SLI3. |
| 3644 | **/ |
| 3645 | static void |
| 3646 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3647 | { |
| 3648 | struct lpfc_dmabuf *mp; |
| 3649 | LPFC_MBOXQ_t *pmb; |
| 3650 | int rc; |
| 3651 | |
| 3652 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3653 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3655 | "2895 Non FC link Event detected.(%d)\n", |
| 3656 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3657 | return; |
| 3658 | } |
| 3659 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3660 | phba->sli4_hba.link_state.speed = |
| 3661 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); |
| 3662 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3663 | phba->sli4_hba.link_state.topology = |
| 3664 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3665 | phba->sli4_hba.link_state.status = |
| 3666 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3667 | phba->sli4_hba.link_state.type = |
| 3668 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3669 | phba->sli4_hba.link_state.number = |
| 3670 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3671 | phba->sli4_hba.link_state.fault = |
| 3672 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3673 | phba->sli4_hba.link_state.logical_speed = |
| 3674 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); |
| 3675 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3676 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3677 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3678 | "%dMbps Fault:%d\n", |
| 3679 | phba->sli4_hba.link_state.speed, |
| 3680 | phba->sli4_hba.link_state.topology, |
| 3681 | phba->sli4_hba.link_state.status, |
| 3682 | phba->sli4_hba.link_state.type, |
| 3683 | phba->sli4_hba.link_state.number, |
| 3684 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3685 | phba->sli4_hba.link_state.fault); |
| 3686 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3687 | if (!pmb) { |
| 3688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3689 | "2897 The mboxq allocation failed\n"); |
| 3690 | return; |
| 3691 | } |
| 3692 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3693 | if (!mp) { |
| 3694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3695 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3696 | goto out_free_pmb; |
| 3697 | } |
| 3698 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3699 | if (!mp->virt) { |
| 3700 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3701 | "2899 The mbuf allocation failed\n"); |
| 3702 | goto out_free_dmabuf; |
| 3703 | } |
| 3704 | |
| 3705 | /* Cleanup any outstanding ELS commands */ |
| 3706 | lpfc_els_flush_all_cmd(phba); |
| 3707 | |
| 3708 | /* Block ELS IOCBs until we have done process link event */ |
| 3709 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3710 | |
| 3711 | /* Update link event statistics */ |
| 3712 | phba->sli.slistat.link_event++; |
| 3713 | |
| 3714 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3715 | lpfc_read_topology(phba, pmb, mp); |
| 3716 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3717 | pmb->vport = phba->pport; |
| 3718 | |
| 3719 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3720 | if (rc == MBX_NOT_FINISHED) |
| 3721 | goto out_free_dmabuf; |
| 3722 | return; |
| 3723 | |
| 3724 | out_free_dmabuf: |
| 3725 | kfree(mp); |
| 3726 | out_free_pmb: |
| 3727 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3728 | } |
| 3729 | |
| 3730 | /** |
| 3731 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3732 | * @phba: pointer to lpfc hba data structure. |
| 3733 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3734 | * |
| 3735 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3736 | **/ |
| 3737 | static void |
| 3738 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3739 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3740 | char port_name; |
| 3741 | char message[80]; |
| 3742 | uint8_t status; |
| 3743 | struct lpfc_acqe_misconfigured_event *misconfigured; |
| 3744 | |
| 3745 | /* special case misconfigured event as it contains data for all ports */ |
| 3746 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3747 | LPFC_SLI_INTF_IF_TYPE_2) || |
| 3748 | (bf_get(lpfc_trailer_type, acqe_sli) != |
| 3749 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { |
| 3750 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3751 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3752 | "x%08x SLI Event Type:%d\n", |
| 3753 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3754 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3755 | return; |
| 3756 | } |
| 3757 | |
| 3758 | port_name = phba->Port[0]; |
| 3759 | if (port_name == 0x00) |
| 3760 | port_name = '?'; /* get port name is empty */ |
| 3761 | |
| 3762 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
| 3763 | &acqe_sli->event_data1; |
| 3764 | |
| 3765 | /* fetch the status for this port */ |
| 3766 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 3767 | case LPFC_LINK_NUMBER_0: |
| 3768 | status = bf_get(lpfc_sli_misconfigured_port0, |
| 3769 | &misconfigured->theEvent); |
| 3770 | break; |
| 3771 | case LPFC_LINK_NUMBER_1: |
| 3772 | status = bf_get(lpfc_sli_misconfigured_port1, |
| 3773 | &misconfigured->theEvent); |
| 3774 | break; |
| 3775 | case LPFC_LINK_NUMBER_2: |
| 3776 | status = bf_get(lpfc_sli_misconfigured_port2, |
| 3777 | &misconfigured->theEvent); |
| 3778 | break; |
| 3779 | case LPFC_LINK_NUMBER_3: |
| 3780 | status = bf_get(lpfc_sli_misconfigured_port3, |
| 3781 | &misconfigured->theEvent); |
| 3782 | break; |
| 3783 | default: |
| 3784 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | switch (status) { |
| 3789 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 3790 | return; /* no message if the sfp is okay */ |
| 3791 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3792 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
| 3793 | "installed - Reseat optics, if issue not " |
| 3794 | "resolved, replace."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3795 | break; |
| 3796 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 3797 | sprintf(message, |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3798 | "Optics of two types installed - Remove one optic or " \ |
| 3799 | "install matching pair of optics."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3800 | break; |
| 3801 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3802 | sprintf(message, "Incompatible optics - Replace with " \ |
| 3803 | "compatible optics for card to function."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3804 | break; |
| 3805 | default: |
| 3806 | /* firmware is reporting a status we don't know about */ |
| 3807 | sprintf(message, "Unknown event status x%02x", status); |
| 3808 | break; |
| 3809 | } |
| 3810 | |
| 3811 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3812 | "3176 Misconfigured Physical Port - " |
| 3813 | "Port Name %c %s\n", port_name, message); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3817 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 3818 | * @vport: pointer to vport data structure. |
| 3819 | * |
| 3820 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 3821 | * response to a CVL event. |
| 3822 | * |
| 3823 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 3824 | * return NULL. |
| 3825 | **/ |
| 3826 | static struct lpfc_nodelist * |
| 3827 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 3828 | { |
| 3829 | struct lpfc_nodelist *ndlp; |
| 3830 | struct Scsi_Host *shost; |
| 3831 | struct lpfc_hba *phba; |
| 3832 | |
| 3833 | if (!vport) |
| 3834 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3835 | phba = vport->phba; |
| 3836 | if (!phba) |
| 3837 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3838 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 3839 | if (!ndlp) { |
| 3840 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 3841 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3842 | if (!ndlp) |
| 3843 | return 0; |
| 3844 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 3845 | /* Set the node type */ |
| 3846 | ndlp->nlp_type |= NLP_FABRIC; |
| 3847 | /* Put ndlp onto node list */ |
| 3848 | lpfc_enqueue_node(vport, ndlp); |
| 3849 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3850 | /* re-setup ndlp without removing from node list */ |
| 3851 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3852 | if (!ndlp) |
| 3853 | return 0; |
| 3854 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3855 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 3856 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3857 | return NULL; |
| 3858 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3859 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 3860 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3861 | return NULL; |
| 3862 | shost = lpfc_shost_from_vport(vport); |
| 3863 | if (!shost) |
| 3864 | return NULL; |
| 3865 | lpfc_linkdown_port(vport); |
| 3866 | lpfc_cleanup_pending_mbox(vport); |
| 3867 | spin_lock_irq(shost->host_lock); |
| 3868 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 3869 | spin_unlock_irq(shost->host_lock); |
| 3870 | |
| 3871 | return ndlp; |
| 3872 | } |
| 3873 | |
| 3874 | /** |
| 3875 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 3876 | * @vport: pointer to lpfc hba data structure. |
| 3877 | * |
| 3878 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 3879 | * response to a FCF dead event. |
| 3880 | **/ |
| 3881 | static void |
| 3882 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 3883 | { |
| 3884 | struct lpfc_vport **vports; |
| 3885 | int i; |
| 3886 | |
| 3887 | vports = lpfc_create_vport_work_array(phba); |
| 3888 | if (vports) |
| 3889 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 3890 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 3891 | lpfc_destroy_vport_work_array(phba, vports); |
| 3892 | } |
| 3893 | |
| 3894 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3895 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3896 | * @phba: pointer to lpfc hba data structure. |
| 3897 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 3898 | * |
| 3899 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 3900 | **/ |
| 3901 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3902 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3903 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3904 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3905 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3906 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3907 | struct lpfc_vport *vport; |
| 3908 | struct lpfc_nodelist *ndlp; |
| 3909 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3910 | int active_vlink_present; |
| 3911 | struct lpfc_vport **vports; |
| 3912 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3913 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3914 | phba->fc_eventTag = acqe_fip->event_tag; |
| 3915 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3916 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3917 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 3918 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 3919 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3920 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 3921 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3922 | "2546 New FCF event, evt_tag:x%x, " |
| 3923 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3924 | acqe_fip->event_tag, |
| 3925 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3926 | else |
| 3927 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 3928 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3929 | "2788 FCF param modified event, " |
| 3930 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3931 | acqe_fip->event_tag, |
| 3932 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3933 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3934 | /* |
| 3935 | * During period of FCF discovery, read the FCF |
| 3936 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3937 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3938 | */ |
| 3939 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 3940 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3941 | "2779 Read FCF (x%x) for updating " |
| 3942 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3943 | acqe_fip->index); |
| 3944 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3945 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3946 | |
| 3947 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3948 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3949 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3950 | spin_unlock_irq(&phba->hbalock); |
| 3951 | break; |
| 3952 | } |
| 3953 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 3954 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 3955 | spin_unlock_irq(&phba->hbalock); |
| 3956 | break; |
| 3957 | } |
| 3958 | |
| 3959 | /* If the FCF has been in discovered state, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3960 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
| 3961 | spin_unlock_irq(&phba->hbalock); |
| 3962 | break; |
| 3963 | } |
| 3964 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3965 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3966 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 3967 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3968 | "2770 Start FCF table scan per async FCF " |
| 3969 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3970 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3971 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3972 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3973 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3974 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 3975 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3976 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3977 | break; |
| 3978 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3979 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3980 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3981 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3982 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 3983 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3984 | break; |
| 3985 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3986 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 3987 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3988 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3989 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3990 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3991 | /* |
| 3992 | * If we are in the middle of FCF failover process, clear |
| 3993 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3994 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3995 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3996 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3997 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3998 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3999 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4000 | break; |
| 4001 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4002 | spin_unlock_irq(&phba->hbalock); |
| 4003 | |
| 4004 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4005 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4006 | break; |
| 4007 | |
| 4008 | /* |
| 4009 | * Otherwise, request the port to rediscover the entire FCF |
| 4010 | * table for a fast recovery from case that the current FCF |
| 4011 | * is no longer valid as we are not in the middle of FCF |
| 4012 | * failover process already. |
| 4013 | */ |
| 4014 | spin_lock_irq(&phba->hbalock); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4015 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4016 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4017 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4018 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4019 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4020 | "2771 Start FCF fast failover process due to " |
| 4021 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4022 | "\n", acqe_fip->event_tag, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4023 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4024 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4025 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4026 | LOG_DISCOVERY, |
| 4027 | "2772 Issue FCF rediscover mabilbox " |
| 4028 | "command failed, fail through to FCF " |
| 4029 | "dead event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4030 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4031 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4032 | spin_unlock_irq(&phba->hbalock); |
| 4033 | /* |
| 4034 | * Last resort will fail over by treating this |
| 4035 | * as a link down to FCF registration. |
| 4036 | */ |
| 4037 | lpfc_sli4_fcf_dead_failthrough(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4038 | } else { |
| 4039 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4040 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4041 | /* |
| 4042 | * Handling fast FCF failover to a DEAD FCF event is |
| 4043 | * considered equalivant to receiving CVL to all vports. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4044 | */ |
| 4045 | lpfc_sli4_perform_all_vport_cvl(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4046 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4047 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4048 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4049 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4050 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4051 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4052 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4053 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4054 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4055 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4056 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4057 | if (!ndlp) |
| 4058 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4059 | active_vlink_present = 0; |
| 4060 | |
| 4061 | vports = lpfc_create_vport_work_array(phba); |
| 4062 | if (vports) { |
| 4063 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4064 | i++) { |
| 4065 | if ((!(vports[i]->fc_flag & |
| 4066 | FC_VPORT_CVL_RCVD)) && |
| 4067 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4068 | active_vlink_present = 1; |
| 4069 | break; |
| 4070 | } |
| 4071 | } |
| 4072 | lpfc_destroy_vport_work_array(phba, vports); |
| 4073 | } |
| 4074 | |
| 4075 | if (active_vlink_present) { |
| 4076 | /* |
| 4077 | * If there are other active VLinks present, |
| 4078 | * re-instantiate the Vlink using FDISC. |
| 4079 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4080 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4081 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4082 | spin_lock_irq(shost->host_lock); |
| 4083 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4084 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4085 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4086 | vport->port_state = LPFC_FDISC; |
| 4087 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4088 | /* |
| 4089 | * Otherwise, we request port to rediscover |
| 4090 | * the entire FCF table for a fast recovery |
| 4091 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4092 | * is no longer valid if we are not already |
| 4093 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4094 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4095 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4096 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4097 | spin_unlock_irq(&phba->hbalock); |
| 4098 | break; |
| 4099 | } |
| 4100 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4101 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4102 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4103 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4104 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4105 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4106 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4107 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4108 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4109 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4110 | LOG_DISCOVERY, |
| 4111 | "2774 Issue FCF rediscover " |
| 4112 | "mabilbox command failed, " |
| 4113 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4114 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4115 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4116 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4117 | /* |
| 4118 | * Last resort will be re-try on the |
| 4119 | * the current registered FCF entry. |
| 4120 | */ |
| 4121 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4122 | } else |
| 4123 | /* |
| 4124 | * Reset FCF roundrobin bmask for new |
| 4125 | * discovery. |
| 4126 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4127 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4128 | } |
| 4129 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4130 | default: |
| 4131 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4132 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4133 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4134 | break; |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | /** |
| 4139 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4140 | * @phba: pointer to lpfc hba data structure. |
| 4141 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4142 | * |
| 4143 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4144 | **/ |
| 4145 | static void |
| 4146 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4147 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4148 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4149 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4150 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4151 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4152 | "handled yet\n"); |
| 4153 | } |
| 4154 | |
| 4155 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4156 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4157 | * @phba: pointer to lpfc hba data structure. |
| 4158 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4159 | * |
| 4160 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4161 | * is an asynchronous notified of a logical link speed change. The Port |
| 4162 | * reports the logical link speed in units of 10Mbps. |
| 4163 | **/ |
| 4164 | static void |
| 4165 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4166 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4167 | { |
| 4168 | uint16_t prev_ll_spd; |
| 4169 | |
| 4170 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4171 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4172 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4173 | phba->sli4_hba.link_state.logical_speed = |
| 4174 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); |
| 4175 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4176 | "2789 GRP5 Async Event: Updating logical link speed " |
| 4177 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), |
| 4178 | (phba->sli4_hba.link_state.logical_speed*10)); |
| 4179 | } |
| 4180 | |
| 4181 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4182 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4183 | * @phba: pointer to lpfc hba data structure. |
| 4184 | * |
| 4185 | * This routine is invoked by the worker thread to process all the pending |
| 4186 | * SLI4 asynchronous events. |
| 4187 | **/ |
| 4188 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4189 | { |
| 4190 | struct lpfc_cq_event *cq_event; |
| 4191 | |
| 4192 | /* First, declare the async event has been handled */ |
| 4193 | spin_lock_irq(&phba->hbalock); |
| 4194 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4195 | spin_unlock_irq(&phba->hbalock); |
| 4196 | /* Now, handle all the async events */ |
| 4197 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4198 | /* Get the first event from the head of the event queue */ |
| 4199 | spin_lock_irq(&phba->hbalock); |
| 4200 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4201 | cq_event, struct lpfc_cq_event, list); |
| 4202 | spin_unlock_irq(&phba->hbalock); |
| 4203 | /* Process the asynchronous event */ |
| 4204 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4205 | case LPFC_TRAILER_CODE_LINK: |
| 4206 | lpfc_sli4_async_link_evt(phba, |
| 4207 | &cq_event->cqe.acqe_link); |
| 4208 | break; |
| 4209 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4210 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4211 | break; |
| 4212 | case LPFC_TRAILER_CODE_DCBX: |
| 4213 | lpfc_sli4_async_dcbx_evt(phba, |
| 4214 | &cq_event->cqe.acqe_dcbx); |
| 4215 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4216 | case LPFC_TRAILER_CODE_GRP5: |
| 4217 | lpfc_sli4_async_grp5_evt(phba, |
| 4218 | &cq_event->cqe.acqe_grp5); |
| 4219 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4220 | case LPFC_TRAILER_CODE_FC: |
| 4221 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4222 | break; |
| 4223 | case LPFC_TRAILER_CODE_SLI: |
| 4224 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4225 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4226 | default: |
| 4227 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4228 | "1804 Invalid asynchrous event code: " |
| 4229 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4230 | &cq_event->cqe.mcqe_cmpl)); |
| 4231 | break; |
| 4232 | } |
| 4233 | /* Free the completion event processed to the free pool */ |
| 4234 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4239 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4240 | * @phba: pointer to lpfc hba data structure. |
| 4241 | * |
| 4242 | * This routine is invoked by the worker thread to process FCF table |
| 4243 | * rediscovery pending completion event. |
| 4244 | **/ |
| 4245 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4246 | { |
| 4247 | int rc; |
| 4248 | |
| 4249 | spin_lock_irq(&phba->hbalock); |
| 4250 | /* Clear FCF rediscovery timeout event */ |
| 4251 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4252 | /* Clear driver fast failover FCF record flag */ |
| 4253 | phba->fcf.failover_rec.flag = 0; |
| 4254 | /* Set state for FCF fast failover */ |
| 4255 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4256 | spin_unlock_irq(&phba->hbalock); |
| 4257 | |
| 4258 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4259 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4260 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4261 | 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] | 4262 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4263 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4264 | "2747 Issue FCF scan read FCF mailbox " |
| 4265 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4269 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4270 | * @phba: pointer to lpfc hba data structure. |
| 4271 | * @dev_grp: The HBA PCI-Device group number. |
| 4272 | * |
| 4273 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4274 | * API jump table entries. |
| 4275 | * |
| 4276 | * Return: 0 if success, otherwise -ENODEV |
| 4277 | **/ |
| 4278 | int |
| 4279 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4280 | { |
| 4281 | int rc; |
| 4282 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4283 | /* Set up lpfc PCI-device group */ |
| 4284 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4285 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4286 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4287 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4288 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4289 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4290 | /* Set up device INIT API function jump table */ |
| 4291 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4292 | if (rc) |
| 4293 | return -ENODEV; |
| 4294 | /* Set up SCSI API function jump table */ |
| 4295 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4296 | if (rc) |
| 4297 | return -ENODEV; |
| 4298 | /* Set up SLI API function jump table */ |
| 4299 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4300 | if (rc) |
| 4301 | return -ENODEV; |
| 4302 | /* Set up MBOX API function jump table */ |
| 4303 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4304 | if (rc) |
| 4305 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4306 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4307 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4311 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4312 | * @phba: pointer to lpfc hba data structure. |
| 4313 | * @intr_mode: active interrupt mode adopted. |
| 4314 | * |
| 4315 | * This routine it invoked to log the currently used active interrupt mode |
| 4316 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4317 | **/ |
| 4318 | 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] | 4319 | { |
| 4320 | switch (intr_mode) { |
| 4321 | case 0: |
| 4322 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4323 | "0470 Enable INTx interrupt mode.\n"); |
| 4324 | break; |
| 4325 | case 1: |
| 4326 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4327 | "0481 Enabled MSI interrupt mode.\n"); |
| 4328 | break; |
| 4329 | case 2: |
| 4330 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4331 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4332 | break; |
| 4333 | default: |
| 4334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4335 | "0482 Illegal interrupt mode.\n"); |
| 4336 | break; |
| 4337 | } |
| 4338 | return; |
| 4339 | } |
| 4340 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4341 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4342 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4343 | * @phba: pointer to lpfc hba data structure. |
| 4344 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4345 | * This routine is invoked to enable the PCI device that is common to all |
| 4346 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4347 | * |
| 4348 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4349 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4350 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4351 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4352 | static int |
| 4353 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4354 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4355 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4356 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4357 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4358 | /* Obtain PCI device reference */ |
| 4359 | if (!phba->pcidev) |
| 4360 | goto out_error; |
| 4361 | else |
| 4362 | pdev = phba->pcidev; |
| 4363 | /* Select PCI BARs */ |
| 4364 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4365 | /* Enable PCI device */ |
| 4366 | if (pci_enable_device_mem(pdev)) |
| 4367 | goto out_error; |
| 4368 | /* Request PCI resource for the device */ |
| 4369 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4370 | goto out_disable_device; |
| 4371 | /* Set up device as PCI master and save state for EEH */ |
| 4372 | pci_set_master(pdev); |
| 4373 | pci_try_set_mwi(pdev); |
| 4374 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4375 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4376 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
| 4377 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) |
| 4378 | pdev->needs_freset = 1; |
| 4379 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4380 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4381 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4382 | out_disable_device: |
| 4383 | pci_disable_device(pdev); |
| 4384 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4386 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4387 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4391 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4392 | * @phba: pointer to lpfc hba data structure. |
| 4393 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4394 | * This routine is invoked to disable the PCI device that is common to all |
| 4395 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4396 | **/ |
| 4397 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4398 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4399 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4400 | struct pci_dev *pdev; |
| 4401 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4402 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4403 | /* Obtain PCI device reference */ |
| 4404 | if (!phba->pcidev) |
| 4405 | return; |
| 4406 | else |
| 4407 | pdev = phba->pcidev; |
| 4408 | /* Select PCI BARs */ |
| 4409 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4410 | /* Release PCI resource and disable PCI device */ |
| 4411 | pci_release_selected_regions(pdev, bars); |
| 4412 | pci_disable_device(pdev); |
| 4413 | /* Null out PCI private reference to driver */ |
| 4414 | pci_set_drvdata(pdev, NULL); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4415 | |
| 4416 | return; |
| 4417 | } |
| 4418 | |
| 4419 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4420 | * lpfc_reset_hba - Reset a hba |
| 4421 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4422 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4423 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4424 | * offline, performs a board restart, and then brings the board back |
| 4425 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4426 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4427 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4428 | void |
| 4429 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4431 | /* If resets are disabled then set error state and return. */ |
| 4432 | if (!phba->cfg_enable_hba_reset) { |
| 4433 | phba->link_state = LPFC_HBA_ERROR; |
| 4434 | return; |
| 4435 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 4436 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4437 | lpfc_offline(phba); |
| 4438 | lpfc_sli_brdrestart(phba); |
| 4439 | lpfc_online(phba); |
| 4440 | lpfc_unblock_mgmt_io(phba); |
| 4441 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4443 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4444 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4445 | * @phba: pointer to lpfc hba data structure. |
| 4446 | * |
| 4447 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4448 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4449 | * enable the number of virtual functions to the physical function. As |
| 4450 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4451 | * API call does not considered as an error condition for most of the device. |
| 4452 | **/ |
| 4453 | uint16_t |
| 4454 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4455 | { |
| 4456 | struct pci_dev *pdev = phba->pcidev; |
| 4457 | uint16_t nr_virtfn; |
| 4458 | int pos; |
| 4459 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4460 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4461 | if (pos == 0) |
| 4462 | return 0; |
| 4463 | |
| 4464 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4465 | return nr_virtfn; |
| 4466 | } |
| 4467 | |
| 4468 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4469 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4470 | * @phba: pointer to lpfc hba data structure. |
| 4471 | * @nr_vfn: number of virtual functions to be enabled. |
| 4472 | * |
| 4473 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4474 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4475 | * enable the number of virtual functions to the physical function. As |
| 4476 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4477 | * API call does not considered as an error condition for most of the device. |
| 4478 | **/ |
| 4479 | int |
| 4480 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4481 | { |
| 4482 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4483 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4484 | int rc; |
| 4485 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4486 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4487 | if (nr_vfn > max_nr_vfn) { |
| 4488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4489 | "3057 Requested vfs (%d) greater than " |
| 4490 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4491 | return -EINVAL; |
| 4492 | } |
| 4493 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4494 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4495 | if (rc) { |
| 4496 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4497 | "2806 Failed to enable sriov on this device " |
| 4498 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4499 | nr_vfn, rc); |
| 4500 | } else |
| 4501 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4502 | "2807 Successful enable sriov on this device " |
| 4503 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4504 | return rc; |
| 4505 | } |
| 4506 | |
| 4507 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4508 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4509 | * @phba: pointer to lpfc hba data structure. |
| 4510 | * |
| 4511 | * This routine is invoked to set up the driver internal resources specific to |
| 4512 | * support the SLI-3 HBA device it attached to. |
| 4513 | * |
| 4514 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4515 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4516 | * other values - error |
| 4517 | **/ |
| 4518 | static int |
| 4519 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4520 | { |
| 4521 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4522 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4523 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4524 | /* |
| 4525 | * Initialize timers used by driver |
| 4526 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4528 | /* Heartbeat timer */ |
| 4529 | init_timer(&phba->hb_tmofunc); |
| 4530 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4531 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4532 | |
| 4533 | psli = &phba->sli; |
| 4534 | /* MBOX heartbeat timer */ |
| 4535 | init_timer(&psli->mbox_tmo); |
| 4536 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4537 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4538 | /* FCP polling mode timer */ |
| 4539 | init_timer(&phba->fcp_poll_timer); |
| 4540 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4541 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4542 | /* Fabric block timer */ |
| 4543 | init_timer(&phba->fabric_block_timer); |
| 4544 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4545 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4546 | /* EA polling mode timer */ |
| 4547 | init_timer(&phba->eratt_poll); |
| 4548 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4549 | phba->eratt_poll.data = (unsigned long) phba; |
| 4550 | |
| 4551 | /* Host attention work mask setup */ |
| 4552 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4553 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4554 | |
| 4555 | /* Get all the module params for configuring this host */ |
| 4556 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4557 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4558 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4559 | /* check for menlo minimum sg count */ |
| 4560 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4561 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4562 | } |
| 4563 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4564 | if (!phba->sli.ring) |
| 4565 | phba->sli.ring = (struct lpfc_sli_ring *) |
| 4566 | kzalloc(LPFC_SLI3_MAX_RING * |
| 4567 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4568 | if (!phba->sli.ring) |
| 4569 | return -ENOMEM; |
| 4570 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4571 | /* |
| 4572 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4573 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4574 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4575 | */ |
| 4576 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4577 | sizeof(struct fcp_rsp) + |
| 4578 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4579 | |
| 4580 | if (phba->cfg_enable_bg) { |
| 4581 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4582 | phba->cfg_sg_dma_buf_size += |
| 4583 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); |
| 4584 | } |
| 4585 | |
| 4586 | /* Also reinitialize the host templates with new values. */ |
| 4587 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4588 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4589 | |
| 4590 | phba->max_vpi = LPFC_MAX_VPI; |
| 4591 | /* This will be set to correct value after config_port mbox */ |
| 4592 | phba->max_vports = 0; |
| 4593 | |
| 4594 | /* |
| 4595 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4596 | */ |
| 4597 | lpfc_sli_setup(phba); |
| 4598 | lpfc_sli_queue_setup(phba); |
| 4599 | |
| 4600 | /* Allocate device driver memory */ |
| 4601 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4602 | return -ENOMEM; |
| 4603 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4604 | /* |
| 4605 | * Enable sr-iov virtual functions if supported and configured |
| 4606 | * through the module parameter. |
| 4607 | */ |
| 4608 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4609 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4610 | phba->cfg_sriov_nr_virtfn); |
| 4611 | if (rc) { |
| 4612 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4613 | "2808 Requested number of SR-IOV " |
| 4614 | "virtual functions (%d) is not " |
| 4615 | "supported\n", |
| 4616 | phba->cfg_sriov_nr_virtfn); |
| 4617 | phba->cfg_sriov_nr_virtfn = 0; |
| 4618 | } |
| 4619 | } |
| 4620 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4621 | return 0; |
| 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4626 | * @phba: pointer to lpfc hba data structure. |
| 4627 | * |
| 4628 | * This routine is invoked to unset the driver internal resources set up |
| 4629 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4630 | **/ |
| 4631 | static void |
| 4632 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4633 | { |
| 4634 | /* Free device driver memory allocated */ |
| 4635 | lpfc_mem_free_all(phba); |
| 4636 | |
| 4637 | return; |
| 4638 | } |
| 4639 | |
| 4640 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4641 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4642 | * @phba: pointer to lpfc hba data structure. |
| 4643 | * |
| 4644 | * This routine is invoked to set up the driver internal resources specific to |
| 4645 | * support the SLI-4 HBA device it attached to. |
| 4646 | * |
| 4647 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4648 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4649 | * other values - error |
| 4650 | **/ |
| 4651 | static int |
| 4652 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4653 | { |
| 4654 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4655 | LPFC_MBOXQ_t *mboxq; |
| 4656 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; |
| 4657 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4658 | struct lpfc_mqe *mqe; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4659 | int longs, sli_family; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4660 | int sges_per_segment; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4661 | |
| 4662 | /* Before proceed, wait for POST done and device ready */ |
| 4663 | rc = lpfc_sli4_post_status_check(phba); |
| 4664 | if (rc) |
| 4665 | return -ENODEV; |
| 4666 | |
| 4667 | /* |
| 4668 | * Initialize timers used by driver |
| 4669 | */ |
| 4670 | |
| 4671 | /* Heartbeat timer */ |
| 4672 | init_timer(&phba->hb_tmofunc); |
| 4673 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4674 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4675 | init_timer(&phba->rrq_tmr); |
| 4676 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4677 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4678 | |
| 4679 | psli = &phba->sli; |
| 4680 | /* MBOX heartbeat timer */ |
| 4681 | init_timer(&psli->mbox_tmo); |
| 4682 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4683 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4684 | /* Fabric block timer */ |
| 4685 | init_timer(&phba->fabric_block_timer); |
| 4686 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4687 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4688 | /* EA polling mode timer */ |
| 4689 | init_timer(&phba->eratt_poll); |
| 4690 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4691 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4692 | /* FCF rediscover timer */ |
| 4693 | init_timer(&phba->fcf.redisc_wait); |
| 4694 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4695 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4696 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4697 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4698 | * Control structure for handling external multi-buffer mailbox |
| 4699 | * command pass-through. |
| 4700 | */ |
| 4701 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4702 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4703 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4704 | |
| 4705 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4706 | * We need to do a READ_CONFIG mailbox command here before |
| 4707 | * calling lpfc_get_cfgparam. For VFs this will report the |
| 4708 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. |
| 4709 | * All of the resources allocated |
| 4710 | * for this Port are tied to these values. |
| 4711 | */ |
| 4712 | /* Get all the module params for configuring this host */ |
| 4713 | lpfc_get_cfgparam(phba); |
| 4714 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4715 | |
| 4716 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 4717 | phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count; |
| 4718 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4719 | /* This will be set to correct value after the read_config mbox */ |
| 4720 | phba->max_vports = 0; |
| 4721 | |
| 4722 | /* Program the default value of vlan_id and fc_map */ |
| 4723 | phba->valid_vlan = 0; |
| 4724 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4725 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4726 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4727 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4728 | /* With BlockGuard we can have multiple SGEs per Data Segemnt */ |
| 4729 | sges_per_segment = 1; |
| 4730 | if (phba->cfg_enable_bg) |
| 4731 | sges_per_segment = 2; |
| 4732 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4733 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4734 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 4735 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 4736 | */ |
| 4737 | if (!phba->sli.ring) |
| 4738 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4739 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4740 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4741 | if (!phba->sli.ring) |
| 4742 | return -ENOMEM; |
| 4743 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4744 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4745 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4746 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4747 | * To insure that the scsi sgl does not cross a 4k page boundary only |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4748 | * sgl sizes of must be a power of 2. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4749 | */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4750 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4751 | (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) * |
| 4752 | sizeof(struct sli4_sge))); |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4753 | |
| 4754 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); |
| 4755 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; |
| 4756 | switch (sli_family) { |
| 4757 | case LPFC_SLI_INTF_FAMILY_BE2: |
| 4758 | case LPFC_SLI_INTF_FAMILY_BE3: |
| 4759 | /* There is a single hint for BE - 2 pages per BPL. */ |
| 4760 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == |
| 4761 | LPFC_SLI_INTF_SLI_HINT1_1) |
| 4762 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; |
| 4763 | break; |
| 4764 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: |
| 4765 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: |
| 4766 | default: |
| 4767 | break; |
| 4768 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4769 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4770 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
| 4771 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; |
| 4772 | dma_buf_size = dma_buf_size << 1) |
| 4773 | ; |
| 4774 | if (dma_buf_size == max_buf_size) |
| 4775 | phba->cfg_sg_seg_cnt = (dma_buf_size - |
| 4776 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - |
| 4777 | (2 * sizeof(struct sli4_sge))) / |
| 4778 | sizeof(struct sli4_sge); |
| 4779 | phba->cfg_sg_dma_buf_size = dma_buf_size; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4780 | |
| 4781 | /* Initialize buffer queue management fields */ |
| 4782 | hbq_count = lpfc_sli_hbq_count(); |
| 4783 | for (i = 0; i < hbq_count; ++i) |
| 4784 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 4785 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 4786 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 4787 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 4788 | |
| 4789 | /* |
| 4790 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 4791 | */ |
| 4792 | /* Initialize the Abort scsi buffer list used by driver */ |
| 4793 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 4794 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 4795 | /* This abort list used by worker thread */ |
| 4796 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 4797 | |
| 4798 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4799 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4800 | */ |
| 4801 | |
| 4802 | /* Driver internel slow-path CQ Event pool */ |
| 4803 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 4804 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4805 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4806 | /* Asynchronous event CQ Event work queue list */ |
| 4807 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 4808 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 4809 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 4810 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 4811 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 4812 | /* Receive queue CQ Event work queue list */ |
| 4813 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 4814 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4815 | /* Initialize extent block lists. */ |
| 4816 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 4817 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 4818 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 4819 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 4820 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4821 | /* Initialize the driver internal SLI layer lists. */ |
| 4822 | lpfc_sli_setup(phba); |
| 4823 | lpfc_sli_queue_setup(phba); |
| 4824 | |
| 4825 | /* Allocate device driver memory */ |
| 4826 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 4827 | if (rc) |
| 4828 | return -ENOMEM; |
| 4829 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4830 | /* IF Type 2 ports get initialized now. */ |
| 4831 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4832 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 4833 | rc = lpfc_pci_function_reset(phba); |
| 4834 | if (unlikely(rc)) |
| 4835 | return -ENODEV; |
| 4836 | } |
| 4837 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4838 | /* Create the bootstrap mailbox command */ |
| 4839 | rc = lpfc_create_bootstrap_mbox(phba); |
| 4840 | if (unlikely(rc)) |
| 4841 | goto out_free_mem; |
| 4842 | |
| 4843 | /* Set up the host's endian order with the device. */ |
| 4844 | rc = lpfc_setup_endian_order(phba); |
| 4845 | if (unlikely(rc)) |
| 4846 | goto out_free_bsmbx; |
| 4847 | |
| 4848 | /* Set up the hba's configuration parameters. */ |
| 4849 | rc = lpfc_sli4_read_config(phba); |
| 4850 | if (unlikely(rc)) |
| 4851 | goto out_free_bsmbx; |
| 4852 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4853 | /* IF Type 0 ports get initialized now. */ |
| 4854 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4855 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 4856 | rc = lpfc_pci_function_reset(phba); |
| 4857 | if (unlikely(rc)) |
| 4858 | goto out_free_bsmbx; |
| 4859 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4860 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4861 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4862 | GFP_KERNEL); |
| 4863 | if (!mboxq) { |
| 4864 | rc = -ENOMEM; |
| 4865 | goto out_free_bsmbx; |
| 4866 | } |
| 4867 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4868 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4869 | lpfc_supported_pages(mboxq); |
| 4870 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4871 | if (!rc) { |
| 4872 | mqe = &mboxq->u.mqe; |
| 4873 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 4874 | LPFC_MAX_SUPPORTED_PAGES); |
| 4875 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 4876 | switch (pn_page[i]) { |
| 4877 | case LPFC_SLI4_PARAMETERS: |
| 4878 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 4879 | break; |
| 4880 | default: |
| 4881 | break; |
| 4882 | } |
| 4883 | } |
| 4884 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 4885 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 4886 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 4887 | if (rc) { |
| 4888 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4889 | rc = -EIO; |
| 4890 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4891 | } |
| 4892 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4893 | /* |
| 4894 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4895 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 4896 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4897 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4898 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 4899 | if (rc) { |
| 4900 | if (phba->sli4_hba.extents_in_use && |
| 4901 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 4902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4903 | "2999 Unsupported SLI4 Parameters " |
| 4904 | "Extents and RPI headers enabled.\n"); |
| 4905 | goto out_free_bsmbx; |
| 4906 | } |
| 4907 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4908 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4909 | /* Verify all the SLI4 queues */ |
| 4910 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4911 | if (rc) |
| 4912 | goto out_free_bsmbx; |
| 4913 | |
| 4914 | /* Create driver internal CQE event pool */ |
| 4915 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 4916 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4917 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4918 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4919 | /* Initialize sgl lists per host */ |
| 4920 | lpfc_init_sgl_list(phba); |
| 4921 | |
| 4922 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4923 | rc = lpfc_init_active_sgl_array(phba); |
| 4924 | if (rc) { |
| 4925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4926 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4927 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4928 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4929 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 4930 | if (rc) { |
| 4931 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4932 | "1432 Failed to initialize rpi headers.\n"); |
| 4933 | goto out_free_active_sgl; |
| 4934 | } |
| 4935 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4936 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4937 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 4938 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4939 | GFP_KERNEL); |
| 4940 | if (!phba->fcf.fcf_rr_bmask) { |
| 4941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4942 | "2759 Failed allocate memory for FCF round " |
| 4943 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4944 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4945 | goto out_remove_rpi_hdrs; |
| 4946 | } |
| 4947 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4948 | phba->sli4_hba.fcp_eq_hdl = |
| 4949 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
| 4950 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 4951 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 4952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4953 | "2572 Failed allocate memory for " |
| 4954 | "fast-path per-EQ handle array\n"); |
| 4955 | rc = -ENOMEM; |
| 4956 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 4960 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4961 | if (!phba->sli4_hba.msix_entries) { |
| 4962 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4963 | "2573 Failed allocate memory for msi-x " |
| 4964 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4965 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4966 | goto out_free_fcp_eq_hdl; |
| 4967 | } |
| 4968 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4969 | /* |
| 4970 | * Enable sr-iov virtual functions if supported and configured |
| 4971 | * through the module parameter. |
| 4972 | */ |
| 4973 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4974 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4975 | phba->cfg_sriov_nr_virtfn); |
| 4976 | if (rc) { |
| 4977 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4978 | "3020 Requested number of SR-IOV " |
| 4979 | "virtual functions (%d) is not " |
| 4980 | "supported\n", |
| 4981 | phba->cfg_sriov_nr_virtfn); |
| 4982 | phba->cfg_sriov_nr_virtfn = 0; |
| 4983 | } |
| 4984 | } |
| 4985 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4986 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4987 | |
| 4988 | out_free_fcp_eq_hdl: |
| 4989 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4990 | out_free_fcf_rr_bmask: |
| 4991 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4992 | out_remove_rpi_hdrs: |
| 4993 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 4994 | out_free_active_sgl: |
| 4995 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4996 | out_destroy_cq_event_pool: |
| 4997 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4998 | out_free_bsmbx: |
| 4999 | lpfc_destroy_bootstrap_mbox(phba); |
| 5000 | out_free_mem: |
| 5001 | lpfc_mem_free(phba); |
| 5002 | return rc; |
| 5003 | } |
| 5004 | |
| 5005 | /** |
| 5006 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5007 | * @phba: pointer to lpfc hba data structure. |
| 5008 | * |
| 5009 | * This routine is invoked to unset the driver internal resources set up |
| 5010 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5011 | **/ |
| 5012 | static void |
| 5013 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5014 | { |
| 5015 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5016 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5017 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5018 | kfree(phba->sli4_hba.msix_entries); |
| 5019 | |
| 5020 | /* Free memory allocated for fast-path work queue handles */ |
| 5021 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5022 | |
| 5023 | /* Free the allocated rpi headers. */ |
| 5024 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5025 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5026 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5027 | /* Free eligible FCF index bmask */ |
| 5028 | kfree(phba->fcf.fcf_rr_bmask); |
| 5029 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5030 | /* Free the ELS sgl list */ |
| 5031 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5032 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5033 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5034 | /* Free the completion queue EQ event pool */ |
| 5035 | lpfc_sli4_cq_event_release_all(phba); |
| 5036 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5037 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5038 | /* Release resource identifiers. */ |
| 5039 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5040 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5041 | /* Free the bsmbx region. */ |
| 5042 | lpfc_destroy_bootstrap_mbox(phba); |
| 5043 | |
| 5044 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5045 | lpfc_mem_free_all(phba); |
| 5046 | |
| 5047 | /* Free the current connect table */ |
| 5048 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5049 | &phba->fcf_conn_rec_list, list) { |
| 5050 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5051 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5052 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5053 | |
| 5054 | return; |
| 5055 | } |
| 5056 | |
| 5057 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5058 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5059 | * @phba: The hba struct for which this call is being executed. |
| 5060 | * @dev_grp: The HBA PCI-Device group number. |
| 5061 | * |
| 5062 | * This routine sets up the device INIT interface API function jump table |
| 5063 | * in @phba struct. |
| 5064 | * |
| 5065 | * Returns: 0 - success, -ENODEV - failure. |
| 5066 | **/ |
| 5067 | int |
| 5068 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5069 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5070 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5071 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5072 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5073 | switch (dev_grp) { |
| 5074 | case LPFC_PCI_DEV_LP: |
| 5075 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5076 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5077 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5078 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5079 | case LPFC_PCI_DEV_OC: |
| 5080 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5081 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5082 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5083 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5084 | default: |
| 5085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5086 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5087 | dev_grp); |
| 5088 | return -ENODEV; |
| 5089 | break; |
| 5090 | } |
| 5091 | return 0; |
| 5092 | } |
| 5093 | |
| 5094 | /** |
| 5095 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5096 | * @phba: pointer to lpfc hba data structure. |
| 5097 | * |
| 5098 | * This routine is invoked to set up the driver internal resources before the |
| 5099 | * device specific resource setup to support the HBA device it attached to. |
| 5100 | * |
| 5101 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5102 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5103 | * other values - error |
| 5104 | **/ |
| 5105 | static int |
| 5106 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5107 | { |
| 5108 | /* |
| 5109 | * Driver resources common to all SLI revisions |
| 5110 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5111 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5112 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5113 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5114 | /* Initialize ndlp management spinlock */ |
| 5115 | spin_lock_init(&phba->ndlp_lock); |
| 5116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5117 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5118 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5119 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5120 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5121 | /* Initialize the wait queue head for the kernel thread */ |
| 5122 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5123 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5124 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
| 5125 | spin_lock_init(&phba->scsi_buf_list_lock); |
| 5126 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5127 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5128 | /* Initialize the fabric iocb list */ |
| 5129 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5130 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5131 | /* Initialize list to save ELS buffers */ |
| 5132 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5133 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5134 | /* Initialize FCF connection rec list */ |
| 5135 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5136 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5137 | return 0; |
| 5138 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5139 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5140 | /** |
| 5141 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5142 | * @phba: pointer to lpfc hba data structure. |
| 5143 | * |
| 5144 | * This routine is invoked to set up the driver internal resources after the |
| 5145 | * device specific resource setup to support the HBA device it attached to. |
| 5146 | * |
| 5147 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5148 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5149 | * other values - error |
| 5150 | **/ |
| 5151 | static int |
| 5152 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5153 | { |
| 5154 | int error; |
| 5155 | |
| 5156 | /* Startup the kernel thread for this host adapter. */ |
| 5157 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5158 | "lpfc_worker_%d", phba->brd_no); |
| 5159 | if (IS_ERR(phba->worker_thread)) { |
| 5160 | error = PTR_ERR(phba->worker_thread); |
| 5161 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5162 | } |
| 5163 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5164 | return 0; |
| 5165 | } |
| 5166 | |
| 5167 | /** |
| 5168 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5169 | * @phba: pointer to lpfc hba data structure. |
| 5170 | * |
| 5171 | * This routine is invoked to unset the driver internal resources set up after |
| 5172 | * the device specific resource setup for supporting the HBA device it |
| 5173 | * attached to. |
| 5174 | **/ |
| 5175 | static void |
| 5176 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5177 | { |
| 5178 | /* Stop kernel worker thread */ |
| 5179 | kthread_stop(phba->worker_thread); |
| 5180 | } |
| 5181 | |
| 5182 | /** |
| 5183 | * lpfc_free_iocb_list - Free iocb list. |
| 5184 | * @phba: pointer to lpfc hba data structure. |
| 5185 | * |
| 5186 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5187 | **/ |
| 5188 | static void |
| 5189 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5190 | { |
| 5191 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5192 | |
| 5193 | spin_lock_irq(&phba->hbalock); |
| 5194 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5195 | &phba->lpfc_iocb_list, list) { |
| 5196 | list_del(&iocbq_entry->list); |
| 5197 | kfree(iocbq_entry); |
| 5198 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5199 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5200 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5201 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5202 | return; |
| 5203 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5204 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5205 | /** |
| 5206 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5207 | * @phba: pointer to lpfc hba data structure. |
| 5208 | * |
| 5209 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5210 | * list and set up the IOCB tag array accordingly. |
| 5211 | * |
| 5212 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5213 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5214 | * other values - error |
| 5215 | **/ |
| 5216 | static int |
| 5217 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5218 | { |
| 5219 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5220 | uint16_t iotag; |
| 5221 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5222 | |
| 5223 | /* Initialize and populate the iocb list per host. */ |
| 5224 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5225 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5226 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5227 | if (iocbq_entry == NULL) { |
| 5228 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5229 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5230 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5231 | goto out_free_iocbq; |
| 5232 | } |
| 5233 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5234 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5235 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5236 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5237 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5238 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5239 | goto out_free_iocbq; |
| 5240 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5241 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5242 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5243 | |
| 5244 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5245 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5246 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5247 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5248 | } |
| 5249 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5250 | return 0; |
| 5251 | |
| 5252 | out_free_iocbq: |
| 5253 | lpfc_free_iocb_list(phba); |
| 5254 | |
| 5255 | return -ENOMEM; |
| 5256 | } |
| 5257 | |
| 5258 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5259 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5260 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5261 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5262 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5263 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5264 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5265 | void |
| 5266 | 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] | 5267 | { |
| 5268 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5269 | |
| 5270 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5271 | list_del(&sglq_entry->list); |
| 5272 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5273 | kfree(sglq_entry); |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5279 | * @phba: pointer to lpfc hba data structure. |
| 5280 | * |
| 5281 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5282 | **/ |
| 5283 | static void |
| 5284 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5285 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5286 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5287 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5288 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5289 | spin_lock_irq(&phba->hbalock); |
| 5290 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5291 | spin_unlock_irq(&phba->hbalock); |
| 5292 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5293 | /* Now free the sgl list */ |
| 5294 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | /** |
| 5298 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5299 | * @phba: pointer to lpfc hba data structure. |
| 5300 | * |
| 5301 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5302 | * This array will hold the sglq_entry's for active IOs. |
| 5303 | **/ |
| 5304 | static int |
| 5305 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5306 | { |
| 5307 | int size; |
| 5308 | size = sizeof(struct lpfc_sglq *); |
| 5309 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5310 | |
| 5311 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5312 | kzalloc(size, GFP_KERNEL); |
| 5313 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5314 | return -ENOMEM; |
| 5315 | return 0; |
| 5316 | } |
| 5317 | |
| 5318 | /** |
| 5319 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5320 | * @phba: pointer to lpfc hba data structure. |
| 5321 | * |
| 5322 | * This routine is invoked to walk through the array of active sglq entries |
| 5323 | * and free all of the resources. |
| 5324 | * This is just a place holder for now. |
| 5325 | **/ |
| 5326 | static void |
| 5327 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5328 | { |
| 5329 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5330 | } |
| 5331 | |
| 5332 | /** |
| 5333 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5334 | * @phba: pointer to lpfc hba data structure. |
| 5335 | * |
| 5336 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5337 | * list and set up the sgl xritag tag array accordingly. |
| 5338 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5339 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5340 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5341 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5342 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5343 | /* Initialize and populate the sglq list per host/VF. */ |
| 5344 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5345 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5346 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5347 | /* els xri-sgl book keeping */ |
| 5348 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5349 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5350 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5351 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | /** |
| 5355 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5356 | * @phba: pointer to lpfc hba data structure. |
| 5357 | * |
| 5358 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5359 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5360 | * 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] | 5361 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5362 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5363 | * |
| 5364 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5365 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5366 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5367 | **/ |
| 5368 | int |
| 5369 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5370 | { |
| 5371 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5372 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5373 | |
| 5374 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5375 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5376 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5377 | if (phba->sli4_hba.extents_in_use) |
| 5378 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5379 | |
| 5380 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5381 | if (!rpi_hdr) { |
| 5382 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5383 | "0391 Error during rpi post operation\n"); |
| 5384 | lpfc_sli4_remove_rpis(phba); |
| 5385 | rc = -ENODEV; |
| 5386 | } |
| 5387 | |
| 5388 | return rc; |
| 5389 | } |
| 5390 | |
| 5391 | /** |
| 5392 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5393 | * @phba: pointer to lpfc hba data structure. |
| 5394 | * |
| 5395 | * This routine is invoked to allocate a single 4KB memory region to |
| 5396 | * support rpis and stores them in the phba. This single region |
| 5397 | * provides support for up to 64 rpis. The region is used globally |
| 5398 | * by the device. |
| 5399 | * |
| 5400 | * Returns: |
| 5401 | * A valid rpi hdr on success. |
| 5402 | * A NULL pointer on any failure. |
| 5403 | **/ |
| 5404 | struct lpfc_rpi_hdr * |
| 5405 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5406 | { |
| 5407 | uint16_t rpi_limit, curr_rpi_range; |
| 5408 | struct lpfc_dmabuf *dmabuf; |
| 5409 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5410 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5411 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5412 | /* |
| 5413 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5414 | * required. Set the expected maximum count and let the actual value |
| 5415 | * get set when extents are fully allocated. |
| 5416 | */ |
| 5417 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5418 | return NULL; |
| 5419 | if (phba->sli4_hba.extents_in_use) |
| 5420 | return NULL; |
| 5421 | |
| 5422 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5423 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5424 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5425 | |
| 5426 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5427 | /* |
| 5428 | * Establish the starting RPI in this header block. The starting |
| 5429 | * rpi is normalized to a zero base because the physical rpi is |
| 5430 | * port based. |
| 5431 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5432 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5433 | spin_unlock_irq(&phba->hbalock); |
| 5434 | |
| 5435 | /* |
| 5436 | * The port has a limited number of rpis. The increment here |
| 5437 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5438 | * and to allow the full max_rpi range per port. |
| 5439 | */ |
| 5440 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5441 | rpi_count = rpi_limit - curr_rpi_range; |
| 5442 | else |
| 5443 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5444 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5445 | if (!rpi_count) |
| 5446 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5447 | /* |
| 5448 | * First allocate the protocol header region for the port. The |
| 5449 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5450 | */ |
| 5451 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5452 | if (!dmabuf) |
| 5453 | return NULL; |
| 5454 | |
| 5455 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5456 | LPFC_HDR_TEMPLATE_SIZE, |
| 5457 | &dmabuf->phys, |
| 5458 | GFP_KERNEL); |
| 5459 | if (!dmabuf->virt) { |
| 5460 | rpi_hdr = NULL; |
| 5461 | goto err_free_dmabuf; |
| 5462 | } |
| 5463 | |
| 5464 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5465 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5466 | rpi_hdr = NULL; |
| 5467 | goto err_free_coherent; |
| 5468 | } |
| 5469 | |
| 5470 | /* Save the rpi header data for cleanup later. */ |
| 5471 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5472 | if (!rpi_hdr) |
| 5473 | goto err_free_coherent; |
| 5474 | |
| 5475 | rpi_hdr->dmabuf = dmabuf; |
| 5476 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5477 | rpi_hdr->page_count = 1; |
| 5478 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5479 | |
| 5480 | /* The rpi_hdr stores the logical index only. */ |
| 5481 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5482 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5483 | |
| 5484 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5485 | * The next_rpi stores the next logical module-64 rpi value used |
| 5486 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5487 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5488 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5489 | spin_unlock_irq(&phba->hbalock); |
| 5490 | return rpi_hdr; |
| 5491 | |
| 5492 | err_free_coherent: |
| 5493 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5494 | dmabuf->virt, dmabuf->phys); |
| 5495 | err_free_dmabuf: |
| 5496 | kfree(dmabuf); |
| 5497 | return NULL; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
| 5501 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5502 | * @phba: pointer to lpfc hba data structure. |
| 5503 | * |
| 5504 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5505 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5506 | * presumes the caller has released all rpis consumed by fabric or port |
| 5507 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5508 | **/ |
| 5509 | void |
| 5510 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5511 | { |
| 5512 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5513 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5514 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5515 | goto exit; |
| 5516 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5517 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5518 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5519 | list_del(&rpi_hdr->list); |
| 5520 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5521 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5522 | kfree(rpi_hdr->dmabuf); |
| 5523 | kfree(rpi_hdr); |
| 5524 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5525 | exit: |
| 5526 | /* There are no rpis available to the port now. */ |
| 5527 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5531 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5532 | * @pdev: pointer to pci device data structure. |
| 5533 | * |
| 5534 | * This routine is invoked to allocate the driver hba data structure for an |
| 5535 | * HBA device. If the allocation is successful, the phba reference to the |
| 5536 | * PCI device data structure is set. |
| 5537 | * |
| 5538 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5539 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5540 | * NULL - error |
| 5541 | **/ |
| 5542 | static struct lpfc_hba * |
| 5543 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5544 | { |
| 5545 | struct lpfc_hba *phba; |
| 5546 | |
| 5547 | /* Allocate memory for HBA structure */ |
| 5548 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5549 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5550 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5551 | return NULL; |
| 5552 | } |
| 5553 | |
| 5554 | /* Set reference to PCI device in HBA structure */ |
| 5555 | phba->pcidev = pdev; |
| 5556 | |
| 5557 | /* Assign an unused board number */ |
| 5558 | phba->brd_no = lpfc_get_instance(); |
| 5559 | if (phba->brd_no < 0) { |
| 5560 | kfree(phba); |
| 5561 | return NULL; |
| 5562 | } |
| 5563 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5564 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5565 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5566 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5567 | return phba; |
| 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5572 | * @phba: pointer to lpfc hba data structure. |
| 5573 | * |
| 5574 | * This routine is invoked to free the driver hba data structure with an |
| 5575 | * HBA device. |
| 5576 | **/ |
| 5577 | static void |
| 5578 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5579 | { |
| 5580 | /* Release the driver assigned board number */ |
| 5581 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5582 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5583 | /* Free memory allocated with sli rings */ |
| 5584 | kfree(phba->sli.ring); |
| 5585 | phba->sli.ring = NULL; |
| 5586 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5587 | kfree(phba); |
| 5588 | return; |
| 5589 | } |
| 5590 | |
| 5591 | /** |
| 5592 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5593 | * @phba: pointer to lpfc hba data structure. |
| 5594 | * |
| 5595 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5596 | * host with it. |
| 5597 | * |
| 5598 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5599 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5600 | * other values - error |
| 5601 | **/ |
| 5602 | static int |
| 5603 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5604 | { |
| 5605 | struct lpfc_vport *vport; |
| 5606 | struct Scsi_Host *shost; |
| 5607 | |
| 5608 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5609 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5610 | phba->fc_ratov = FF_DEF_RATOV; |
| 5611 | phba->fc_altov = FF_DEF_ALTOV; |
| 5612 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5613 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5614 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5615 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5616 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5617 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5618 | |
| 5619 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5620 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5621 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5622 | /* Put reference to SCSI host to driver's device private data */ |
| 5623 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5624 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5625 | return 0; |
| 5626 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5627 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5628 | /** |
| 5629 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5630 | * @phba: pointer to lpfc hba data structure. |
| 5631 | * |
| 5632 | * This routine is invoked to destroy HBA physical port and the associated |
| 5633 | * SCSI host. |
| 5634 | **/ |
| 5635 | static void |
| 5636 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5637 | { |
| 5638 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5639 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5640 | /* Destroy physical port that associated with the SCSI host */ |
| 5641 | destroy_port(vport); |
| 5642 | |
| 5643 | return; |
| 5644 | } |
| 5645 | |
| 5646 | /** |
| 5647 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5648 | * @phba: pointer to lpfc hba data structure. |
| 5649 | * @shost: the shost to be used to detect Block guard settings. |
| 5650 | * |
| 5651 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5652 | * This routine also allocates memory for debugging bg buffers. |
| 5653 | **/ |
| 5654 | static void |
| 5655 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5656 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5657 | uint32_t old_mask; |
| 5658 | uint32_t old_guard; |
| 5659 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5660 | int pagecnt = 10; |
| 5661 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5662 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5663 | "1478 Registering BlockGuard with the " |
| 5664 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5665 | |
| 5666 | old_mask = lpfc_prot_mask; |
| 5667 | old_guard = lpfc_prot_guard; |
| 5668 | |
| 5669 | /* Only allow supported values */ |
| 5670 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 5671 | SHOST_DIX_TYPE0_PROTECTION | |
| 5672 | SHOST_DIX_TYPE1_PROTECTION); |
| 5673 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 5674 | |
| 5675 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 5676 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 5677 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 5678 | |
| 5679 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5680 | if ((old_mask != lpfc_prot_mask) || |
| 5681 | (old_guard != lpfc_prot_guard)) |
| 5682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5683 | "1475 Registering BlockGuard with the " |
| 5684 | "SCSI layer: mask %d guard %d\n", |
| 5685 | lpfc_prot_mask, lpfc_prot_guard); |
| 5686 | |
| 5687 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 5688 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 5689 | } else |
| 5690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5691 | "1479 Not Registering BlockGuard with the SCSI " |
| 5692 | "layer, Bad protection parameters: %d %d\n", |
| 5693 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5694 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5695 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5696 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5697 | while (pagecnt) { |
| 5698 | spin_lock_init(&_dump_buf_lock); |
| 5699 | _dump_buf_data = |
| 5700 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5701 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5702 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5703 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5704 | "_dump_buf_data at 0x%p\n", |
| 5705 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5706 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5707 | memset(_dump_buf_data, 0, |
| 5708 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5709 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5710 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5711 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5712 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5713 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5714 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5715 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5716 | "memory for hexdump\n"); |
| 5717 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5718 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5719 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5720 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5721 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5722 | while (pagecnt) { |
| 5723 | _dump_buf_dif = |
| 5724 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5725 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5726 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5727 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5728 | "_dump_buf_dif at 0x%p\n", |
| 5729 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5730 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5731 | memset(_dump_buf_dif, 0, |
| 5732 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5733 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5734 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5735 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5736 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5737 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5738 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5739 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5740 | "memory for hexdump\n"); |
| 5741 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5742 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5743 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5744 | _dump_buf_dif); |
| 5745 | } |
| 5746 | |
| 5747 | /** |
| 5748 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 5749 | * @phba: pointer to lpfc hba data structure. |
| 5750 | * |
| 5751 | * This routine is invoked to perform all the necessary post initialization |
| 5752 | * setup for the device. |
| 5753 | **/ |
| 5754 | static void |
| 5755 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 5756 | { |
| 5757 | struct Scsi_Host *shost; |
| 5758 | struct lpfc_adapter_event_header adapter_event; |
| 5759 | |
| 5760 | /* Get the default values for Model Name and Description */ |
| 5761 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 5762 | |
| 5763 | /* |
| 5764 | * hba setup may have changed the hba_queue_depth so we need to |
| 5765 | * adjust the value of can_queue. |
| 5766 | */ |
| 5767 | shost = pci_get_drvdata(phba->pcidev); |
| 5768 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 5769 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 5770 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5771 | |
| 5772 | lpfc_host_attrib_init(shost); |
| 5773 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5774 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5775 | spin_lock_irq(shost->host_lock); |
| 5776 | lpfc_poll_start_timer(phba); |
| 5777 | spin_unlock_irq(shost->host_lock); |
| 5778 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 5779 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5780 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5781 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5782 | /* Send board arrival event to upper layer */ |
| 5783 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 5784 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 5785 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5786 | sizeof(adapter_event), |
| 5787 | (char *) &adapter_event, |
| 5788 | LPFC_NL_VENDOR_ID); |
| 5789 | return; |
| 5790 | } |
| 5791 | |
| 5792 | /** |
| 5793 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 5794 | * @phba: pointer to lpfc hba data structure. |
| 5795 | * |
| 5796 | * This routine is invoked to set up the PCI device memory space for device |
| 5797 | * with SLI-3 interface spec. |
| 5798 | * |
| 5799 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5800 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5801 | * other values - error |
| 5802 | **/ |
| 5803 | static int |
| 5804 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 5805 | { |
| 5806 | struct pci_dev *pdev; |
| 5807 | unsigned long bar0map_len, bar2map_len; |
| 5808 | int i, hbq_count; |
| 5809 | void *ptr; |
| 5810 | int error = -ENODEV; |
| 5811 | |
| 5812 | /* Obtain PCI device reference */ |
| 5813 | if (!phba->pcidev) |
| 5814 | return error; |
| 5815 | else |
| 5816 | pdev = phba->pcidev; |
| 5817 | |
| 5818 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5819 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 5820 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 5821 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 5822 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5823 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5824 | } |
| 5825 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5826 | |
| 5827 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 5828 | * required by each mapping. |
| 5829 | */ |
| 5830 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 5831 | bar0map_len = pci_resource_len(pdev, 0); |
| 5832 | |
| 5833 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 5834 | bar2map_len = pci_resource_len(pdev, 2); |
| 5835 | |
| 5836 | /* Map HBA SLIM to a kernel virtual address. */ |
| 5837 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 5838 | if (!phba->slim_memmap_p) { |
| 5839 | dev_printk(KERN_ERR, &pdev->dev, |
| 5840 | "ioremap failed for SLIM memory.\n"); |
| 5841 | goto out; |
| 5842 | } |
| 5843 | |
| 5844 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 5845 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 5846 | if (!phba->ctrl_regs_memmap_p) { |
| 5847 | dev_printk(KERN_ERR, &pdev->dev, |
| 5848 | "ioremap failed for HBA control registers.\n"); |
| 5849 | goto out_iounmap_slim; |
| 5850 | } |
| 5851 | |
| 5852 | /* Allocate memory for SLI-2 structures */ |
| 5853 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 5854 | SLI2_SLIM_SIZE, |
| 5855 | &phba->slim2p.phys, |
| 5856 | GFP_KERNEL); |
| 5857 | if (!phba->slim2p.virt) |
| 5858 | goto out_iounmap; |
| 5859 | |
| 5860 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 5861 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 5862 | phba->mbox_ext = (phba->slim2p.virt + |
| 5863 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5864 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 5865 | phba->IOCBs = (phba->slim2p.virt + |
| 5866 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 5867 | |
| 5868 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 5869 | lpfc_sli_hbq_size(), |
| 5870 | &phba->hbqslimp.phys, |
| 5871 | GFP_KERNEL); |
| 5872 | if (!phba->hbqslimp.virt) |
| 5873 | goto out_free_slim; |
| 5874 | |
| 5875 | hbq_count = lpfc_sli_hbq_count(); |
| 5876 | ptr = phba->hbqslimp.virt; |
| 5877 | for (i = 0; i < hbq_count; ++i) { |
| 5878 | phba->hbqs[i].hbq_virt = ptr; |
| 5879 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5880 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 5881 | sizeof(struct lpfc_hbq_entry)); |
| 5882 | } |
| 5883 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 5884 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 5885 | |
| 5886 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 5887 | |
| 5888 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5889 | |
| 5890 | phba->MBslimaddr = phba->slim_memmap_p; |
| 5891 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 5892 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 5893 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 5894 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5896 | return 0; |
| 5897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5898 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5899 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5900 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5901 | out_iounmap: |
| 5902 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5903 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5904 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5905 | out: |
| 5906 | return error; |
| 5907 | } |
| 5908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5909 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5910 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 5911 | * @phba: pointer to lpfc hba data structure. |
| 5912 | * |
| 5913 | * This routine is invoked to unset the PCI device memory space for device |
| 5914 | * with SLI-3 interface spec. |
| 5915 | **/ |
| 5916 | static void |
| 5917 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 5918 | { |
| 5919 | struct pci_dev *pdev; |
| 5920 | |
| 5921 | /* Obtain PCI device reference */ |
| 5922 | if (!phba->pcidev) |
| 5923 | return; |
| 5924 | else |
| 5925 | pdev = phba->pcidev; |
| 5926 | |
| 5927 | /* Free coherent DMA memory allocated */ |
| 5928 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 5929 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 5930 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5931 | phba->slim2p.virt, phba->slim2p.phys); |
| 5932 | |
| 5933 | /* I/O memory unmap */ |
| 5934 | iounmap(phba->ctrl_regs_memmap_p); |
| 5935 | iounmap(phba->slim_memmap_p); |
| 5936 | |
| 5937 | return; |
| 5938 | } |
| 5939 | |
| 5940 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5941 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 5942 | * @phba: pointer to lpfc hba data structure. |
| 5943 | * |
| 5944 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 5945 | * done and check status. |
| 5946 | * |
| 5947 | * Return 0 if successful, otherwise -ENODEV. |
| 5948 | **/ |
| 5949 | int |
| 5950 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 5951 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5952 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 5953 | struct lpfc_register reg_data; |
| 5954 | int i, port_error = 0; |
| 5955 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5956 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5957 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 5958 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5959 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5960 | return -ENODEV; |
| 5961 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5962 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 5963 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5964 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 5965 | &portsmphr_reg.word0) || |
| 5966 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5967 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5968 | port_error = -ENODEV; |
| 5969 | break; |
| 5970 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5971 | if (LPFC_POST_STAGE_PORT_READY == |
| 5972 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5973 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5974 | msleep(10); |
| 5975 | } |
| 5976 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5977 | /* |
| 5978 | * If there was a port error during POST, then don't proceed with |
| 5979 | * other register reads as the data may not be valid. Just exit. |
| 5980 | */ |
| 5981 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5983 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 5984 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 5985 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 5986 | portsmphr_reg.word0, |
| 5987 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 5988 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 5989 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 5990 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 5991 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 5992 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 5993 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 5994 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 5995 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5996 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5997 | "2534 Device Info: SLIFamily=0x%x, " |
| 5998 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 5999 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6000 | bf_get(lpfc_sli_intf_sli_family, |
| 6001 | &phba->sli4_hba.sli_intf), |
| 6002 | bf_get(lpfc_sli_intf_slirev, |
| 6003 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6004 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6005 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6006 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6007 | &phba->sli4_hba.sli_intf), |
| 6008 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6009 | &phba->sli4_hba.sli_intf), |
| 6010 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6011 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6012 | /* |
| 6013 | * Check for other Port errors during the initialization |
| 6014 | * process. Fail the load if the port did not come up |
| 6015 | * correctly. |
| 6016 | */ |
| 6017 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6018 | &phba->sli4_hba.sli_intf); |
| 6019 | switch (if_type) { |
| 6020 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6021 | phba->sli4_hba.ue_mask_lo = |
| 6022 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6023 | phba->sli4_hba.ue_mask_hi = |
| 6024 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6025 | uerrlo_reg.word0 = |
| 6026 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6027 | uerrhi_reg.word0 = |
| 6028 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6029 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6030 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6032 | "1422 Unrecoverable Error " |
| 6033 | "Detected during POST " |
| 6034 | "uerr_lo_reg=0x%x, " |
| 6035 | "uerr_hi_reg=0x%x, " |
| 6036 | "ue_mask_lo_reg=0x%x, " |
| 6037 | "ue_mask_hi_reg=0x%x\n", |
| 6038 | uerrlo_reg.word0, |
| 6039 | uerrhi_reg.word0, |
| 6040 | phba->sli4_hba.ue_mask_lo, |
| 6041 | phba->sli4_hba.ue_mask_hi); |
| 6042 | port_error = -ENODEV; |
| 6043 | } |
| 6044 | break; |
| 6045 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6046 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6047 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6048 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6049 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6050 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6051 | phba->work_status[0] = |
| 6052 | readl(phba->sli4_hba.u.if_type2. |
| 6053 | ERR1regaddr); |
| 6054 | phba->work_status[1] = |
| 6055 | readl(phba->sli4_hba.u.if_type2. |
| 6056 | ERR2regaddr); |
| 6057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6058 | "2888 Unrecoverable port error " |
| 6059 | "following POST: port status reg " |
| 6060 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6061 | "error 1=0x%x, error 2=0x%x\n", |
| 6062 | reg_data.word0, |
| 6063 | portsmphr_reg.word0, |
| 6064 | phba->work_status[0], |
| 6065 | phba->work_status[1]); |
| 6066 | port_error = -ENODEV; |
| 6067 | } |
| 6068 | break; |
| 6069 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6070 | default: |
| 6071 | break; |
| 6072 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6073 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6074 | return port_error; |
| 6075 | } |
| 6076 | |
| 6077 | /** |
| 6078 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6079 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6080 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6081 | * |
| 6082 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6083 | * memory map. |
| 6084 | **/ |
| 6085 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6086 | 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] | 6087 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6088 | switch (if_type) { |
| 6089 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6090 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6091 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6092 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6093 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6094 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6095 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6096 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6097 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6098 | phba->sli4_hba.SLIINTFregaddr = |
| 6099 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6100 | break; |
| 6101 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6102 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6103 | phba->sli4_hba.conf_regs_memmap_p + |
| 6104 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6105 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6106 | phba->sli4_hba.conf_regs_memmap_p + |
| 6107 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6108 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6109 | phba->sli4_hba.conf_regs_memmap_p + |
| 6110 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6111 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6112 | phba->sli4_hba.conf_regs_memmap_p + |
| 6113 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6114 | phba->sli4_hba.SLIINTFregaddr = |
| 6115 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6116 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6117 | phba->sli4_hba.conf_regs_memmap_p + |
| 6118 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6119 | phba->sli4_hba.RQDBregaddr = |
| 6120 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; |
| 6121 | phba->sli4_hba.WQDBregaddr = |
| 6122 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; |
| 6123 | phba->sli4_hba.EQCQDBregaddr = |
| 6124 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6125 | phba->sli4_hba.MQDBregaddr = |
| 6126 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6127 | phba->sli4_hba.BMBXregaddr = |
| 6128 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6129 | break; |
| 6130 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6131 | default: |
| 6132 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6133 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6134 | if_type); |
| 6135 | break; |
| 6136 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | /** |
| 6140 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6141 | * @phba: pointer to lpfc hba data structure. |
| 6142 | * |
| 6143 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6144 | * memory map. |
| 6145 | **/ |
| 6146 | static void |
| 6147 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6148 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6149 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6150 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6151 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6152 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6153 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6154 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6155 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6156 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | /** |
| 6160 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6161 | * @phba: pointer to lpfc hba data structure. |
| 6162 | * @vf: virtual function number |
| 6163 | * |
| 6164 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6165 | * based on the given viftual function number, @vf. |
| 6166 | * |
| 6167 | * Return 0 if successful, otherwise -ENODEV. |
| 6168 | **/ |
| 6169 | static int |
| 6170 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6171 | { |
| 6172 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6173 | return -ENODEV; |
| 6174 | |
| 6175 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6176 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); |
| 6177 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6178 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); |
| 6179 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6180 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6181 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6182 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6183 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6184 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6185 | return 0; |
| 6186 | } |
| 6187 | |
| 6188 | /** |
| 6189 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6190 | * @phba: pointer to lpfc hba data structure. |
| 6191 | * |
| 6192 | * This routine is invoked to create the bootstrap mailbox |
| 6193 | * region consistent with the SLI-4 interface spec. This |
| 6194 | * routine allocates all memory necessary to communicate |
| 6195 | * mailbox commands to the port and sets up all alignment |
| 6196 | * needs. No locks are expected to be held when calling |
| 6197 | * this routine. |
| 6198 | * |
| 6199 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6200 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6201 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6202 | **/ |
| 6203 | static int |
| 6204 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6205 | { |
| 6206 | uint32_t bmbx_size; |
| 6207 | struct lpfc_dmabuf *dmabuf; |
| 6208 | struct dma_address *dma_address; |
| 6209 | uint32_t pa_addr; |
| 6210 | uint64_t phys_addr; |
| 6211 | |
| 6212 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6213 | if (!dmabuf) |
| 6214 | return -ENOMEM; |
| 6215 | |
| 6216 | /* |
| 6217 | * The bootstrap mailbox region is comprised of 2 parts |
| 6218 | * plus an alignment restriction of 16 bytes. |
| 6219 | */ |
| 6220 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 6221 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6222 | bmbx_size, |
| 6223 | &dmabuf->phys, |
| 6224 | GFP_KERNEL); |
| 6225 | if (!dmabuf->virt) { |
| 6226 | kfree(dmabuf); |
| 6227 | return -ENOMEM; |
| 6228 | } |
| 6229 | memset(dmabuf->virt, 0, bmbx_size); |
| 6230 | |
| 6231 | /* |
| 6232 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6233 | * operations are simple later. The mailbox dma address is required |
| 6234 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6235 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6236 | * command to the port. |
| 6237 | */ |
| 6238 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6239 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6240 | |
| 6241 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6242 | LPFC_ALIGN_16_BYTE); |
| 6243 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6244 | LPFC_ALIGN_16_BYTE); |
| 6245 | |
| 6246 | /* |
| 6247 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6248 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6249 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6250 | * the 30-bit address is the high or low address. |
| 6251 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6252 | * clean on 32 bit machines. |
| 6253 | */ |
| 6254 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6255 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6256 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6257 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6258 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6259 | |
| 6260 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6261 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6262 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6263 | return 0; |
| 6264 | } |
| 6265 | |
| 6266 | /** |
| 6267 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6268 | * @phba: pointer to lpfc hba data structure. |
| 6269 | * |
| 6270 | * This routine is invoked to teardown the bootstrap mailbox |
| 6271 | * region and release all host resources. This routine requires |
| 6272 | * the caller to ensure all mailbox commands recovered, no |
| 6273 | * additional mailbox comands are sent, and interrupts are disabled |
| 6274 | * before calling this routine. |
| 6275 | * |
| 6276 | **/ |
| 6277 | static void |
| 6278 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6279 | { |
| 6280 | dma_free_coherent(&phba->pcidev->dev, |
| 6281 | phba->sli4_hba.bmbx.bmbx_size, |
| 6282 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6283 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6284 | |
| 6285 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6286 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6287 | } |
| 6288 | |
| 6289 | /** |
| 6290 | * lpfc_sli4_read_config - Get the config parameters. |
| 6291 | * @phba: pointer to lpfc hba data structure. |
| 6292 | * |
| 6293 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6294 | * The configuration parameters are used to set the base and maximum values |
| 6295 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6296 | * allocation for the port. |
| 6297 | * |
| 6298 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6299 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6300 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6301 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6302 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6303 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6304 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6305 | { |
| 6306 | LPFC_MBOXQ_t *pmb; |
| 6307 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6308 | union lpfc_sli4_cfg_shdr *shdr; |
| 6309 | uint32_t shdr_status, shdr_add_status; |
| 6310 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6311 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6312 | char *pdesc_0; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6313 | uint32_t desc_count; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6314 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6315 | |
| 6316 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6317 | if (!pmb) { |
| 6318 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6319 | "2011 Unable to allocate memory for issuing " |
| 6320 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6321 | return -ENOMEM; |
| 6322 | } |
| 6323 | |
| 6324 | lpfc_read_config(phba, pmb); |
| 6325 | |
| 6326 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6327 | if (rc != MBX_SUCCESS) { |
| 6328 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6329 | "2012 Mailbox failed , mbxCmd x%x " |
| 6330 | "READ_CONFIG, mbxStatus x%x\n", |
| 6331 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6332 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6333 | rc = -EIO; |
| 6334 | } else { |
| 6335 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6336 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6337 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6338 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6339 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6340 | phba->sli4_hba.lnk_info.lnk_no = |
| 6341 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6342 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6343 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6344 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6345 | phba->sli4_hba.lnk_info.lnk_no); |
| 6346 | } else |
| 6347 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6348 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6349 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6350 | phba->sli4_hba.extents_in_use = |
| 6351 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6352 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6353 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6354 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6355 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6356 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6357 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6358 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6359 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6360 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6361 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6362 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6363 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6364 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6365 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6366 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6367 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6368 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6369 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6370 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6371 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6372 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6373 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6374 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6375 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6376 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6377 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6378 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6379 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6380 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6381 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6382 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6383 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6384 | phba->max_vports = phba->max_vpi; |
| 6385 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6386 | "2003 cfg params Extents? %d " |
| 6387 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6388 | "VPI(B:%d M:%d) " |
| 6389 | "VFI(B:%d M:%d) " |
| 6390 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6391 | "FCFI(Count:%d)\n", |
| 6392 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6393 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6394 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6395 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6396 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6397 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6398 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6399 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6400 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6401 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6402 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6403 | |
| 6404 | if (rc) |
| 6405 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6406 | |
| 6407 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6408 | if (phba->cfg_hba_queue_depth > |
| 6409 | (phba->sli4_hba.max_cfg_param.max_xri - |
| 6410 | lpfc_sli4_get_els_iocb_cnt(phba))) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6411 | phba->cfg_hba_queue_depth = |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6412 | phba->sli4_hba.max_cfg_param.max_xri - |
| 6413 | lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6414 | |
| 6415 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6416 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6417 | goto read_cfg_out; |
| 6418 | |
| 6419 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6420 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6421 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6422 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6423 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6424 | length, LPFC_SLI4_MBX_EMBED); |
| 6425 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6426 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6427 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6428 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6429 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6430 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6431 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6432 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6433 | "3026 Mailbox failed , mbxCmd x%x " |
| 6434 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6435 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6436 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6437 | goto read_cfg_out; |
| 6438 | } |
| 6439 | |
| 6440 | /* search for fc_fcoe resrouce descriptor */ |
| 6441 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6442 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6443 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6444 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6445 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6446 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6447 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6448 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6449 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6450 | goto read_cfg_out; |
| 6451 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6452 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6453 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6454 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6455 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6456 | phba->sli4_hba.iov.pf_number = |
| 6457 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6458 | phba->sli4_hba.iov.vf_number = |
| 6459 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6460 | break; |
| 6461 | } |
| 6462 | } |
| 6463 | |
| 6464 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6465 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6466 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6467 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6468 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6469 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6470 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6471 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6472 | "Resrouce Descriptor:x%x\n", |
| 6473 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6474 | |
| 6475 | read_cfg_out: |
| 6476 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6477 | return rc; |
| 6478 | } |
| 6479 | |
| 6480 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6481 | * 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] | 6482 | * @phba: pointer to lpfc hba data structure. |
| 6483 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6484 | * This routine is invoked to setup the port-side endian order when |
| 6485 | * the port if_type is 0. This routine has no function for other |
| 6486 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6487 | * |
| 6488 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6489 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6490 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6491 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6492 | **/ |
| 6493 | static int |
| 6494 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6495 | { |
| 6496 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6497 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6498 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6499 | HOST_ENDIAN_HIGH_WORD1}; |
| 6500 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6501 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6502 | switch (if_type) { |
| 6503 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6504 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6505 | GFP_KERNEL); |
| 6506 | if (!mboxq) { |
| 6507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6508 | "0492 Unable to allocate memory for " |
| 6509 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6510 | "command\n"); |
| 6511 | return -ENOMEM; |
| 6512 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6513 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6514 | /* |
| 6515 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6516 | * two words to contain special data values and no other data. |
| 6517 | */ |
| 6518 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6519 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6520 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6521 | if (rc != MBX_SUCCESS) { |
| 6522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6523 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6524 | "failed with status x%x\n", |
| 6525 | rc); |
| 6526 | rc = -EIO; |
| 6527 | } |
| 6528 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6529 | break; |
| 6530 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6531 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6532 | default: |
| 6533 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6534 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6535 | return rc; |
| 6536 | } |
| 6537 | |
| 6538 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6539 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6540 | * @phba: pointer to lpfc hba data structure. |
| 6541 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6542 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6543 | * CQs. after this routine is called the counts will be set to valid values that |
| 6544 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6545 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6546 | * |
| 6547 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6548 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6549 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6550 | **/ |
| 6551 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6552 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6553 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6554 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6555 | uint32_t cpu; |
| 6556 | uint32_t i = 0; |
| 6557 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6558 | |
| 6559 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6560 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6561 | * device parameters |
| 6562 | */ |
| 6563 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6564 | /* Sanity check on HBA EQ parameters */ |
| 6565 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6566 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6567 | /* It doesn't make sense to have more io channels then CPUs */ |
| 6568 | for_each_online_cpu(cpu) { |
| 6569 | i++; |
| 6570 | } |
| 6571 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6572 | lpfc_printf_log(phba, |
| 6573 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6574 | "3188 Reducing IO channels to match number of " |
| 6575 | "CPUs: from %d to %d\n", cfg_fcp_io_channel, i); |
| 6576 | cfg_fcp_io_channel = i; |
| 6577 | } |
| 6578 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6579 | if (cfg_fcp_io_channel > |
| 6580 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6581 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 6582 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6584 | "2574 Not enough EQs (%d) from the " |
| 6585 | "pci function for supporting FCP " |
| 6586 | "EQs (%d)\n", |
| 6587 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6588 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6589 | goto out_error; |
| 6590 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6591 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6592 | "2575 Reducing IO channels to match number of " |
| 6593 | "available EQs: from %d to %d\n", |
| 6594 | cfg_fcp_io_channel, |
| 6595 | phba->sli4_hba.max_cfg_param.max_eq); |
| 6596 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6597 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6598 | |
| 6599 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 6600 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6601 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6602 | phba->cfg_fcp_eq_count = cfg_fcp_io_channel; |
| 6603 | phba->cfg_fcp_wq_count = cfg_fcp_io_channel; |
| 6604 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6605 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6606 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6607 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6608 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6609 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6610 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6611 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6612 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6613 | |
| 6614 | return 0; |
| 6615 | out_error: |
| 6616 | return -ENOMEM; |
| 6617 | } |
| 6618 | |
| 6619 | /** |
| 6620 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6621 | * @phba: pointer to lpfc hba data structure. |
| 6622 | * |
| 6623 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6624 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6625 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6626 | * we just use some constant number as place holder. |
| 6627 | * |
| 6628 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 6629 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6630 | * -ENOMEM - No availble memory |
| 6631 | * -EIO - The mailbox failed to complete successfully. |
| 6632 | **/ |
| 6633 | int |
| 6634 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6635 | { |
| 6636 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6637 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6638 | |
| 6639 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6640 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6641 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6642 | if (!phba->cfg_fcp_io_channel) |
| 6643 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6644 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6645 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6646 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6647 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6648 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6649 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6650 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6651 | |
| 6652 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6653 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6654 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6656 | "2576 Failed allocate memory for " |
| 6657 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6658 | goto out_error; |
| 6659 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6660 | |
| 6661 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6662 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6663 | if (!phba->sli4_hba.fcp_cq) { |
| 6664 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6665 | "2577 Failed allocate memory for fast-path " |
| 6666 | "CQ record array\n"); |
| 6667 | goto out_error; |
| 6668 | } |
| 6669 | |
| 6670 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6671 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6672 | if (!phba->sli4_hba.fcp_wq) { |
| 6673 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6674 | "2578 Failed allocate memory for fast-path " |
| 6675 | "WQ record array\n"); |
| 6676 | goto out_error; |
| 6677 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6678 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6679 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6680 | * Since the first EQ can have multiple CQs associated with it, |
| 6681 | * this array is used to quickly see if we have a FCP fast-path |
| 6682 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6683 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6684 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 6685 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6686 | if (!phba->sli4_hba.fcp_cq_map) { |
| 6687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6688 | "2545 Failed allocate memory for fast-path " |
| 6689 | "CQ map\n"); |
| 6690 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6691 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6692 | |
| 6693 | /* |
| 6694 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 6695 | * how many EQs to create. |
| 6696 | */ |
| 6697 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6698 | |
| 6699 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6700 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6701 | phba->sli4_hba.eq_ecount); |
| 6702 | if (!qdesc) { |
| 6703 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6704 | "0497 Failed allocate EQ (%d)\n", idx); |
| 6705 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6706 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6707 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 6708 | |
| 6709 | /* Create Fast Path FCP CQs */ |
| 6710 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6711 | phba->sli4_hba.cq_ecount); |
| 6712 | if (!qdesc) { |
| 6713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6714 | "0499 Failed allocate fast-path FCP " |
| 6715 | "CQ (%d)\n", idx); |
| 6716 | goto out_error; |
| 6717 | } |
| 6718 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 6719 | |
| 6720 | /* Create Fast Path FCP WQs */ |
| 6721 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6722 | phba->sli4_hba.wq_ecount); |
| 6723 | if (!qdesc) { |
| 6724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6725 | "0503 Failed allocate fast-path FCP " |
| 6726 | "WQ (%d)\n", idx); |
| 6727 | goto out_error; |
| 6728 | } |
| 6729 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6730 | } |
| 6731 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6732 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6733 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6734 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6735 | */ |
| 6736 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6737 | /* Create slow-path Mailbox Command Complete Queue */ |
| 6738 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6739 | phba->sli4_hba.cq_ecount); |
| 6740 | if (!qdesc) { |
| 6741 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6742 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6743 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6744 | } |
| 6745 | phba->sli4_hba.mbx_cq = qdesc; |
| 6746 | |
| 6747 | /* Create slow-path ELS Complete Queue */ |
| 6748 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6749 | phba->sli4_hba.cq_ecount); |
| 6750 | if (!qdesc) { |
| 6751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6752 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6753 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6754 | } |
| 6755 | phba->sli4_hba.els_cq = qdesc; |
| 6756 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6757 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6758 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6759 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6760 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6761 | |
| 6762 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6763 | |
| 6764 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 6765 | phba->sli4_hba.mq_ecount); |
| 6766 | if (!qdesc) { |
| 6767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6768 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6769 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6770 | } |
| 6771 | phba->sli4_hba.mbx_wq = qdesc; |
| 6772 | |
| 6773 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6774 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6775 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6776 | |
| 6777 | /* Create slow-path ELS Work Queue */ |
| 6778 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6779 | phba->sli4_hba.wq_ecount); |
| 6780 | if (!qdesc) { |
| 6781 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6782 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6783 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6784 | } |
| 6785 | phba->sli4_hba.els_wq = qdesc; |
| 6786 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6787 | /* |
| 6788 | * Create Receive Queue (RQ) |
| 6789 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6790 | |
| 6791 | /* Create Receive Queue for header */ |
| 6792 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6793 | phba->sli4_hba.rq_ecount); |
| 6794 | if (!qdesc) { |
| 6795 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6796 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6797 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6798 | } |
| 6799 | phba->sli4_hba.hdr_rq = qdesc; |
| 6800 | |
| 6801 | /* Create Receive Queue for data */ |
| 6802 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6803 | phba->sli4_hba.rq_ecount); |
| 6804 | if (!qdesc) { |
| 6805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6806 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6807 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6808 | } |
| 6809 | phba->sli4_hba.dat_rq = qdesc; |
| 6810 | |
| 6811 | return 0; |
| 6812 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6813 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6814 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6815 | return -ENOMEM; |
| 6816 | } |
| 6817 | |
| 6818 | /** |
| 6819 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 6820 | * @phba: pointer to lpfc hba data structure. |
| 6821 | * |
| 6822 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 6823 | * operation. |
| 6824 | * |
| 6825 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6826 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6827 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6828 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6829 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6830 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6831 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 6832 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6833 | int idx; |
| 6834 | |
| 6835 | if (phba->sli4_hba.hba_eq != NULL) { |
| 6836 | /* Release HBA event queue */ |
| 6837 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6838 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 6839 | lpfc_sli4_queue_free( |
| 6840 | phba->sli4_hba.hba_eq[idx]); |
| 6841 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 6842 | } |
| 6843 | } |
| 6844 | kfree(phba->sli4_hba.hba_eq); |
| 6845 | phba->sli4_hba.hba_eq = NULL; |
| 6846 | } |
| 6847 | |
| 6848 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 6849 | /* Release FCP completion queue */ |
| 6850 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6851 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 6852 | lpfc_sli4_queue_free( |
| 6853 | phba->sli4_hba.fcp_cq[idx]); |
| 6854 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 6855 | } |
| 6856 | } |
| 6857 | kfree(phba->sli4_hba.fcp_cq); |
| 6858 | phba->sli4_hba.fcp_cq = NULL; |
| 6859 | } |
| 6860 | |
| 6861 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 6862 | /* Release FCP work queue */ |
| 6863 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6864 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 6865 | lpfc_sli4_queue_free( |
| 6866 | phba->sli4_hba.fcp_wq[idx]); |
| 6867 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 6868 | } |
| 6869 | } |
| 6870 | kfree(phba->sli4_hba.fcp_wq); |
| 6871 | phba->sli4_hba.fcp_wq = NULL; |
| 6872 | } |
| 6873 | |
| 6874 | /* Release FCP CQ mapping array */ |
| 6875 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 6876 | kfree(phba->sli4_hba.fcp_cq_map); |
| 6877 | phba->sli4_hba.fcp_cq_map = NULL; |
| 6878 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6879 | |
| 6880 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6881 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 6882 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 6883 | phba->sli4_hba.mbx_wq = NULL; |
| 6884 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6885 | |
| 6886 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6887 | if (phba->sli4_hba.els_wq != NULL) { |
| 6888 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 6889 | phba->sli4_hba.els_wq = NULL; |
| 6890 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6891 | |
| 6892 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6893 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 6894 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 6895 | phba->sli4_hba.hdr_rq = NULL; |
| 6896 | } |
| 6897 | if (phba->sli4_hba.dat_rq != NULL) { |
| 6898 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 6899 | phba->sli4_hba.dat_rq = NULL; |
| 6900 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6901 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6902 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6903 | if (phba->sli4_hba.els_cq != NULL) { |
| 6904 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 6905 | phba->sli4_hba.els_cq = NULL; |
| 6906 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6907 | |
| 6908 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6909 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 6910 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 6911 | phba->sli4_hba.mbx_cq = NULL; |
| 6912 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6913 | |
| 6914 | return; |
| 6915 | } |
| 6916 | |
| 6917 | /** |
| 6918 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 6919 | * @phba: pointer to lpfc hba data structure. |
| 6920 | * |
| 6921 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 6922 | * operation. |
| 6923 | * |
| 6924 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6925 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6926 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6927 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6928 | **/ |
| 6929 | int |
| 6930 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 6931 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6932 | struct lpfc_sli *psli = &phba->sli; |
| 6933 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6934 | int rc = -ENOMEM; |
| 6935 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 6936 | int fcp_cq_index = 0; |
| 6937 | |
| 6938 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6939 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6940 | */ |
| 6941 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6942 | /* Set up HBA event queue */ |
| 6943 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6944 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6945 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6946 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6947 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6948 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6949 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 6950 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6951 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6952 | "0522 Fast-path EQ (%d) not " |
| 6953 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6954 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6955 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6956 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6957 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 6958 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6959 | if (rc) { |
| 6960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6961 | "0523 Failed setup of fast-path EQ " |
| 6962 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6963 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6964 | } |
| 6965 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6966 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6967 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6968 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6969 | } |
| 6970 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6971 | /* Set up fast-path FCP Response Complete Queue */ |
| 6972 | if (!phba->sli4_hba.fcp_cq) { |
| 6973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6974 | "3148 Fast-path FCP CQ array not " |
| 6975 | "allocated\n"); |
| 6976 | rc = -ENOMEM; |
| 6977 | goto out_destroy_hba_eq; |
| 6978 | } |
| 6979 | |
| 6980 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 6981 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 6982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6983 | "0526 Fast-path FCP CQ (%d) not " |
| 6984 | "allocated\n", fcp_cqidx); |
| 6985 | rc = -ENOMEM; |
| 6986 | goto out_destroy_fcp_cq; |
| 6987 | } |
| 6988 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 6989 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 6990 | if (rc) { |
| 6991 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6992 | "0527 Failed setup of fast-path FCP " |
| 6993 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 6994 | goto out_destroy_fcp_cq; |
| 6995 | } |
| 6996 | |
| 6997 | /* Setup fcp_cq_map for fast lookup */ |
| 6998 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 6999 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7000 | |
| 7001 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7002 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7003 | "parent seq[%d]-id=%d\n", |
| 7004 | fcp_cqidx, |
| 7005 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7006 | fcp_cqidx, |
| 7007 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7008 | } |
| 7009 | |
| 7010 | /* Set up fast-path FCP Work Queue */ |
| 7011 | if (!phba->sli4_hba.fcp_wq) { |
| 7012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7013 | "3149 Fast-path FCP WQ array not " |
| 7014 | "allocated\n"); |
| 7015 | rc = -ENOMEM; |
| 7016 | goto out_destroy_fcp_cq; |
| 7017 | } |
| 7018 | |
| 7019 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7020 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7022 | "0534 Fast-path FCP WQ (%d) not " |
| 7023 | "allocated\n", fcp_wqidx); |
| 7024 | rc = -ENOMEM; |
| 7025 | goto out_destroy_fcp_wq; |
| 7026 | } |
| 7027 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7028 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7029 | LPFC_FCP); |
| 7030 | if (rc) { |
| 7031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7032 | "0535 Failed setup of fast-path FCP " |
| 7033 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 7034 | goto out_destroy_fcp_wq; |
| 7035 | } |
| 7036 | |
| 7037 | /* Bind this WQ to the next FCP ring */ |
| 7038 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7039 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7040 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7041 | |
| 7042 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7043 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7044 | "parent cq[%d]-id=%d\n", |
| 7045 | fcp_wqidx, |
| 7046 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7047 | fcp_cq_index, |
| 7048 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7049 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7050 | /* |
| 7051 | * Set up Complete Queues (CQs) |
| 7052 | */ |
| 7053 | |
| 7054 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7055 | if (!phba->sli4_hba.mbx_cq) { |
| 7056 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7057 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7058 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7059 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7060 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7061 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7062 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | if (rc) { |
| 7064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7065 | "0529 Failed setup of slow-path mailbox CQ: " |
| 7066 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7067 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7068 | } |
| 7069 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7070 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7071 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7072 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7073 | |
| 7074 | /* Set up slow-path ELS Complete Queue */ |
| 7075 | if (!phba->sli4_hba.els_cq) { |
| 7076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7077 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7078 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7079 | goto out_destroy_mbx_cq; |
| 7080 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7081 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7082 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7083 | if (rc) { |
| 7084 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7085 | "0531 Failed setup of slow-path ELS CQ: " |
| 7086 | "rc = 0x%x\n", rc); |
| 7087 | goto out_destroy_mbx_cq; |
| 7088 | } |
| 7089 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7090 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7091 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7092 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7093 | |
| 7094 | /* |
| 7095 | * Set up all the Work Queues (WQs) |
| 7096 | */ |
| 7097 | |
| 7098 | /* Set up Mailbox Command Queue */ |
| 7099 | if (!phba->sli4_hba.mbx_wq) { |
| 7100 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7101 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7102 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7103 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7104 | } |
| 7105 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7106 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7107 | if (rc) { |
| 7108 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7109 | "0539 Failed setup of slow-path MQ: " |
| 7110 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7111 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7112 | } |
| 7113 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7114 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7115 | phba->sli4_hba.mbx_wq->queue_id, |
| 7116 | phba->sli4_hba.mbx_cq->queue_id); |
| 7117 | |
| 7118 | /* Set up slow-path ELS Work Queue */ |
| 7119 | if (!phba->sli4_hba.els_wq) { |
| 7120 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7121 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7122 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7123 | goto out_destroy_mbx_wq; |
| 7124 | } |
| 7125 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7126 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7127 | if (rc) { |
| 7128 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7129 | "0537 Failed setup of slow-path ELS WQ: " |
| 7130 | "rc = 0x%x\n", rc); |
| 7131 | goto out_destroy_mbx_wq; |
| 7132 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7133 | |
| 7134 | /* Bind this WQ to the ELS ring */ |
| 7135 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7136 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7137 | phba->sli4_hba.els_cq->pring = pring; |
| 7138 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7139 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7140 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7141 | phba->sli4_hba.els_wq->queue_id, |
| 7142 | phba->sli4_hba.els_cq->queue_id); |
| 7143 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7144 | /* |
| 7145 | * Create Receive Queue (RQ) |
| 7146 | */ |
| 7147 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7149 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7150 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7151 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7152 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7153 | |
| 7154 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7155 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7156 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7157 | 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] | 7158 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7159 | if (rc) { |
| 7160 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7161 | "0541 Failed setup of Receive Queue: " |
| 7162 | "rc = 0x%x\n", rc); |
| 7163 | goto out_destroy_fcp_wq; |
| 7164 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7165 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7166 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7167 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7168 | "parent cq-id=%d\n", |
| 7169 | phba->sli4_hba.hdr_rq->queue_id, |
| 7170 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7171 | phba->sli4_hba.els_cq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7172 | return 0; |
| 7173 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7174 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7175 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7176 | out_destroy_mbx_wq: |
| 7177 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7178 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7179 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7180 | out_destroy_mbx_cq: |
| 7181 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7182 | out_destroy_fcp_wq: |
| 7183 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7184 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7185 | out_destroy_fcp_cq: |
| 7186 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7187 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7188 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7189 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7190 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7191 | out_error: |
| 7192 | return rc; |
| 7193 | } |
| 7194 | |
| 7195 | /** |
| 7196 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7197 | * @phba: pointer to lpfc hba data structure. |
| 7198 | * |
| 7199 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7200 | * operation. |
| 7201 | * |
| 7202 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7203 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7204 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7205 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7206 | **/ |
| 7207 | void |
| 7208 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7209 | { |
| 7210 | int fcp_qidx; |
| 7211 | |
| 7212 | /* Unset mailbox command work queue */ |
| 7213 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7214 | /* Unset ELS work queue */ |
| 7215 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7216 | /* Unset unsolicited receive queue */ |
| 7217 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7218 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7219 | if (phba->sli4_hba.fcp_wq) { |
| 7220 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7221 | fcp_qidx++) |
| 7222 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7223 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7224 | /* Unset mailbox command complete queue */ |
| 7225 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7226 | /* Unset ELS complete queue */ |
| 7227 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7228 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7229 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7230 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7231 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7232 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7233 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7234 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7235 | if (phba->sli4_hba.hba_eq) { |
| 7236 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7237 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7238 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7239 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | /** |
| 7243 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7244 | * @phba: pointer to lpfc hba data structure. |
| 7245 | * |
| 7246 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7247 | * events. The body of the completion queue event is a completion queue entry |
| 7248 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7249 | * the following HBA completion queue events for the worker thread to process: |
| 7250 | * - Mailbox asynchronous events |
| 7251 | * - Receive queue completion unsolicited events |
| 7252 | * Later, this can be used for all the slow-path events. |
| 7253 | * |
| 7254 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7255 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7256 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7257 | **/ |
| 7258 | static int |
| 7259 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7260 | { |
| 7261 | struct lpfc_cq_event *cq_event; |
| 7262 | int i; |
| 7263 | |
| 7264 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7265 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7266 | if (!cq_event) |
| 7267 | goto out_pool_create_fail; |
| 7268 | list_add_tail(&cq_event->list, |
| 7269 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7270 | } |
| 7271 | return 0; |
| 7272 | |
| 7273 | out_pool_create_fail: |
| 7274 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7275 | return -ENOMEM; |
| 7276 | } |
| 7277 | |
| 7278 | /** |
| 7279 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7280 | * @phba: pointer to lpfc hba data structure. |
| 7281 | * |
| 7282 | * This routine is invoked to free the pool of completion queue events at |
| 7283 | * driver unload time. Note that, it is the responsibility of the driver |
| 7284 | * cleanup routine to free all the outstanding completion-queue events |
| 7285 | * allocated from this pool back into the pool before invoking this routine |
| 7286 | * to destroy the pool. |
| 7287 | **/ |
| 7288 | static void |
| 7289 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7290 | { |
| 7291 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7292 | |
| 7293 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7294 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7295 | list_del(&cq_event->list); |
| 7296 | kfree(cq_event); |
| 7297 | } |
| 7298 | } |
| 7299 | |
| 7300 | /** |
| 7301 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7302 | * @phba: pointer to lpfc hba data structure. |
| 7303 | * |
| 7304 | * This routine is the lock free version of the API invoked to allocate a |
| 7305 | * completion-queue event from the free pool. |
| 7306 | * |
| 7307 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7308 | * NULL otherwise. |
| 7309 | **/ |
| 7310 | struct lpfc_cq_event * |
| 7311 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7312 | { |
| 7313 | struct lpfc_cq_event *cq_event = NULL; |
| 7314 | |
| 7315 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7316 | struct lpfc_cq_event, list); |
| 7317 | return cq_event; |
| 7318 | } |
| 7319 | |
| 7320 | /** |
| 7321 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7322 | * @phba: pointer to lpfc hba data structure. |
| 7323 | * |
| 7324 | * This routine is the lock version of the API invoked to allocate a |
| 7325 | * completion-queue event from the free pool. |
| 7326 | * |
| 7327 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7328 | * NULL otherwise. |
| 7329 | **/ |
| 7330 | struct lpfc_cq_event * |
| 7331 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7332 | { |
| 7333 | struct lpfc_cq_event *cq_event; |
| 7334 | unsigned long iflags; |
| 7335 | |
| 7336 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7337 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7338 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7339 | return cq_event; |
| 7340 | } |
| 7341 | |
| 7342 | /** |
| 7343 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7344 | * @phba: pointer to lpfc hba data structure. |
| 7345 | * @cq_event: pointer to the completion queue event to be freed. |
| 7346 | * |
| 7347 | * This routine is the lock free version of the API invoked to release a |
| 7348 | * completion-queue event back into the free pool. |
| 7349 | **/ |
| 7350 | void |
| 7351 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7352 | struct lpfc_cq_event *cq_event) |
| 7353 | { |
| 7354 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7355 | } |
| 7356 | |
| 7357 | /** |
| 7358 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7359 | * @phba: pointer to lpfc hba data structure. |
| 7360 | * @cq_event: pointer to the completion queue event to be freed. |
| 7361 | * |
| 7362 | * This routine is the lock version of the API invoked to release a |
| 7363 | * completion-queue event back into the free pool. |
| 7364 | **/ |
| 7365 | void |
| 7366 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7367 | struct lpfc_cq_event *cq_event) |
| 7368 | { |
| 7369 | unsigned long iflags; |
| 7370 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7371 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7372 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7373 | } |
| 7374 | |
| 7375 | /** |
| 7376 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7377 | * @phba: pointer to lpfc hba data structure. |
| 7378 | * |
| 7379 | * This routine is to free all the pending completion-queue events to the |
| 7380 | * back into the free pool for device reset. |
| 7381 | **/ |
| 7382 | static void |
| 7383 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7384 | { |
| 7385 | LIST_HEAD(cqelist); |
| 7386 | struct lpfc_cq_event *cqe; |
| 7387 | unsigned long iflags; |
| 7388 | |
| 7389 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7390 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7391 | /* Pending FCP XRI abort events */ |
| 7392 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7393 | &cqelist); |
| 7394 | /* Pending ELS XRI abort events */ |
| 7395 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7396 | &cqelist); |
| 7397 | /* Pending asynnc events */ |
| 7398 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7399 | &cqelist); |
| 7400 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7401 | |
| 7402 | while (!list_empty(&cqelist)) { |
| 7403 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7404 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | /** |
| 7409 | * lpfc_pci_function_reset - Reset pci function. |
| 7410 | * @phba: pointer to lpfc hba data structure. |
| 7411 | * |
| 7412 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7413 | * all resources assigned to the PCI function which originates this request. |
| 7414 | * |
| 7415 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7416 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7417 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7418 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7419 | **/ |
| 7420 | int |
| 7421 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7422 | { |
| 7423 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7424 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7425 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7426 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7427 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7428 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7429 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7430 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7431 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7432 | switch (if_type) { |
| 7433 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7434 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7435 | GFP_KERNEL); |
| 7436 | if (!mboxq) { |
| 7437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7438 | "0494 Unable to allocate memory for " |
| 7439 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7440 | "command\n"); |
| 7441 | return -ENOMEM; |
| 7442 | } |
| 7443 | |
| 7444 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7445 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7446 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7447 | LPFC_SLI4_MBX_EMBED); |
| 7448 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7449 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7450 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7451 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7452 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7453 | &shdr->response); |
| 7454 | if (rc != MBX_TIMEOUT) |
| 7455 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7456 | if (shdr_status || shdr_add_status || rc) { |
| 7457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7458 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7459 | "failed with status x%x add_status x%x," |
| 7460 | " mbx status x%x\n", |
| 7461 | shdr_status, shdr_add_status, rc); |
| 7462 | rc = -ENXIO; |
| 7463 | } |
| 7464 | break; |
| 7465 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7466 | for (num_resets = 0; |
| 7467 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7468 | num_resets++) { |
| 7469 | reg_data.word0 = 0; |
| 7470 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7471 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7472 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7473 | LPFC_SLIPORT_INIT_PORT); |
| 7474 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7475 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7476 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7477 | pci_read_config_word(phba->pcidev, |
| 7478 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7479 | /* |
| 7480 | * Poll the Port Status Register and wait for RDY for |
| 7481 | * up to 10 seconds. If the port doesn't respond, treat |
| 7482 | * it as an error. If the port responds with RN, start |
| 7483 | * the loop again. |
| 7484 | */ |
| 7485 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7486 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7487 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7488 | STATUSregaddr, ®_data.word0)) { |
| 7489 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7490 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7491 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7492 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7493 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7494 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7495 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | /* |
| 7499 | * If the port responds to the init request with |
| 7500 | * reset needed, delay for a bit and restart the loop. |
| 7501 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7502 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7503 | msleep(10); |
| 7504 | reset_again = 0; |
| 7505 | continue; |
| 7506 | } |
| 7507 | |
| 7508 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7509 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7510 | (rdy_chk >= 1000)) { |
| 7511 | phba->work_status[0] = readl( |
| 7512 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7513 | phba->work_status[1] = readl( |
| 7514 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7516 | "2890 Port error detected during port " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7517 | "reset(%d): wait_tmo:%d ms, " |
| 7518 | "port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7519 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7520 | num_resets, rdy_chk*10, |
| 7521 | reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7522 | phba->work_status[0], |
| 7523 | phba->work_status[1]); |
| 7524 | rc = -ENODEV; |
| 7525 | } |
| 7526 | |
| 7527 | /* |
| 7528 | * Terminate the outer loop provided the Port indicated |
| 7529 | * ready within 10 seconds. |
| 7530 | */ |
| 7531 | if (rdy_chk < 1000) |
| 7532 | break; |
| 7533 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7534 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7535 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7536 | break; |
| 7537 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7538 | default: |
| 7539 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | } |
| 7541 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7542 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7543 | /* Catch the not-ready port failure after a port reset. */ |
| 7544 | if (num_resets >= MAX_IF_TYPE_2_RESETS) |
| 7545 | rc = -ENODEV; |
| 7546 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7547 | return rc; |
| 7548 | } |
| 7549 | |
| 7550 | /** |
| 7551 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands |
| 7552 | * @phba: pointer to lpfc hba data structure. |
| 7553 | * @cnt: number of nop mailbox commands to send. |
| 7554 | * |
| 7555 | * This routine is invoked to send a number @cnt of NOP mailbox command and |
| 7556 | * wait for each command to complete. |
| 7557 | * |
| 7558 | * Return: the number of NOP mailbox command completed. |
| 7559 | **/ |
| 7560 | static int |
| 7561 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) |
| 7562 | { |
| 7563 | LPFC_MBOXQ_t *mboxq; |
| 7564 | int length, cmdsent; |
| 7565 | uint32_t mbox_tmo; |
| 7566 | uint32_t rc = 0; |
| 7567 | uint32_t shdr_status, shdr_add_status; |
| 7568 | union lpfc_sli4_cfg_shdr *shdr; |
| 7569 | |
| 7570 | if (cnt == 0) { |
| 7571 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7572 | "2518 Requested to send 0 NOP mailbox cmd\n"); |
| 7573 | return cnt; |
| 7574 | } |
| 7575 | |
| 7576 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7577 | if (!mboxq) { |
| 7578 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7579 | "2519 Unable to allocate memory for issuing " |
| 7580 | "NOP mailbox command\n"); |
| 7581 | return 0; |
| 7582 | } |
| 7583 | |
| 7584 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ |
| 7585 | length = (sizeof(struct lpfc_mbx_nop) - |
| 7586 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7587 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7588 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
James Smart | 59df3ac | 2012-08-03 12:34:29 -0400 | [diff] [blame] | 7589 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7590 | LPFC_MBOX_OPCODE_NOP, length, |
| 7591 | LPFC_SLI4_MBX_EMBED); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7592 | if (!phba->sli4_hba.intr_enable) |
| 7593 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7594 | else { |
| 7595 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7596 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7597 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7598 | if (rc == MBX_TIMEOUT) |
| 7599 | break; |
| 7600 | /* Check return status */ |
| 7601 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7602 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7603 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7604 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7605 | &shdr->response); |
| 7606 | if (shdr_status || shdr_add_status || rc) { |
| 7607 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7608 | "2520 NOP mailbox command failed " |
| 7609 | "status x%x add_status x%x mbx " |
| 7610 | "status x%x\n", shdr_status, |
| 7611 | shdr_add_status, rc); |
| 7612 | break; |
| 7613 | } |
| 7614 | } |
| 7615 | |
| 7616 | if (rc != MBX_TIMEOUT) |
| 7617 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7618 | |
| 7619 | return cmdsent; |
| 7620 | } |
| 7621 | |
| 7622 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7623 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7624 | * @phba: pointer to lpfc hba data structure. |
| 7625 | * |
| 7626 | * This routine is invoked to set up the PCI device memory space for device |
| 7627 | * with SLI-4 interface spec. |
| 7628 | * |
| 7629 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7630 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7631 | * other values - error |
| 7632 | **/ |
| 7633 | static int |
| 7634 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7635 | { |
| 7636 | struct pci_dev *pdev; |
| 7637 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7638 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7639 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7640 | |
| 7641 | /* Obtain PCI device reference */ |
| 7642 | if (!phba->pcidev) |
| 7643 | return error; |
| 7644 | else |
| 7645 | pdev = phba->pcidev; |
| 7646 | |
| 7647 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7648 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7649 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7650 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7651 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7652 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7653 | } |
| 7654 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7655 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7656 | /* |
| 7657 | * The BARs and register set definitions and offset locations are |
| 7658 | * dependent on the if_type. |
| 7659 | */ |
| 7660 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 7661 | &phba->sli4_hba.sli_intf.word0)) { |
| 7662 | return error; |
| 7663 | } |
| 7664 | |
| 7665 | /* There is no SLI3 failback for SLI4 devices. */ |
| 7666 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 7667 | LPFC_SLI_INTF_VALID) { |
| 7668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7669 | "2894 SLI_INTF reg contents invalid " |
| 7670 | "sli_intf reg 0x%x\n", |
| 7671 | phba->sli4_hba.sli_intf.word0); |
| 7672 | return error; |
| 7673 | } |
| 7674 | |
| 7675 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7676 | /* |
| 7677 | * Get the bus address of SLI4 device Bar regions and the |
| 7678 | * number of bytes required by each mapping. The mapping of the |
| 7679 | * particular PCI BARs regions is dependent on the type of |
| 7680 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7681 | */ |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7682 | if (pci_resource_start(pdev, 0)) { |
| 7683 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7684 | bar0map_len = pci_resource_len(pdev, 0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7685 | |
| 7686 | /* |
| 7687 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 7688 | * addr |
| 7689 | */ |
| 7690 | phba->sli4_hba.conf_regs_memmap_p = |
| 7691 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 7692 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7693 | dev_printk(KERN_ERR, &pdev->dev, |
| 7694 | "ioremap failed for SLI4 PCI config " |
| 7695 | "registers.\n"); |
| 7696 | goto out; |
| 7697 | } |
| 7698 | /* Set up BAR0 PCI config space register memory map */ |
| 7699 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7700 | } else { |
| 7701 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 7702 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7703 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7704 | dev_printk(KERN_ERR, &pdev->dev, |
| 7705 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 7706 | goto out; |
| 7707 | } |
| 7708 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7709 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7710 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7711 | dev_printk(KERN_ERR, &pdev->dev, |
| 7712 | "ioremap failed for SLI4 PCI config " |
| 7713 | "registers.\n"); |
| 7714 | goto out; |
| 7715 | } |
| 7716 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7717 | } |
| 7718 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7719 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7720 | (pci_resource_start(pdev, 2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7721 | /* |
| 7722 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 7723 | * virtual address and setup the registers. |
| 7724 | */ |
| 7725 | phba->pci_bar1_map = pci_resource_start(pdev, 2); |
| 7726 | bar1map_len = pci_resource_len(pdev, 2); |
| 7727 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7728 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7729 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 7730 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7731 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7732 | goto out_iounmap_conf; |
| 7733 | } |
| 7734 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7735 | } |
| 7736 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7737 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7738 | (pci_resource_start(pdev, 4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7739 | /* |
| 7740 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 7741 | * virtual address and setup the registers. |
| 7742 | */ |
| 7743 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
| 7744 | bar2map_len = pci_resource_len(pdev, 4); |
| 7745 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7746 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7747 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 7748 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7749 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7750 | goto out_iounmap_ctrl; |
| 7751 | } |
| 7752 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 7753 | if (error) |
| 7754 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7755 | } |
| 7756 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7757 | return 0; |
| 7758 | |
| 7759 | out_iounmap_all: |
| 7760 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7761 | out_iounmap_ctrl: |
| 7762 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7763 | out_iounmap_conf: |
| 7764 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7765 | out: |
| 7766 | return error; |
| 7767 | } |
| 7768 | |
| 7769 | /** |
| 7770 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 7771 | * @phba: pointer to lpfc hba data structure. |
| 7772 | * |
| 7773 | * This routine is invoked to unset the PCI device memory space for device |
| 7774 | * with SLI-4 interface spec. |
| 7775 | **/ |
| 7776 | static void |
| 7777 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 7778 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7779 | uint32_t if_type; |
| 7780 | 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] | 7781 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7782 | switch (if_type) { |
| 7783 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7784 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7785 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7786 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7787 | break; |
| 7788 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7789 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7790 | break; |
| 7791 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7792 | default: |
| 7793 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 7794 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7795 | if_type); |
| 7796 | break; |
| 7797 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7798 | } |
| 7799 | |
| 7800 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7801 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 7802 | * @phba: pointer to lpfc hba data structure. |
| 7803 | * |
| 7804 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 7805 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 7806 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 7807 | * invoked, enables either all or nothing, depending on the current |
| 7808 | * availability of PCI vector resources. The device driver is responsible |
| 7809 | * for calling the individual request_irq() to register each MSI-X vector |
| 7810 | * with a interrupt handler, which is done in this function. Note that |
| 7811 | * later when device is unloading, the driver should always call free_irq() |
| 7812 | * on all MSI-X vectors it has done request_irq() on before calling |
| 7813 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 7814 | * will be left with MSI-X enabled and leaks its vectors. |
| 7815 | * |
| 7816 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7817 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7818 | * other values - error |
| 7819 | **/ |
| 7820 | static int |
| 7821 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 7822 | { |
| 7823 | int rc, i; |
| 7824 | LPFC_MBOXQ_t *pmb; |
| 7825 | |
| 7826 | /* Set up MSI-X multi-message vectors */ |
| 7827 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7828 | phba->msix_entries[i].entry = i; |
| 7829 | |
| 7830 | /* Configure MSI-X capability structure */ |
| 7831 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 7832 | ARRAY_SIZE(phba->msix_entries)); |
| 7833 | if (rc) { |
| 7834 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7835 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 7836 | goto msi_fail_out; |
| 7837 | } |
| 7838 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7839 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7840 | "0477 MSI-X entry[%d]: vector=x%x " |
| 7841 | "message=%d\n", i, |
| 7842 | phba->msix_entries[i].vector, |
| 7843 | phba->msix_entries[i].entry); |
| 7844 | /* |
| 7845 | * Assign MSI-X vectors to interrupt handlers |
| 7846 | */ |
| 7847 | |
| 7848 | /* vector-0 is associated to slow-path handler */ |
| 7849 | rc = request_irq(phba->msix_entries[0].vector, |
| 7850 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 7851 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 7852 | if (rc) { |
| 7853 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7854 | "0421 MSI-X slow-path request_irq failed " |
| 7855 | "(%d)\n", rc); |
| 7856 | goto msi_fail_out; |
| 7857 | } |
| 7858 | |
| 7859 | /* vector-1 is associated to fast-path handler */ |
| 7860 | rc = request_irq(phba->msix_entries[1].vector, |
| 7861 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 7862 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 7863 | |
| 7864 | if (rc) { |
| 7865 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7866 | "0429 MSI-X fast-path request_irq failed " |
| 7867 | "(%d)\n", rc); |
| 7868 | goto irq_fail_out; |
| 7869 | } |
| 7870 | |
| 7871 | /* |
| 7872 | * Configure HBA MSI-X attention conditions to messages |
| 7873 | */ |
| 7874 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7875 | |
| 7876 | if (!pmb) { |
| 7877 | rc = -ENOMEM; |
| 7878 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7879 | "0474 Unable to allocate memory for issuing " |
| 7880 | "MBOX_CONFIG_MSI command\n"); |
| 7881 | goto mem_fail_out; |
| 7882 | } |
| 7883 | rc = lpfc_config_msi(phba, pmb); |
| 7884 | if (rc) |
| 7885 | goto mbx_fail_out; |
| 7886 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 7887 | if (rc != MBX_SUCCESS) { |
| 7888 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 7889 | "0351 Config MSI mailbox command failed, " |
| 7890 | "mbxCmd x%x, mbxStatus x%x\n", |
| 7891 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 7892 | goto mbx_fail_out; |
| 7893 | } |
| 7894 | |
| 7895 | /* Free memory allocated for mailbox command */ |
| 7896 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7897 | return rc; |
| 7898 | |
| 7899 | mbx_fail_out: |
| 7900 | /* Free memory allocated for mailbox command */ |
| 7901 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7902 | |
| 7903 | mem_fail_out: |
| 7904 | /* free the irq already requested */ |
| 7905 | free_irq(phba->msix_entries[1].vector, phba); |
| 7906 | |
| 7907 | irq_fail_out: |
| 7908 | /* free the irq already requested */ |
| 7909 | free_irq(phba->msix_entries[0].vector, phba); |
| 7910 | |
| 7911 | msi_fail_out: |
| 7912 | /* Unconfigure MSI-X capability structure */ |
| 7913 | pci_disable_msix(phba->pcidev); |
| 7914 | return rc; |
| 7915 | } |
| 7916 | |
| 7917 | /** |
| 7918 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 7919 | * @phba: pointer to lpfc hba data structure. |
| 7920 | * |
| 7921 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 7922 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 7923 | **/ |
| 7924 | static void |
| 7925 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 7926 | { |
| 7927 | int i; |
| 7928 | |
| 7929 | /* Free up MSI-X multi-message vectors */ |
| 7930 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7931 | free_irq(phba->msix_entries[i].vector, phba); |
| 7932 | /* Disable MSI-X */ |
| 7933 | pci_disable_msix(phba->pcidev); |
| 7934 | |
| 7935 | return; |
| 7936 | } |
| 7937 | |
| 7938 | /** |
| 7939 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 7940 | * @phba: pointer to lpfc hba data structure. |
| 7941 | * |
| 7942 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 7943 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 7944 | * enable the MSI vector. The device driver is responsible for calling the |
| 7945 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 7946 | * is done in this function. |
| 7947 | * |
| 7948 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7949 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7950 | * other values - error |
| 7951 | */ |
| 7952 | static int |
| 7953 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 7954 | { |
| 7955 | int rc; |
| 7956 | |
| 7957 | rc = pci_enable_msi(phba->pcidev); |
| 7958 | if (!rc) |
| 7959 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7960 | "0462 PCI enable MSI mode success.\n"); |
| 7961 | else { |
| 7962 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7963 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 7964 | return rc; |
| 7965 | } |
| 7966 | |
| 7967 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 7968 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 7969 | if (rc) { |
| 7970 | pci_disable_msi(phba->pcidev); |
| 7971 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7972 | "0478 MSI request_irq failed (%d)\n", rc); |
| 7973 | } |
| 7974 | return rc; |
| 7975 | } |
| 7976 | |
| 7977 | /** |
| 7978 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 7979 | * @phba: pointer to lpfc hba data structure. |
| 7980 | * |
| 7981 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 7982 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 7983 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 7984 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 7985 | * its vector. |
| 7986 | */ |
| 7987 | static void |
| 7988 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 7989 | { |
| 7990 | free_irq(phba->pcidev->irq, phba); |
| 7991 | pci_disable_msi(phba->pcidev); |
| 7992 | return; |
| 7993 | } |
| 7994 | |
| 7995 | /** |
| 7996 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 7997 | * @phba: pointer to lpfc hba data structure. |
| 7998 | * |
| 7999 | * This routine is invoked to enable device interrupt and associate driver's |
| 8000 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8001 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8002 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8003 | * mode which is supported by the platform, kernel, and device in the order |
| 8004 | * of: |
| 8005 | * MSI-X -> MSI -> IRQ. |
| 8006 | * |
| 8007 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8008 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8009 | * other values - error |
| 8010 | **/ |
| 8011 | static uint32_t |
| 8012 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8013 | { |
| 8014 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8015 | int retval; |
| 8016 | |
| 8017 | if (cfg_mode == 2) { |
| 8018 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8019 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8020 | if (!retval) { |
| 8021 | /* Now, try to enable MSI-X interrupt mode */ |
| 8022 | retval = lpfc_sli_enable_msix(phba); |
| 8023 | if (!retval) { |
| 8024 | /* Indicate initialization to MSI-X mode */ |
| 8025 | phba->intr_type = MSIX; |
| 8026 | intr_mode = 2; |
| 8027 | } |
| 8028 | } |
| 8029 | } |
| 8030 | |
| 8031 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8032 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8033 | retval = lpfc_sli_enable_msi(phba); |
| 8034 | if (!retval) { |
| 8035 | /* Indicate initialization to MSI mode */ |
| 8036 | phba->intr_type = MSI; |
| 8037 | intr_mode = 1; |
| 8038 | } |
| 8039 | } |
| 8040 | |
| 8041 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8042 | if (phba->intr_type == NONE) { |
| 8043 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8044 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8045 | if (!retval) { |
| 8046 | /* Indicate initialization to INTx mode */ |
| 8047 | phba->intr_type = INTx; |
| 8048 | intr_mode = 0; |
| 8049 | } |
| 8050 | } |
| 8051 | return intr_mode; |
| 8052 | } |
| 8053 | |
| 8054 | /** |
| 8055 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8056 | * @phba: pointer to lpfc hba data structure. |
| 8057 | * |
| 8058 | * This routine is invoked to disable device interrupt and disassociate the |
| 8059 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8060 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8061 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8062 | **/ |
| 8063 | static void |
| 8064 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8065 | { |
| 8066 | /* Disable the currently initialized interrupt mode */ |
| 8067 | if (phba->intr_type == MSIX) |
| 8068 | lpfc_sli_disable_msix(phba); |
| 8069 | else if (phba->intr_type == MSI) |
| 8070 | lpfc_sli_disable_msi(phba); |
| 8071 | else if (phba->intr_type == INTx) |
| 8072 | free_irq(phba->pcidev->irq, phba); |
| 8073 | |
| 8074 | /* Reset interrupt management states */ |
| 8075 | phba->intr_type = NONE; |
| 8076 | phba->sli.slistat.sli_intr = 0; |
| 8077 | |
| 8078 | return; |
| 8079 | } |
| 8080 | |
| 8081 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8082 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8083 | * @phba: pointer to lpfc hba data structure. |
| 8084 | * |
| 8085 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8086 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 8087 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 8088 | * enables either all or nothing, depending on the current availability of |
| 8089 | * PCI vector resources. The device driver is responsible for calling the |
| 8090 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 8091 | * handler, which is done in this function. Note that later when device is |
| 8092 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 8093 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 8094 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 8095 | * enabled and leaks its vectors. |
| 8096 | * |
| 8097 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8098 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8099 | * other values - error |
| 8100 | **/ |
| 8101 | static int |
| 8102 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8103 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8104 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8105 | |
| 8106 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8107 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8108 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8109 | |
| 8110 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8111 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8112 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8113 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8114 | vectors); |
| 8115 | if (rc > 1) { |
| 8116 | vectors = rc; |
| 8117 | goto enable_msix_vectors; |
| 8118 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8119 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8120 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 8121 | goto msi_fail_out; |
| 8122 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8123 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8124 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8125 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8126 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8127 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8128 | "message=%d\n", index, |
| 8129 | phba->sli4_hba.msix_entries[index].vector, |
| 8130 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8131 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8132 | /* |
| 8133 | * Assign MSI-X vectors to interrupt handlers |
| 8134 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8135 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8136 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
| 8137 | sprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8138 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8139 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8140 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8141 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8142 | 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] | 8143 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8144 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8145 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8146 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8147 | if (rc) { |
| 8148 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8149 | "0486 MSI-X fast-path (%d) " |
| 8150 | "request_irq failed (%d)\n", index, rc); |
| 8151 | goto cfg_fail_out; |
| 8152 | } |
| 8153 | } |
| 8154 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8155 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8157 | "3238 Reducing IO channels to match number of " |
| 8158 | "MSI-X vectors, requested %d got %d\n", |
| 8159 | phba->cfg_fcp_io_channel, vectors); |
| 8160 | phba->cfg_fcp_io_channel = vectors; |
| 8161 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8162 | return rc; |
| 8163 | |
| 8164 | cfg_fail_out: |
| 8165 | /* free the irq already requested */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8166 | for (--index; index >= 0; index--) |
| 8167 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8168 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8169 | |
| 8170 | msi_fail_out: |
| 8171 | /* Unconfigure MSI-X capability structure */ |
| 8172 | pci_disable_msix(phba->pcidev); |
| 8173 | return rc; |
| 8174 | } |
| 8175 | |
| 8176 | /** |
| 8177 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 8178 | * @phba: pointer to lpfc hba data structure. |
| 8179 | * |
| 8180 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8181 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 8182 | **/ |
| 8183 | static void |
| 8184 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 8185 | { |
| 8186 | int index; |
| 8187 | |
| 8188 | /* Free up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8189 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8190 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8191 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8192 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8193 | /* Disable MSI-X */ |
| 8194 | pci_disable_msix(phba->pcidev); |
| 8195 | |
| 8196 | return; |
| 8197 | } |
| 8198 | |
| 8199 | /** |
| 8200 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8201 | * @phba: pointer to lpfc hba data structure. |
| 8202 | * |
| 8203 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8204 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8205 | * to enable the MSI vector. The device driver is responsible for calling |
| 8206 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8207 | * which is done in this function. |
| 8208 | * |
| 8209 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8210 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8211 | * other values - error |
| 8212 | **/ |
| 8213 | static int |
| 8214 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8215 | { |
| 8216 | int rc, index; |
| 8217 | |
| 8218 | rc = pci_enable_msi(phba->pcidev); |
| 8219 | if (!rc) |
| 8220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8221 | "0487 PCI enable MSI mode success.\n"); |
| 8222 | else { |
| 8223 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8224 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8225 | return rc; |
| 8226 | } |
| 8227 | |
| 8228 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8229 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8230 | if (rc) { |
| 8231 | pci_disable_msi(phba->pcidev); |
| 8232 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8233 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8234 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8235 | } |
| 8236 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8237 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8238 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8239 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8240 | } |
| 8241 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8242 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8243 | } |
| 8244 | |
| 8245 | /** |
| 8246 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8247 | * @phba: pointer to lpfc hba data structure. |
| 8248 | * |
| 8249 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8250 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8251 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8252 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8253 | * its vector. |
| 8254 | **/ |
| 8255 | static void |
| 8256 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8257 | { |
| 8258 | free_irq(phba->pcidev->irq, phba); |
| 8259 | pci_disable_msi(phba->pcidev); |
| 8260 | return; |
| 8261 | } |
| 8262 | |
| 8263 | /** |
| 8264 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8265 | * @phba: pointer to lpfc hba data structure. |
| 8266 | * |
| 8267 | * This routine is invoked to enable device interrupt and associate driver's |
| 8268 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8269 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8270 | * the driver will try to fallback from the configured interrupt mode to an |
| 8271 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8272 | * the order of: |
| 8273 | * MSI-X -> MSI -> IRQ. |
| 8274 | * |
| 8275 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8276 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8277 | * other values - error |
| 8278 | **/ |
| 8279 | static uint32_t |
| 8280 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8281 | { |
| 8282 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8283 | int retval, index; |
| 8284 | |
| 8285 | if (cfg_mode == 2) { |
| 8286 | /* Preparation before conf_msi mbox cmd */ |
| 8287 | retval = 0; |
| 8288 | if (!retval) { |
| 8289 | /* Now, try to enable MSI-X interrupt mode */ |
| 8290 | retval = lpfc_sli4_enable_msix(phba); |
| 8291 | if (!retval) { |
| 8292 | /* Indicate initialization to MSI-X mode */ |
| 8293 | phba->intr_type = MSIX; |
| 8294 | intr_mode = 2; |
| 8295 | } |
| 8296 | } |
| 8297 | } |
| 8298 | |
| 8299 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8300 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8301 | retval = lpfc_sli4_enable_msi(phba); |
| 8302 | if (!retval) { |
| 8303 | /* Indicate initialization to MSI mode */ |
| 8304 | phba->intr_type = MSI; |
| 8305 | intr_mode = 1; |
| 8306 | } |
| 8307 | } |
| 8308 | |
| 8309 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8310 | if (phba->intr_type == NONE) { |
| 8311 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8312 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8313 | if (!retval) { |
| 8314 | /* Indicate initialization to INTx mode */ |
| 8315 | phba->intr_type = INTx; |
| 8316 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8317 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8318 | index++) { |
| 8319 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8320 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8321 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8322 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8323 | } |
| 8324 | } |
| 8325 | } |
| 8326 | return intr_mode; |
| 8327 | } |
| 8328 | |
| 8329 | /** |
| 8330 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8331 | * @phba: pointer to lpfc hba data structure. |
| 8332 | * |
| 8333 | * This routine is invoked to disable device interrupt and disassociate |
| 8334 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8335 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8336 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8337 | **/ |
| 8338 | static void |
| 8339 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 8340 | { |
| 8341 | /* Disable the currently initialized interrupt mode */ |
| 8342 | if (phba->intr_type == MSIX) |
| 8343 | lpfc_sli4_disable_msix(phba); |
| 8344 | else if (phba->intr_type == MSI) |
| 8345 | lpfc_sli4_disable_msi(phba); |
| 8346 | else if (phba->intr_type == INTx) |
| 8347 | free_irq(phba->pcidev->irq, phba); |
| 8348 | |
| 8349 | /* Reset interrupt management states */ |
| 8350 | phba->intr_type = NONE; |
| 8351 | phba->sli.slistat.sli_intr = 0; |
| 8352 | |
| 8353 | return; |
| 8354 | } |
| 8355 | |
| 8356 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8357 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 8358 | * @phba: pointer to lpfc hba data structure. |
| 8359 | * |
| 8360 | * This routine is invoked to unset the HBA device initialization steps to |
| 8361 | * a device with SLI-3 interface spec. |
| 8362 | **/ |
| 8363 | static void |
| 8364 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 8365 | { |
| 8366 | struct lpfc_vport *vport = phba->pport; |
| 8367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8368 | |
| 8369 | spin_lock_irq(shost->host_lock); |
| 8370 | vport->load_flag |= FC_UNLOADING; |
| 8371 | spin_unlock_irq(shost->host_lock); |
| 8372 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8373 | kfree(phba->vpi_bmask); |
| 8374 | kfree(phba->vpi_ids); |
| 8375 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8376 | lpfc_stop_hba_timers(phba); |
| 8377 | |
| 8378 | phba->pport->work_port_events = 0; |
| 8379 | |
| 8380 | lpfc_sli_hba_down(phba); |
| 8381 | |
| 8382 | lpfc_sli_brdrestart(phba); |
| 8383 | |
| 8384 | lpfc_sli_disable_intr(phba); |
| 8385 | |
| 8386 | return; |
| 8387 | } |
| 8388 | |
| 8389 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8390 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. |
| 8391 | * @phba: pointer to lpfc hba data structure. |
| 8392 | * |
| 8393 | * This routine is invoked to unset the HBA device initialization steps to |
| 8394 | * a device with SLI-4 interface spec. |
| 8395 | **/ |
| 8396 | static void |
| 8397 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) |
| 8398 | { |
| 8399 | struct lpfc_vport *vport = phba->pport; |
| 8400 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8401 | |
| 8402 | spin_lock_irq(shost->host_lock); |
| 8403 | vport->load_flag |= FC_UNLOADING; |
| 8404 | spin_unlock_irq(shost->host_lock); |
| 8405 | |
| 8406 | phba->pport->work_port_events = 0; |
| 8407 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8408 | /* Stop the SLI4 device port */ |
| 8409 | lpfc_stop_port(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8410 | |
| 8411 | lpfc_sli4_disable_intr(phba); |
| 8412 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8413 | /* Reset SLI4 HBA FCoE function */ |
| 8414 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8415 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8416 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8417 | return; |
| 8418 | } |
| 8419 | |
| 8420 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8421 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 8422 | * @phba: Pointer to HBA context object. |
| 8423 | * |
| 8424 | * This function is called in the SLI4 code path to wait for completion |
| 8425 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 8426 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 8427 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 8428 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 8429 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 8430 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 8431 | * the rest of the driver unload resource release. |
| 8432 | **/ |
| 8433 | static void |
| 8434 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 8435 | { |
| 8436 | int wait_time = 0; |
| 8437 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8438 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8439 | |
| 8440 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 8441 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 8442 | if (!fcp_xri_cmpl) |
| 8443 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8444 | "2877 FCP XRI exchange busy " |
| 8445 | "wait time: %d seconds.\n", |
| 8446 | wait_time/1000); |
| 8447 | if (!els_xri_cmpl) |
| 8448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8449 | "2878 ELS XRI exchange busy " |
| 8450 | "wait time: %d seconds.\n", |
| 8451 | wait_time/1000); |
| 8452 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 8453 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 8454 | } else { |
| 8455 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 8456 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 8457 | } |
| 8458 | fcp_xri_cmpl = |
| 8459 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8460 | els_xri_cmpl = |
| 8461 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 8467 | * @phba: Pointer to HBA context object. |
| 8468 | * |
| 8469 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 8470 | * function. The caller is not required to hold any lock. This routine |
| 8471 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 8472 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 8473 | * free any pending commands. |
| 8474 | **/ |
| 8475 | static void |
| 8476 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 8477 | { |
| 8478 | int wait_cnt = 0; |
| 8479 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8480 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8481 | |
| 8482 | lpfc_stop_hba_timers(phba); |
| 8483 | phba->sli4_hba.intr_enable = 0; |
| 8484 | |
| 8485 | /* |
| 8486 | * Gracefully wait out the potential current outstanding asynchronous |
| 8487 | * mailbox command. |
| 8488 | */ |
| 8489 | |
| 8490 | /* First, block any pending async mailbox command from posted */ |
| 8491 | spin_lock_irq(&phba->hbalock); |
| 8492 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 8493 | spin_unlock_irq(&phba->hbalock); |
| 8494 | /* Now, trying to wait it out if we can */ |
| 8495 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8496 | msleep(10); |
| 8497 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 8498 | break; |
| 8499 | } |
| 8500 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 8501 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8502 | spin_lock_irq(&phba->hbalock); |
| 8503 | mboxq = phba->sli.mbox_active; |
| 8504 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8505 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8506 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8507 | phba->sli.mbox_active = NULL; |
| 8508 | spin_unlock_irq(&phba->hbalock); |
| 8509 | } |
| 8510 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8511 | /* Abort all iocbs associated with the hba */ |
| 8512 | lpfc_sli_hba_iocb_abort(phba); |
| 8513 | |
| 8514 | /* Wait for completion of device XRI exchange busy */ |
| 8515 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 8516 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8517 | /* Disable PCI subsystem interrupt */ |
| 8518 | lpfc_sli4_disable_intr(phba); |
| 8519 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8520 | /* Disable SR-IOV if enabled */ |
| 8521 | if (phba->cfg_sriov_nr_virtfn) |
| 8522 | pci_disable_sriov(pdev); |
| 8523 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8524 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8525 | kthread_stop(phba->worker_thread); |
| 8526 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8527 | /* Reset SLI4 HBA FCoE function */ |
| 8528 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8529 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8530 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8531 | /* Stop the SLI4 device port */ |
| 8532 | phba->pport->work_port_events = 0; |
| 8533 | } |
| 8534 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8535 | /** |
| 8536 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 8537 | * @phba: Pointer to HBA context object. |
| 8538 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8539 | * |
| 8540 | * This function is called in the SLI4 code path to read the port's |
| 8541 | * sli4 capabilities. |
| 8542 | * |
| 8543 | * This function may be be called from any context that can block-wait |
| 8544 | * for the completion. The expectation is that this routine is called |
| 8545 | * typically from probe_one or from the online routine. |
| 8546 | **/ |
| 8547 | int |
| 8548 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8549 | { |
| 8550 | int rc; |
| 8551 | struct lpfc_mqe *mqe; |
| 8552 | struct lpfc_pc_sli4_params *sli4_params; |
| 8553 | uint32_t mbox_tmo; |
| 8554 | |
| 8555 | rc = 0; |
| 8556 | mqe = &mboxq->u.mqe; |
| 8557 | |
| 8558 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8559 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8560 | if (!phba->sli4_hba.intr_enable) |
| 8561 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8562 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8563 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8564 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8565 | } |
| 8566 | |
| 8567 | if (unlikely(rc)) |
| 8568 | return 1; |
| 8569 | |
| 8570 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8571 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 8572 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 8573 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 8574 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 8575 | &mqe->un.sli4_params); |
| 8576 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 8577 | &mqe->un.sli4_params); |
| 8578 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 8579 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 8580 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 8581 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 8582 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 8583 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 8584 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 8585 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 8586 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 8587 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 8588 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 8589 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 8590 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 8591 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 8592 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 8593 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 8594 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 8595 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 8596 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 8597 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 8598 | 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] | 8599 | |
| 8600 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8601 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8602 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8603 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8604 | return rc; |
| 8605 | } |
| 8606 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8607 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8608 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 8609 | * @phba: Pointer to HBA context object. |
| 8610 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8611 | * |
| 8612 | * This function is called in the SLI4 code path to read the port's |
| 8613 | * sli4 capabilities. |
| 8614 | * |
| 8615 | * This function may be be called from any context that can block-wait |
| 8616 | * for the completion. The expectation is that this routine is called |
| 8617 | * typically from probe_one or from the online routine. |
| 8618 | **/ |
| 8619 | int |
| 8620 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8621 | { |
| 8622 | int rc; |
| 8623 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 8624 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8625 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8626 | int length; |
| 8627 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 8628 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8629 | /* |
| 8630 | * By default, the driver assumes the SLI4 port requires RPI |
| 8631 | * header postings. The SLI4_PARAM response will correct this |
| 8632 | * assumption. |
| 8633 | */ |
| 8634 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 8635 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8636 | /* Read the port's SLI4 Config Parameters */ |
| 8637 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 8638 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8639 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8640 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 8641 | length, LPFC_SLI4_MBX_EMBED); |
| 8642 | if (!phba->sli4_hba.intr_enable) |
| 8643 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8644 | else { |
| 8645 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 8646 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8647 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8648 | if (unlikely(rc)) |
| 8649 | return rc; |
| 8650 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8651 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 8652 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 8653 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 8654 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 8655 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 8656 | mbx_sli4_parameters); |
| 8657 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 8658 | mbx_sli4_parameters); |
| 8659 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 8660 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 8661 | else |
| 8662 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 8663 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 8664 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
| 8665 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 8666 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 8667 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 8668 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
| 8669 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 8670 | mbx_sli4_parameters); |
| 8671 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 8672 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8673 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 8674 | 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] | 8675 | |
| 8676 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8677 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8678 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8679 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8680 | return 0; |
| 8681 | } |
| 8682 | |
| 8683 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8684 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 8685 | * @pdev: pointer to PCI device |
| 8686 | * @pid: pointer to PCI device identifier |
| 8687 | * |
| 8688 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 8689 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8690 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 8691 | * information of the device and driver to see if the driver state that it can |
| 8692 | * support this kind of device. If the match is successful, the driver core |
| 8693 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 8694 | * does all the initialization that it needs to do to handle the HBA properly. |
| 8695 | * |
| 8696 | * Return code |
| 8697 | * 0 - driver can claim the device |
| 8698 | * negative value - driver can not claim the device |
| 8699 | **/ |
| 8700 | static int __devinit |
| 8701 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 8702 | { |
| 8703 | struct lpfc_hba *phba; |
| 8704 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8705 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8706 | int error; |
| 8707 | uint32_t cfg_mode, intr_mode; |
| 8708 | |
| 8709 | /* Allocate memory for HBA structure */ |
| 8710 | phba = lpfc_hba_alloc(pdev); |
| 8711 | if (!phba) |
| 8712 | return -ENOMEM; |
| 8713 | |
| 8714 | /* Perform generic PCI device enabling operation */ |
| 8715 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8716 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8717 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8718 | |
| 8719 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 8720 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 8721 | if (error) |
| 8722 | goto out_disable_pci_dev; |
| 8723 | |
| 8724 | /* Set up SLI-3 specific device PCI memory space */ |
| 8725 | error = lpfc_sli_pci_mem_setup(phba); |
| 8726 | if (error) { |
| 8727 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8728 | "1402 Failed to set up pci memory space.\n"); |
| 8729 | goto out_disable_pci_dev; |
| 8730 | } |
| 8731 | |
| 8732 | /* Set up phase-1 common device driver resources */ |
| 8733 | error = lpfc_setup_driver_resource_phase1(phba); |
| 8734 | if (error) { |
| 8735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8736 | "1403 Failed to set up driver resource.\n"); |
| 8737 | goto out_unset_pci_mem_s3; |
| 8738 | } |
| 8739 | |
| 8740 | /* Set up SLI-3 specific device driver resources */ |
| 8741 | error = lpfc_sli_driver_resource_setup(phba); |
| 8742 | if (error) { |
| 8743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8744 | "1404 Failed to set up driver resource.\n"); |
| 8745 | goto out_unset_pci_mem_s3; |
| 8746 | } |
| 8747 | |
| 8748 | /* Initialize and populate the iocb list per host */ |
| 8749 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 8750 | if (error) { |
| 8751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8752 | "1405 Failed to initialize iocb list.\n"); |
| 8753 | goto out_unset_driver_resource_s3; |
| 8754 | } |
| 8755 | |
| 8756 | /* Set up common device driver resources */ |
| 8757 | error = lpfc_setup_driver_resource_phase2(phba); |
| 8758 | if (error) { |
| 8759 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8760 | "1406 Failed to set up driver resource.\n"); |
| 8761 | goto out_free_iocb_list; |
| 8762 | } |
| 8763 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8764 | /* Get the default values for Model Name and Description */ |
| 8765 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 8766 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8767 | /* Create SCSI host to the physical port */ |
| 8768 | error = lpfc_create_shost(phba); |
| 8769 | if (error) { |
| 8770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8771 | "1407 Failed to create scsi host.\n"); |
| 8772 | goto out_unset_driver_resource; |
| 8773 | } |
| 8774 | |
| 8775 | /* Configure sysfs attributes */ |
| 8776 | vport = phba->pport; |
| 8777 | error = lpfc_alloc_sysfs_attr(vport); |
| 8778 | if (error) { |
| 8779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8780 | "1476 Failed to allocate sysfs attr\n"); |
| 8781 | goto out_destroy_shost; |
| 8782 | } |
| 8783 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8784 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8785 | /* Now, trying to enable interrupt and bring up the device */ |
| 8786 | cfg_mode = phba->cfg_use_msi; |
| 8787 | while (true) { |
| 8788 | /* Put device to a known state before enabling interrupt */ |
| 8789 | lpfc_stop_port(phba); |
| 8790 | /* Configure and enable interrupt */ |
| 8791 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 8792 | if (intr_mode == LPFC_INTR_ERROR) { |
| 8793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8794 | "0431 Failed to enable interrupt.\n"); |
| 8795 | error = -ENODEV; |
| 8796 | goto out_free_sysfs_attr; |
| 8797 | } |
| 8798 | /* SLI-3 HBA setup */ |
| 8799 | if (lpfc_sli_hba_setup(phba)) { |
| 8800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8801 | "1477 Failed to set up hba\n"); |
| 8802 | error = -ENODEV; |
| 8803 | goto out_remove_device; |
| 8804 | } |
| 8805 | |
| 8806 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 8807 | msleep(50); |
| 8808 | /* Check active interrupts on message signaled interrupts */ |
| 8809 | if (intr_mode == 0 || |
| 8810 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 8811 | /* Log the current active interrupt mode */ |
| 8812 | phba->intr_mode = intr_mode; |
| 8813 | lpfc_log_intr_mode(phba, intr_mode); |
| 8814 | break; |
| 8815 | } else { |
| 8816 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8817 | "0447 Configure interrupt mode (%d) " |
| 8818 | "failed active interrupt test.\n", |
| 8819 | intr_mode); |
| 8820 | /* Disable the current interrupt mode */ |
| 8821 | lpfc_sli_disable_intr(phba); |
| 8822 | /* Try next level of interrupt mode */ |
| 8823 | cfg_mode = --intr_mode; |
| 8824 | } |
| 8825 | } |
| 8826 | |
| 8827 | /* Perform post initialization setup */ |
| 8828 | lpfc_post_init_setup(phba); |
| 8829 | |
| 8830 | /* Check if there are static vports to be created. */ |
| 8831 | lpfc_create_static_vport(phba); |
| 8832 | |
| 8833 | return 0; |
| 8834 | |
| 8835 | out_remove_device: |
| 8836 | lpfc_unset_hba(phba); |
| 8837 | out_free_sysfs_attr: |
| 8838 | lpfc_free_sysfs_attr(vport); |
| 8839 | out_destroy_shost: |
| 8840 | lpfc_destroy_shost(phba); |
| 8841 | out_unset_driver_resource: |
| 8842 | lpfc_unset_driver_resource_phase2(phba); |
| 8843 | out_free_iocb_list: |
| 8844 | lpfc_free_iocb_list(phba); |
| 8845 | out_unset_driver_resource_s3: |
| 8846 | lpfc_sli_driver_resource_unset(phba); |
| 8847 | out_unset_pci_mem_s3: |
| 8848 | lpfc_sli_pci_mem_unset(phba); |
| 8849 | out_disable_pci_dev: |
| 8850 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8851 | if (shost) |
| 8852 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8853 | out_free_phba: |
| 8854 | lpfc_hba_free(phba); |
| 8855 | return error; |
| 8856 | } |
| 8857 | |
| 8858 | /** |
| 8859 | * 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] | 8860 | * @pdev: pointer to PCI device |
| 8861 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8862 | * This routine is to be called to disattach a device with SLI-3 interface |
| 8863 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8864 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 8865 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8866 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8867 | static void __devexit |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8868 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8869 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8870 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8871 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8872 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8873 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8874 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8875 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 8876 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8877 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8878 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8879 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8880 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8881 | lpfc_free_sysfs_attr(vport); |
| 8882 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8883 | /* Release all the vports against this physical port */ |
| 8884 | vports = lpfc_create_vport_work_array(phba); |
| 8885 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 8886 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8887 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 8888 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8889 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 8890 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8891 | lpfc_destroy_vport_work_array(phba, vports); |
| 8892 | |
| 8893 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8894 | fc_remove_host(shost); |
| 8895 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8896 | lpfc_cleanup(vport); |
| 8897 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8898 | /* |
| 8899 | * Bring down the SLI Layer. This step disable all interrupts, |
| 8900 | * clears the rings, discards all mailbox commands, and resets |
| 8901 | * the HBA. |
| 8902 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8903 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 8904 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8905 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8906 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8907 | kthread_stop(phba->worker_thread); |
| 8908 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8909 | lpfc_sli_brdrestart(phba); |
| 8910 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8911 | kfree(phba->vpi_bmask); |
| 8912 | kfree(phba->vpi_ids); |
| 8913 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8914 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8915 | spin_lock_irq(&phba->hbalock); |
| 8916 | list_del_init(&vport->listentry); |
| 8917 | spin_unlock_irq(&phba->hbalock); |
| 8918 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8919 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8920 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8921 | /* Disable SR-IOV if enabled */ |
| 8922 | if (phba->cfg_sriov_nr_virtfn) |
| 8923 | pci_disable_sriov(pdev); |
| 8924 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8925 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8926 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8927 | |
| 8928 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8929 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8930 | |
| 8931 | /* |
| 8932 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 8933 | * corresponding pools here. |
| 8934 | */ |
| 8935 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8936 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8937 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8938 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 8939 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8940 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8941 | /* Free resources associated with SLI2 interface */ |
| 8942 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8943 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8944 | |
| 8945 | /* unmap adapter SLIM and Control Registers */ |
| 8946 | iounmap(phba->ctrl_regs_memmap_p); |
| 8947 | iounmap(phba->slim_memmap_p); |
| 8948 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8949 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8950 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8951 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8952 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8953 | } |
| 8954 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8955 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8956 | * 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] | 8957 | * @pdev: pointer to PCI device |
| 8958 | * @msg: power management message |
| 8959 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8960 | * This routine is to be called from the kernel's PCI subsystem to support |
| 8961 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 8962 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 8963 | * worker thread for the device, turning off device's interrupt and DMA, |
| 8964 | * and bring the device offline. Note that as the driver implements the |
| 8965 | * minimum PM requirements to a power-aware driver's PM support for the |
| 8966 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 8967 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 8968 | * fully reinitialize its device during resume() method call, the driver will |
| 8969 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 8970 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8971 | * |
| 8972 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8973 | * 0 - driver suspended the device |
| 8974 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8975 | **/ |
| 8976 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8977 | 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] | 8978 | { |
| 8979 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8980 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 8981 | |
| 8982 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8983 | "0473 PCI device Power Management suspend.\n"); |
| 8984 | |
| 8985 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 8986 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8987 | lpfc_offline(phba); |
| 8988 | kthread_stop(phba->worker_thread); |
| 8989 | |
| 8990 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8991 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8992 | |
| 8993 | /* Save device state to PCI config space */ |
| 8994 | pci_save_state(pdev); |
| 8995 | pci_set_power_state(pdev, PCI_D3hot); |
| 8996 | |
| 8997 | return 0; |
| 8998 | } |
| 8999 | |
| 9000 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9001 | * 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] | 9002 | * @pdev: pointer to PCI device |
| 9003 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9004 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9005 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9006 | * invokes this method, it restores the device's PCI config space state and |
| 9007 | * fully reinitializes the device and brings it online. Note that as the |
| 9008 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9009 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9010 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9011 | * driver will fully reinitialize its device during resume() method call, |
| 9012 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9013 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9014 | * |
| 9015 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9016 | * 0 - driver suspended the device |
| 9017 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9018 | **/ |
| 9019 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9020 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9021 | { |
| 9022 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9023 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9024 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9025 | int error; |
| 9026 | |
| 9027 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9028 | "0452 PCI device Power Management resume.\n"); |
| 9029 | |
| 9030 | /* Restore device state from PCI config space */ |
| 9031 | pci_set_power_state(pdev, PCI_D0); |
| 9032 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9033 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9034 | /* |
| 9035 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9036 | * device saved_state flag, need to save the restored state again. |
| 9037 | */ |
| 9038 | pci_save_state(pdev); |
| 9039 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9040 | if (pdev->is_busmaster) |
| 9041 | pci_set_master(pdev); |
| 9042 | |
| 9043 | /* Startup the kernel thread for this host adapter. */ |
| 9044 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9045 | "lpfc_worker_%d", phba->brd_no); |
| 9046 | if (IS_ERR(phba->worker_thread)) { |
| 9047 | error = PTR_ERR(phba->worker_thread); |
| 9048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9049 | "0434 PM resume failed to start worker " |
| 9050 | "thread: error=x%x.\n", error); |
| 9051 | return error; |
| 9052 | } |
| 9053 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9054 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9055 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9056 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9058 | "0430 PM resume Failed to enable interrupt\n"); |
| 9059 | return -EIO; |
| 9060 | } else |
| 9061 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9062 | |
| 9063 | /* Restart HBA and bring it online */ |
| 9064 | lpfc_sli_brdrestart(phba); |
| 9065 | lpfc_online(phba); |
| 9066 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9067 | /* Log the current active interrupt mode */ |
| 9068 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9069 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9070 | return 0; |
| 9071 | } |
| 9072 | |
| 9073 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9074 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9075 | * @phba: pointer to lpfc hba data structure. |
| 9076 | * |
| 9077 | * 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] | 9078 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9079 | **/ |
| 9080 | static void |
| 9081 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9082 | { |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9083 | struct lpfc_sli *psli = &phba->sli; |
| 9084 | struct lpfc_sli_ring *pring; |
| 9085 | |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9087 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9088 | |
| 9089 | /* |
| 9090 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9091 | * and let the SCSI mid-layer to retry them to recover. |
| 9092 | */ |
| 9093 | pring = &psli->ring[psli->fcp_ring]; |
| 9094 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9095 | } |
| 9096 | |
| 9097 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9098 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9099 | * @phba: pointer to lpfc hba data structure. |
| 9100 | * |
| 9101 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9102 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9103 | * pending I/Os. |
| 9104 | **/ |
| 9105 | static void |
| 9106 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9107 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9108 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9109 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9110 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9111 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9112 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9113 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9114 | /* Block all SCSI devices' I/Os on the host */ |
| 9115 | lpfc_scsi_dev_block(phba); |
| 9116 | |
| 9117 | /* stop all timers */ |
| 9118 | lpfc_stop_hba_timers(phba); |
| 9119 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9120 | /* Disable interrupt and pci device */ |
| 9121 | lpfc_sli_disable_intr(phba); |
| 9122 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9123 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9124 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9125 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9126 | } |
| 9127 | |
| 9128 | /** |
| 9129 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9130 | * @phba: pointer to lpfc hba data structure. |
| 9131 | * |
| 9132 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9133 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9134 | * pending I/Os. |
| 9135 | **/ |
| 9136 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9137 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9138 | { |
| 9139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9140 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9141 | /* Block all SCSI devices' I/Os on the host */ |
| 9142 | lpfc_scsi_dev_block(phba); |
| 9143 | |
| 9144 | /* stop all timers */ |
| 9145 | lpfc_stop_hba_timers(phba); |
| 9146 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9147 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9148 | lpfc_sli_flush_fcp_rings(phba); |
| 9149 | } |
| 9150 | |
| 9151 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9152 | * 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] | 9153 | * @pdev: pointer to PCI device. |
| 9154 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9155 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9156 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9157 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9158 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9159 | * When this function is invoked, it will need to stop all the I/Os and |
| 9160 | * interrupt(s) to the device. Once that is done, it will return |
| 9161 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9162 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9163 | * |
| 9164 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9165 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9166 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9167 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9168 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9169 | static pci_ers_result_t |
| 9170 | 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] | 9171 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9172 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9173 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9174 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9175 | switch (state) { |
| 9176 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9177 | /* Non-fatal error, prepare for recovery */ |
| 9178 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9179 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9180 | case pci_channel_io_frozen: |
| 9181 | /* Fatal error, prepare for slot reset */ |
| 9182 | lpfc_sli_prep_dev_for_reset(phba); |
| 9183 | return PCI_ERS_RESULT_NEED_RESET; |
| 9184 | case pci_channel_io_perm_failure: |
| 9185 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9186 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9187 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9188 | default: |
| 9189 | /* Unknown state, prepare and request slot reset */ |
| 9190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9191 | "0472 Unknown PCI error state: x%x\n", state); |
| 9192 | lpfc_sli_prep_dev_for_reset(phba); |
| 9193 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9194 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9195 | } |
| 9196 | |
| 9197 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9198 | * 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] | 9199 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9200 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9201 | * This routine is called from the PCI subsystem for error handling to |
| 9202 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9203 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9204 | * During the PCI subsystem error recovery, after driver returns |
| 9205 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9206 | * recovery and then call this routine before calling the .resume method |
| 9207 | * to recover the device. This function will initialize the HBA device, |
| 9208 | * enable the interrupt, but it will just put the HBA to offline state |
| 9209 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9210 | * |
| 9211 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9212 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9213 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9214 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9215 | static pci_ers_result_t |
| 9216 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9217 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9218 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9219 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9220 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9221 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9222 | |
| 9223 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9224 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9225 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9226 | "PCI device after reset.\n"); |
| 9227 | return PCI_ERS_RESULT_DISCONNECT; |
| 9228 | } |
| 9229 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9230 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9231 | |
| 9232 | /* |
| 9233 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9234 | * device saved_state flag, need to save the restored state again. |
| 9235 | */ |
| 9236 | pci_save_state(pdev); |
| 9237 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9238 | if (pdev->is_busmaster) |
| 9239 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9240 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9241 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9242 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9243 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9244 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9245 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9246 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9247 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9249 | "0427 Cannot re-enable interrupt after " |
| 9250 | "slot reset.\n"); |
| 9251 | return PCI_ERS_RESULT_DISCONNECT; |
| 9252 | } else |
| 9253 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9254 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9255 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9256 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9257 | lpfc_offline(phba); |
| 9258 | lpfc_sli_brdrestart(phba); |
| 9259 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9260 | /* Log the current active interrupt mode */ |
| 9261 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9262 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9263 | return PCI_ERS_RESULT_RECOVERED; |
| 9264 | } |
| 9265 | |
| 9266 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9267 | * 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] | 9268 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9269 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9270 | * This routine is called from the PCI subsystem for error handling to device |
| 9271 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9272 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9273 | * error recovery. After this call, traffic can start to flow from this device |
| 9274 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9275 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9276 | static void |
| 9277 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9278 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9279 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9280 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9281 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9282 | /* 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] | 9283 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9284 | |
| 9285 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9286 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9287 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9288 | } |
| 9289 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9290 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9291 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9292 | * @phba: pointer to lpfc hba data structure. |
| 9293 | * |
| 9294 | * returns the number of ELS/CT IOCBs to reserve |
| 9295 | **/ |
| 9296 | int |
| 9297 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9298 | { |
| 9299 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9300 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9301 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9302 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9303 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9304 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9305 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9306 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9307 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9308 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9309 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9310 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9311 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9312 | else if (max_xri <= 2048) |
| 9313 | return 200; |
| 9314 | else |
| 9315 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9316 | } else |
| 9317 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9318 | } |
| 9319 | |
| 9320 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9321 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9322 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9323 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9324 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9325 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9326 | static void |
| 9327 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9328 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9329 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9330 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9331 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9332 | struct list_head dma_buffer_list; |
| 9333 | int i, rc = 0; |
| 9334 | struct lpfc_dmabuf *dmabuf, *next; |
| 9335 | uint32_t offset = 0, temp_offset = 0; |
| 9336 | |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9337 | /* It can be null, sanity check */ |
| 9338 | if (!fw) { |
| 9339 | rc = -ENXIO; |
| 9340 | goto out; |
| 9341 | } |
| 9342 | image = (struct lpfc_grp_hdr *)fw->data; |
| 9343 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9344 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9345 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9346 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9347 | LPFC_FILE_TYPE_GROUP) || |
| 9348 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9349 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9350 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9351 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9352 | "Magic:%x Type:%x ID:%x\n", |
| 9353 | be32_to_cpu(image->magic_number), |
| 9354 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9355 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9356 | rc = -EINVAL; |
| 9357 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9358 | } |
| 9359 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9360 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9362 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9363 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9364 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9365 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9366 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9367 | GFP_KERNEL); |
| 9368 | if (!dmabuf) { |
| 9369 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9370 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9371 | } |
| 9372 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 9373 | SLI4_PAGE_SIZE, |
| 9374 | &dmabuf->phys, |
| 9375 | GFP_KERNEL); |
| 9376 | if (!dmabuf->virt) { |
| 9377 | kfree(dmabuf); |
| 9378 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9379 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9380 | } |
| 9381 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 9382 | } |
| 9383 | while (offset < fw->size) { |
| 9384 | temp_offset = offset; |
| 9385 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9386 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9387 | memcpy(dmabuf->virt, |
| 9388 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9389 | fw->size - temp_offset); |
| 9390 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9391 | break; |
| 9392 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9393 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 9394 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9395 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9396 | } |
| 9397 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 9398 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9399 | if (rc) |
| 9400 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9401 | } |
| 9402 | rc = offset; |
| 9403 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9404 | |
| 9405 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9406 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 9407 | list_del(&dmabuf->list); |
| 9408 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 9409 | dmabuf->virt, dmabuf->phys); |
| 9410 | kfree(dmabuf); |
| 9411 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9412 | release_firmware(fw); |
| 9413 | out: |
| 9414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9415 | "3024 Firmware update done: %d.", rc); |
| 9416 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9417 | } |
| 9418 | |
| 9419 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9420 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 9421 | * @pdev: pointer to PCI device |
| 9422 | * @pid: pointer to PCI device identifier |
| 9423 | * |
| 9424 | * This routine is called from the kernel's PCI subsystem to device with |
| 9425 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9426 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9427 | * information of the device and driver to see if the driver state that it |
| 9428 | * can support this kind of device. If the match is successful, the driver |
| 9429 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 9430 | * it does all the initialization that it needs to do to handle the HBA |
| 9431 | * properly. |
| 9432 | * |
| 9433 | * Return code |
| 9434 | * 0 - driver can claim the device |
| 9435 | * negative value - driver can not claim the device |
| 9436 | **/ |
| 9437 | static int __devinit |
| 9438 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9439 | { |
| 9440 | struct lpfc_hba *phba; |
| 9441 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9442 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9443 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9444 | uint32_t cfg_mode, intr_mode; |
| 9445 | int mcnt; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9446 | int adjusted_fcp_io_channel; |
James Smart | 5402a31 | 2012-09-29 11:30:06 -0400 | [diff] [blame] | 9447 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9448 | |
| 9449 | /* Allocate memory for HBA structure */ |
| 9450 | phba = lpfc_hba_alloc(pdev); |
| 9451 | if (!phba) |
| 9452 | return -ENOMEM; |
| 9453 | |
| 9454 | /* Perform generic PCI device enabling operation */ |
| 9455 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9456 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9457 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9458 | |
| 9459 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 9460 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 9461 | if (error) |
| 9462 | goto out_disable_pci_dev; |
| 9463 | |
| 9464 | /* Set up SLI-4 specific device PCI memory space */ |
| 9465 | error = lpfc_sli4_pci_mem_setup(phba); |
| 9466 | if (error) { |
| 9467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9468 | "1410 Failed to set up pci memory space.\n"); |
| 9469 | goto out_disable_pci_dev; |
| 9470 | } |
| 9471 | |
| 9472 | /* Set up phase-1 common device driver resources */ |
| 9473 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9474 | if (error) { |
| 9475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9476 | "1411 Failed to set up driver resource.\n"); |
| 9477 | goto out_unset_pci_mem_s4; |
| 9478 | } |
| 9479 | |
| 9480 | /* Set up SLI-4 Specific device driver resources */ |
| 9481 | error = lpfc_sli4_driver_resource_setup(phba); |
| 9482 | if (error) { |
| 9483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9484 | "1412 Failed to set up driver resource.\n"); |
| 9485 | goto out_unset_pci_mem_s4; |
| 9486 | } |
| 9487 | |
| 9488 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9489 | |
| 9490 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9491 | "2821 initialize iocb list %d.\n", |
| 9492 | phba->cfg_iocb_cnt*1024); |
| 9493 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 9494 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9495 | if (error) { |
| 9496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9497 | "1413 Failed to initialize iocb list.\n"); |
| 9498 | goto out_unset_driver_resource_s4; |
| 9499 | } |
| 9500 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9501 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 9502 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9503 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9504 | /* Set up common device driver resources */ |
| 9505 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9506 | if (error) { |
| 9507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9508 | "1414 Failed to set up driver resource.\n"); |
| 9509 | goto out_free_iocb_list; |
| 9510 | } |
| 9511 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9512 | /* Get the default values for Model Name and Description */ |
| 9513 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9514 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9515 | /* Create SCSI host to the physical port */ |
| 9516 | error = lpfc_create_shost(phba); |
| 9517 | if (error) { |
| 9518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9519 | "1415 Failed to create scsi host.\n"); |
| 9520 | goto out_unset_driver_resource; |
| 9521 | } |
| 9522 | |
| 9523 | /* Configure sysfs attributes */ |
| 9524 | vport = phba->pport; |
| 9525 | error = lpfc_alloc_sysfs_attr(vport); |
| 9526 | if (error) { |
| 9527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9528 | "1416 Failed to allocate sysfs attr\n"); |
| 9529 | goto out_destroy_shost; |
| 9530 | } |
| 9531 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9532 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9533 | /* Now, trying to enable interrupt and bring up the device */ |
| 9534 | cfg_mode = phba->cfg_use_msi; |
| 9535 | while (true) { |
| 9536 | /* Put device to a known state before enabling interrupt */ |
| 9537 | lpfc_stop_port(phba); |
| 9538 | /* Configure and enable interrupt */ |
| 9539 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 9540 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9542 | "0426 Failed to enable interrupt.\n"); |
| 9543 | error = -ENODEV; |
| 9544 | goto out_free_sysfs_attr; |
| 9545 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9546 | /* Default to single EQ for non-MSI-X */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 9547 | if (phba->intr_type != MSIX) |
James Smart | 1c13bf6 | 2012-08-14 14:26:20 -0400 | [diff] [blame] | 9548 | adjusted_fcp_io_channel = 1; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9549 | else |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9550 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 9551 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9552 | /* Set up SLI-4 HBA */ |
| 9553 | if (lpfc_sli4_hba_setup(phba)) { |
| 9554 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9555 | "1421 Failed to set up hba\n"); |
| 9556 | error = -ENODEV; |
| 9557 | goto out_disable_intr; |
| 9558 | } |
| 9559 | |
| 9560 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
| 9561 | if (intr_mode != 0) |
| 9562 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, |
| 9563 | LPFC_ACT_INTR_CNT); |
| 9564 | |
| 9565 | /* Check active interrupts received only for MSI/MSI-X */ |
| 9566 | if (intr_mode == 0 || |
| 9567 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
| 9568 | /* Log the current active interrupt mode */ |
| 9569 | phba->intr_mode = intr_mode; |
| 9570 | lpfc_log_intr_mode(phba, intr_mode); |
| 9571 | break; |
| 9572 | } |
| 9573 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9574 | "0451 Configure interrupt mode (%d) " |
| 9575 | "failed active interrupt test.\n", |
| 9576 | intr_mode); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9577 | /* Unset the previous SLI-4 HBA setup. */ |
| 9578 | /* |
| 9579 | * TODO: Is this operation compatible with IF TYPE 2 |
| 9580 | * devices? All port state is deleted and cleared. |
| 9581 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9582 | lpfc_sli4_unset_hba(phba); |
| 9583 | /* Try next level of interrupt mode */ |
| 9584 | cfg_mode = --intr_mode; |
| 9585 | } |
| 9586 | |
| 9587 | /* Perform post initialization setup */ |
| 9588 | lpfc_post_init_setup(phba); |
| 9589 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 9590 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
| 9591 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 9592 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 5402a31 | 2012-09-29 11:30:06 -0400 | [diff] [blame] | 9593 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", |
| 9594 | phba->ModelName); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9595 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 9596 | file_name, &phba->pcidev->dev, |
| 9597 | GFP_KERNEL, (void *)phba, |
| 9598 | lpfc_write_firmware); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9599 | } |
| 9600 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 9601 | /* Check if there are static vports to be created. */ |
| 9602 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9603 | return 0; |
| 9604 | |
| 9605 | out_disable_intr: |
| 9606 | lpfc_sli4_disable_intr(phba); |
| 9607 | out_free_sysfs_attr: |
| 9608 | lpfc_free_sysfs_attr(vport); |
| 9609 | out_destroy_shost: |
| 9610 | lpfc_destroy_shost(phba); |
| 9611 | out_unset_driver_resource: |
| 9612 | lpfc_unset_driver_resource_phase2(phba); |
| 9613 | out_free_iocb_list: |
| 9614 | lpfc_free_iocb_list(phba); |
| 9615 | out_unset_driver_resource_s4: |
| 9616 | lpfc_sli4_driver_resource_unset(phba); |
| 9617 | out_unset_pci_mem_s4: |
| 9618 | lpfc_sli4_pci_mem_unset(phba); |
| 9619 | out_disable_pci_dev: |
| 9620 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9621 | if (shost) |
| 9622 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9623 | out_free_phba: |
| 9624 | lpfc_hba_free(phba); |
| 9625 | return error; |
| 9626 | } |
| 9627 | |
| 9628 | /** |
| 9629 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 9630 | * @pdev: pointer to PCI device |
| 9631 | * |
| 9632 | * This routine is called from the kernel's PCI subsystem to device with |
| 9633 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9634 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9635 | * device to be removed from the PCI subsystem properly. |
| 9636 | **/ |
| 9637 | static void __devexit |
| 9638 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 9639 | { |
| 9640 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9641 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 9642 | struct lpfc_vport **vports; |
| 9643 | struct lpfc_hba *phba = vport->phba; |
| 9644 | int i; |
| 9645 | |
| 9646 | /* Mark the device unloading flag */ |
| 9647 | spin_lock_irq(&phba->hbalock); |
| 9648 | vport->load_flag |= FC_UNLOADING; |
| 9649 | spin_unlock_irq(&phba->hbalock); |
| 9650 | |
| 9651 | /* Free the HBA sysfs attributes */ |
| 9652 | lpfc_free_sysfs_attr(vport); |
| 9653 | |
| 9654 | /* Release all the vports against this physical port */ |
| 9655 | vports = lpfc_create_vport_work_array(phba); |
| 9656 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9657 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9658 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9659 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9660 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9661 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9662 | lpfc_destroy_vport_work_array(phba, vports); |
| 9663 | |
| 9664 | /* Remove FC host and then SCSI host with the physical port */ |
| 9665 | fc_remove_host(shost); |
| 9666 | scsi_remove_host(shost); |
| 9667 | |
| 9668 | /* Perform cleanup on the physical port */ |
| 9669 | lpfc_cleanup(vport); |
| 9670 | |
| 9671 | /* |
| 9672 | * Bring down the SLI Layer. This step disables all interrupts, |
| 9673 | * clears the rings, discards all mailbox commands, and resets |
| 9674 | * the HBA FCoE function. |
| 9675 | */ |
| 9676 | lpfc_debugfs_terminate(vport); |
| 9677 | lpfc_sli4_hba_unset(phba); |
| 9678 | |
| 9679 | spin_lock_irq(&phba->hbalock); |
| 9680 | list_del_init(&vport->listentry); |
| 9681 | spin_unlock_irq(&phba->hbalock); |
| 9682 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9683 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9684 | * buffers are released to their corresponding pools here. |
| 9685 | */ |
| 9686 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9687 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9688 | lpfc_sli4_driver_resource_unset(phba); |
| 9689 | |
| 9690 | /* Unmap adapter Control and Doorbell registers */ |
| 9691 | lpfc_sli4_pci_mem_unset(phba); |
| 9692 | |
| 9693 | /* Release PCI resources and disable device's PCI function */ |
| 9694 | scsi_host_put(shost); |
| 9695 | lpfc_disable_pci_dev(phba); |
| 9696 | |
| 9697 | /* Finally, free the driver's device data structure */ |
| 9698 | lpfc_hba_free(phba); |
| 9699 | |
| 9700 | return; |
| 9701 | } |
| 9702 | |
| 9703 | /** |
| 9704 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 9705 | * @pdev: pointer to PCI device |
| 9706 | * @msg: power management message |
| 9707 | * |
| 9708 | * This routine is called from the kernel's PCI subsystem to support system |
| 9709 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 9710 | * this method, it quiesces the device by stopping the driver's worker |
| 9711 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 9712 | * the device offline. Note that as the driver implements the minimum PM |
| 9713 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 9714 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 9715 | * method call will be treated as SUSPEND and the driver will fully |
| 9716 | * reinitialize its device during resume() method call, the driver will set |
| 9717 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 9718 | * according to the @msg provided by the PM. |
| 9719 | * |
| 9720 | * Return code |
| 9721 | * 0 - driver suspended the device |
| 9722 | * Error otherwise |
| 9723 | **/ |
| 9724 | static int |
| 9725 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 9726 | { |
| 9727 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9728 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9729 | |
| 9730 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9731 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9732 | |
| 9733 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9734 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9735 | lpfc_offline(phba); |
| 9736 | kthread_stop(phba->worker_thread); |
| 9737 | |
| 9738 | /* Disable interrupt from device */ |
| 9739 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9740 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9741 | |
| 9742 | /* Save device state to PCI config space */ |
| 9743 | pci_save_state(pdev); |
| 9744 | pci_set_power_state(pdev, PCI_D3hot); |
| 9745 | |
| 9746 | return 0; |
| 9747 | } |
| 9748 | |
| 9749 | /** |
| 9750 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 9751 | * @pdev: pointer to PCI device |
| 9752 | * |
| 9753 | * This routine is called from the kernel's PCI subsystem to support system |
| 9754 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 9755 | * this method, it restores the device's PCI config space state and fully |
| 9756 | * reinitializes the device and brings it online. Note that as the driver |
| 9757 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 9758 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9759 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 9760 | * will fully reinitialize its device during resume() method call, the device |
| 9761 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 9762 | * state. |
| 9763 | * |
| 9764 | * Return code |
| 9765 | * 0 - driver suspended the device |
| 9766 | * Error otherwise |
| 9767 | **/ |
| 9768 | static int |
| 9769 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 9770 | { |
| 9771 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9772 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9773 | uint32_t intr_mode; |
| 9774 | int error; |
| 9775 | |
| 9776 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9777 | "0292 PCI device Power Management resume.\n"); |
| 9778 | |
| 9779 | /* Restore device state from PCI config space */ |
| 9780 | pci_set_power_state(pdev, PCI_D0); |
| 9781 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9782 | |
| 9783 | /* |
| 9784 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9785 | * device saved_state flag, need to save the restored state again. |
| 9786 | */ |
| 9787 | pci_save_state(pdev); |
| 9788 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9789 | if (pdev->is_busmaster) |
| 9790 | pci_set_master(pdev); |
| 9791 | |
| 9792 | /* Startup the kernel thread for this host adapter. */ |
| 9793 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9794 | "lpfc_worker_%d", phba->brd_no); |
| 9795 | if (IS_ERR(phba->worker_thread)) { |
| 9796 | error = PTR_ERR(phba->worker_thread); |
| 9797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9798 | "0293 PM resume failed to start worker " |
| 9799 | "thread: error=x%x.\n", error); |
| 9800 | return error; |
| 9801 | } |
| 9802 | |
| 9803 | /* Configure and enable interrupt */ |
| 9804 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9805 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9807 | "0294 PM resume Failed to enable interrupt\n"); |
| 9808 | return -EIO; |
| 9809 | } else |
| 9810 | phba->intr_mode = intr_mode; |
| 9811 | |
| 9812 | /* Restart HBA and bring it online */ |
| 9813 | lpfc_sli_brdrestart(phba); |
| 9814 | lpfc_online(phba); |
| 9815 | |
| 9816 | /* Log the current active interrupt mode */ |
| 9817 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9818 | |
| 9819 | return 0; |
| 9820 | } |
| 9821 | |
| 9822 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9823 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 9824 | * @phba: pointer to lpfc hba data structure. |
| 9825 | * |
| 9826 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 9827 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 9828 | **/ |
| 9829 | static void |
| 9830 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9831 | { |
| 9832 | struct lpfc_sli *psli = &phba->sli; |
| 9833 | struct lpfc_sli_ring *pring; |
| 9834 | |
| 9835 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9836 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 9837 | /* |
| 9838 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9839 | * and let the SCSI mid-layer to retry them to recover. |
| 9840 | */ |
| 9841 | pring = &psli->ring[psli->fcp_ring]; |
| 9842 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 9843 | } |
| 9844 | |
| 9845 | /** |
| 9846 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 9847 | * @phba: pointer to lpfc hba data structure. |
| 9848 | * |
| 9849 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 9850 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9851 | * pending I/Os. |
| 9852 | **/ |
| 9853 | static void |
| 9854 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9855 | { |
| 9856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9857 | "2826 PCI channel disable preparing for reset\n"); |
| 9858 | |
| 9859 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9860 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9861 | |
| 9862 | /* Block all SCSI devices' I/Os on the host */ |
| 9863 | lpfc_scsi_dev_block(phba); |
| 9864 | |
| 9865 | /* stop all timers */ |
| 9866 | lpfc_stop_hba_timers(phba); |
| 9867 | |
| 9868 | /* Disable interrupt and pci device */ |
| 9869 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9870 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9871 | pci_disable_device(phba->pcidev); |
| 9872 | |
| 9873 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9874 | lpfc_sli_flush_fcp_rings(phba); |
| 9875 | } |
| 9876 | |
| 9877 | /** |
| 9878 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 9879 | * @phba: pointer to lpfc hba data structure. |
| 9880 | * |
| 9881 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 9882 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9883 | * pending I/Os. |
| 9884 | **/ |
| 9885 | static void |
| 9886 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 9887 | { |
| 9888 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9889 | "2827 PCI channel permanent disable for failure\n"); |
| 9890 | |
| 9891 | /* Block all SCSI devices' I/Os on the host */ |
| 9892 | lpfc_scsi_dev_block(phba); |
| 9893 | |
| 9894 | /* stop all timers */ |
| 9895 | lpfc_stop_hba_timers(phba); |
| 9896 | |
| 9897 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9898 | lpfc_sli_flush_fcp_rings(phba); |
| 9899 | } |
| 9900 | |
| 9901 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9902 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 9903 | * @pdev: pointer to PCI device. |
| 9904 | * @state: the current PCI connection state. |
| 9905 | * |
| 9906 | * This routine is called from the PCI subsystem for error handling to device |
| 9907 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 9908 | * after a PCI bus error affecting this device has been detected. When this |
| 9909 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 9910 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 9911 | * for the PCI subsystem to perform proper recovery as desired. |
| 9912 | * |
| 9913 | * Return codes |
| 9914 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9915 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9916 | **/ |
| 9917 | static pci_ers_result_t |
| 9918 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 9919 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9920 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9921 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9922 | |
| 9923 | switch (state) { |
| 9924 | case pci_channel_io_normal: |
| 9925 | /* Non-fatal error, prepare for recovery */ |
| 9926 | lpfc_sli4_prep_dev_for_recover(phba); |
| 9927 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9928 | case pci_channel_io_frozen: |
| 9929 | /* Fatal error, prepare for slot reset */ |
| 9930 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9931 | return PCI_ERS_RESULT_NEED_RESET; |
| 9932 | case pci_channel_io_perm_failure: |
| 9933 | /* Permanent failure, prepare for device down */ |
| 9934 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 9935 | return PCI_ERS_RESULT_DISCONNECT; |
| 9936 | default: |
| 9937 | /* Unknown state, prepare and request slot reset */ |
| 9938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9939 | "2825 Unknown PCI error state: x%x\n", state); |
| 9940 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9941 | return PCI_ERS_RESULT_NEED_RESET; |
| 9942 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9943 | } |
| 9944 | |
| 9945 | /** |
| 9946 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 9947 | * @pdev: pointer to PCI device. |
| 9948 | * |
| 9949 | * This routine is called from the PCI subsystem for error handling to device |
| 9950 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 9951 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 9952 | * PCI subsystem error recovery, after the driver returns |
| 9953 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9954 | * recovery and then call this routine before calling the .resume method to |
| 9955 | * recover the device. This function will initialize the HBA device, enable |
| 9956 | * the interrupt, but it will just put the HBA to offline state without |
| 9957 | * passing any I/O traffic. |
| 9958 | * |
| 9959 | * Return codes |
| 9960 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9961 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9962 | */ |
| 9963 | static pci_ers_result_t |
| 9964 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 9965 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9966 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9967 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9968 | struct lpfc_sli *psli = &phba->sli; |
| 9969 | uint32_t intr_mode; |
| 9970 | |
| 9971 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 9972 | if (pci_enable_device_mem(pdev)) { |
| 9973 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9974 | "PCI device after reset.\n"); |
| 9975 | return PCI_ERS_RESULT_DISCONNECT; |
| 9976 | } |
| 9977 | |
| 9978 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 9979 | |
| 9980 | /* |
| 9981 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9982 | * device saved_state flag, need to save the restored state again. |
| 9983 | */ |
| 9984 | pci_save_state(pdev); |
| 9985 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9986 | if (pdev->is_busmaster) |
| 9987 | pci_set_master(pdev); |
| 9988 | |
| 9989 | spin_lock_irq(&phba->hbalock); |
| 9990 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 9991 | spin_unlock_irq(&phba->hbalock); |
| 9992 | |
| 9993 | /* Configure and enable interrupt */ |
| 9994 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9995 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9997 | "2824 Cannot re-enable interrupt after " |
| 9998 | "slot reset.\n"); |
| 9999 | return PCI_ERS_RESULT_DISCONNECT; |
| 10000 | } else |
| 10001 | phba->intr_mode = intr_mode; |
| 10002 | |
| 10003 | /* Log the current active interrupt mode */ |
| 10004 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10005 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10006 | return PCI_ERS_RESULT_RECOVERED; |
| 10007 | } |
| 10008 | |
| 10009 | /** |
| 10010 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10011 | * @pdev: pointer to PCI device |
| 10012 | * |
| 10013 | * This routine is called from the PCI subsystem for error handling to device |
| 10014 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10015 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10016 | * error recovery. After this call, traffic can start to flow from this device |
| 10017 | * again. |
| 10018 | **/ |
| 10019 | static void |
| 10020 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10021 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10022 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10023 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10024 | |
| 10025 | /* |
| 10026 | * In case of slot reset, as function reset is performed through |
| 10027 | * mailbox command which needs DMA to be enabled, this operation |
| 10028 | * has to be moved to the io resume phase. Taking device offline |
| 10029 | * will perform the necessary cleanup. |
| 10030 | */ |
| 10031 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10032 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10033 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10034 | lpfc_offline(phba); |
| 10035 | lpfc_sli_brdrestart(phba); |
| 10036 | /* Bring the device back online */ |
| 10037 | lpfc_online(phba); |
| 10038 | } |
| 10039 | |
| 10040 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10041 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10042 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10043 | } |
| 10044 | |
| 10045 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10046 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10047 | * @pdev: pointer to PCI device |
| 10048 | * @pid: pointer to PCI device identifier |
| 10049 | * |
| 10050 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10051 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10052 | * at PCI device-specific information of the device and driver to see if the |
| 10053 | * driver state that it can support this kind of device. If the match is |
| 10054 | * successful, the driver core invokes this routine. This routine dispatches |
| 10055 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10056 | * do all the initialization that it needs to do to handle the HBA device |
| 10057 | * properly. |
| 10058 | * |
| 10059 | * Return code |
| 10060 | * 0 - driver can claim the device |
| 10061 | * negative value - driver can not claim the device |
| 10062 | **/ |
| 10063 | static int __devinit |
| 10064 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10065 | { |
| 10066 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10067 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10068 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10069 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10070 | return -ENODEV; |
| 10071 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10072 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10073 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10074 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10075 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10076 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10077 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10078 | return rc; |
| 10079 | } |
| 10080 | |
| 10081 | /** |
| 10082 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10083 | * @pdev: pointer to PCI device |
| 10084 | * |
| 10085 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10086 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10087 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10088 | * remove routine, which will perform all the necessary cleanup for the |
| 10089 | * device to be removed from the PCI subsystem properly. |
| 10090 | **/ |
| 10091 | static void __devexit |
| 10092 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10093 | { |
| 10094 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10095 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10096 | |
| 10097 | switch (phba->pci_dev_grp) { |
| 10098 | case LPFC_PCI_DEV_LP: |
| 10099 | lpfc_pci_remove_one_s3(pdev); |
| 10100 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10101 | case LPFC_PCI_DEV_OC: |
| 10102 | lpfc_pci_remove_one_s4(pdev); |
| 10103 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10104 | default: |
| 10105 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10106 | "1424 Invalid PCI device group: 0x%x\n", |
| 10107 | phba->pci_dev_grp); |
| 10108 | break; |
| 10109 | } |
| 10110 | return; |
| 10111 | } |
| 10112 | |
| 10113 | /** |
| 10114 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10115 | * @pdev: pointer to PCI device |
| 10116 | * @msg: power management message |
| 10117 | * |
| 10118 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10119 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10120 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10121 | * suspend the device. |
| 10122 | * |
| 10123 | * Return code |
| 10124 | * 0 - driver suspended the device |
| 10125 | * Error otherwise |
| 10126 | **/ |
| 10127 | static int |
| 10128 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10129 | { |
| 10130 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10131 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10132 | int rc = -ENODEV; |
| 10133 | |
| 10134 | switch (phba->pci_dev_grp) { |
| 10135 | case LPFC_PCI_DEV_LP: |
| 10136 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10137 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10138 | case LPFC_PCI_DEV_OC: |
| 10139 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10140 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10141 | default: |
| 10142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10143 | "1425 Invalid PCI device group: 0x%x\n", |
| 10144 | phba->pci_dev_grp); |
| 10145 | break; |
| 10146 | } |
| 10147 | return rc; |
| 10148 | } |
| 10149 | |
| 10150 | /** |
| 10151 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10152 | * @pdev: pointer to PCI device |
| 10153 | * |
| 10154 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10155 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10156 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10157 | * resume the device. |
| 10158 | * |
| 10159 | * Return code |
| 10160 | * 0 - driver suspended the device |
| 10161 | * Error otherwise |
| 10162 | **/ |
| 10163 | static int |
| 10164 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10165 | { |
| 10166 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10167 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10168 | int rc = -ENODEV; |
| 10169 | |
| 10170 | switch (phba->pci_dev_grp) { |
| 10171 | case LPFC_PCI_DEV_LP: |
| 10172 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10173 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10174 | case LPFC_PCI_DEV_OC: |
| 10175 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10176 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10177 | default: |
| 10178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10179 | "1426 Invalid PCI device group: 0x%x\n", |
| 10180 | phba->pci_dev_grp); |
| 10181 | break; |
| 10182 | } |
| 10183 | return rc; |
| 10184 | } |
| 10185 | |
| 10186 | /** |
| 10187 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10188 | * @pdev: pointer to PCI device. |
| 10189 | * @state: the current PCI connection state. |
| 10190 | * |
| 10191 | * This routine is registered to the PCI subsystem for error handling. This |
| 10192 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10193 | * this device has been detected. When this routine is invoked, it dispatches |
| 10194 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 10195 | * routine, which will perform the proper error detected operation. |
| 10196 | * |
| 10197 | * Return codes |
| 10198 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10199 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10200 | **/ |
| 10201 | static pci_ers_result_t |
| 10202 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 10203 | { |
| 10204 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10205 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10206 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10207 | |
| 10208 | switch (phba->pci_dev_grp) { |
| 10209 | case LPFC_PCI_DEV_LP: |
| 10210 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10211 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10212 | case LPFC_PCI_DEV_OC: |
| 10213 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10214 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10215 | default: |
| 10216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10217 | "1427 Invalid PCI device group: 0x%x\n", |
| 10218 | phba->pci_dev_grp); |
| 10219 | break; |
| 10220 | } |
| 10221 | return rc; |
| 10222 | } |
| 10223 | |
| 10224 | /** |
| 10225 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10226 | * @pdev: pointer to PCI device. |
| 10227 | * |
| 10228 | * This routine is registered to the PCI subsystem for error handling. This |
| 10229 | * function is called after PCI bus has been reset to restart the PCI card |
| 10230 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10231 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10232 | * routine, which will perform the proper device reset. |
| 10233 | * |
| 10234 | * Return codes |
| 10235 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10236 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10237 | **/ |
| 10238 | static pci_ers_result_t |
| 10239 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10240 | { |
| 10241 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10242 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10243 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10244 | |
| 10245 | switch (phba->pci_dev_grp) { |
| 10246 | case LPFC_PCI_DEV_LP: |
| 10247 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10248 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10249 | case LPFC_PCI_DEV_OC: |
| 10250 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10251 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10252 | default: |
| 10253 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10254 | "1428 Invalid PCI device group: 0x%x\n", |
| 10255 | phba->pci_dev_grp); |
| 10256 | break; |
| 10257 | } |
| 10258 | return rc; |
| 10259 | } |
| 10260 | |
| 10261 | /** |
| 10262 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10263 | * @pdev: pointer to PCI device |
| 10264 | * |
| 10265 | * This routine is registered to the PCI subsystem for error handling. It |
| 10266 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10267 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10268 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10269 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10270 | **/ |
| 10271 | static void |
| 10272 | lpfc_io_resume(struct pci_dev *pdev) |
| 10273 | { |
| 10274 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10275 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10276 | |
| 10277 | switch (phba->pci_dev_grp) { |
| 10278 | case LPFC_PCI_DEV_LP: |
| 10279 | lpfc_io_resume_s3(pdev); |
| 10280 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10281 | case LPFC_PCI_DEV_OC: |
| 10282 | lpfc_io_resume_s4(pdev); |
| 10283 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10284 | default: |
| 10285 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10286 | "1429 Invalid PCI device group: 0x%x\n", |
| 10287 | phba->pci_dev_grp); |
| 10288 | break; |
| 10289 | } |
| 10290 | return; |
| 10291 | } |
| 10292 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10293 | /** |
| 10294 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace |
| 10295 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10296 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10297 | * |
| 10298 | * This routine puts a reference count on the lpfc module whenever the |
| 10299 | * character device is opened |
| 10300 | **/ |
| 10301 | static int |
| 10302 | lpfc_mgmt_open(struct inode *inode, struct file *filep) |
| 10303 | { |
| 10304 | try_module_get(THIS_MODULE); |
| 10305 | return 0; |
| 10306 | } |
| 10307 | |
| 10308 | /** |
| 10309 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace |
| 10310 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10311 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10312 | * |
| 10313 | * This routine removes a reference count from the lpfc module when the |
| 10314 | * character device is closed |
| 10315 | **/ |
| 10316 | static int |
| 10317 | lpfc_mgmt_release(struct inode *inode, struct file *filep) |
| 10318 | { |
| 10319 | module_put(THIS_MODULE); |
| 10320 | return 0; |
| 10321 | } |
| 10322 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10323 | static struct pci_device_id lpfc_id_table[] = { |
| 10324 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 10325 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 10326 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 10327 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10328 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 10329 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10330 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 10331 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10332 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 10333 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10334 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 10335 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10336 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 10337 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10338 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 10339 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10340 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 10341 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10342 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 10343 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10344 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 10345 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10346 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 10347 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10348 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 10349 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10350 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 10351 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10352 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 10353 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10354 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 10355 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10356 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 10357 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10358 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 10359 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10360 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 10361 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10362 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 10363 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10364 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 10365 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10366 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 10367 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10368 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 10369 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10370 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 10371 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10372 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 10373 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10374 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 10375 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10376 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 10377 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10378 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 10379 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 10380 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 10381 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10382 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 10383 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10384 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 10385 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10386 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 10387 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10388 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 10389 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10390 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 10391 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10392 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 10393 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10394 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 10395 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10396 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 10397 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10398 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 10399 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10400 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 10401 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10402 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10403 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 10404 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 10405 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 10406 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 10407 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10408 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 10409 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 10410 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 10411 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10412 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 10413 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 10414 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 10415 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10416 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 10417 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10418 | { 0 } |
| 10419 | }; |
| 10420 | |
| 10421 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 10422 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 10423 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10424 | .error_detected = lpfc_io_error_detected, |
| 10425 | .slot_reset = lpfc_io_slot_reset, |
| 10426 | .resume = lpfc_io_resume, |
| 10427 | }; |
| 10428 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10429 | static struct pci_driver lpfc_driver = { |
| 10430 | .name = LPFC_DRIVER_NAME, |
| 10431 | .id_table = lpfc_id_table, |
| 10432 | .probe = lpfc_pci_probe_one, |
| 10433 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10434 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10435 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10436 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10437 | }; |
| 10438 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10439 | static const struct file_operations lpfc_mgmt_fop = { |
| 10440 | .open = lpfc_mgmt_open, |
| 10441 | .release = lpfc_mgmt_release, |
| 10442 | }; |
| 10443 | |
| 10444 | static struct miscdevice lpfc_mgmt_dev = { |
| 10445 | .minor = MISC_DYNAMIC_MINOR, |
| 10446 | .name = "lpfcmgmt", |
| 10447 | .fops = &lpfc_mgmt_fop, |
| 10448 | }; |
| 10449 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10450 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10451 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10452 | * |
| 10453 | * This routine is to be invoked when the lpfc module is loaded into the |
| 10454 | * kernel. The special kernel macro module_init() is used to indicate the |
| 10455 | * role of this routine to the kernel as lpfc module entry point. |
| 10456 | * |
| 10457 | * Return codes |
| 10458 | * 0 - successful |
| 10459 | * -ENOMEM - FC attach transport failed |
| 10460 | * all others - failed |
| 10461 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10462 | static int __init |
| 10463 | lpfc_init(void) |
| 10464 | { |
| 10465 | int error = 0; |
| 10466 | |
| 10467 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10468 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10469 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10470 | error = misc_register(&lpfc_mgmt_dev); |
| 10471 | if (error) |
| 10472 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 10473 | "misc_register returned with status %d", error); |
| 10474 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10475 | if (lpfc_enable_npiv) { |
| 10476 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 10477 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 10478 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10479 | lpfc_transport_template = |
| 10480 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10481 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10482 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10483 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10484 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10485 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 10486 | if (lpfc_vport_transport_template == NULL) { |
| 10487 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10488 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10489 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10491 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10492 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10493 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10494 | if (lpfc_enable_npiv) |
| 10495 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10496 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10497 | |
| 10498 | return error; |
| 10499 | } |
| 10500 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10501 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10502 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10503 | * |
| 10504 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 10505 | * The special kernel macro module_exit() is used to indicate the role of |
| 10506 | * this routine to the kernel as lpfc module exit point. |
| 10507 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10508 | static void __exit |
| 10509 | lpfc_exit(void) |
| 10510 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10511 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10512 | pci_unregister_driver(&lpfc_driver); |
| 10513 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10514 | if (lpfc_enable_npiv) |
| 10515 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10516 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10517 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 10518 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10519 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 10520 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 10521 | } |
| 10522 | |
| 10523 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10524 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 10525 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10526 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 10527 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 10528 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10529 | } |
| 10530 | |
| 10531 | module_init(lpfc_init); |
| 10532 | module_exit(lpfc_exit); |
| 10533 | MODULE_LICENSE("GPL"); |
| 10534 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 10535 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 10536 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |