| 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; |
| 1895 | else |
| 1896 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | |
| 1898 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1899 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1900 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1901 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1902 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1903 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | case PCI_DEVICE_ID_SUPERFLY: |
| 1905 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1906 | m = (typeof(m)){"LP7000", "PCI", |
| 1907 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1908 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1909 | m = (typeof(m)){"LP7000E", "PCI", |
| 1910 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | break; |
| 1912 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1913 | m = (typeof(m)){"LP8000", "PCI", |
| 1914 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | break; |
| 1916 | case PCI_DEVICE_ID_CENTAUR: |
| 1917 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1918 | m = (typeof(m)){"LP9002", "PCI", |
| 1919 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1920 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1921 | m = (typeof(m)){"LP9000", "PCI", |
| 1922 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | break; |
| 1924 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1925 | m = (typeof(m)){"LP952", "PCI", |
| 1926 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | break; |
| 1928 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1929 | m = (typeof(m)){"LP9802", "PCI-X", |
| 1930 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | break; |
| 1932 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1933 | m = (typeof(m)){"LP10000", "PCI-X", |
| 1934 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | break; |
| 1936 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1937 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 1938 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | break; |
| 1940 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1941 | m = (typeof(m)){"LP982", "PCI-X", |
| 1942 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | break; |
| 1944 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1945 | m = (typeof(m)){"LP1050", "PCI-X", |
| 1946 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | break; |
| 1948 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1949 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 1950 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1952 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1953 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 1954 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1955 | break; |
| 1956 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1957 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 1958 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1959 | break; |
| 1960 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1961 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1962 | break; |
| 1963 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1964 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1965 | break; |
| 1966 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1967 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1968 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1969 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1970 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1971 | break; |
| 1972 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1973 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | break; |
| 1975 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1976 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1978 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1979 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1980 | break; |
| 1981 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1982 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1983 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1984 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1986 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1987 | break; |
| 1988 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1989 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1990 | break; |
| 1991 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1992 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1993 | break; |
| 1994 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1995 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1996 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1997 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1998 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1999 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2000 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2001 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2002 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2003 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2004 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2005 | break; |
| 2006 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2007 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2008 | break; |
| 2009 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2010 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2011 | break; |
| 2012 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2013 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2014 | break; |
| 2015 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2016 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2017 | break; |
| 2018 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2019 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2020 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2021 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2022 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2023 | GE = 1; |
| 2024 | break; |
| 2025 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2026 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2027 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2028 | break; |
| 2029 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2030 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2031 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2032 | break; |
| 2033 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2034 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 2035 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2036 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2037 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2038 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2039 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2040 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2041 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2042 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2043 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2044 | break; |
| 2045 | case PCI_DEVICE_ID_FALCON: |
| 2046 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2047 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2048 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2049 | case PCI_DEVICE_ID_BALIUS: |
| 2050 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2051 | "Fibre Channel Adapter"}; |
| 2052 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2053 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2054 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2055 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2056 | break; |
| 2057 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2058 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2059 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2060 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2061 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2062 | case PCI_DEVICE_ID_SKYHAWK: |
| 2063 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2064 | oneConnect = 1; |
| 2065 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2066 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2067 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2068 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2069 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2070 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2071 | |
| 2072 | if (mdp && mdp[0] == '\0') |
| 2073 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2074 | /* |
| 2075 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2076 | * and we put the port number on the end |
| 2077 | */ |
| 2078 | if (descp && descp[0] == '\0') { |
| 2079 | if (oneConnect) |
| 2080 | snprintf(descp, 255, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2081 | "Emulex OneConnect %s, %s Initiator, Port %s", |
| 2082 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2083 | phba->Port); |
| 2084 | else |
| 2085 | snprintf(descp, 255, |
| 2086 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2087 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2088 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2089 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2090 | } |
| 2091 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2092 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2093 | * 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] | 2094 | * @phba: pointer to lpfc hba data structure. |
| 2095 | * @pring: pointer to a IOCB ring. |
| 2096 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2097 | * |
| 2098 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2099 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2100 | * |
| 2101 | * Return codes |
| 2102 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2103 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2105 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | { |
| 2107 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2108 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | struct lpfc_dmabuf *mp1, *mp2; |
| 2110 | |
| 2111 | cnt += pring->missbufcnt; |
| 2112 | |
| 2113 | /* While there are buffers to post */ |
| 2114 | while (cnt > 0) { |
| 2115 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2116 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2117 | if (iocb == NULL) { |
| 2118 | pring->missbufcnt = cnt; |
| 2119 | return cnt; |
| 2120 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | icmd = &iocb->iocb; |
| 2122 | |
| 2123 | /* 2 buffers can be posted per command */ |
| 2124 | /* Allocate buffer to post */ |
| 2125 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2126 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2127 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2128 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2129 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2130 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | pring->missbufcnt = cnt; |
| 2132 | return cnt; |
| 2133 | } |
| 2134 | |
| 2135 | INIT_LIST_HEAD(&mp1->list); |
| 2136 | /* Allocate buffer to post */ |
| 2137 | if (cnt > 1) { |
| 2138 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2139 | if (mp2) |
| 2140 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2141 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2142 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2143 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2145 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2146 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | pring->missbufcnt = cnt; |
| 2148 | return cnt; |
| 2149 | } |
| 2150 | |
| 2151 | INIT_LIST_HEAD(&mp2->list); |
| 2152 | } else { |
| 2153 | mp2 = NULL; |
| 2154 | } |
| 2155 | |
| 2156 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2157 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2158 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2159 | icmd->ulpBdeCount = 1; |
| 2160 | cnt--; |
| 2161 | if (mp2) { |
| 2162 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2163 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2164 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2165 | cnt--; |
| 2166 | icmd->ulpBdeCount = 2; |
| 2167 | } |
| 2168 | |
| 2169 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2170 | icmd->ulpLe = 1; |
| 2171 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2172 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2173 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2175 | kfree(mp1); |
| 2176 | cnt++; |
| 2177 | if (mp2) { |
| 2178 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2179 | kfree(mp2); |
| 2180 | cnt++; |
| 2181 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2182 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2184 | return cnt; |
| 2185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2187 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2188 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | } |
| 2190 | pring->missbufcnt = 0; |
| 2191 | return 0; |
| 2192 | } |
| 2193 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2194 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2195 | * 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] | 2196 | * @phba: pointer to lpfc hba data structure. |
| 2197 | * |
| 2198 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2199 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2200 | * set to 64 IOCBs. |
| 2201 | * |
| 2202 | * Return codes |
| 2203 | * 0 - success (currently always success) |
| 2204 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2206 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2207 | { |
| 2208 | struct lpfc_sli *psli = &phba->sli; |
| 2209 | |
| 2210 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2211 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | /* Ring 2 - FCP no buffers needed */ |
| 2213 | |
| 2214 | return 0; |
| 2215 | } |
| 2216 | |
| 2217 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2218 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2220 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2221 | * @HashResultPointer: pointer to an array as hash table. |
| 2222 | * |
| 2223 | * This routine sets up the initial values to the array of hash table entries |
| 2224 | * for the LC HBAs. |
| 2225 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2226 | static void |
| 2227 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2228 | { |
| 2229 | HashResultPointer[0] = 0x67452301; |
| 2230 | HashResultPointer[1] = 0xEFCDAB89; |
| 2231 | HashResultPointer[2] = 0x98BADCFE; |
| 2232 | HashResultPointer[3] = 0x10325476; |
| 2233 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2234 | } |
| 2235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2237 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2238 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2239 | * @HashWorkingPointer: pointer to an working hash table. |
| 2240 | * |
| 2241 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2242 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2243 | * The results are putting back to the initial hash table, returned through |
| 2244 | * the @HashResultPointer as the result hash table. |
| 2245 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | static void |
| 2247 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2248 | { |
| 2249 | int t; |
| 2250 | uint32_t TEMP; |
| 2251 | uint32_t A, B, C, D, E; |
| 2252 | t = 16; |
| 2253 | do { |
| 2254 | HashWorkingPointer[t] = |
| 2255 | S(1, |
| 2256 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2257 | 8] ^ |
| 2258 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2259 | } while (++t <= 79); |
| 2260 | t = 0; |
| 2261 | A = HashResultPointer[0]; |
| 2262 | B = HashResultPointer[1]; |
| 2263 | C = HashResultPointer[2]; |
| 2264 | D = HashResultPointer[3]; |
| 2265 | E = HashResultPointer[4]; |
| 2266 | |
| 2267 | do { |
| 2268 | if (t < 20) { |
| 2269 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2270 | } else if (t < 40) { |
| 2271 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2272 | } else if (t < 60) { |
| 2273 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2274 | } else { |
| 2275 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2276 | } |
| 2277 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2278 | E = D; |
| 2279 | D = C; |
| 2280 | C = S(30, B); |
| 2281 | B = A; |
| 2282 | A = TEMP; |
| 2283 | } while (++t <= 79); |
| 2284 | |
| 2285 | HashResultPointer[0] += A; |
| 2286 | HashResultPointer[1] += B; |
| 2287 | HashResultPointer[2] += C; |
| 2288 | HashResultPointer[3] += D; |
| 2289 | HashResultPointer[4] += E; |
| 2290 | |
| 2291 | } |
| 2292 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2293 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2294 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2296 | * @HashWorking: pointer to the entry of the working hash array. |
| 2297 | * |
| 2298 | * This routine calculates the working hash array referred by @HashWorking |
| 2299 | * from the challenge random numbers associated with the host, referred by |
| 2300 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2301 | * array and returned by reference through @HashWorking. |
| 2302 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | static void |
| 2304 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2305 | { |
| 2306 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2307 | } |
| 2308 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2309 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2310 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2311 | * @phba: pointer to lpfc hba data structure. |
| 2312 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2313 | * |
| 2314 | * This routine performs the special handling for LC HBA initialization. |
| 2315 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2316 | void |
| 2317 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2318 | { |
| 2319 | int t; |
| 2320 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2321 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2323 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2324 | if (!HashWorking) |
| 2325 | return; |
| 2326 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2327 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2328 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2329 | |
| 2330 | for (t = 0; t < 7; t++) |
| 2331 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2332 | |
| 2333 | lpfc_sha_init(hbainit); |
| 2334 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2335 | kfree(HashWorking); |
| 2336 | } |
| 2337 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2338 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2339 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2340 | * @vport: pointer to a virtual N_Port data structure. |
| 2341 | * |
| 2342 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2343 | * It invokes the discovery state machine to perform necessary state |
| 2344 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2345 | * the physical port is treated as @vport 0. |
| 2346 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2347 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2348 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2350 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2352 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2354 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2355 | lpfc_port_link_failure(vport); |
| 2356 | |
| 2357 | 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] | 2358 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2359 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2360 | NLP_STE_UNUSED_NODE); |
| 2361 | if (!ndlp) |
| 2362 | continue; |
| 2363 | spin_lock_irq(&phba->ndlp_lock); |
| 2364 | NLP_SET_FREE_REQ(ndlp); |
| 2365 | spin_unlock_irq(&phba->ndlp_lock); |
| 2366 | /* Trigger the release of the ndlp memory */ |
| 2367 | lpfc_nlp_put(ndlp); |
| 2368 | continue; |
| 2369 | } |
| 2370 | spin_lock_irq(&phba->ndlp_lock); |
| 2371 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2372 | /* The ndlp should not be in memory free mode already */ |
| 2373 | spin_unlock_irq(&phba->ndlp_lock); |
| 2374 | continue; |
| 2375 | } else |
| 2376 | /* Indicate request for freeing ndlp memory */ |
| 2377 | NLP_SET_FREE_REQ(ndlp); |
| 2378 | spin_unlock_irq(&phba->ndlp_lock); |
| 2379 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2380 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2381 | ndlp->nlp_DID == Fabric_DID) { |
| 2382 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2383 | lpfc_nlp_put(ndlp); |
| 2384 | continue; |
| 2385 | } |
| 2386 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2387 | /* take care of nodes in unused state before the state |
| 2388 | * machine taking action. |
| 2389 | */ |
| 2390 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2391 | lpfc_nlp_put(ndlp); |
| 2392 | continue; |
| 2393 | } |
| 2394 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2395 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2396 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2397 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2398 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2399 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2400 | NLP_EVT_DEVICE_RM); |
| 2401 | } |
| 2402 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2403 | /* At this point, ALL ndlp's should be gone |
| 2404 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2405 | * Lets wait for this to happen, if needed. |
| 2406 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2407 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2408 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2410 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2411 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2412 | &vport->fc_nodes, nlp_listp) { |
| 2413 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2414 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2415 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2416 | "usgmap:x%x refcnt:%d\n", |
| 2417 | ndlp->nlp_DID, (void *)ndlp, |
| 2418 | ndlp->nlp_usg_map, |
| 2419 | atomic_read( |
| 2420 | &ndlp->kref.refcount)); |
| 2421 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2422 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2423 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2424 | |
| 2425 | /* Wait for any activity on ndlps to settle */ |
| 2426 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2427 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2428 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | } |
| 2430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2432 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2433 | * @vport: pointer to a virtual N_Port data structure. |
| 2434 | * |
| 2435 | * This routine stops all the timers associated with a @vport. This function |
| 2436 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2437 | * port is treated as @vport 0. |
| 2438 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2439 | void |
| 2440 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2442 | del_timer_sync(&vport->els_tmofunc); |
| 2443 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2444 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2445 | lpfc_can_disctmo(vport); |
| 2446 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | } |
| 2448 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2449 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2450 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2451 | * @phba: pointer to lpfc hba data structure. |
| 2452 | * |
| 2453 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2454 | * caller of this routine should already hold the host lock. |
| 2455 | **/ |
| 2456 | void |
| 2457 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2458 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2459 | /* Clear pending FCF rediscovery wait flag */ |
| 2460 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2461 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2462 | /* Now, try to stop the timer */ |
| 2463 | del_timer(&phba->fcf.redisc_wait); |
| 2464 | } |
| 2465 | |
| 2466 | /** |
| 2467 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2468 | * @phba: pointer to lpfc hba data structure. |
| 2469 | * |
| 2470 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2471 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2472 | * lock held before proceeding with disabling the timer and clearing the |
| 2473 | * wait timer pendig flag. |
| 2474 | **/ |
| 2475 | void |
| 2476 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2477 | { |
| 2478 | spin_lock_irq(&phba->hbalock); |
| 2479 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2480 | /* FCF rediscovery timer already fired or stopped */ |
| 2481 | spin_unlock_irq(&phba->hbalock); |
| 2482 | return; |
| 2483 | } |
| 2484 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2485 | /* Clear failover in progress flags */ |
| 2486 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2487 | spin_unlock_irq(&phba->hbalock); |
| 2488 | } |
| 2489 | |
| 2490 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2491 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2492 | * @phba: pointer to lpfc hba data structure. |
| 2493 | * |
| 2494 | * This routine stops all the timers associated with a HBA. This function is |
| 2495 | * invoked before either putting a HBA offline or unloading the driver. |
| 2496 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2497 | void |
| 2498 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2500 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2501 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2502 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2503 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2504 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2505 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2506 | del_timer_sync(&phba->rrq_tmr); |
| 2507 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2508 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2509 | phba->hb_outstanding = 0; |
| 2510 | |
| 2511 | switch (phba->pci_dev_grp) { |
| 2512 | case LPFC_PCI_DEV_LP: |
| 2513 | /* Stop any LightPulse device specific driver timers */ |
| 2514 | del_timer_sync(&phba->fcp_poll_timer); |
| 2515 | break; |
| 2516 | case LPFC_PCI_DEV_OC: |
| 2517 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2518 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2519 | break; |
| 2520 | default: |
| 2521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2522 | "0297 Invalid device group (x%x)\n", |
| 2523 | phba->pci_dev_grp); |
| 2524 | break; |
| 2525 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2526 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2527 | } |
| 2528 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2529 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2530 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2531 | * @phba: pointer to lpfc hba data structure. |
| 2532 | * |
| 2533 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2534 | * management interface is marked as blocked, all the user space access to |
| 2535 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2536 | * all be blocked. The HBA is set to block the management interface when the |
| 2537 | * driver prepares the HBA interface for online or offline. |
| 2538 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2539 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2540 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2541 | { |
| 2542 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2543 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2544 | unsigned long timeout; |
| 2545 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2546 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2547 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2548 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2549 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2550 | return; |
| 2551 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2552 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2553 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2554 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2555 | /* Determine how long we might wait for the active mailbox |
| 2556 | * command to be gracefully completed by firmware. |
| 2557 | */ |
| 2558 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2559 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2560 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2561 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2562 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2563 | /* Wait for the outstnading mailbox command to complete */ |
| 2564 | while (phba->sli.mbox_active) { |
| 2565 | /* Check active mailbox complete status every 2ms */ |
| 2566 | msleep(2); |
| 2567 | if (time_after(jiffies, timeout)) { |
| 2568 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2569 | "2813 Mgmt IO is Blocked %x " |
| 2570 | "- mbox cmd %x still active\n", |
| 2571 | phba->sli.sli_flag, actcmd); |
| 2572 | break; |
| 2573 | } |
| 2574 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2575 | } |
| 2576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2577 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2578 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2579 | * @phba: pointer to lpfc hba data structure. |
| 2580 | * |
| 2581 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2582 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2583 | * is to fixup the temporary rpi assignments. |
| 2584 | **/ |
| 2585 | void |
| 2586 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2587 | { |
| 2588 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2589 | struct lpfc_vport **vports; |
| 2590 | int i; |
| 2591 | |
| 2592 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2593 | return; |
| 2594 | |
| 2595 | vports = lpfc_create_vport_work_array(phba); |
| 2596 | if (vports != NULL) { |
| 2597 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2598 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2599 | continue; |
| 2600 | |
| 2601 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2602 | &vports[i]->fc_nodes, |
| 2603 | nlp_listp) { |
| 2604 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2605 | ndlp->nlp_rpi = |
| 2606 | lpfc_sli4_alloc_rpi(phba); |
| 2607 | } |
| 2608 | } |
| 2609 | } |
| 2610 | lpfc_destroy_vport_work_array(phba, vports); |
| 2611 | } |
| 2612 | |
| 2613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2614 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2615 | * @phba: pointer to lpfc hba data structure. |
| 2616 | * |
| 2617 | * This routine initializes the HBA and brings a HBA online. During this |
| 2618 | * process, the management interface is blocked to prevent user space access |
| 2619 | * to the HBA interfering with the driver initialization. |
| 2620 | * |
| 2621 | * Return codes |
| 2622 | * 0 - successful |
| 2623 | * 1 - failed |
| 2624 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2626 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2628 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2629 | struct lpfc_vport **vports; |
| 2630 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2631 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | if (!phba) |
| 2633 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2634 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2635 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2636 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2637 | return 0; |
| 2638 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2639 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2640 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2642 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2644 | if (!lpfc_sli_queue_setup(phba)) { |
| 2645 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2649 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2650 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2651 | lpfc_unblock_mgmt_io(phba); |
| 2652 | return 1; |
| 2653 | } |
| 2654 | } else { |
| 2655 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2656 | lpfc_unblock_mgmt_io(phba); |
| 2657 | return 1; |
| 2658 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2659 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2661 | vports = lpfc_create_vport_work_array(phba); |
| 2662 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2663 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2664 | struct Scsi_Host *shost; |
| 2665 | shost = lpfc_shost_from_vport(vports[i]); |
| 2666 | spin_lock_irq(shost->host_lock); |
| 2667 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2668 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2669 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2670 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2671 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2672 | spin_unlock_irq(shost->host_lock); |
| 2673 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2674 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2676 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | return 0; |
| 2678 | } |
| 2679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2680 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2681 | * 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] | 2682 | * @phba: pointer to lpfc hba data structure. |
| 2683 | * |
| 2684 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2685 | * HBA's management interface is marked as not blocked, all the user space |
| 2686 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2687 | * interface will be allowed. The HBA is set to block the management interface |
| 2688 | * when the driver prepares the HBA interface for online or offline and then |
| 2689 | * set to unblock the management interface afterwards. |
| 2690 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2691 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2692 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2693 | { |
| 2694 | unsigned long iflag; |
| 2695 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2696 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2697 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2698 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2699 | } |
| 2700 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2701 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2702 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2703 | * @phba: pointer to lpfc hba data structure. |
| 2704 | * |
| 2705 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2706 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2707 | * queue to make it ready to be brought offline. |
| 2708 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2709 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2710 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2711 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2712 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2713 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2714 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2715 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2716 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2718 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2719 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2721 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | |
| 2723 | lpfc_linkdown(phba); |
| 2724 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2725 | /* Issue an unreg_login to all nodes on all vports */ |
| 2726 | vports = lpfc_create_vport_work_array(phba); |
| 2727 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2728 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2729 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2730 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2731 | shost = lpfc_shost_from_vport(vports[i]); |
| 2732 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2733 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2734 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2735 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2736 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2737 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2738 | shost = lpfc_shost_from_vport(vports[i]); |
| 2739 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2740 | &vports[i]->fc_nodes, |
| 2741 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2742 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2743 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2744 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2745 | continue; |
| 2746 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2747 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2748 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2749 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2750 | NULL, NLP_EVT_DEVICE_RM); |
| 2751 | } |
| 2752 | spin_lock_irq(shost->host_lock); |
| 2753 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2754 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2755 | /* |
| 2756 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2757 | * RPI. Get a new RPI when the adapter port |
| 2758 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2759 | */ |
| 2760 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2761 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2762 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2763 | } |
| 2764 | } |
| 2765 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2766 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2768 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2769 | } |
| 2770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2772 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2773 | * @phba: pointer to lpfc hba data structure. |
| 2774 | * |
| 2775 | * This routine actually brings a HBA offline. It stops all the timers |
| 2776 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2777 | * marks the HBA as in offline state for the upper layer protocol. |
| 2778 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2779 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2780 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2781 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2782 | struct Scsi_Host *shost; |
| 2783 | struct lpfc_vport **vports; |
| 2784 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2785 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2786 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2787 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2788 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2789 | /* stop port and all timers associated with this hba */ |
| 2790 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2791 | vports = lpfc_create_vport_work_array(phba); |
| 2792 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2793 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2794 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2795 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2796 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2797 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2798 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2799 | now. */ |
| 2800 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2801 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2802 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2803 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2804 | vports = lpfc_create_vport_work_array(phba); |
| 2805 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2806 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2807 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2808 | spin_lock_irq(shost->host_lock); |
| 2809 | vports[i]->work_port_events = 0; |
| 2810 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2811 | spin_unlock_irq(shost->host_lock); |
| 2812 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2813 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2814 | } |
| 2815 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2817 | * 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] | 2818 | * @phba: pointer to lpfc hba data structure. |
| 2819 | * |
| 2820 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2821 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2822 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2823 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2824 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2825 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | { |
| 2827 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2828 | struct lpfc_iocbq *io, *io_next; |
| 2829 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2830 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2832 | spin_lock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 2834 | list_del(&sb->list); |
| 2835 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2836 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2837 | kfree(sb); |
| 2838 | phba->total_scsi_bufs--; |
| 2839 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2840 | spin_unlock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2841 | |
| 2842 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2843 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2844 | list_del(&io->list); |
| 2845 | kfree(io); |
| 2846 | phba->total_iocbq_bufs--; |
| 2847 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2848 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2849 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | /** |
| 2853 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 2854 | * @phba: pointer to lpfc hba data structure. |
| 2855 | * |
| 2856 | * This routine first calculates the sizes of the current els and allocated |
| 2857 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 2858 | * XRIs assigned due to port function reset. During port initialization, the |
| 2859 | * current els and allocated scsi sgl lists are 0s. |
| 2860 | * |
| 2861 | * Return codes |
| 2862 | * 0 - successful (for now, it always returns 0) |
| 2863 | **/ |
| 2864 | int |
| 2865 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 2866 | { |
| 2867 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 2868 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 2869 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 2870 | LIST_HEAD(els_sgl_list); |
| 2871 | LIST_HEAD(scsi_sgl_list); |
| 2872 | int rc; |
| 2873 | |
| 2874 | /* |
| 2875 | * update on pci function's els xri-sgl list |
| 2876 | */ |
| 2877 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 2878 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 2879 | /* els xri-sgl expanded */ |
| 2880 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 2881 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2882 | "3157 ELS xri-sgl count increased from " |
| 2883 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2884 | els_xri_cnt); |
| 2885 | /* allocate the additional els sgls */ |
| 2886 | for (i = 0; i < xri_cnt; i++) { |
| 2887 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 2888 | GFP_KERNEL); |
| 2889 | if (sglq_entry == NULL) { |
| 2890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2891 | "2562 Failure to allocate an " |
| 2892 | "ELS sgl entry:%d\n", i); |
| 2893 | rc = -ENOMEM; |
| 2894 | goto out_free_mem; |
| 2895 | } |
| 2896 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 2897 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 2898 | &sglq_entry->phys); |
| 2899 | if (sglq_entry->virt == NULL) { |
| 2900 | kfree(sglq_entry); |
| 2901 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2902 | "2563 Failure to allocate an " |
| 2903 | "ELS mbuf:%d\n", i); |
| 2904 | rc = -ENOMEM; |
| 2905 | goto out_free_mem; |
| 2906 | } |
| 2907 | sglq_entry->sgl = sglq_entry->virt; |
| 2908 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 2909 | sglq_entry->state = SGL_FREED; |
| 2910 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 2911 | } |
| 2912 | spin_lock(&phba->hbalock); |
| 2913 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2914 | spin_unlock(&phba->hbalock); |
| 2915 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 2916 | /* els xri-sgl shrinked */ |
| 2917 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 2918 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2919 | "3158 ELS xri-sgl count decreased from " |
| 2920 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2921 | els_xri_cnt); |
| 2922 | spin_lock_irq(&phba->hbalock); |
| 2923 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
| 2924 | spin_unlock_irq(&phba->hbalock); |
| 2925 | /* release extra els sgls from list */ |
| 2926 | for (i = 0; i < xri_cnt; i++) { |
| 2927 | list_remove_head(&els_sgl_list, |
| 2928 | sglq_entry, struct lpfc_sglq, list); |
| 2929 | if (sglq_entry) { |
| 2930 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 2931 | sglq_entry->phys); |
| 2932 | kfree(sglq_entry); |
| 2933 | } |
| 2934 | } |
| 2935 | spin_lock_irq(&phba->hbalock); |
| 2936 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2937 | spin_unlock_irq(&phba->hbalock); |
| 2938 | } else |
| 2939 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2940 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 2941 | els_xri_cnt); |
| 2942 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 2943 | |
| 2944 | /* update xris to els sgls on the list */ |
| 2945 | sglq_entry = NULL; |
| 2946 | sglq_entry_next = NULL; |
| 2947 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 2948 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 2949 | lxri = lpfc_sli4_next_xritag(phba); |
| 2950 | if (lxri == NO_XRI) { |
| 2951 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2952 | "2400 Failed to allocate xri for " |
| 2953 | "ELS sgl\n"); |
| 2954 | rc = -ENOMEM; |
| 2955 | goto out_free_mem; |
| 2956 | } |
| 2957 | sglq_entry->sli4_lxritag = lxri; |
| 2958 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 2959 | } |
| 2960 | |
| 2961 | /* |
| 2962 | * update on pci function's allocated scsi xri-sgl list |
| 2963 | */ |
| 2964 | phba->total_scsi_bufs = 0; |
| 2965 | |
| 2966 | /* maximum number of xris available for scsi buffers */ |
| 2967 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 2968 | els_xri_cnt; |
| 2969 | |
| 2970 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2971 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 2972 | "maximum SCSI xri count:%d\n", |
| 2973 | phba->sli4_hba.scsi_xri_cnt, |
| 2974 | phba->sli4_hba.scsi_xri_max); |
| 2975 | |
| 2976 | spin_lock_irq(&phba->scsi_buf_list_lock); |
| 2977 | list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list); |
| 2978 | spin_unlock_irq(&phba->scsi_buf_list_lock); |
| 2979 | |
| 2980 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 2981 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 2982 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 2983 | phba->sli4_hba.scsi_xri_max; |
| 2984 | /* release the extra allocated scsi buffers */ |
| 2985 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 2986 | list_remove_head(&scsi_sgl_list, psb, |
| 2987 | struct lpfc_scsi_buf, list); |
| 2988 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, |
| 2989 | psb->dma_handle); |
| 2990 | kfree(psb); |
| 2991 | } |
| 2992 | spin_lock_irq(&phba->scsi_buf_list_lock); |
| 2993 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
| 2994 | spin_unlock_irq(&phba->scsi_buf_list_lock); |
| 2995 | } |
| 2996 | |
| 2997 | /* update xris associated to remaining allocated scsi buffers */ |
| 2998 | psb = NULL; |
| 2999 | psb_next = NULL; |
| 3000 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3001 | lxri = lpfc_sli4_next_xritag(phba); |
| 3002 | if (lxri == NO_XRI) { |
| 3003 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3004 | "2560 Failed to allocate xri for " |
| 3005 | "scsi buffer\n"); |
| 3006 | rc = -ENOMEM; |
| 3007 | goto out_free_mem; |
| 3008 | } |
| 3009 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3010 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3011 | } |
| 3012 | spin_lock(&phba->scsi_buf_list_lock); |
| 3013 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list); |
| 3014 | spin_unlock(&phba->scsi_buf_list_lock); |
| 3015 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3016 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3017 | |
| 3018 | out_free_mem: |
| 3019 | lpfc_free_els_sgl_list(phba); |
| 3020 | lpfc_scsi_free(phba); |
| 3021 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | } |
| 3023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3025 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3026 | * @phba: pointer to lpfc hba data structure. |
| 3027 | * @instance: a unique integer ID to this FC port. |
| 3028 | * @dev: pointer to the device data structure. |
| 3029 | * |
| 3030 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3031 | * can be created on top of either a physical port or a virtual port provided |
| 3032 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3033 | * and associates the FC port created before adding the shost into the SCSI |
| 3034 | * layer. |
| 3035 | * |
| 3036 | * Return codes |
| 3037 | * @vport - pointer to the virtual N_Port data structure. |
| 3038 | * NULL - port create failed. |
| 3039 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3040 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3041 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3042 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3043 | struct lpfc_vport *vport; |
| 3044 | struct Scsi_Host *shost; |
| 3045 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3046 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3047 | if (dev != &phba->pcidev->dev) |
| 3048 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3049 | sizeof(struct lpfc_vport)); |
| 3050 | else |
| 3051 | shost = scsi_host_alloc(&lpfc_template, |
| 3052 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3053 | if (!shost) |
| 3054 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3055 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3056 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3057 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3058 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3059 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3060 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3061 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3062 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3063 | shost->unique_id = instance; |
| 3064 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3065 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3066 | shost->this_id = -1; |
| 3067 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3068 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3069 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3070 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3071 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3072 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3073 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3074 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3075 | * Set initial can_queue value since 0 is no longer supported and |
| 3076 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3077 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3078 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3079 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3080 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3081 | shost->transportt = lpfc_vport_transport_template; |
| 3082 | vport->port_type = LPFC_NPIV_PORT; |
| 3083 | } else { |
| 3084 | shost->transportt = lpfc_transport_template; |
| 3085 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3086 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3087 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3088 | /* Initialize all internally managed lists. */ |
| 3089 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3090 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3091 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3092 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3093 | init_timer(&vport->fc_disctmo); |
| 3094 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3095 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3096 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3097 | init_timer(&vport->fc_fdmitmo); |
| 3098 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3099 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3100 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3101 | init_timer(&vport->els_tmofunc); |
| 3102 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3103 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3104 | |
| 3105 | init_timer(&vport->delayed_disc_tmo); |
| 3106 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3107 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3108 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3109 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3110 | if (error) |
| 3111 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3112 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3113 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3114 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3115 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3116 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3117 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3118 | out_put_shost: |
| 3119 | scsi_host_put(shost); |
| 3120 | out: |
| 3121 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3122 | } |
| 3123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3125 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3126 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3127 | * |
| 3128 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3129 | * resources associated with the port are released. |
| 3130 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3131 | void |
| 3132 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3133 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3134 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3135 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3136 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3137 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3138 | fc_remove_host(shost); |
| 3139 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3140 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | spin_lock_irq(&phba->hbalock); |
| 3142 | list_del_init(&vport->listentry); |
| 3143 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3144 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3145 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3146 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3147 | } |
| 3148 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3149 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3150 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3151 | * |
| 3152 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3153 | * uses the kernel idr facility to perform the task. |
| 3154 | * |
| 3155 | * Return codes: |
| 3156 | * instance - a unique integer ID allocated as the new instance. |
| 3157 | * -1 - lpfc get instance failed. |
| 3158 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3159 | int |
| 3160 | lpfc_get_instance(void) |
| 3161 | { |
| 3162 | int instance = 0; |
| 3163 | |
| 3164 | /* Assign an unused number */ |
| 3165 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 3166 | return -1; |
| 3167 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 3168 | return -1; |
| 3169 | return instance; |
| 3170 | } |
| 3171 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3172 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3173 | * 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] | 3174 | * @shost: pointer to SCSI host data structure. |
| 3175 | * @time: elapsed time of the scan in jiffies. |
| 3176 | * |
| 3177 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3178 | * whether the scan host is finished. |
| 3179 | * |
| 3180 | * Note: there is no scan_start function as adapter initialization will have |
| 3181 | * asynchronously kicked off the link initialization. |
| 3182 | * |
| 3183 | * Return codes |
| 3184 | * 0 - SCSI host scan is not over yet. |
| 3185 | * 1 - SCSI host scan is over. |
| 3186 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3187 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3188 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3189 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3190 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3191 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3192 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3193 | spin_lock_irq(shost->host_lock); |
| 3194 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3195 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3196 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3197 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3198 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3199 | if (time >= 30 * HZ) { |
| 3200 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3201 | "0461 Scanning longer than 30 " |
| 3202 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3203 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3204 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3205 | } |
| 3206 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 3207 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3208 | "0465 Link down longer than 15 " |
| 3209 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3210 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3211 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3212 | } |
| 3213 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3214 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3215 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3217 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3218 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3219 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3220 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3221 | goto finished; |
| 3222 | |
| 3223 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3224 | |
| 3225 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3226 | spin_unlock_irq(shost->host_lock); |
| 3227 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3228 | } |
| 3229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3230 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3231 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3232 | * @shost: pointer to SCSI host data structure. |
| 3233 | * |
| 3234 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3235 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3236 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3237 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3238 | { |
| 3239 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3240 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3241 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3242 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3243 | */ |
| 3244 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3246 | 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] | 3247 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3248 | |
| 3249 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3251 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3252 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3253 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3254 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3255 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3256 | |
| 3257 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3258 | if (phba->lmt & LMT_16Gb) |
| 3259 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3260 | if (phba->lmt & LMT_10Gb) |
| 3261 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3262 | if (phba->lmt & LMT_8Gb) |
| 3263 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3264 | if (phba->lmt & LMT_4Gb) |
| 3265 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3266 | if (phba->lmt & LMT_2Gb) |
| 3267 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3268 | if (phba->lmt & LMT_1Gb) |
| 3269 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3270 | |
| 3271 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3272 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3273 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3274 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3275 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3276 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3277 | /* This value is also unchanging */ |
| 3278 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3279 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3280 | fc_host_active_fc4s(shost)[2] = 1; |
| 3281 | fc_host_active_fc4s(shost)[7] = 1; |
| 3282 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3283 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3284 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3285 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3286 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3287 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3289 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3290 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3291 | * @phba: pointer to lpfc hba data structure. |
| 3292 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3293 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3294 | * from generating interrupts and stops the device driver's timers for the |
| 3295 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3296 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3297 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3298 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3299 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3300 | /* Clear all interrupt enable conditions */ |
| 3301 | writel(0, phba->HCregaddr); |
| 3302 | readl(phba->HCregaddr); /* flush */ |
| 3303 | /* Clear all pending interrupts */ |
| 3304 | writel(0xffffffff, phba->HAregaddr); |
| 3305 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3306 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3307 | /* Reset some HBA SLI setup states */ |
| 3308 | lpfc_stop_hba_timers(phba); |
| 3309 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3310 | } |
| 3311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3312 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3313 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3314 | * @phba: pointer to lpfc hba data structure. |
| 3315 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3316 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3317 | * from generating interrupts and stops the device driver's timers for the |
| 3318 | * device. |
| 3319 | **/ |
| 3320 | static void |
| 3321 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3322 | { |
| 3323 | /* Reset some HBA SLI4 setup states */ |
| 3324 | lpfc_stop_hba_timers(phba); |
| 3325 | phba->pport->work_port_events = 0; |
| 3326 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | /** |
| 3330 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3331 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3332 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3333 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3334 | * the API jump table function pointer from the lpfc_hba struct. |
| 3335 | **/ |
| 3336 | void |
| 3337 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3338 | { |
| 3339 | phba->lpfc_stop_port(phba); |
| 3340 | } |
| 3341 | |
| 3342 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3343 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3344 | * @phba: Pointer to hba for which this call is being executed. |
| 3345 | * |
| 3346 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3347 | **/ |
| 3348 | void |
| 3349 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3350 | { |
| 3351 | unsigned long fcf_redisc_wait_tmo = |
| 3352 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3353 | /* Start fcf rediscovery wait period timer */ |
| 3354 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3355 | spin_lock_irq(&phba->hbalock); |
| 3356 | /* Allow action to new fcf asynchronous event */ |
| 3357 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3358 | /* Mark the FCF rediscovery pending state */ |
| 3359 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3360 | spin_unlock_irq(&phba->hbalock); |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3365 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3366 | * |
| 3367 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3368 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3369 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3370 | * list, and then worker thread shall be waked up for processing from the |
| 3371 | * worker thread context. |
| 3372 | **/ |
| 3373 | void |
| 3374 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3375 | { |
| 3376 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3377 | |
| 3378 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3379 | spin_lock_irq(&phba->hbalock); |
| 3380 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3381 | spin_unlock_irq(&phba->hbalock); |
| 3382 | return; |
| 3383 | } |
| 3384 | /* Clear FCF rediscovery timer pending flag */ |
| 3385 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3386 | /* FCF rediscovery event to worker thread */ |
| 3387 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3388 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3389 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3390 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3391 | /* wake up worker thread */ |
| 3392 | lpfc_worker_wake_up(phba); |
| 3393 | } |
| 3394 | |
| 3395 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3396 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3397 | * @phba: pointer to lpfc hba data structure. |
| 3398 | * @acqe_link: pointer to the async link completion queue entry. |
| 3399 | * |
| 3400 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3401 | * translate it into the base driver's read link attention mailbox command |
| 3402 | * status. |
| 3403 | * |
| 3404 | * Return: Link-attention status in terms of base driver's coding. |
| 3405 | **/ |
| 3406 | static uint16_t |
| 3407 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3408 | struct lpfc_acqe_link *acqe_link) |
| 3409 | { |
| 3410 | uint16_t latt_fault; |
| 3411 | |
| 3412 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3413 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3414 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3415 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3416 | latt_fault = 0; |
| 3417 | break; |
| 3418 | default: |
| 3419 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3420 | "0398 Invalid link fault code: x%x\n", |
| 3421 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3422 | latt_fault = MBXERR_ERROR; |
| 3423 | break; |
| 3424 | } |
| 3425 | return latt_fault; |
| 3426 | } |
| 3427 | |
| 3428 | /** |
| 3429 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3430 | * @phba: pointer to lpfc hba data structure. |
| 3431 | * @acqe_link: pointer to the async link completion queue entry. |
| 3432 | * |
| 3433 | * This routine is to parse the SLI4 link attention type and translate it |
| 3434 | * into the base driver's link attention type coding. |
| 3435 | * |
| 3436 | * Return: Link attention type in terms of base driver's coding. |
| 3437 | **/ |
| 3438 | static uint8_t |
| 3439 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3440 | struct lpfc_acqe_link *acqe_link) |
| 3441 | { |
| 3442 | uint8_t att_type; |
| 3443 | |
| 3444 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3445 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3446 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3447 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3448 | break; |
| 3449 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3450 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3451 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3452 | break; |
| 3453 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3454 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3455 | break; |
| 3456 | default: |
| 3457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3458 | "0399 Invalid link attention type: x%x\n", |
| 3459 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3460 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3461 | break; |
| 3462 | } |
| 3463 | return att_type; |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3468 | * @phba: pointer to lpfc hba data structure. |
| 3469 | * @acqe_link: pointer to the async link completion queue entry. |
| 3470 | * |
| 3471 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3472 | * it into the base driver's link-attention link speed coding. |
| 3473 | * |
| 3474 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3475 | **/ |
| 3476 | static uint8_t |
| 3477 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3478 | struct lpfc_acqe_link *acqe_link) |
| 3479 | { |
| 3480 | uint8_t link_speed; |
| 3481 | |
| 3482 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3483 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3484 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3485 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3486 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3487 | break; |
| 3488 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3489 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3490 | break; |
| 3491 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3492 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3493 | break; |
| 3494 | default: |
| 3495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3496 | "0483 Invalid link-attention link speed: x%x\n", |
| 3497 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3498 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3499 | break; |
| 3500 | } |
| 3501 | return link_speed; |
| 3502 | } |
| 3503 | |
| 3504 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3505 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3506 | * @phba: pointer to lpfc hba data structure. |
| 3507 | * @acqe_link: pointer to the async link completion queue entry. |
| 3508 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3509 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3510 | **/ |
| 3511 | static void |
| 3512 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3513 | struct lpfc_acqe_link *acqe_link) |
| 3514 | { |
| 3515 | struct lpfc_dmabuf *mp; |
| 3516 | LPFC_MBOXQ_t *pmb; |
| 3517 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3518 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3519 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3520 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3521 | |
| 3522 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3523 | 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] | 3524 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3525 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3526 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3527 | if (!pmb) { |
| 3528 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3529 | "0395 The mboxq allocation failed\n"); |
| 3530 | return; |
| 3531 | } |
| 3532 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3533 | if (!mp) { |
| 3534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3535 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3536 | goto out_free_pmb; |
| 3537 | } |
| 3538 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3539 | if (!mp->virt) { |
| 3540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3541 | "0397 The mbuf allocation failed\n"); |
| 3542 | goto out_free_dmabuf; |
| 3543 | } |
| 3544 | |
| 3545 | /* Cleanup any outstanding ELS commands */ |
| 3546 | lpfc_els_flush_all_cmd(phba); |
| 3547 | |
| 3548 | /* Block ELS IOCBs until we have done process link event */ |
| 3549 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3550 | |
| 3551 | /* Update link event statistics */ |
| 3552 | phba->sli.slistat.link_event++; |
| 3553 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3554 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3555 | lpfc_read_topology(phba, pmb, mp); |
| 3556 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3557 | pmb->vport = phba->pport; |
| 3558 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3559 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3560 | phba->sli4_hba.link_state.speed = |
| 3561 | bf_get(lpfc_acqe_link_speed, acqe_link); |
| 3562 | phba->sli4_hba.link_state.duplex = |
| 3563 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3564 | phba->sli4_hba.link_state.status = |
| 3565 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3566 | phba->sli4_hba.link_state.type = |
| 3567 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3568 | phba->sli4_hba.link_state.number = |
| 3569 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3570 | phba->sli4_hba.link_state.fault = |
| 3571 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3572 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3573 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
| 3574 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3575 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3576 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3577 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3578 | phba->sli4_hba.link_state.speed, |
| 3579 | phba->sli4_hba.link_state.topology, |
| 3580 | phba->sli4_hba.link_state.status, |
| 3581 | phba->sli4_hba.link_state.type, |
| 3582 | phba->sli4_hba.link_state.number, |
| 3583 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3584 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3585 | /* |
| 3586 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3587 | * topology info. Note: Optional for non FC-AL ports. |
| 3588 | */ |
| 3589 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3590 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3591 | if (rc == MBX_NOT_FINISHED) |
| 3592 | goto out_free_dmabuf; |
| 3593 | return; |
| 3594 | } |
| 3595 | /* |
| 3596 | * For FCoE Mode: fill in all the topology information we need and call |
| 3597 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3598 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3599 | */ |
| 3600 | /* Parse and translate status field */ |
| 3601 | mb = &pmb->u.mb; |
| 3602 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3603 | |
| 3604 | /* Parse and translate link attention fields */ |
| 3605 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3606 | la->eventTag = acqe_link->event_tag; |
| 3607 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3608 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3609 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3610 | |
| 3611 | /* Fake the the following irrelvant fields */ |
| 3612 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3613 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3614 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3615 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3616 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3617 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3618 | |
| 3619 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3620 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3621 | |
| 3622 | return; |
| 3623 | |
| 3624 | out_free_dmabuf: |
| 3625 | kfree(mp); |
| 3626 | out_free_pmb: |
| 3627 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3628 | } |
| 3629 | |
| 3630 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3631 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3632 | * @phba: pointer to lpfc hba data structure. |
| 3633 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3634 | * |
| 3635 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3636 | * that the event was received and then issue a read_topology mailbox command so |
| 3637 | * that the rest of the driver will treat it the same as SLI3. |
| 3638 | **/ |
| 3639 | static void |
| 3640 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3641 | { |
| 3642 | struct lpfc_dmabuf *mp; |
| 3643 | LPFC_MBOXQ_t *pmb; |
| 3644 | int rc; |
| 3645 | |
| 3646 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3647 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3648 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3649 | "2895 Non FC link Event detected.(%d)\n", |
| 3650 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3651 | return; |
| 3652 | } |
| 3653 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3654 | phba->sli4_hba.link_state.speed = |
| 3655 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); |
| 3656 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3657 | phba->sli4_hba.link_state.topology = |
| 3658 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3659 | phba->sli4_hba.link_state.status = |
| 3660 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3661 | phba->sli4_hba.link_state.type = |
| 3662 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3663 | phba->sli4_hba.link_state.number = |
| 3664 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3665 | phba->sli4_hba.link_state.fault = |
| 3666 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3667 | phba->sli4_hba.link_state.logical_speed = |
| 3668 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); |
| 3669 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3670 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3671 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3672 | "%dMbps Fault:%d\n", |
| 3673 | phba->sli4_hba.link_state.speed, |
| 3674 | phba->sli4_hba.link_state.topology, |
| 3675 | phba->sli4_hba.link_state.status, |
| 3676 | phba->sli4_hba.link_state.type, |
| 3677 | phba->sli4_hba.link_state.number, |
| 3678 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3679 | phba->sli4_hba.link_state.fault); |
| 3680 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3681 | if (!pmb) { |
| 3682 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3683 | "2897 The mboxq allocation failed\n"); |
| 3684 | return; |
| 3685 | } |
| 3686 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3687 | if (!mp) { |
| 3688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3689 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3690 | goto out_free_pmb; |
| 3691 | } |
| 3692 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3693 | if (!mp->virt) { |
| 3694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3695 | "2899 The mbuf allocation failed\n"); |
| 3696 | goto out_free_dmabuf; |
| 3697 | } |
| 3698 | |
| 3699 | /* Cleanup any outstanding ELS commands */ |
| 3700 | lpfc_els_flush_all_cmd(phba); |
| 3701 | |
| 3702 | /* Block ELS IOCBs until we have done process link event */ |
| 3703 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3704 | |
| 3705 | /* Update link event statistics */ |
| 3706 | phba->sli.slistat.link_event++; |
| 3707 | |
| 3708 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3709 | lpfc_read_topology(phba, pmb, mp); |
| 3710 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3711 | pmb->vport = phba->pport; |
| 3712 | |
| 3713 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3714 | if (rc == MBX_NOT_FINISHED) |
| 3715 | goto out_free_dmabuf; |
| 3716 | return; |
| 3717 | |
| 3718 | out_free_dmabuf: |
| 3719 | kfree(mp); |
| 3720 | out_free_pmb: |
| 3721 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3722 | } |
| 3723 | |
| 3724 | /** |
| 3725 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3726 | * @phba: pointer to lpfc hba data structure. |
| 3727 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3728 | * |
| 3729 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3730 | **/ |
| 3731 | static void |
| 3732 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3733 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3734 | char port_name; |
| 3735 | char message[80]; |
| 3736 | uint8_t status; |
| 3737 | struct lpfc_acqe_misconfigured_event *misconfigured; |
| 3738 | |
| 3739 | /* special case misconfigured event as it contains data for all ports */ |
| 3740 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3741 | LPFC_SLI_INTF_IF_TYPE_2) || |
| 3742 | (bf_get(lpfc_trailer_type, acqe_sli) != |
| 3743 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { |
| 3744 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3745 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3746 | "x%08x SLI Event Type:%d\n", |
| 3747 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3748 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3749 | return; |
| 3750 | } |
| 3751 | |
| 3752 | port_name = phba->Port[0]; |
| 3753 | if (port_name == 0x00) |
| 3754 | port_name = '?'; /* get port name is empty */ |
| 3755 | |
| 3756 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
| 3757 | &acqe_sli->event_data1; |
| 3758 | |
| 3759 | /* fetch the status for this port */ |
| 3760 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 3761 | case LPFC_LINK_NUMBER_0: |
| 3762 | status = bf_get(lpfc_sli_misconfigured_port0, |
| 3763 | &misconfigured->theEvent); |
| 3764 | break; |
| 3765 | case LPFC_LINK_NUMBER_1: |
| 3766 | status = bf_get(lpfc_sli_misconfigured_port1, |
| 3767 | &misconfigured->theEvent); |
| 3768 | break; |
| 3769 | case LPFC_LINK_NUMBER_2: |
| 3770 | status = bf_get(lpfc_sli_misconfigured_port2, |
| 3771 | &misconfigured->theEvent); |
| 3772 | break; |
| 3773 | case LPFC_LINK_NUMBER_3: |
| 3774 | status = bf_get(lpfc_sli_misconfigured_port3, |
| 3775 | &misconfigured->theEvent); |
| 3776 | break; |
| 3777 | default: |
| 3778 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 3779 | break; |
| 3780 | } |
| 3781 | |
| 3782 | switch (status) { |
| 3783 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 3784 | return; /* no message if the sfp is okay */ |
| 3785 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame^] | 3786 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
| 3787 | "installed - Reseat optics, if issue not " |
| 3788 | "resolved, replace."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3789 | break; |
| 3790 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 3791 | sprintf(message, |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame^] | 3792 | "Optics of two types installed - Remove one optic or " \ |
| 3793 | "install matching pair of optics."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3794 | break; |
| 3795 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame^] | 3796 | sprintf(message, "Incompatible optics - Replace with " \ |
| 3797 | "compatible optics for card to function."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3798 | break; |
| 3799 | default: |
| 3800 | /* firmware is reporting a status we don't know about */ |
| 3801 | sprintf(message, "Unknown event status x%02x", status); |
| 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3806 | "3176 Misconfigured Physical Port - " |
| 3807 | "Port Name %c %s\n", port_name, message); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3811 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 3812 | * @vport: pointer to vport data structure. |
| 3813 | * |
| 3814 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 3815 | * response to a CVL event. |
| 3816 | * |
| 3817 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 3818 | * return NULL. |
| 3819 | **/ |
| 3820 | static struct lpfc_nodelist * |
| 3821 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 3822 | { |
| 3823 | struct lpfc_nodelist *ndlp; |
| 3824 | struct Scsi_Host *shost; |
| 3825 | struct lpfc_hba *phba; |
| 3826 | |
| 3827 | if (!vport) |
| 3828 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3829 | phba = vport->phba; |
| 3830 | if (!phba) |
| 3831 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3832 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 3833 | if (!ndlp) { |
| 3834 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 3835 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3836 | if (!ndlp) |
| 3837 | return 0; |
| 3838 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 3839 | /* Set the node type */ |
| 3840 | ndlp->nlp_type |= NLP_FABRIC; |
| 3841 | /* Put ndlp onto node list */ |
| 3842 | lpfc_enqueue_node(vport, ndlp); |
| 3843 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3844 | /* re-setup ndlp without removing from node list */ |
| 3845 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3846 | if (!ndlp) |
| 3847 | return 0; |
| 3848 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3849 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 3850 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3851 | return NULL; |
| 3852 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3853 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 3854 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3855 | return NULL; |
| 3856 | shost = lpfc_shost_from_vport(vport); |
| 3857 | if (!shost) |
| 3858 | return NULL; |
| 3859 | lpfc_linkdown_port(vport); |
| 3860 | lpfc_cleanup_pending_mbox(vport); |
| 3861 | spin_lock_irq(shost->host_lock); |
| 3862 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 3863 | spin_unlock_irq(shost->host_lock); |
| 3864 | |
| 3865 | return ndlp; |
| 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 3870 | * @vport: pointer to lpfc hba data structure. |
| 3871 | * |
| 3872 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 3873 | * response to a FCF dead event. |
| 3874 | **/ |
| 3875 | static void |
| 3876 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 3877 | { |
| 3878 | struct lpfc_vport **vports; |
| 3879 | int i; |
| 3880 | |
| 3881 | vports = lpfc_create_vport_work_array(phba); |
| 3882 | if (vports) |
| 3883 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 3884 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 3885 | lpfc_destroy_vport_work_array(phba, vports); |
| 3886 | } |
| 3887 | |
| 3888 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3889 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3890 | * @phba: pointer to lpfc hba data structure. |
| 3891 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 3892 | * |
| 3893 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 3894 | **/ |
| 3895 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3896 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3897 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3898 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3899 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3900 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3901 | struct lpfc_vport *vport; |
| 3902 | struct lpfc_nodelist *ndlp; |
| 3903 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3904 | int active_vlink_present; |
| 3905 | struct lpfc_vport **vports; |
| 3906 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3907 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3908 | phba->fc_eventTag = acqe_fip->event_tag; |
| 3909 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3910 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3911 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 3912 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 3913 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3914 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 3915 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3916 | "2546 New FCF event, evt_tag:x%x, " |
| 3917 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3918 | acqe_fip->event_tag, |
| 3919 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3920 | else |
| 3921 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 3922 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3923 | "2788 FCF param modified event, " |
| 3924 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3925 | acqe_fip->event_tag, |
| 3926 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3927 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3928 | /* |
| 3929 | * During period of FCF discovery, read the FCF |
| 3930 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3931 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3932 | */ |
| 3933 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 3934 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3935 | "2779 Read FCF (x%x) for updating " |
| 3936 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3937 | acqe_fip->index); |
| 3938 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3939 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3940 | |
| 3941 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3942 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3943 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3944 | spin_unlock_irq(&phba->hbalock); |
| 3945 | break; |
| 3946 | } |
| 3947 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 3948 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 3949 | spin_unlock_irq(&phba->hbalock); |
| 3950 | break; |
| 3951 | } |
| 3952 | |
| 3953 | /* If the FCF has been in discovered state, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3954 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
| 3955 | spin_unlock_irq(&phba->hbalock); |
| 3956 | break; |
| 3957 | } |
| 3958 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3959 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3960 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 3961 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3962 | "2770 Start FCF table scan per async FCF " |
| 3963 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3964 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3965 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3966 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3967 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3968 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 3969 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3970 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3971 | break; |
| 3972 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3973 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3975 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3976 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 3977 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3978 | break; |
| 3979 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3980 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 3981 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3982 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3983 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3984 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3985 | /* |
| 3986 | * If we are in the middle of FCF failover process, clear |
| 3987 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3988 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3989 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3990 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3991 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3992 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3993 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3994 | break; |
| 3995 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3996 | spin_unlock_irq(&phba->hbalock); |
| 3997 | |
| 3998 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3999 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4000 | break; |
| 4001 | |
| 4002 | /* |
| 4003 | * Otherwise, request the port to rediscover the entire FCF |
| 4004 | * table for a fast recovery from case that the current FCF |
| 4005 | * is no longer valid as we are not in the middle of FCF |
| 4006 | * failover process already. |
| 4007 | */ |
| 4008 | spin_lock_irq(&phba->hbalock); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4009 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4010 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4011 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4012 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4013 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4014 | "2771 Start FCF fast failover process due to " |
| 4015 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4016 | "\n", acqe_fip->event_tag, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4017 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4018 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4019 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4020 | LOG_DISCOVERY, |
| 4021 | "2772 Issue FCF rediscover mabilbox " |
| 4022 | "command failed, fail through to FCF " |
| 4023 | "dead event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4024 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4025 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4026 | spin_unlock_irq(&phba->hbalock); |
| 4027 | /* |
| 4028 | * Last resort will fail over by treating this |
| 4029 | * as a link down to FCF registration. |
| 4030 | */ |
| 4031 | lpfc_sli4_fcf_dead_failthrough(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4032 | } else { |
| 4033 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4034 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4035 | /* |
| 4036 | * Handling fast FCF failover to a DEAD FCF event is |
| 4037 | * considered equalivant to receiving CVL to all vports. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4038 | */ |
| 4039 | lpfc_sli4_perform_all_vport_cvl(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4040 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4041 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4042 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4043 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4044 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4045 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4046 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4047 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4048 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4049 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4050 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4051 | if (!ndlp) |
| 4052 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4053 | active_vlink_present = 0; |
| 4054 | |
| 4055 | vports = lpfc_create_vport_work_array(phba); |
| 4056 | if (vports) { |
| 4057 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4058 | i++) { |
| 4059 | if ((!(vports[i]->fc_flag & |
| 4060 | FC_VPORT_CVL_RCVD)) && |
| 4061 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4062 | active_vlink_present = 1; |
| 4063 | break; |
| 4064 | } |
| 4065 | } |
| 4066 | lpfc_destroy_vport_work_array(phba, vports); |
| 4067 | } |
| 4068 | |
| 4069 | if (active_vlink_present) { |
| 4070 | /* |
| 4071 | * If there are other active VLinks present, |
| 4072 | * re-instantiate the Vlink using FDISC. |
| 4073 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4074 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4075 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4076 | spin_lock_irq(shost->host_lock); |
| 4077 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4078 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4079 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4080 | vport->port_state = LPFC_FDISC; |
| 4081 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4082 | /* |
| 4083 | * Otherwise, we request port to rediscover |
| 4084 | * the entire FCF table for a fast recovery |
| 4085 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4086 | * is no longer valid if we are not already |
| 4087 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4088 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4089 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4090 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4091 | spin_unlock_irq(&phba->hbalock); |
| 4092 | break; |
| 4093 | } |
| 4094 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4095 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4096 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4097 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4098 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4099 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4100 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4101 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4102 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4103 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4104 | LOG_DISCOVERY, |
| 4105 | "2774 Issue FCF rediscover " |
| 4106 | "mabilbox command failed, " |
| 4107 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4108 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4109 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4110 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4111 | /* |
| 4112 | * Last resort will be re-try on the |
| 4113 | * the current registered FCF entry. |
| 4114 | */ |
| 4115 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4116 | } else |
| 4117 | /* |
| 4118 | * Reset FCF roundrobin bmask for new |
| 4119 | * discovery. |
| 4120 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4121 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4122 | } |
| 4123 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4124 | default: |
| 4125 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4126 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4127 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | /** |
| 4133 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4134 | * @phba: pointer to lpfc hba data structure. |
| 4135 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4136 | * |
| 4137 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4138 | **/ |
| 4139 | static void |
| 4140 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4141 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4142 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4143 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4144 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4145 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4146 | "handled yet\n"); |
| 4147 | } |
| 4148 | |
| 4149 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4150 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4151 | * @phba: pointer to lpfc hba data structure. |
| 4152 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4153 | * |
| 4154 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4155 | * is an asynchronous notified of a logical link speed change. The Port |
| 4156 | * reports the logical link speed in units of 10Mbps. |
| 4157 | **/ |
| 4158 | static void |
| 4159 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4160 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4161 | { |
| 4162 | uint16_t prev_ll_spd; |
| 4163 | |
| 4164 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4165 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4166 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4167 | phba->sli4_hba.link_state.logical_speed = |
| 4168 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); |
| 4169 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4170 | "2789 GRP5 Async Event: Updating logical link speed " |
| 4171 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), |
| 4172 | (phba->sli4_hba.link_state.logical_speed*10)); |
| 4173 | } |
| 4174 | |
| 4175 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4176 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4177 | * @phba: pointer to lpfc hba data structure. |
| 4178 | * |
| 4179 | * This routine is invoked by the worker thread to process all the pending |
| 4180 | * SLI4 asynchronous events. |
| 4181 | **/ |
| 4182 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4183 | { |
| 4184 | struct lpfc_cq_event *cq_event; |
| 4185 | |
| 4186 | /* First, declare the async event has been handled */ |
| 4187 | spin_lock_irq(&phba->hbalock); |
| 4188 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4189 | spin_unlock_irq(&phba->hbalock); |
| 4190 | /* Now, handle all the async events */ |
| 4191 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4192 | /* Get the first event from the head of the event queue */ |
| 4193 | spin_lock_irq(&phba->hbalock); |
| 4194 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4195 | cq_event, struct lpfc_cq_event, list); |
| 4196 | spin_unlock_irq(&phba->hbalock); |
| 4197 | /* Process the asynchronous event */ |
| 4198 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4199 | case LPFC_TRAILER_CODE_LINK: |
| 4200 | lpfc_sli4_async_link_evt(phba, |
| 4201 | &cq_event->cqe.acqe_link); |
| 4202 | break; |
| 4203 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4204 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4205 | break; |
| 4206 | case LPFC_TRAILER_CODE_DCBX: |
| 4207 | lpfc_sli4_async_dcbx_evt(phba, |
| 4208 | &cq_event->cqe.acqe_dcbx); |
| 4209 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4210 | case LPFC_TRAILER_CODE_GRP5: |
| 4211 | lpfc_sli4_async_grp5_evt(phba, |
| 4212 | &cq_event->cqe.acqe_grp5); |
| 4213 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4214 | case LPFC_TRAILER_CODE_FC: |
| 4215 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4216 | break; |
| 4217 | case LPFC_TRAILER_CODE_SLI: |
| 4218 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4219 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4220 | default: |
| 4221 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4222 | "1804 Invalid asynchrous event code: " |
| 4223 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4224 | &cq_event->cqe.mcqe_cmpl)); |
| 4225 | break; |
| 4226 | } |
| 4227 | /* Free the completion event processed to the free pool */ |
| 4228 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4233 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4234 | * @phba: pointer to lpfc hba data structure. |
| 4235 | * |
| 4236 | * This routine is invoked by the worker thread to process FCF table |
| 4237 | * rediscovery pending completion event. |
| 4238 | **/ |
| 4239 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4240 | { |
| 4241 | int rc; |
| 4242 | |
| 4243 | spin_lock_irq(&phba->hbalock); |
| 4244 | /* Clear FCF rediscovery timeout event */ |
| 4245 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4246 | /* Clear driver fast failover FCF record flag */ |
| 4247 | phba->fcf.failover_rec.flag = 0; |
| 4248 | /* Set state for FCF fast failover */ |
| 4249 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4250 | spin_unlock_irq(&phba->hbalock); |
| 4251 | |
| 4252 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4253 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4254 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4255 | 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] | 4256 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4257 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4258 | "2747 Issue FCF scan read FCF mailbox " |
| 4259 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4263 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4264 | * @phba: pointer to lpfc hba data structure. |
| 4265 | * @dev_grp: The HBA PCI-Device group number. |
| 4266 | * |
| 4267 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4268 | * API jump table entries. |
| 4269 | * |
| 4270 | * Return: 0 if success, otherwise -ENODEV |
| 4271 | **/ |
| 4272 | int |
| 4273 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4274 | { |
| 4275 | int rc; |
| 4276 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4277 | /* Set up lpfc PCI-device group */ |
| 4278 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4279 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4280 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4281 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4282 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4283 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4284 | /* Set up device INIT API function jump table */ |
| 4285 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4286 | if (rc) |
| 4287 | return -ENODEV; |
| 4288 | /* Set up SCSI API function jump table */ |
| 4289 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4290 | if (rc) |
| 4291 | return -ENODEV; |
| 4292 | /* Set up SLI API function jump table */ |
| 4293 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4294 | if (rc) |
| 4295 | return -ENODEV; |
| 4296 | /* Set up MBOX API function jump table */ |
| 4297 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4298 | if (rc) |
| 4299 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4300 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4301 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4305 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4306 | * @phba: pointer to lpfc hba data structure. |
| 4307 | * @intr_mode: active interrupt mode adopted. |
| 4308 | * |
| 4309 | * This routine it invoked to log the currently used active interrupt mode |
| 4310 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4311 | **/ |
| 4312 | 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] | 4313 | { |
| 4314 | switch (intr_mode) { |
| 4315 | case 0: |
| 4316 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4317 | "0470 Enable INTx interrupt mode.\n"); |
| 4318 | break; |
| 4319 | case 1: |
| 4320 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4321 | "0481 Enabled MSI interrupt mode.\n"); |
| 4322 | break; |
| 4323 | case 2: |
| 4324 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4325 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4326 | break; |
| 4327 | default: |
| 4328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4329 | "0482 Illegal interrupt mode.\n"); |
| 4330 | break; |
| 4331 | } |
| 4332 | return; |
| 4333 | } |
| 4334 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4335 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4336 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4337 | * @phba: pointer to lpfc hba data structure. |
| 4338 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4339 | * This routine is invoked to enable the PCI device that is common to all |
| 4340 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4341 | * |
| 4342 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4343 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4344 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4345 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4346 | static int |
| 4347 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4348 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4349 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4350 | int bars = 0; |
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 | /* Obtain PCI device reference */ |
| 4353 | if (!phba->pcidev) |
| 4354 | goto out_error; |
| 4355 | else |
| 4356 | pdev = phba->pcidev; |
| 4357 | /* Select PCI BARs */ |
| 4358 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4359 | /* Enable PCI device */ |
| 4360 | if (pci_enable_device_mem(pdev)) |
| 4361 | goto out_error; |
| 4362 | /* Request PCI resource for the device */ |
| 4363 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4364 | goto out_disable_device; |
| 4365 | /* Set up device as PCI master and save state for EEH */ |
| 4366 | pci_set_master(pdev); |
| 4367 | pci_try_set_mwi(pdev); |
| 4368 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4369 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4370 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
| 4371 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) |
| 4372 | pdev->needs_freset = 1; |
| 4373 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4374 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4375 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4376 | out_disable_device: |
| 4377 | pci_disable_device(pdev); |
| 4378 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4380 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4381 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4385 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4386 | * @phba: pointer to lpfc hba data structure. |
| 4387 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4388 | * This routine is invoked to disable the PCI device that is common to all |
| 4389 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4390 | **/ |
| 4391 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4392 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4393 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4394 | struct pci_dev *pdev; |
| 4395 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4396 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4397 | /* Obtain PCI device reference */ |
| 4398 | if (!phba->pcidev) |
| 4399 | return; |
| 4400 | else |
| 4401 | pdev = phba->pcidev; |
| 4402 | /* Select PCI BARs */ |
| 4403 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4404 | /* Release PCI resource and disable PCI device */ |
| 4405 | pci_release_selected_regions(pdev, bars); |
| 4406 | pci_disable_device(pdev); |
| 4407 | /* Null out PCI private reference to driver */ |
| 4408 | pci_set_drvdata(pdev, NULL); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4409 | |
| 4410 | return; |
| 4411 | } |
| 4412 | |
| 4413 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4414 | * lpfc_reset_hba - Reset a hba |
| 4415 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4416 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4417 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4418 | * offline, performs a board restart, and then brings the board back |
| 4419 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4420 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4421 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4422 | void |
| 4423 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4424 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4425 | /* If resets are disabled then set error state and return. */ |
| 4426 | if (!phba->cfg_enable_hba_reset) { |
| 4427 | phba->link_state = LPFC_HBA_ERROR; |
| 4428 | return; |
| 4429 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 4430 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4431 | lpfc_offline(phba); |
| 4432 | lpfc_sli_brdrestart(phba); |
| 4433 | lpfc_online(phba); |
| 4434 | lpfc_unblock_mgmt_io(phba); |
| 4435 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4436 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4437 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4438 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4439 | * @phba: pointer to lpfc hba data structure. |
| 4440 | * |
| 4441 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4442 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4443 | * enable the number of virtual functions to the physical function. As |
| 4444 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4445 | * API call does not considered as an error condition for most of the device. |
| 4446 | **/ |
| 4447 | uint16_t |
| 4448 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4449 | { |
| 4450 | struct pci_dev *pdev = phba->pcidev; |
| 4451 | uint16_t nr_virtfn; |
| 4452 | int pos; |
| 4453 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4454 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4455 | if (pos == 0) |
| 4456 | return 0; |
| 4457 | |
| 4458 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4459 | return nr_virtfn; |
| 4460 | } |
| 4461 | |
| 4462 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4463 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4464 | * @phba: pointer to lpfc hba data structure. |
| 4465 | * @nr_vfn: number of virtual functions to be enabled. |
| 4466 | * |
| 4467 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4468 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4469 | * enable the number of virtual functions to the physical function. As |
| 4470 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4471 | * API call does not considered as an error condition for most of the device. |
| 4472 | **/ |
| 4473 | int |
| 4474 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4475 | { |
| 4476 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4477 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4478 | int rc; |
| 4479 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4480 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4481 | if (nr_vfn > max_nr_vfn) { |
| 4482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4483 | "3057 Requested vfs (%d) greater than " |
| 4484 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4485 | return -EINVAL; |
| 4486 | } |
| 4487 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4488 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4489 | if (rc) { |
| 4490 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4491 | "2806 Failed to enable sriov on this device " |
| 4492 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4493 | nr_vfn, rc); |
| 4494 | } else |
| 4495 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4496 | "2807 Successful enable sriov on this device " |
| 4497 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4498 | return rc; |
| 4499 | } |
| 4500 | |
| 4501 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4502 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4503 | * @phba: pointer to lpfc hba data structure. |
| 4504 | * |
| 4505 | * This routine is invoked to set up the driver internal resources specific to |
| 4506 | * support the SLI-3 HBA device it attached to. |
| 4507 | * |
| 4508 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4509 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4510 | * other values - error |
| 4511 | **/ |
| 4512 | static int |
| 4513 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4514 | { |
| 4515 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4516 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4517 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4518 | /* |
| 4519 | * Initialize timers used by driver |
| 4520 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4521 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4522 | /* Heartbeat timer */ |
| 4523 | init_timer(&phba->hb_tmofunc); |
| 4524 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4525 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4526 | |
| 4527 | psli = &phba->sli; |
| 4528 | /* MBOX heartbeat timer */ |
| 4529 | init_timer(&psli->mbox_tmo); |
| 4530 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4531 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4532 | /* FCP polling mode timer */ |
| 4533 | init_timer(&phba->fcp_poll_timer); |
| 4534 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4535 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4536 | /* Fabric block timer */ |
| 4537 | init_timer(&phba->fabric_block_timer); |
| 4538 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4539 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4540 | /* EA polling mode timer */ |
| 4541 | init_timer(&phba->eratt_poll); |
| 4542 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4543 | phba->eratt_poll.data = (unsigned long) phba; |
| 4544 | |
| 4545 | /* Host attention work mask setup */ |
| 4546 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4547 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4548 | |
| 4549 | /* Get all the module params for configuring this host */ |
| 4550 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4551 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4552 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4553 | /* check for menlo minimum sg count */ |
| 4554 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4555 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4556 | } |
| 4557 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4558 | if (!phba->sli.ring) |
| 4559 | phba->sli.ring = (struct lpfc_sli_ring *) |
| 4560 | kzalloc(LPFC_SLI3_MAX_RING * |
| 4561 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4562 | if (!phba->sli.ring) |
| 4563 | return -ENOMEM; |
| 4564 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4565 | /* |
| 4566 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4567 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4568 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4569 | */ |
| 4570 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4571 | sizeof(struct fcp_rsp) + |
| 4572 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4573 | |
| 4574 | if (phba->cfg_enable_bg) { |
| 4575 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4576 | phba->cfg_sg_dma_buf_size += |
| 4577 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); |
| 4578 | } |
| 4579 | |
| 4580 | /* Also reinitialize the host templates with new values. */ |
| 4581 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4582 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4583 | |
| 4584 | phba->max_vpi = LPFC_MAX_VPI; |
| 4585 | /* This will be set to correct value after config_port mbox */ |
| 4586 | phba->max_vports = 0; |
| 4587 | |
| 4588 | /* |
| 4589 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4590 | */ |
| 4591 | lpfc_sli_setup(phba); |
| 4592 | lpfc_sli_queue_setup(phba); |
| 4593 | |
| 4594 | /* Allocate device driver memory */ |
| 4595 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4596 | return -ENOMEM; |
| 4597 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4598 | /* |
| 4599 | * Enable sr-iov virtual functions if supported and configured |
| 4600 | * through the module parameter. |
| 4601 | */ |
| 4602 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4603 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4604 | phba->cfg_sriov_nr_virtfn); |
| 4605 | if (rc) { |
| 4606 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4607 | "2808 Requested number of SR-IOV " |
| 4608 | "virtual functions (%d) is not " |
| 4609 | "supported\n", |
| 4610 | phba->cfg_sriov_nr_virtfn); |
| 4611 | phba->cfg_sriov_nr_virtfn = 0; |
| 4612 | } |
| 4613 | } |
| 4614 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4615 | return 0; |
| 4616 | } |
| 4617 | |
| 4618 | /** |
| 4619 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4620 | * @phba: pointer to lpfc hba data structure. |
| 4621 | * |
| 4622 | * This routine is invoked to unset the driver internal resources set up |
| 4623 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4624 | **/ |
| 4625 | static void |
| 4626 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4627 | { |
| 4628 | /* Free device driver memory allocated */ |
| 4629 | lpfc_mem_free_all(phba); |
| 4630 | |
| 4631 | return; |
| 4632 | } |
| 4633 | |
| 4634 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4635 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4636 | * @phba: pointer to lpfc hba data structure. |
| 4637 | * |
| 4638 | * This routine is invoked to set up the driver internal resources specific to |
| 4639 | * support the SLI-4 HBA device it attached to. |
| 4640 | * |
| 4641 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4642 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4643 | * other values - error |
| 4644 | **/ |
| 4645 | static int |
| 4646 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4647 | { |
| 4648 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4649 | LPFC_MBOXQ_t *mboxq; |
| 4650 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; |
| 4651 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4652 | struct lpfc_mqe *mqe; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4653 | int longs, sli_family; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4654 | int sges_per_segment; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4655 | |
| 4656 | /* Before proceed, wait for POST done and device ready */ |
| 4657 | rc = lpfc_sli4_post_status_check(phba); |
| 4658 | if (rc) |
| 4659 | return -ENODEV; |
| 4660 | |
| 4661 | /* |
| 4662 | * Initialize timers used by driver |
| 4663 | */ |
| 4664 | |
| 4665 | /* Heartbeat timer */ |
| 4666 | init_timer(&phba->hb_tmofunc); |
| 4667 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4668 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4669 | init_timer(&phba->rrq_tmr); |
| 4670 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4671 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | |
| 4673 | psli = &phba->sli; |
| 4674 | /* MBOX heartbeat timer */ |
| 4675 | init_timer(&psli->mbox_tmo); |
| 4676 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4677 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4678 | /* Fabric block timer */ |
| 4679 | init_timer(&phba->fabric_block_timer); |
| 4680 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4681 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4682 | /* EA polling mode timer */ |
| 4683 | init_timer(&phba->eratt_poll); |
| 4684 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4685 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4686 | /* FCF rediscover timer */ |
| 4687 | init_timer(&phba->fcf.redisc_wait); |
| 4688 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4689 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4690 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4691 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4692 | * Control structure for handling external multi-buffer mailbox |
| 4693 | * command pass-through. |
| 4694 | */ |
| 4695 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4696 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4697 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4698 | |
| 4699 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4700 | * We need to do a READ_CONFIG mailbox command here before |
| 4701 | * calling lpfc_get_cfgparam. For VFs this will report the |
| 4702 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. |
| 4703 | * All of the resources allocated |
| 4704 | * for this Port are tied to these values. |
| 4705 | */ |
| 4706 | /* Get all the module params for configuring this host */ |
| 4707 | lpfc_get_cfgparam(phba); |
| 4708 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4709 | |
| 4710 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 4711 | phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count; |
| 4712 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4713 | /* This will be set to correct value after the read_config mbox */ |
| 4714 | phba->max_vports = 0; |
| 4715 | |
| 4716 | /* Program the default value of vlan_id and fc_map */ |
| 4717 | phba->valid_vlan = 0; |
| 4718 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4719 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4720 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4721 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4722 | /* With BlockGuard we can have multiple SGEs per Data Segemnt */ |
| 4723 | sges_per_segment = 1; |
| 4724 | if (phba->cfg_enable_bg) |
| 4725 | sges_per_segment = 2; |
| 4726 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4727 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4728 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 4729 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 4730 | */ |
| 4731 | if (!phba->sli.ring) |
| 4732 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4733 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4734 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4735 | if (!phba->sli.ring) |
| 4736 | return -ENOMEM; |
| 4737 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4738 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4739 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4740 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4741 | * 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] | 4742 | * sgl sizes of must be a power of 2. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4743 | */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4744 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4745 | (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) * |
| 4746 | sizeof(struct sli4_sge))); |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4747 | |
| 4748 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); |
| 4749 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; |
| 4750 | switch (sli_family) { |
| 4751 | case LPFC_SLI_INTF_FAMILY_BE2: |
| 4752 | case LPFC_SLI_INTF_FAMILY_BE3: |
| 4753 | /* There is a single hint for BE - 2 pages per BPL. */ |
| 4754 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == |
| 4755 | LPFC_SLI_INTF_SLI_HINT1_1) |
| 4756 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; |
| 4757 | break; |
| 4758 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: |
| 4759 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: |
| 4760 | default: |
| 4761 | break; |
| 4762 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4763 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4764 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
| 4765 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; |
| 4766 | dma_buf_size = dma_buf_size << 1) |
| 4767 | ; |
| 4768 | if (dma_buf_size == max_buf_size) |
| 4769 | phba->cfg_sg_seg_cnt = (dma_buf_size - |
| 4770 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - |
| 4771 | (2 * sizeof(struct sli4_sge))) / |
| 4772 | sizeof(struct sli4_sge); |
| 4773 | phba->cfg_sg_dma_buf_size = dma_buf_size; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4774 | |
| 4775 | /* Initialize buffer queue management fields */ |
| 4776 | hbq_count = lpfc_sli_hbq_count(); |
| 4777 | for (i = 0; i < hbq_count; ++i) |
| 4778 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 4779 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 4780 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 4781 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 4782 | |
| 4783 | /* |
| 4784 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 4785 | */ |
| 4786 | /* Initialize the Abort scsi buffer list used by driver */ |
| 4787 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 4788 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 4789 | /* This abort list used by worker thread */ |
| 4790 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 4791 | |
| 4792 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4793 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4794 | */ |
| 4795 | |
| 4796 | /* Driver internel slow-path CQ Event pool */ |
| 4797 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 4798 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4799 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4800 | /* Asynchronous event CQ Event work queue list */ |
| 4801 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 4802 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 4803 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 4804 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 4805 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 4806 | /* Receive queue CQ Event work queue list */ |
| 4807 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 4808 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4809 | /* Initialize extent block lists. */ |
| 4810 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 4811 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 4812 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 4813 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 4814 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4815 | /* Initialize the driver internal SLI layer lists. */ |
| 4816 | lpfc_sli_setup(phba); |
| 4817 | lpfc_sli_queue_setup(phba); |
| 4818 | |
| 4819 | /* Allocate device driver memory */ |
| 4820 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 4821 | if (rc) |
| 4822 | return -ENOMEM; |
| 4823 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4824 | /* IF Type 2 ports get initialized now. */ |
| 4825 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4826 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 4827 | rc = lpfc_pci_function_reset(phba); |
| 4828 | if (unlikely(rc)) |
| 4829 | return -ENODEV; |
| 4830 | } |
| 4831 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4832 | /* Create the bootstrap mailbox command */ |
| 4833 | rc = lpfc_create_bootstrap_mbox(phba); |
| 4834 | if (unlikely(rc)) |
| 4835 | goto out_free_mem; |
| 4836 | |
| 4837 | /* Set up the host's endian order with the device. */ |
| 4838 | rc = lpfc_setup_endian_order(phba); |
| 4839 | if (unlikely(rc)) |
| 4840 | goto out_free_bsmbx; |
| 4841 | |
| 4842 | /* Set up the hba's configuration parameters. */ |
| 4843 | rc = lpfc_sli4_read_config(phba); |
| 4844 | if (unlikely(rc)) |
| 4845 | goto out_free_bsmbx; |
| 4846 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4847 | /* IF Type 0 ports get initialized now. */ |
| 4848 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4849 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 4850 | rc = lpfc_pci_function_reset(phba); |
| 4851 | if (unlikely(rc)) |
| 4852 | goto out_free_bsmbx; |
| 4853 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4854 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4855 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4856 | GFP_KERNEL); |
| 4857 | if (!mboxq) { |
| 4858 | rc = -ENOMEM; |
| 4859 | goto out_free_bsmbx; |
| 4860 | } |
| 4861 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4862 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4863 | lpfc_supported_pages(mboxq); |
| 4864 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4865 | if (!rc) { |
| 4866 | mqe = &mboxq->u.mqe; |
| 4867 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 4868 | LPFC_MAX_SUPPORTED_PAGES); |
| 4869 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 4870 | switch (pn_page[i]) { |
| 4871 | case LPFC_SLI4_PARAMETERS: |
| 4872 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 4873 | break; |
| 4874 | default: |
| 4875 | break; |
| 4876 | } |
| 4877 | } |
| 4878 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 4879 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 4880 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 4881 | if (rc) { |
| 4882 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4883 | rc = -EIO; |
| 4884 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4885 | } |
| 4886 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4887 | /* |
| 4888 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4889 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 4890 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4891 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4892 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 4893 | if (rc) { |
| 4894 | if (phba->sli4_hba.extents_in_use && |
| 4895 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 4896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4897 | "2999 Unsupported SLI4 Parameters " |
| 4898 | "Extents and RPI headers enabled.\n"); |
| 4899 | goto out_free_bsmbx; |
| 4900 | } |
| 4901 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4902 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4903 | /* Verify all the SLI4 queues */ |
| 4904 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4905 | if (rc) |
| 4906 | goto out_free_bsmbx; |
| 4907 | |
| 4908 | /* Create driver internal CQE event pool */ |
| 4909 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 4910 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4911 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4912 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4913 | /* Initialize sgl lists per host */ |
| 4914 | lpfc_init_sgl_list(phba); |
| 4915 | |
| 4916 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4917 | rc = lpfc_init_active_sgl_array(phba); |
| 4918 | if (rc) { |
| 4919 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4920 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4921 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4922 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4923 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 4924 | if (rc) { |
| 4925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4926 | "1432 Failed to initialize rpi headers.\n"); |
| 4927 | goto out_free_active_sgl; |
| 4928 | } |
| 4929 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4930 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4931 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 4932 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4933 | GFP_KERNEL); |
| 4934 | if (!phba->fcf.fcf_rr_bmask) { |
| 4935 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4936 | "2759 Failed allocate memory for FCF round " |
| 4937 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4938 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4939 | goto out_remove_rpi_hdrs; |
| 4940 | } |
| 4941 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4942 | phba->sli4_hba.fcp_eq_hdl = |
| 4943 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
| 4944 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 4945 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 4946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4947 | "2572 Failed allocate memory for " |
| 4948 | "fast-path per-EQ handle array\n"); |
| 4949 | rc = -ENOMEM; |
| 4950 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 4954 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4955 | if (!phba->sli4_hba.msix_entries) { |
| 4956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4957 | "2573 Failed allocate memory for msi-x " |
| 4958 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4959 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4960 | goto out_free_fcp_eq_hdl; |
| 4961 | } |
| 4962 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4963 | /* |
| 4964 | * Enable sr-iov virtual functions if supported and configured |
| 4965 | * through the module parameter. |
| 4966 | */ |
| 4967 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4968 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4969 | phba->cfg_sriov_nr_virtfn); |
| 4970 | if (rc) { |
| 4971 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4972 | "3020 Requested number of SR-IOV " |
| 4973 | "virtual functions (%d) is not " |
| 4974 | "supported\n", |
| 4975 | phba->cfg_sriov_nr_virtfn); |
| 4976 | phba->cfg_sriov_nr_virtfn = 0; |
| 4977 | } |
| 4978 | } |
| 4979 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4980 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4981 | |
| 4982 | out_free_fcp_eq_hdl: |
| 4983 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4984 | out_free_fcf_rr_bmask: |
| 4985 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4986 | out_remove_rpi_hdrs: |
| 4987 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 4988 | out_free_active_sgl: |
| 4989 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4990 | out_destroy_cq_event_pool: |
| 4991 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4992 | out_free_bsmbx: |
| 4993 | lpfc_destroy_bootstrap_mbox(phba); |
| 4994 | out_free_mem: |
| 4995 | lpfc_mem_free(phba); |
| 4996 | return rc; |
| 4997 | } |
| 4998 | |
| 4999 | /** |
| 5000 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5001 | * @phba: pointer to lpfc hba data structure. |
| 5002 | * |
| 5003 | * This routine is invoked to unset the driver internal resources set up |
| 5004 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5005 | **/ |
| 5006 | static void |
| 5007 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5008 | { |
| 5009 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5010 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5011 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5012 | kfree(phba->sli4_hba.msix_entries); |
| 5013 | |
| 5014 | /* Free memory allocated for fast-path work queue handles */ |
| 5015 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5016 | |
| 5017 | /* Free the allocated rpi headers. */ |
| 5018 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5019 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5020 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5021 | /* Free eligible FCF index bmask */ |
| 5022 | kfree(phba->fcf.fcf_rr_bmask); |
| 5023 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5024 | /* Free the ELS sgl list */ |
| 5025 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5026 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5027 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5028 | /* Free the completion queue EQ event pool */ |
| 5029 | lpfc_sli4_cq_event_release_all(phba); |
| 5030 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5031 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5032 | /* Release resource identifiers. */ |
| 5033 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5034 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5035 | /* Free the bsmbx region. */ |
| 5036 | lpfc_destroy_bootstrap_mbox(phba); |
| 5037 | |
| 5038 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5039 | lpfc_mem_free_all(phba); |
| 5040 | |
| 5041 | /* Free the current connect table */ |
| 5042 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5043 | &phba->fcf_conn_rec_list, list) { |
| 5044 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5045 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5046 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5047 | |
| 5048 | return; |
| 5049 | } |
| 5050 | |
| 5051 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5052 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5053 | * @phba: The hba struct for which this call is being executed. |
| 5054 | * @dev_grp: The HBA PCI-Device group number. |
| 5055 | * |
| 5056 | * This routine sets up the device INIT interface API function jump table |
| 5057 | * in @phba struct. |
| 5058 | * |
| 5059 | * Returns: 0 - success, -ENODEV - failure. |
| 5060 | **/ |
| 5061 | int |
| 5062 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5063 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5064 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5065 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5066 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5067 | switch (dev_grp) { |
| 5068 | case LPFC_PCI_DEV_LP: |
| 5069 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5070 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5071 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5072 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | case LPFC_PCI_DEV_OC: |
| 5074 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5075 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5076 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5077 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5078 | default: |
| 5079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5080 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5081 | dev_grp); |
| 5082 | return -ENODEV; |
| 5083 | break; |
| 5084 | } |
| 5085 | return 0; |
| 5086 | } |
| 5087 | |
| 5088 | /** |
| 5089 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5090 | * @phba: pointer to lpfc hba data structure. |
| 5091 | * |
| 5092 | * This routine is invoked to set up the driver internal resources before the |
| 5093 | * device specific resource setup to support the HBA device it attached to. |
| 5094 | * |
| 5095 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5096 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5097 | * other values - error |
| 5098 | **/ |
| 5099 | static int |
| 5100 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5101 | { |
| 5102 | /* |
| 5103 | * Driver resources common to all SLI revisions |
| 5104 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5105 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5106 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5107 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5108 | /* Initialize ndlp management spinlock */ |
| 5109 | spin_lock_init(&phba->ndlp_lock); |
| 5110 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5111 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5112 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5113 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5114 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5115 | /* Initialize the wait queue head for the kernel thread */ |
| 5116 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5117 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5118 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
| 5119 | spin_lock_init(&phba->scsi_buf_list_lock); |
| 5120 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5121 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5122 | /* Initialize the fabric iocb list */ |
| 5123 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5124 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5125 | /* Initialize list to save ELS buffers */ |
| 5126 | INIT_LIST_HEAD(&phba->elsbuf); |
| 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 FCF connection rec list */ |
| 5129 | INIT_LIST_HEAD(&phba->fcf_conn_rec_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 | return 0; |
| 5132 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5133 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5134 | /** |
| 5135 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5136 | * @phba: pointer to lpfc hba data structure. |
| 5137 | * |
| 5138 | * This routine is invoked to set up the driver internal resources after the |
| 5139 | * device specific resource setup to support the HBA device it attached to. |
| 5140 | * |
| 5141 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5142 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5143 | * other values - error |
| 5144 | **/ |
| 5145 | static int |
| 5146 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5147 | { |
| 5148 | int error; |
| 5149 | |
| 5150 | /* Startup the kernel thread for this host adapter. */ |
| 5151 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5152 | "lpfc_worker_%d", phba->brd_no); |
| 5153 | if (IS_ERR(phba->worker_thread)) { |
| 5154 | error = PTR_ERR(phba->worker_thread); |
| 5155 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5156 | } |
| 5157 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5158 | return 0; |
| 5159 | } |
| 5160 | |
| 5161 | /** |
| 5162 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5163 | * @phba: pointer to lpfc hba data structure. |
| 5164 | * |
| 5165 | * This routine is invoked to unset the driver internal resources set up after |
| 5166 | * the device specific resource setup for supporting the HBA device it |
| 5167 | * attached to. |
| 5168 | **/ |
| 5169 | static void |
| 5170 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5171 | { |
| 5172 | /* Stop kernel worker thread */ |
| 5173 | kthread_stop(phba->worker_thread); |
| 5174 | } |
| 5175 | |
| 5176 | /** |
| 5177 | * lpfc_free_iocb_list - Free iocb list. |
| 5178 | * @phba: pointer to lpfc hba data structure. |
| 5179 | * |
| 5180 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5181 | **/ |
| 5182 | static void |
| 5183 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5184 | { |
| 5185 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5186 | |
| 5187 | spin_lock_irq(&phba->hbalock); |
| 5188 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5189 | &phba->lpfc_iocb_list, list) { |
| 5190 | list_del(&iocbq_entry->list); |
| 5191 | kfree(iocbq_entry); |
| 5192 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5193 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5194 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5196 | return; |
| 5197 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5198 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5199 | /** |
| 5200 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5201 | * @phba: pointer to lpfc hba data structure. |
| 5202 | * |
| 5203 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5204 | * list and set up the IOCB tag array accordingly. |
| 5205 | * |
| 5206 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5207 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5208 | * other values - error |
| 5209 | **/ |
| 5210 | static int |
| 5211 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5212 | { |
| 5213 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5214 | uint16_t iotag; |
| 5215 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5216 | |
| 5217 | /* Initialize and populate the iocb list per host. */ |
| 5218 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5219 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5220 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5221 | if (iocbq_entry == NULL) { |
| 5222 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5223 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5224 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5225 | goto out_free_iocbq; |
| 5226 | } |
| 5227 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5228 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5229 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5230 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5231 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5232 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5233 | goto out_free_iocbq; |
| 5234 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5235 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5236 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5237 | |
| 5238 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5239 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5240 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5241 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5242 | } |
| 5243 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5244 | return 0; |
| 5245 | |
| 5246 | out_free_iocbq: |
| 5247 | lpfc_free_iocb_list(phba); |
| 5248 | |
| 5249 | return -ENOMEM; |
| 5250 | } |
| 5251 | |
| 5252 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5253 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5254 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5255 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5256 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5257 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5258 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5259 | void |
| 5260 | 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] | 5261 | { |
| 5262 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5263 | |
| 5264 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5265 | list_del(&sglq_entry->list); |
| 5266 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5267 | kfree(sglq_entry); |
| 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | /** |
| 5272 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5273 | * @phba: pointer to lpfc hba data structure. |
| 5274 | * |
| 5275 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5276 | **/ |
| 5277 | static void |
| 5278 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5279 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5280 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5281 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5282 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5283 | spin_lock_irq(&phba->hbalock); |
| 5284 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5285 | spin_unlock_irq(&phba->hbalock); |
| 5286 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5287 | /* Now free the sgl list */ |
| 5288 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5293 | * @phba: pointer to lpfc hba data structure. |
| 5294 | * |
| 5295 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5296 | * This array will hold the sglq_entry's for active IOs. |
| 5297 | **/ |
| 5298 | static int |
| 5299 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5300 | { |
| 5301 | int size; |
| 5302 | size = sizeof(struct lpfc_sglq *); |
| 5303 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5304 | |
| 5305 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5306 | kzalloc(size, GFP_KERNEL); |
| 5307 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5308 | return -ENOMEM; |
| 5309 | return 0; |
| 5310 | } |
| 5311 | |
| 5312 | /** |
| 5313 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5314 | * @phba: pointer to lpfc hba data structure. |
| 5315 | * |
| 5316 | * This routine is invoked to walk through the array of active sglq entries |
| 5317 | * and free all of the resources. |
| 5318 | * This is just a place holder for now. |
| 5319 | **/ |
| 5320 | static void |
| 5321 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5322 | { |
| 5323 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5328 | * @phba: pointer to lpfc hba data structure. |
| 5329 | * |
| 5330 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5331 | * list and set up the sgl xritag tag array accordingly. |
| 5332 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5333 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5334 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5335 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5336 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5337 | /* Initialize and populate the sglq list per host/VF. */ |
| 5338 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5339 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5340 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5341 | /* els xri-sgl book keeping */ |
| 5342 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5343 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5344 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5345 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5350 | * @phba: pointer to lpfc hba data structure. |
| 5351 | * |
| 5352 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5353 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5354 | * 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] | 5355 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5356 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5357 | * |
| 5358 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5359 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5360 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5361 | **/ |
| 5362 | int |
| 5363 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5364 | { |
| 5365 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5366 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5367 | |
| 5368 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5369 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5370 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5371 | if (phba->sli4_hba.extents_in_use) |
| 5372 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5373 | |
| 5374 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5375 | if (!rpi_hdr) { |
| 5376 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5377 | "0391 Error during rpi post operation\n"); |
| 5378 | lpfc_sli4_remove_rpis(phba); |
| 5379 | rc = -ENODEV; |
| 5380 | } |
| 5381 | |
| 5382 | return rc; |
| 5383 | } |
| 5384 | |
| 5385 | /** |
| 5386 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5387 | * @phba: pointer to lpfc hba data structure. |
| 5388 | * |
| 5389 | * This routine is invoked to allocate a single 4KB memory region to |
| 5390 | * support rpis and stores them in the phba. This single region |
| 5391 | * provides support for up to 64 rpis. The region is used globally |
| 5392 | * by the device. |
| 5393 | * |
| 5394 | * Returns: |
| 5395 | * A valid rpi hdr on success. |
| 5396 | * A NULL pointer on any failure. |
| 5397 | **/ |
| 5398 | struct lpfc_rpi_hdr * |
| 5399 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5400 | { |
| 5401 | uint16_t rpi_limit, curr_rpi_range; |
| 5402 | struct lpfc_dmabuf *dmabuf; |
| 5403 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5404 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5405 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5406 | /* |
| 5407 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5408 | * required. Set the expected maximum count and let the actual value |
| 5409 | * get set when extents are fully allocated. |
| 5410 | */ |
| 5411 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5412 | return NULL; |
| 5413 | if (phba->sli4_hba.extents_in_use) |
| 5414 | return NULL; |
| 5415 | |
| 5416 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5417 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5418 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5419 | |
| 5420 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5421 | /* |
| 5422 | * Establish the starting RPI in this header block. The starting |
| 5423 | * rpi is normalized to a zero base because the physical rpi is |
| 5424 | * port based. |
| 5425 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5426 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5427 | spin_unlock_irq(&phba->hbalock); |
| 5428 | |
| 5429 | /* |
| 5430 | * The port has a limited number of rpis. The increment here |
| 5431 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5432 | * and to allow the full max_rpi range per port. |
| 5433 | */ |
| 5434 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5435 | rpi_count = rpi_limit - curr_rpi_range; |
| 5436 | else |
| 5437 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5438 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5439 | if (!rpi_count) |
| 5440 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5441 | /* |
| 5442 | * First allocate the protocol header region for the port. The |
| 5443 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5444 | */ |
| 5445 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5446 | if (!dmabuf) |
| 5447 | return NULL; |
| 5448 | |
| 5449 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5450 | LPFC_HDR_TEMPLATE_SIZE, |
| 5451 | &dmabuf->phys, |
| 5452 | GFP_KERNEL); |
| 5453 | if (!dmabuf->virt) { |
| 5454 | rpi_hdr = NULL; |
| 5455 | goto err_free_dmabuf; |
| 5456 | } |
| 5457 | |
| 5458 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5459 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5460 | rpi_hdr = NULL; |
| 5461 | goto err_free_coherent; |
| 5462 | } |
| 5463 | |
| 5464 | /* Save the rpi header data for cleanup later. */ |
| 5465 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5466 | if (!rpi_hdr) |
| 5467 | goto err_free_coherent; |
| 5468 | |
| 5469 | rpi_hdr->dmabuf = dmabuf; |
| 5470 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5471 | rpi_hdr->page_count = 1; |
| 5472 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5473 | |
| 5474 | /* The rpi_hdr stores the logical index only. */ |
| 5475 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5476 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5477 | |
| 5478 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5479 | * The next_rpi stores the next logical module-64 rpi value used |
| 5480 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5481 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5482 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5483 | spin_unlock_irq(&phba->hbalock); |
| 5484 | return rpi_hdr; |
| 5485 | |
| 5486 | err_free_coherent: |
| 5487 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5488 | dmabuf->virt, dmabuf->phys); |
| 5489 | err_free_dmabuf: |
| 5490 | kfree(dmabuf); |
| 5491 | return NULL; |
| 5492 | } |
| 5493 | |
| 5494 | /** |
| 5495 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5496 | * @phba: pointer to lpfc hba data structure. |
| 5497 | * |
| 5498 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5499 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5500 | * presumes the caller has released all rpis consumed by fabric or port |
| 5501 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5502 | **/ |
| 5503 | void |
| 5504 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5505 | { |
| 5506 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5507 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5508 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5509 | goto exit; |
| 5510 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5511 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5512 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5513 | list_del(&rpi_hdr->list); |
| 5514 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5515 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5516 | kfree(rpi_hdr->dmabuf); |
| 5517 | kfree(rpi_hdr); |
| 5518 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5519 | exit: |
| 5520 | /* There are no rpis available to the port now. */ |
| 5521 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5522 | } |
| 5523 | |
| 5524 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5525 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5526 | * @pdev: pointer to pci device data structure. |
| 5527 | * |
| 5528 | * This routine is invoked to allocate the driver hba data structure for an |
| 5529 | * HBA device. If the allocation is successful, the phba reference to the |
| 5530 | * PCI device data structure is set. |
| 5531 | * |
| 5532 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5533 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5534 | * NULL - error |
| 5535 | **/ |
| 5536 | static struct lpfc_hba * |
| 5537 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5538 | { |
| 5539 | struct lpfc_hba *phba; |
| 5540 | |
| 5541 | /* Allocate memory for HBA structure */ |
| 5542 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5543 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5544 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5545 | return NULL; |
| 5546 | } |
| 5547 | |
| 5548 | /* Set reference to PCI device in HBA structure */ |
| 5549 | phba->pcidev = pdev; |
| 5550 | |
| 5551 | /* Assign an unused board number */ |
| 5552 | phba->brd_no = lpfc_get_instance(); |
| 5553 | if (phba->brd_no < 0) { |
| 5554 | kfree(phba); |
| 5555 | return NULL; |
| 5556 | } |
| 5557 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5558 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5559 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5560 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5561 | return phba; |
| 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5566 | * @phba: pointer to lpfc hba data structure. |
| 5567 | * |
| 5568 | * This routine is invoked to free the driver hba data structure with an |
| 5569 | * HBA device. |
| 5570 | **/ |
| 5571 | static void |
| 5572 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5573 | { |
| 5574 | /* Release the driver assigned board number */ |
| 5575 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5576 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5577 | /* Free memory allocated with sli rings */ |
| 5578 | kfree(phba->sli.ring); |
| 5579 | phba->sli.ring = NULL; |
| 5580 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5581 | kfree(phba); |
| 5582 | return; |
| 5583 | } |
| 5584 | |
| 5585 | /** |
| 5586 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5587 | * @phba: pointer to lpfc hba data structure. |
| 5588 | * |
| 5589 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5590 | * host with it. |
| 5591 | * |
| 5592 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5593 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5594 | * other values - error |
| 5595 | **/ |
| 5596 | static int |
| 5597 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5598 | { |
| 5599 | struct lpfc_vport *vport; |
| 5600 | struct Scsi_Host *shost; |
| 5601 | |
| 5602 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5603 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5604 | phba->fc_ratov = FF_DEF_RATOV; |
| 5605 | phba->fc_altov = FF_DEF_ALTOV; |
| 5606 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5607 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5608 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5609 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5610 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5611 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5612 | |
| 5613 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5614 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5615 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5616 | /* Put reference to SCSI host to driver's device private data */ |
| 5617 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5618 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5619 | return 0; |
| 5620 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5621 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5622 | /** |
| 5623 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5624 | * @phba: pointer to lpfc hba data structure. |
| 5625 | * |
| 5626 | * This routine is invoked to destroy HBA physical port and the associated |
| 5627 | * SCSI host. |
| 5628 | **/ |
| 5629 | static void |
| 5630 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5631 | { |
| 5632 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5633 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5634 | /* Destroy physical port that associated with the SCSI host */ |
| 5635 | destroy_port(vport); |
| 5636 | |
| 5637 | return; |
| 5638 | } |
| 5639 | |
| 5640 | /** |
| 5641 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5642 | * @phba: pointer to lpfc hba data structure. |
| 5643 | * @shost: the shost to be used to detect Block guard settings. |
| 5644 | * |
| 5645 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5646 | * This routine also allocates memory for debugging bg buffers. |
| 5647 | **/ |
| 5648 | static void |
| 5649 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5650 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5651 | uint32_t old_mask; |
| 5652 | uint32_t old_guard; |
| 5653 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5654 | int pagecnt = 10; |
| 5655 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5656 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5657 | "1478 Registering BlockGuard with the " |
| 5658 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5659 | |
| 5660 | old_mask = lpfc_prot_mask; |
| 5661 | old_guard = lpfc_prot_guard; |
| 5662 | |
| 5663 | /* Only allow supported values */ |
| 5664 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 5665 | SHOST_DIX_TYPE0_PROTECTION | |
| 5666 | SHOST_DIX_TYPE1_PROTECTION); |
| 5667 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 5668 | |
| 5669 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 5670 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 5671 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 5672 | |
| 5673 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5674 | if ((old_mask != lpfc_prot_mask) || |
| 5675 | (old_guard != lpfc_prot_guard)) |
| 5676 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5677 | "1475 Registering BlockGuard with the " |
| 5678 | "SCSI layer: mask %d guard %d\n", |
| 5679 | lpfc_prot_mask, lpfc_prot_guard); |
| 5680 | |
| 5681 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 5682 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 5683 | } else |
| 5684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5685 | "1479 Not Registering BlockGuard with the SCSI " |
| 5686 | "layer, Bad protection parameters: %d %d\n", |
| 5687 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5688 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5689 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5690 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5691 | while (pagecnt) { |
| 5692 | spin_lock_init(&_dump_buf_lock); |
| 5693 | _dump_buf_data = |
| 5694 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5695 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5696 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5697 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5698 | "_dump_buf_data at 0x%p\n", |
| 5699 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5700 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5701 | memset(_dump_buf_data, 0, |
| 5702 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5703 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5704 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5705 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5706 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5707 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5708 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5709 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5710 | "memory for hexdump\n"); |
| 5711 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5712 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5713 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5714 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5715 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5716 | while (pagecnt) { |
| 5717 | _dump_buf_dif = |
| 5718 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5719 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5720 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5721 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5722 | "_dump_buf_dif at 0x%p\n", |
| 5723 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5724 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5725 | memset(_dump_buf_dif, 0, |
| 5726 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5727 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5728 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5729 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5730 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5731 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5732 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5733 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5734 | "memory for hexdump\n"); |
| 5735 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5736 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5737 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5738 | _dump_buf_dif); |
| 5739 | } |
| 5740 | |
| 5741 | /** |
| 5742 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 5743 | * @phba: pointer to lpfc hba data structure. |
| 5744 | * |
| 5745 | * This routine is invoked to perform all the necessary post initialization |
| 5746 | * setup for the device. |
| 5747 | **/ |
| 5748 | static void |
| 5749 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 5750 | { |
| 5751 | struct Scsi_Host *shost; |
| 5752 | struct lpfc_adapter_event_header adapter_event; |
| 5753 | |
| 5754 | /* Get the default values for Model Name and Description */ |
| 5755 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 5756 | |
| 5757 | /* |
| 5758 | * hba setup may have changed the hba_queue_depth so we need to |
| 5759 | * adjust the value of can_queue. |
| 5760 | */ |
| 5761 | shost = pci_get_drvdata(phba->pcidev); |
| 5762 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 5763 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 5764 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5765 | |
| 5766 | lpfc_host_attrib_init(shost); |
| 5767 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5768 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5769 | spin_lock_irq(shost->host_lock); |
| 5770 | lpfc_poll_start_timer(phba); |
| 5771 | spin_unlock_irq(shost->host_lock); |
| 5772 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 5773 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5774 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5775 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5776 | /* Send board arrival event to upper layer */ |
| 5777 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 5778 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 5779 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5780 | sizeof(adapter_event), |
| 5781 | (char *) &adapter_event, |
| 5782 | LPFC_NL_VENDOR_ID); |
| 5783 | return; |
| 5784 | } |
| 5785 | |
| 5786 | /** |
| 5787 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 5788 | * @phba: pointer to lpfc hba data structure. |
| 5789 | * |
| 5790 | * This routine is invoked to set up the PCI device memory space for device |
| 5791 | * with SLI-3 interface spec. |
| 5792 | * |
| 5793 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5794 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5795 | * other values - error |
| 5796 | **/ |
| 5797 | static int |
| 5798 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 5799 | { |
| 5800 | struct pci_dev *pdev; |
| 5801 | unsigned long bar0map_len, bar2map_len; |
| 5802 | int i, hbq_count; |
| 5803 | void *ptr; |
| 5804 | int error = -ENODEV; |
| 5805 | |
| 5806 | /* Obtain PCI device reference */ |
| 5807 | if (!phba->pcidev) |
| 5808 | return error; |
| 5809 | else |
| 5810 | pdev = phba->pcidev; |
| 5811 | |
| 5812 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5813 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 5814 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 5815 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 5816 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5817 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5818 | } |
| 5819 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5820 | |
| 5821 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 5822 | * required by each mapping. |
| 5823 | */ |
| 5824 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 5825 | bar0map_len = pci_resource_len(pdev, 0); |
| 5826 | |
| 5827 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 5828 | bar2map_len = pci_resource_len(pdev, 2); |
| 5829 | |
| 5830 | /* Map HBA SLIM to a kernel virtual address. */ |
| 5831 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 5832 | if (!phba->slim_memmap_p) { |
| 5833 | dev_printk(KERN_ERR, &pdev->dev, |
| 5834 | "ioremap failed for SLIM memory.\n"); |
| 5835 | goto out; |
| 5836 | } |
| 5837 | |
| 5838 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 5839 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 5840 | if (!phba->ctrl_regs_memmap_p) { |
| 5841 | dev_printk(KERN_ERR, &pdev->dev, |
| 5842 | "ioremap failed for HBA control registers.\n"); |
| 5843 | goto out_iounmap_slim; |
| 5844 | } |
| 5845 | |
| 5846 | /* Allocate memory for SLI-2 structures */ |
| 5847 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 5848 | SLI2_SLIM_SIZE, |
| 5849 | &phba->slim2p.phys, |
| 5850 | GFP_KERNEL); |
| 5851 | if (!phba->slim2p.virt) |
| 5852 | goto out_iounmap; |
| 5853 | |
| 5854 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 5855 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 5856 | phba->mbox_ext = (phba->slim2p.virt + |
| 5857 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5858 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 5859 | phba->IOCBs = (phba->slim2p.virt + |
| 5860 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 5861 | |
| 5862 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 5863 | lpfc_sli_hbq_size(), |
| 5864 | &phba->hbqslimp.phys, |
| 5865 | GFP_KERNEL); |
| 5866 | if (!phba->hbqslimp.virt) |
| 5867 | goto out_free_slim; |
| 5868 | |
| 5869 | hbq_count = lpfc_sli_hbq_count(); |
| 5870 | ptr = phba->hbqslimp.virt; |
| 5871 | for (i = 0; i < hbq_count; ++i) { |
| 5872 | phba->hbqs[i].hbq_virt = ptr; |
| 5873 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5874 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 5875 | sizeof(struct lpfc_hbq_entry)); |
| 5876 | } |
| 5877 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 5878 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 5879 | |
| 5880 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 5881 | |
| 5882 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5883 | |
| 5884 | phba->MBslimaddr = phba->slim_memmap_p; |
| 5885 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 5886 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 5887 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 5888 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5889 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5890 | return 0; |
| 5891 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5892 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5893 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5894 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5895 | out_iounmap: |
| 5896 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5897 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5898 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5899 | out: |
| 5900 | return error; |
| 5901 | } |
| 5902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5903 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5904 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 5905 | * @phba: pointer to lpfc hba data structure. |
| 5906 | * |
| 5907 | * This routine is invoked to unset the PCI device memory space for device |
| 5908 | * with SLI-3 interface spec. |
| 5909 | **/ |
| 5910 | static void |
| 5911 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 5912 | { |
| 5913 | struct pci_dev *pdev; |
| 5914 | |
| 5915 | /* Obtain PCI device reference */ |
| 5916 | if (!phba->pcidev) |
| 5917 | return; |
| 5918 | else |
| 5919 | pdev = phba->pcidev; |
| 5920 | |
| 5921 | /* Free coherent DMA memory allocated */ |
| 5922 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 5923 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 5924 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5925 | phba->slim2p.virt, phba->slim2p.phys); |
| 5926 | |
| 5927 | /* I/O memory unmap */ |
| 5928 | iounmap(phba->ctrl_regs_memmap_p); |
| 5929 | iounmap(phba->slim_memmap_p); |
| 5930 | |
| 5931 | return; |
| 5932 | } |
| 5933 | |
| 5934 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5935 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 5936 | * @phba: pointer to lpfc hba data structure. |
| 5937 | * |
| 5938 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 5939 | * done and check status. |
| 5940 | * |
| 5941 | * Return 0 if successful, otherwise -ENODEV. |
| 5942 | **/ |
| 5943 | int |
| 5944 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 5945 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5946 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 5947 | struct lpfc_register reg_data; |
| 5948 | int i, port_error = 0; |
| 5949 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5950 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5951 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 5952 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5953 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5954 | return -ENODEV; |
| 5955 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5956 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 5957 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5958 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 5959 | &portsmphr_reg.word0) || |
| 5960 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5961 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5962 | port_error = -ENODEV; |
| 5963 | break; |
| 5964 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5965 | if (LPFC_POST_STAGE_PORT_READY == |
| 5966 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5967 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5968 | msleep(10); |
| 5969 | } |
| 5970 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5971 | /* |
| 5972 | * If there was a port error during POST, then don't proceed with |
| 5973 | * other register reads as the data may not be valid. Just exit. |
| 5974 | */ |
| 5975 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5976 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5977 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 5978 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 5979 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 5980 | portsmphr_reg.word0, |
| 5981 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 5982 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 5983 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 5984 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 5985 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 5986 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 5987 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 5988 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 5989 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5990 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5991 | "2534 Device Info: SLIFamily=0x%x, " |
| 5992 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 5993 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5994 | bf_get(lpfc_sli_intf_sli_family, |
| 5995 | &phba->sli4_hba.sli_intf), |
| 5996 | bf_get(lpfc_sli_intf_slirev, |
| 5997 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5998 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5999 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6000 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6001 | &phba->sli4_hba.sli_intf), |
| 6002 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6003 | &phba->sli4_hba.sli_intf), |
| 6004 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6005 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6006 | /* |
| 6007 | * Check for other Port errors during the initialization |
| 6008 | * process. Fail the load if the port did not come up |
| 6009 | * correctly. |
| 6010 | */ |
| 6011 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6012 | &phba->sli4_hba.sli_intf); |
| 6013 | switch (if_type) { |
| 6014 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6015 | phba->sli4_hba.ue_mask_lo = |
| 6016 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6017 | phba->sli4_hba.ue_mask_hi = |
| 6018 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6019 | uerrlo_reg.word0 = |
| 6020 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6021 | uerrhi_reg.word0 = |
| 6022 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6023 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6024 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6026 | "1422 Unrecoverable Error " |
| 6027 | "Detected during POST " |
| 6028 | "uerr_lo_reg=0x%x, " |
| 6029 | "uerr_hi_reg=0x%x, " |
| 6030 | "ue_mask_lo_reg=0x%x, " |
| 6031 | "ue_mask_hi_reg=0x%x\n", |
| 6032 | uerrlo_reg.word0, |
| 6033 | uerrhi_reg.word0, |
| 6034 | phba->sli4_hba.ue_mask_lo, |
| 6035 | phba->sli4_hba.ue_mask_hi); |
| 6036 | port_error = -ENODEV; |
| 6037 | } |
| 6038 | break; |
| 6039 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6040 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6041 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6042 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6043 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6044 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6045 | phba->work_status[0] = |
| 6046 | readl(phba->sli4_hba.u.if_type2. |
| 6047 | ERR1regaddr); |
| 6048 | phba->work_status[1] = |
| 6049 | readl(phba->sli4_hba.u.if_type2. |
| 6050 | ERR2regaddr); |
| 6051 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6052 | "2888 Unrecoverable port error " |
| 6053 | "following POST: port status reg " |
| 6054 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6055 | "error 1=0x%x, error 2=0x%x\n", |
| 6056 | reg_data.word0, |
| 6057 | portsmphr_reg.word0, |
| 6058 | phba->work_status[0], |
| 6059 | phba->work_status[1]); |
| 6060 | port_error = -ENODEV; |
| 6061 | } |
| 6062 | break; |
| 6063 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6064 | default: |
| 6065 | break; |
| 6066 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6067 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6068 | return port_error; |
| 6069 | } |
| 6070 | |
| 6071 | /** |
| 6072 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6073 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6074 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6075 | * |
| 6076 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6077 | * memory map. |
| 6078 | **/ |
| 6079 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6080 | 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] | 6081 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6082 | switch (if_type) { |
| 6083 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6084 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6085 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6086 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6087 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6088 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6089 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6090 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6091 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6092 | phba->sli4_hba.SLIINTFregaddr = |
| 6093 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6094 | break; |
| 6095 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6096 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6097 | phba->sli4_hba.conf_regs_memmap_p + |
| 6098 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6099 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6100 | phba->sli4_hba.conf_regs_memmap_p + |
| 6101 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6102 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6103 | phba->sli4_hba.conf_regs_memmap_p + |
| 6104 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6105 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6106 | phba->sli4_hba.conf_regs_memmap_p + |
| 6107 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6108 | phba->sli4_hba.SLIINTFregaddr = |
| 6109 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6110 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6111 | phba->sli4_hba.conf_regs_memmap_p + |
| 6112 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6113 | phba->sli4_hba.RQDBregaddr = |
| 6114 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; |
| 6115 | phba->sli4_hba.WQDBregaddr = |
| 6116 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; |
| 6117 | phba->sli4_hba.EQCQDBregaddr = |
| 6118 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6119 | phba->sli4_hba.MQDBregaddr = |
| 6120 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6121 | phba->sli4_hba.BMBXregaddr = |
| 6122 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6123 | break; |
| 6124 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6125 | default: |
| 6126 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6127 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6128 | if_type); |
| 6129 | break; |
| 6130 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6131 | } |
| 6132 | |
| 6133 | /** |
| 6134 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6135 | * @phba: pointer to lpfc hba data structure. |
| 6136 | * |
| 6137 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6138 | * memory map. |
| 6139 | **/ |
| 6140 | static void |
| 6141 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6142 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6143 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6144 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6145 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6146 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6147 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6148 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6149 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6150 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | /** |
| 6154 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6155 | * @phba: pointer to lpfc hba data structure. |
| 6156 | * @vf: virtual function number |
| 6157 | * |
| 6158 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6159 | * based on the given viftual function number, @vf. |
| 6160 | * |
| 6161 | * Return 0 if successful, otherwise -ENODEV. |
| 6162 | **/ |
| 6163 | static int |
| 6164 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6165 | { |
| 6166 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6167 | return -ENODEV; |
| 6168 | |
| 6169 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6170 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); |
| 6171 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6172 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); |
| 6173 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6174 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6175 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6176 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6177 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6178 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6179 | return 0; |
| 6180 | } |
| 6181 | |
| 6182 | /** |
| 6183 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6184 | * @phba: pointer to lpfc hba data structure. |
| 6185 | * |
| 6186 | * This routine is invoked to create the bootstrap mailbox |
| 6187 | * region consistent with the SLI-4 interface spec. This |
| 6188 | * routine allocates all memory necessary to communicate |
| 6189 | * mailbox commands to the port and sets up all alignment |
| 6190 | * needs. No locks are expected to be held when calling |
| 6191 | * this routine. |
| 6192 | * |
| 6193 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6194 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6195 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6196 | **/ |
| 6197 | static int |
| 6198 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6199 | { |
| 6200 | uint32_t bmbx_size; |
| 6201 | struct lpfc_dmabuf *dmabuf; |
| 6202 | struct dma_address *dma_address; |
| 6203 | uint32_t pa_addr; |
| 6204 | uint64_t phys_addr; |
| 6205 | |
| 6206 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6207 | if (!dmabuf) |
| 6208 | return -ENOMEM; |
| 6209 | |
| 6210 | /* |
| 6211 | * The bootstrap mailbox region is comprised of 2 parts |
| 6212 | * plus an alignment restriction of 16 bytes. |
| 6213 | */ |
| 6214 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 6215 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6216 | bmbx_size, |
| 6217 | &dmabuf->phys, |
| 6218 | GFP_KERNEL); |
| 6219 | if (!dmabuf->virt) { |
| 6220 | kfree(dmabuf); |
| 6221 | return -ENOMEM; |
| 6222 | } |
| 6223 | memset(dmabuf->virt, 0, bmbx_size); |
| 6224 | |
| 6225 | /* |
| 6226 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6227 | * operations are simple later. The mailbox dma address is required |
| 6228 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6229 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6230 | * command to the port. |
| 6231 | */ |
| 6232 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6233 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6234 | |
| 6235 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6236 | LPFC_ALIGN_16_BYTE); |
| 6237 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6238 | LPFC_ALIGN_16_BYTE); |
| 6239 | |
| 6240 | /* |
| 6241 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6242 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6243 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6244 | * the 30-bit address is the high or low address. |
| 6245 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6246 | * clean on 32 bit machines. |
| 6247 | */ |
| 6248 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6249 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6250 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6251 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6252 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6253 | |
| 6254 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6255 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6256 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6257 | return 0; |
| 6258 | } |
| 6259 | |
| 6260 | /** |
| 6261 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6262 | * @phba: pointer to lpfc hba data structure. |
| 6263 | * |
| 6264 | * This routine is invoked to teardown the bootstrap mailbox |
| 6265 | * region and release all host resources. This routine requires |
| 6266 | * the caller to ensure all mailbox commands recovered, no |
| 6267 | * additional mailbox comands are sent, and interrupts are disabled |
| 6268 | * before calling this routine. |
| 6269 | * |
| 6270 | **/ |
| 6271 | static void |
| 6272 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6273 | { |
| 6274 | dma_free_coherent(&phba->pcidev->dev, |
| 6275 | phba->sli4_hba.bmbx.bmbx_size, |
| 6276 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6277 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6278 | |
| 6279 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6280 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6281 | } |
| 6282 | |
| 6283 | /** |
| 6284 | * lpfc_sli4_read_config - Get the config parameters. |
| 6285 | * @phba: pointer to lpfc hba data structure. |
| 6286 | * |
| 6287 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6288 | * The configuration parameters are used to set the base and maximum values |
| 6289 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6290 | * allocation for the port. |
| 6291 | * |
| 6292 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6293 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6294 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6295 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6296 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6297 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6298 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6299 | { |
| 6300 | LPFC_MBOXQ_t *pmb; |
| 6301 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6302 | union lpfc_sli4_cfg_shdr *shdr; |
| 6303 | uint32_t shdr_status, shdr_add_status; |
| 6304 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6305 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6306 | char *pdesc_0; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6307 | uint32_t desc_count; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6308 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6309 | |
| 6310 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6311 | if (!pmb) { |
| 6312 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6313 | "2011 Unable to allocate memory for issuing " |
| 6314 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6315 | return -ENOMEM; |
| 6316 | } |
| 6317 | |
| 6318 | lpfc_read_config(phba, pmb); |
| 6319 | |
| 6320 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6321 | if (rc != MBX_SUCCESS) { |
| 6322 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6323 | "2012 Mailbox failed , mbxCmd x%x " |
| 6324 | "READ_CONFIG, mbxStatus x%x\n", |
| 6325 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6326 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6327 | rc = -EIO; |
| 6328 | } else { |
| 6329 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6330 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6331 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6332 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6333 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6334 | phba->sli4_hba.lnk_info.lnk_no = |
| 6335 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6336 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6337 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6338 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6339 | phba->sli4_hba.lnk_info.lnk_no); |
| 6340 | } else |
| 6341 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6342 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6343 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6344 | phba->sli4_hba.extents_in_use = |
| 6345 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6346 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6347 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6348 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6349 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6350 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6351 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6352 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6353 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6354 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6355 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6356 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6357 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6358 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6359 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6360 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6361 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6362 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6363 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6364 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6365 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6366 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6367 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6368 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6369 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6370 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6371 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6372 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6373 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6374 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6375 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6376 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6377 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6378 | phba->max_vports = phba->max_vpi; |
| 6379 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6380 | "2003 cfg params Extents? %d " |
| 6381 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6382 | "VPI(B:%d M:%d) " |
| 6383 | "VFI(B:%d M:%d) " |
| 6384 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6385 | "FCFI(Count:%d)\n", |
| 6386 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6387 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6388 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6389 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6390 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6391 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6392 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6393 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6394 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6395 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6396 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6397 | |
| 6398 | if (rc) |
| 6399 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6400 | |
| 6401 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6402 | if (phba->cfg_hba_queue_depth > |
| 6403 | (phba->sli4_hba.max_cfg_param.max_xri - |
| 6404 | lpfc_sli4_get_els_iocb_cnt(phba))) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6405 | phba->cfg_hba_queue_depth = |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6406 | phba->sli4_hba.max_cfg_param.max_xri - |
| 6407 | lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6408 | |
| 6409 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6410 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6411 | goto read_cfg_out; |
| 6412 | |
| 6413 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6414 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6415 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6416 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6417 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6418 | length, LPFC_SLI4_MBX_EMBED); |
| 6419 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6420 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6421 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6422 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6423 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6424 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6425 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6426 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6427 | "3026 Mailbox failed , mbxCmd x%x " |
| 6428 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6429 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6430 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6431 | goto read_cfg_out; |
| 6432 | } |
| 6433 | |
| 6434 | /* search for fc_fcoe resrouce descriptor */ |
| 6435 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6436 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6437 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6438 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6439 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6440 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6441 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6442 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6443 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6444 | goto read_cfg_out; |
| 6445 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6446 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6447 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6448 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6449 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6450 | phba->sli4_hba.iov.pf_number = |
| 6451 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6452 | phba->sli4_hba.iov.vf_number = |
| 6453 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6454 | break; |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6459 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6460 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6461 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6462 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6463 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6464 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6465 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6466 | "Resrouce Descriptor:x%x\n", |
| 6467 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6468 | |
| 6469 | read_cfg_out: |
| 6470 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6471 | return rc; |
| 6472 | } |
| 6473 | |
| 6474 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6475 | * 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] | 6476 | * @phba: pointer to lpfc hba data structure. |
| 6477 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6478 | * This routine is invoked to setup the port-side endian order when |
| 6479 | * the port if_type is 0. This routine has no function for other |
| 6480 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6481 | * |
| 6482 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6483 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6484 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6485 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6486 | **/ |
| 6487 | static int |
| 6488 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6489 | { |
| 6490 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6491 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6492 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6493 | HOST_ENDIAN_HIGH_WORD1}; |
| 6494 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6495 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6496 | switch (if_type) { |
| 6497 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6498 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6499 | GFP_KERNEL); |
| 6500 | if (!mboxq) { |
| 6501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6502 | "0492 Unable to allocate memory for " |
| 6503 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6504 | "command\n"); |
| 6505 | return -ENOMEM; |
| 6506 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6507 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6508 | /* |
| 6509 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6510 | * two words to contain special data values and no other data. |
| 6511 | */ |
| 6512 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6513 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6514 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6515 | if (rc != MBX_SUCCESS) { |
| 6516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6517 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6518 | "failed with status x%x\n", |
| 6519 | rc); |
| 6520 | rc = -EIO; |
| 6521 | } |
| 6522 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6523 | break; |
| 6524 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6525 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6526 | default: |
| 6527 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6528 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6529 | return rc; |
| 6530 | } |
| 6531 | |
| 6532 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6533 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6534 | * @phba: pointer to lpfc hba data structure. |
| 6535 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6536 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6537 | * CQs. after this routine is called the counts will be set to valid values that |
| 6538 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6539 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6540 | * |
| 6541 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6542 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6543 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6544 | **/ |
| 6545 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6546 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6547 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6548 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6549 | uint32_t cpu; |
| 6550 | uint32_t i = 0; |
| 6551 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6552 | |
| 6553 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6554 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6555 | * device parameters |
| 6556 | */ |
| 6557 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6558 | /* Sanity check on HBA EQ parameters */ |
| 6559 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6560 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6561 | /* It doesn't make sense to have more io channels then CPUs */ |
| 6562 | for_each_online_cpu(cpu) { |
| 6563 | i++; |
| 6564 | } |
| 6565 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6566 | lpfc_printf_log(phba, |
| 6567 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6568 | "3188 Reducing IO channels to match number of " |
| 6569 | "CPUs: from %d to %d\n", cfg_fcp_io_channel, i); |
| 6570 | cfg_fcp_io_channel = i; |
| 6571 | } |
| 6572 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6573 | if (cfg_fcp_io_channel > |
| 6574 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6575 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 6576 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6577 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6578 | "2574 Not enough EQs (%d) from the " |
| 6579 | "pci function for supporting FCP " |
| 6580 | "EQs (%d)\n", |
| 6581 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6582 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6583 | goto out_error; |
| 6584 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6585 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6586 | "2575 Reducing IO channels to match number of " |
| 6587 | "available EQs: from %d to %d\n", |
| 6588 | cfg_fcp_io_channel, |
| 6589 | phba->sli4_hba.max_cfg_param.max_eq); |
| 6590 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6591 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6592 | |
| 6593 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 6594 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6595 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6596 | phba->cfg_fcp_eq_count = cfg_fcp_io_channel; |
| 6597 | phba->cfg_fcp_wq_count = cfg_fcp_io_channel; |
| 6598 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6599 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6600 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6601 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6602 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6603 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6604 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6605 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6606 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6607 | |
| 6608 | return 0; |
| 6609 | out_error: |
| 6610 | return -ENOMEM; |
| 6611 | } |
| 6612 | |
| 6613 | /** |
| 6614 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6615 | * @phba: pointer to lpfc hba data structure. |
| 6616 | * |
| 6617 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6618 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6619 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6620 | * we just use some constant number as place holder. |
| 6621 | * |
| 6622 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 6623 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6624 | * -ENOMEM - No availble memory |
| 6625 | * -EIO - The mailbox failed to complete successfully. |
| 6626 | **/ |
| 6627 | int |
| 6628 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6629 | { |
| 6630 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6631 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6632 | |
| 6633 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6634 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6635 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6636 | if (!phba->cfg_fcp_io_channel) |
| 6637 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6638 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6639 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6640 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6641 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6642 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6643 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6644 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6645 | |
| 6646 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6647 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6648 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6650 | "2576 Failed allocate memory for " |
| 6651 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6652 | goto out_error; |
| 6653 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6654 | |
| 6655 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6656 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6657 | if (!phba->sli4_hba.fcp_cq) { |
| 6658 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6659 | "2577 Failed allocate memory for fast-path " |
| 6660 | "CQ record array\n"); |
| 6661 | goto out_error; |
| 6662 | } |
| 6663 | |
| 6664 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6665 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6666 | if (!phba->sli4_hba.fcp_wq) { |
| 6667 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6668 | "2578 Failed allocate memory for fast-path " |
| 6669 | "WQ record array\n"); |
| 6670 | goto out_error; |
| 6671 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6672 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6673 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6674 | * Since the first EQ can have multiple CQs associated with it, |
| 6675 | * this array is used to quickly see if we have a FCP fast-path |
| 6676 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6677 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6678 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 6679 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6680 | if (!phba->sli4_hba.fcp_cq_map) { |
| 6681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6682 | "2545 Failed allocate memory for fast-path " |
| 6683 | "CQ map\n"); |
| 6684 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6685 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6686 | |
| 6687 | /* |
| 6688 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 6689 | * how many EQs to create. |
| 6690 | */ |
| 6691 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6692 | |
| 6693 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6694 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6695 | phba->sli4_hba.eq_ecount); |
| 6696 | if (!qdesc) { |
| 6697 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6698 | "0497 Failed allocate EQ (%d)\n", idx); |
| 6699 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6700 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6701 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 6702 | |
| 6703 | /* Create Fast Path FCP CQs */ |
| 6704 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6705 | phba->sli4_hba.cq_ecount); |
| 6706 | if (!qdesc) { |
| 6707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6708 | "0499 Failed allocate fast-path FCP " |
| 6709 | "CQ (%d)\n", idx); |
| 6710 | goto out_error; |
| 6711 | } |
| 6712 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 6713 | |
| 6714 | /* Create Fast Path FCP WQs */ |
| 6715 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6716 | phba->sli4_hba.wq_ecount); |
| 6717 | if (!qdesc) { |
| 6718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6719 | "0503 Failed allocate fast-path FCP " |
| 6720 | "WQ (%d)\n", idx); |
| 6721 | goto out_error; |
| 6722 | } |
| 6723 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6724 | } |
| 6725 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6726 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6727 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6728 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6729 | */ |
| 6730 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6731 | /* Create slow-path Mailbox Command Complete Queue */ |
| 6732 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6733 | phba->sli4_hba.cq_ecount); |
| 6734 | if (!qdesc) { |
| 6735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6736 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6737 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6738 | } |
| 6739 | phba->sli4_hba.mbx_cq = qdesc; |
| 6740 | |
| 6741 | /* Create slow-path ELS Complete Queue */ |
| 6742 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6743 | phba->sli4_hba.cq_ecount); |
| 6744 | if (!qdesc) { |
| 6745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6746 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6747 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6748 | } |
| 6749 | phba->sli4_hba.els_cq = qdesc; |
| 6750 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6751 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6752 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6753 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6754 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6755 | |
| 6756 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6757 | |
| 6758 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 6759 | phba->sli4_hba.mq_ecount); |
| 6760 | if (!qdesc) { |
| 6761 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6762 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6763 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6764 | } |
| 6765 | phba->sli4_hba.mbx_wq = qdesc; |
| 6766 | |
| 6767 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6768 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6769 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6770 | |
| 6771 | /* Create slow-path ELS Work Queue */ |
| 6772 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6773 | phba->sli4_hba.wq_ecount); |
| 6774 | if (!qdesc) { |
| 6775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6776 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6777 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6778 | } |
| 6779 | phba->sli4_hba.els_wq = qdesc; |
| 6780 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6781 | /* |
| 6782 | * Create Receive Queue (RQ) |
| 6783 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6784 | |
| 6785 | /* Create Receive Queue for header */ |
| 6786 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6787 | phba->sli4_hba.rq_ecount); |
| 6788 | if (!qdesc) { |
| 6789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6790 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6791 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6792 | } |
| 6793 | phba->sli4_hba.hdr_rq = qdesc; |
| 6794 | |
| 6795 | /* Create Receive Queue for data */ |
| 6796 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6797 | phba->sli4_hba.rq_ecount); |
| 6798 | if (!qdesc) { |
| 6799 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6800 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6801 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6802 | } |
| 6803 | phba->sli4_hba.dat_rq = qdesc; |
| 6804 | |
| 6805 | return 0; |
| 6806 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6807 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6808 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6809 | return -ENOMEM; |
| 6810 | } |
| 6811 | |
| 6812 | /** |
| 6813 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 6814 | * @phba: pointer to lpfc hba data structure. |
| 6815 | * |
| 6816 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 6817 | * operation. |
| 6818 | * |
| 6819 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6820 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6821 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6822 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6823 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6824 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6825 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 6826 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6827 | int idx; |
| 6828 | |
| 6829 | if (phba->sli4_hba.hba_eq != NULL) { |
| 6830 | /* Release HBA event queue */ |
| 6831 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6832 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 6833 | lpfc_sli4_queue_free( |
| 6834 | phba->sli4_hba.hba_eq[idx]); |
| 6835 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 6836 | } |
| 6837 | } |
| 6838 | kfree(phba->sli4_hba.hba_eq); |
| 6839 | phba->sli4_hba.hba_eq = NULL; |
| 6840 | } |
| 6841 | |
| 6842 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 6843 | /* Release FCP completion queue */ |
| 6844 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6845 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 6846 | lpfc_sli4_queue_free( |
| 6847 | phba->sli4_hba.fcp_cq[idx]); |
| 6848 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 6849 | } |
| 6850 | } |
| 6851 | kfree(phba->sli4_hba.fcp_cq); |
| 6852 | phba->sli4_hba.fcp_cq = NULL; |
| 6853 | } |
| 6854 | |
| 6855 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 6856 | /* Release FCP work queue */ |
| 6857 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6858 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 6859 | lpfc_sli4_queue_free( |
| 6860 | phba->sli4_hba.fcp_wq[idx]); |
| 6861 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 6862 | } |
| 6863 | } |
| 6864 | kfree(phba->sli4_hba.fcp_wq); |
| 6865 | phba->sli4_hba.fcp_wq = NULL; |
| 6866 | } |
| 6867 | |
| 6868 | /* Release FCP CQ mapping array */ |
| 6869 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 6870 | kfree(phba->sli4_hba.fcp_cq_map); |
| 6871 | phba->sli4_hba.fcp_cq_map = NULL; |
| 6872 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6873 | |
| 6874 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6875 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 6876 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 6877 | phba->sli4_hba.mbx_wq = NULL; |
| 6878 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6879 | |
| 6880 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6881 | if (phba->sli4_hba.els_wq != NULL) { |
| 6882 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 6883 | phba->sli4_hba.els_wq = NULL; |
| 6884 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6885 | |
| 6886 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6887 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 6888 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 6889 | phba->sli4_hba.hdr_rq = NULL; |
| 6890 | } |
| 6891 | if (phba->sli4_hba.dat_rq != NULL) { |
| 6892 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 6893 | phba->sli4_hba.dat_rq = NULL; |
| 6894 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6895 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6896 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6897 | if (phba->sli4_hba.els_cq != NULL) { |
| 6898 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 6899 | phba->sli4_hba.els_cq = NULL; |
| 6900 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6901 | |
| 6902 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6903 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 6904 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 6905 | phba->sli4_hba.mbx_cq = NULL; |
| 6906 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6907 | |
| 6908 | return; |
| 6909 | } |
| 6910 | |
| 6911 | /** |
| 6912 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 6913 | * @phba: pointer to lpfc hba data structure. |
| 6914 | * |
| 6915 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 6916 | * operation. |
| 6917 | * |
| 6918 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6919 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6920 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6921 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6922 | **/ |
| 6923 | int |
| 6924 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 6925 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6926 | struct lpfc_sli *psli = &phba->sli; |
| 6927 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6928 | int rc = -ENOMEM; |
| 6929 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 6930 | int fcp_cq_index = 0; |
| 6931 | |
| 6932 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6933 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6934 | */ |
| 6935 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6936 | /* Set up HBA event queue */ |
| 6937 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6939 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6940 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6941 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6942 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6943 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 6944 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6946 | "0522 Fast-path EQ (%d) not " |
| 6947 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6948 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6949 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6950 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6951 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 6952 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6953 | if (rc) { |
| 6954 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6955 | "0523 Failed setup of fast-path EQ " |
| 6956 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6957 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6958 | } |
| 6959 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6960 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6961 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6962 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6963 | } |
| 6964 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6965 | /* Set up fast-path FCP Response Complete Queue */ |
| 6966 | if (!phba->sli4_hba.fcp_cq) { |
| 6967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6968 | "3148 Fast-path FCP CQ array not " |
| 6969 | "allocated\n"); |
| 6970 | rc = -ENOMEM; |
| 6971 | goto out_destroy_hba_eq; |
| 6972 | } |
| 6973 | |
| 6974 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 6975 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 6976 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6977 | "0526 Fast-path FCP CQ (%d) not " |
| 6978 | "allocated\n", fcp_cqidx); |
| 6979 | rc = -ENOMEM; |
| 6980 | goto out_destroy_fcp_cq; |
| 6981 | } |
| 6982 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 6983 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 6984 | if (rc) { |
| 6985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6986 | "0527 Failed setup of fast-path FCP " |
| 6987 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 6988 | goto out_destroy_fcp_cq; |
| 6989 | } |
| 6990 | |
| 6991 | /* Setup fcp_cq_map for fast lookup */ |
| 6992 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 6993 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 6994 | |
| 6995 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6996 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 6997 | "parent seq[%d]-id=%d\n", |
| 6998 | fcp_cqidx, |
| 6999 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7000 | fcp_cqidx, |
| 7001 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7002 | } |
| 7003 | |
| 7004 | /* Set up fast-path FCP Work Queue */ |
| 7005 | if (!phba->sli4_hba.fcp_wq) { |
| 7006 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7007 | "3149 Fast-path FCP WQ array not " |
| 7008 | "allocated\n"); |
| 7009 | rc = -ENOMEM; |
| 7010 | goto out_destroy_fcp_cq; |
| 7011 | } |
| 7012 | |
| 7013 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7014 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7015 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7016 | "0534 Fast-path FCP WQ (%d) not " |
| 7017 | "allocated\n", fcp_wqidx); |
| 7018 | rc = -ENOMEM; |
| 7019 | goto out_destroy_fcp_wq; |
| 7020 | } |
| 7021 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7022 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7023 | LPFC_FCP); |
| 7024 | if (rc) { |
| 7025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7026 | "0535 Failed setup of fast-path FCP " |
| 7027 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 7028 | goto out_destroy_fcp_wq; |
| 7029 | } |
| 7030 | |
| 7031 | /* Bind this WQ to the next FCP ring */ |
| 7032 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7033 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7034 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7035 | |
| 7036 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7037 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7038 | "parent cq[%d]-id=%d\n", |
| 7039 | fcp_wqidx, |
| 7040 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7041 | fcp_cq_index, |
| 7042 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7043 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7044 | /* |
| 7045 | * Set up Complete Queues (CQs) |
| 7046 | */ |
| 7047 | |
| 7048 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7049 | if (!phba->sli4_hba.mbx_cq) { |
| 7050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7051 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7052 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7053 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7054 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7055 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7056 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7057 | if (rc) { |
| 7058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7059 | "0529 Failed setup of slow-path mailbox CQ: " |
| 7060 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7061 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7062 | } |
| 7063 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7064 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7065 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7066 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7067 | |
| 7068 | /* Set up slow-path ELS Complete Queue */ |
| 7069 | if (!phba->sli4_hba.els_cq) { |
| 7070 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7071 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7072 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7073 | goto out_destroy_mbx_cq; |
| 7074 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7075 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7076 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7077 | if (rc) { |
| 7078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7079 | "0531 Failed setup of slow-path ELS CQ: " |
| 7080 | "rc = 0x%x\n", rc); |
| 7081 | goto out_destroy_mbx_cq; |
| 7082 | } |
| 7083 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7084 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7085 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7086 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7087 | |
| 7088 | /* |
| 7089 | * Set up all the Work Queues (WQs) |
| 7090 | */ |
| 7091 | |
| 7092 | /* Set up Mailbox Command Queue */ |
| 7093 | if (!phba->sli4_hba.mbx_wq) { |
| 7094 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7095 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7096 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7097 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7098 | } |
| 7099 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7100 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7101 | if (rc) { |
| 7102 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7103 | "0539 Failed setup of slow-path MQ: " |
| 7104 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7105 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7106 | } |
| 7107 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7108 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7109 | phba->sli4_hba.mbx_wq->queue_id, |
| 7110 | phba->sli4_hba.mbx_cq->queue_id); |
| 7111 | |
| 7112 | /* Set up slow-path ELS Work Queue */ |
| 7113 | if (!phba->sli4_hba.els_wq) { |
| 7114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7115 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7116 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7117 | goto out_destroy_mbx_wq; |
| 7118 | } |
| 7119 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7120 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7121 | if (rc) { |
| 7122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7123 | "0537 Failed setup of slow-path ELS WQ: " |
| 7124 | "rc = 0x%x\n", rc); |
| 7125 | goto out_destroy_mbx_wq; |
| 7126 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7127 | |
| 7128 | /* Bind this WQ to the ELS ring */ |
| 7129 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7130 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7131 | phba->sli4_hba.els_cq->pring = pring; |
| 7132 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7133 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7134 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7135 | phba->sli4_hba.els_wq->queue_id, |
| 7136 | phba->sli4_hba.els_cq->queue_id); |
| 7137 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7138 | /* |
| 7139 | * Create Receive Queue (RQ) |
| 7140 | */ |
| 7141 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7143 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7144 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7145 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7146 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7147 | |
| 7148 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7149 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7150 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7151 | 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] | 7152 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7153 | if (rc) { |
| 7154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7155 | "0541 Failed setup of Receive Queue: " |
| 7156 | "rc = 0x%x\n", rc); |
| 7157 | goto out_destroy_fcp_wq; |
| 7158 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7159 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7160 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7161 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7162 | "parent cq-id=%d\n", |
| 7163 | phba->sli4_hba.hdr_rq->queue_id, |
| 7164 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7165 | phba->sli4_hba.els_cq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7166 | return 0; |
| 7167 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7168 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7169 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7170 | out_destroy_mbx_wq: |
| 7171 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7172 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7173 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7174 | out_destroy_mbx_cq: |
| 7175 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7176 | out_destroy_fcp_wq: |
| 7177 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7178 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7179 | out_destroy_fcp_cq: |
| 7180 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7181 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7182 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7183 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7184 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7185 | out_error: |
| 7186 | return rc; |
| 7187 | } |
| 7188 | |
| 7189 | /** |
| 7190 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7191 | * @phba: pointer to lpfc hba data structure. |
| 7192 | * |
| 7193 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7194 | * operation. |
| 7195 | * |
| 7196 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7197 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7198 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7199 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7200 | **/ |
| 7201 | void |
| 7202 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7203 | { |
| 7204 | int fcp_qidx; |
| 7205 | |
| 7206 | /* Unset mailbox command work queue */ |
| 7207 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7208 | /* Unset ELS work queue */ |
| 7209 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7210 | /* Unset unsolicited receive queue */ |
| 7211 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7212 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7213 | if (phba->sli4_hba.fcp_wq) { |
| 7214 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7215 | fcp_qidx++) |
| 7216 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7217 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7218 | /* Unset mailbox command complete queue */ |
| 7219 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7220 | /* Unset ELS complete queue */ |
| 7221 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7222 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7223 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7224 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7225 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7226 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7227 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7228 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7229 | if (phba->sli4_hba.hba_eq) { |
| 7230 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7231 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7232 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[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 | } |
| 7235 | |
| 7236 | /** |
| 7237 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7238 | * @phba: pointer to lpfc hba data structure. |
| 7239 | * |
| 7240 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7241 | * events. The body of the completion queue event is a completion queue entry |
| 7242 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7243 | * the following HBA completion queue events for the worker thread to process: |
| 7244 | * - Mailbox asynchronous events |
| 7245 | * - Receive queue completion unsolicited events |
| 7246 | * Later, this can be used for all the slow-path events. |
| 7247 | * |
| 7248 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7249 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7250 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7251 | **/ |
| 7252 | static int |
| 7253 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7254 | { |
| 7255 | struct lpfc_cq_event *cq_event; |
| 7256 | int i; |
| 7257 | |
| 7258 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7259 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7260 | if (!cq_event) |
| 7261 | goto out_pool_create_fail; |
| 7262 | list_add_tail(&cq_event->list, |
| 7263 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7264 | } |
| 7265 | return 0; |
| 7266 | |
| 7267 | out_pool_create_fail: |
| 7268 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7269 | return -ENOMEM; |
| 7270 | } |
| 7271 | |
| 7272 | /** |
| 7273 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7274 | * @phba: pointer to lpfc hba data structure. |
| 7275 | * |
| 7276 | * This routine is invoked to free the pool of completion queue events at |
| 7277 | * driver unload time. Note that, it is the responsibility of the driver |
| 7278 | * cleanup routine to free all the outstanding completion-queue events |
| 7279 | * allocated from this pool back into the pool before invoking this routine |
| 7280 | * to destroy the pool. |
| 7281 | **/ |
| 7282 | static void |
| 7283 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7284 | { |
| 7285 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7286 | |
| 7287 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7288 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7289 | list_del(&cq_event->list); |
| 7290 | kfree(cq_event); |
| 7291 | } |
| 7292 | } |
| 7293 | |
| 7294 | /** |
| 7295 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7296 | * @phba: pointer to lpfc hba data structure. |
| 7297 | * |
| 7298 | * This routine is the lock free version of the API invoked to allocate a |
| 7299 | * completion-queue event from the free pool. |
| 7300 | * |
| 7301 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7302 | * NULL otherwise. |
| 7303 | **/ |
| 7304 | struct lpfc_cq_event * |
| 7305 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7306 | { |
| 7307 | struct lpfc_cq_event *cq_event = NULL; |
| 7308 | |
| 7309 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7310 | struct lpfc_cq_event, list); |
| 7311 | return cq_event; |
| 7312 | } |
| 7313 | |
| 7314 | /** |
| 7315 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7316 | * @phba: pointer to lpfc hba data structure. |
| 7317 | * |
| 7318 | * This routine is the lock version of the API invoked to allocate a |
| 7319 | * completion-queue event from the free pool. |
| 7320 | * |
| 7321 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7322 | * NULL otherwise. |
| 7323 | **/ |
| 7324 | struct lpfc_cq_event * |
| 7325 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7326 | { |
| 7327 | struct lpfc_cq_event *cq_event; |
| 7328 | unsigned long iflags; |
| 7329 | |
| 7330 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7331 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7332 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7333 | return cq_event; |
| 7334 | } |
| 7335 | |
| 7336 | /** |
| 7337 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7338 | * @phba: pointer to lpfc hba data structure. |
| 7339 | * @cq_event: pointer to the completion queue event to be freed. |
| 7340 | * |
| 7341 | * This routine is the lock free version of the API invoked to release a |
| 7342 | * completion-queue event back into the free pool. |
| 7343 | **/ |
| 7344 | void |
| 7345 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7346 | struct lpfc_cq_event *cq_event) |
| 7347 | { |
| 7348 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7349 | } |
| 7350 | |
| 7351 | /** |
| 7352 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7353 | * @phba: pointer to lpfc hba data structure. |
| 7354 | * @cq_event: pointer to the completion queue event to be freed. |
| 7355 | * |
| 7356 | * This routine is the lock version of the API invoked to release a |
| 7357 | * completion-queue event back into the free pool. |
| 7358 | **/ |
| 7359 | void |
| 7360 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7361 | struct lpfc_cq_event *cq_event) |
| 7362 | { |
| 7363 | unsigned long iflags; |
| 7364 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7365 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7366 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7367 | } |
| 7368 | |
| 7369 | /** |
| 7370 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7371 | * @phba: pointer to lpfc hba data structure. |
| 7372 | * |
| 7373 | * This routine is to free all the pending completion-queue events to the |
| 7374 | * back into the free pool for device reset. |
| 7375 | **/ |
| 7376 | static void |
| 7377 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7378 | { |
| 7379 | LIST_HEAD(cqelist); |
| 7380 | struct lpfc_cq_event *cqe; |
| 7381 | unsigned long iflags; |
| 7382 | |
| 7383 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7384 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7385 | /* Pending FCP XRI abort events */ |
| 7386 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7387 | &cqelist); |
| 7388 | /* Pending ELS XRI abort events */ |
| 7389 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7390 | &cqelist); |
| 7391 | /* Pending asynnc events */ |
| 7392 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7393 | &cqelist); |
| 7394 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7395 | |
| 7396 | while (!list_empty(&cqelist)) { |
| 7397 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7398 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | /** |
| 7403 | * lpfc_pci_function_reset - Reset pci function. |
| 7404 | * @phba: pointer to lpfc hba data structure. |
| 7405 | * |
| 7406 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7407 | * all resources assigned to the PCI function which originates this request. |
| 7408 | * |
| 7409 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7410 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7411 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7412 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7413 | **/ |
| 7414 | int |
| 7415 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7416 | { |
| 7417 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7418 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7419 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7420 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7421 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7422 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7423 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7424 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7425 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7426 | switch (if_type) { |
| 7427 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7428 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7429 | GFP_KERNEL); |
| 7430 | if (!mboxq) { |
| 7431 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7432 | "0494 Unable to allocate memory for " |
| 7433 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7434 | "command\n"); |
| 7435 | return -ENOMEM; |
| 7436 | } |
| 7437 | |
| 7438 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7439 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7440 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7441 | LPFC_SLI4_MBX_EMBED); |
| 7442 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7443 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7444 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7445 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7446 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7447 | &shdr->response); |
| 7448 | if (rc != MBX_TIMEOUT) |
| 7449 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7450 | if (shdr_status || shdr_add_status || rc) { |
| 7451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7452 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7453 | "failed with status x%x add_status x%x," |
| 7454 | " mbx status x%x\n", |
| 7455 | shdr_status, shdr_add_status, rc); |
| 7456 | rc = -ENXIO; |
| 7457 | } |
| 7458 | break; |
| 7459 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7460 | for (num_resets = 0; |
| 7461 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7462 | num_resets++) { |
| 7463 | reg_data.word0 = 0; |
| 7464 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7465 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7466 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7467 | LPFC_SLIPORT_INIT_PORT); |
| 7468 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7469 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7470 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7471 | pci_read_config_word(phba->pcidev, |
| 7472 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7473 | /* |
| 7474 | * Poll the Port Status Register and wait for RDY for |
| 7475 | * up to 10 seconds. If the port doesn't respond, treat |
| 7476 | * it as an error. If the port responds with RN, start |
| 7477 | * the loop again. |
| 7478 | */ |
| 7479 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7480 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7481 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7482 | STATUSregaddr, ®_data.word0)) { |
| 7483 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7484 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7485 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7486 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7487 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7488 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7489 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7490 | } |
| 7491 | |
| 7492 | /* |
| 7493 | * If the port responds to the init request with |
| 7494 | * reset needed, delay for a bit and restart the loop. |
| 7495 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7496 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7497 | msleep(10); |
| 7498 | reset_again = 0; |
| 7499 | continue; |
| 7500 | } |
| 7501 | |
| 7502 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7503 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7504 | (rdy_chk >= 1000)) { |
| 7505 | phba->work_status[0] = readl( |
| 7506 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7507 | phba->work_status[1] = readl( |
| 7508 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7509 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7510 | "2890 Port error detected during port " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7511 | "reset(%d): wait_tmo:%d ms, " |
| 7512 | "port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7513 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7514 | num_resets, rdy_chk*10, |
| 7515 | reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7516 | phba->work_status[0], |
| 7517 | phba->work_status[1]); |
| 7518 | rc = -ENODEV; |
| 7519 | } |
| 7520 | |
| 7521 | /* |
| 7522 | * Terminate the outer loop provided the Port indicated |
| 7523 | * ready within 10 seconds. |
| 7524 | */ |
| 7525 | if (rdy_chk < 1000) |
| 7526 | break; |
| 7527 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7528 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7529 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7530 | break; |
| 7531 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7532 | default: |
| 7533 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7534 | } |
| 7535 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7536 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7537 | /* Catch the not-ready port failure after a port reset. */ |
| 7538 | if (num_resets >= MAX_IF_TYPE_2_RESETS) |
| 7539 | rc = -ENODEV; |
| 7540 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7541 | return rc; |
| 7542 | } |
| 7543 | |
| 7544 | /** |
| 7545 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands |
| 7546 | * @phba: pointer to lpfc hba data structure. |
| 7547 | * @cnt: number of nop mailbox commands to send. |
| 7548 | * |
| 7549 | * This routine is invoked to send a number @cnt of NOP mailbox command and |
| 7550 | * wait for each command to complete. |
| 7551 | * |
| 7552 | * Return: the number of NOP mailbox command completed. |
| 7553 | **/ |
| 7554 | static int |
| 7555 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) |
| 7556 | { |
| 7557 | LPFC_MBOXQ_t *mboxq; |
| 7558 | int length, cmdsent; |
| 7559 | uint32_t mbox_tmo; |
| 7560 | uint32_t rc = 0; |
| 7561 | uint32_t shdr_status, shdr_add_status; |
| 7562 | union lpfc_sli4_cfg_shdr *shdr; |
| 7563 | |
| 7564 | if (cnt == 0) { |
| 7565 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7566 | "2518 Requested to send 0 NOP mailbox cmd\n"); |
| 7567 | return cnt; |
| 7568 | } |
| 7569 | |
| 7570 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7571 | if (!mboxq) { |
| 7572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7573 | "2519 Unable to allocate memory for issuing " |
| 7574 | "NOP mailbox command\n"); |
| 7575 | return 0; |
| 7576 | } |
| 7577 | |
| 7578 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ |
| 7579 | length = (sizeof(struct lpfc_mbx_nop) - |
| 7580 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7581 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7582 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
James Smart | 59df3ac | 2012-08-03 12:34:29 -0400 | [diff] [blame] | 7583 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7584 | LPFC_MBOX_OPCODE_NOP, length, |
| 7585 | LPFC_SLI4_MBX_EMBED); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7586 | if (!phba->sli4_hba.intr_enable) |
| 7587 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7588 | else { |
| 7589 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7590 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7591 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7592 | if (rc == MBX_TIMEOUT) |
| 7593 | break; |
| 7594 | /* Check return status */ |
| 7595 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7596 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7597 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7598 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7599 | &shdr->response); |
| 7600 | if (shdr_status || shdr_add_status || rc) { |
| 7601 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7602 | "2520 NOP mailbox command failed " |
| 7603 | "status x%x add_status x%x mbx " |
| 7604 | "status x%x\n", shdr_status, |
| 7605 | shdr_add_status, rc); |
| 7606 | break; |
| 7607 | } |
| 7608 | } |
| 7609 | |
| 7610 | if (rc != MBX_TIMEOUT) |
| 7611 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7612 | |
| 7613 | return cmdsent; |
| 7614 | } |
| 7615 | |
| 7616 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7617 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7618 | * @phba: pointer to lpfc hba data structure. |
| 7619 | * |
| 7620 | * This routine is invoked to set up the PCI device memory space for device |
| 7621 | * with SLI-4 interface spec. |
| 7622 | * |
| 7623 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7624 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7625 | * other values - error |
| 7626 | **/ |
| 7627 | static int |
| 7628 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7629 | { |
| 7630 | struct pci_dev *pdev; |
| 7631 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7632 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7633 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7634 | |
| 7635 | /* Obtain PCI device reference */ |
| 7636 | if (!phba->pcidev) |
| 7637 | return error; |
| 7638 | else |
| 7639 | pdev = phba->pcidev; |
| 7640 | |
| 7641 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7642 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7643 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7644 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7645 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7646 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7647 | } |
| 7648 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7649 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7650 | /* |
| 7651 | * The BARs and register set definitions and offset locations are |
| 7652 | * dependent on the if_type. |
| 7653 | */ |
| 7654 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 7655 | &phba->sli4_hba.sli_intf.word0)) { |
| 7656 | return error; |
| 7657 | } |
| 7658 | |
| 7659 | /* There is no SLI3 failback for SLI4 devices. */ |
| 7660 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 7661 | LPFC_SLI_INTF_VALID) { |
| 7662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7663 | "2894 SLI_INTF reg contents invalid " |
| 7664 | "sli_intf reg 0x%x\n", |
| 7665 | phba->sli4_hba.sli_intf.word0); |
| 7666 | return error; |
| 7667 | } |
| 7668 | |
| 7669 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7670 | /* |
| 7671 | * Get the bus address of SLI4 device Bar regions and the |
| 7672 | * number of bytes required by each mapping. The mapping of the |
| 7673 | * particular PCI BARs regions is dependent on the type of |
| 7674 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7675 | */ |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7676 | if (pci_resource_start(pdev, 0)) { |
| 7677 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7678 | bar0map_len = pci_resource_len(pdev, 0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7679 | |
| 7680 | /* |
| 7681 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 7682 | * addr |
| 7683 | */ |
| 7684 | phba->sli4_hba.conf_regs_memmap_p = |
| 7685 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 7686 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7687 | dev_printk(KERN_ERR, &pdev->dev, |
| 7688 | "ioremap failed for SLI4 PCI config " |
| 7689 | "registers.\n"); |
| 7690 | goto out; |
| 7691 | } |
| 7692 | /* Set up BAR0 PCI config space register memory map */ |
| 7693 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7694 | } else { |
| 7695 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 7696 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7697 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7698 | dev_printk(KERN_ERR, &pdev->dev, |
| 7699 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 7700 | goto out; |
| 7701 | } |
| 7702 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7703 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7704 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7705 | dev_printk(KERN_ERR, &pdev->dev, |
| 7706 | "ioremap failed for SLI4 PCI config " |
| 7707 | "registers.\n"); |
| 7708 | goto out; |
| 7709 | } |
| 7710 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7711 | } |
| 7712 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7713 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7714 | (pci_resource_start(pdev, 2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7715 | /* |
| 7716 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 7717 | * virtual address and setup the registers. |
| 7718 | */ |
| 7719 | phba->pci_bar1_map = pci_resource_start(pdev, 2); |
| 7720 | bar1map_len = pci_resource_len(pdev, 2); |
| 7721 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7722 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7723 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 7724 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7725 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7726 | goto out_iounmap_conf; |
| 7727 | } |
| 7728 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7729 | } |
| 7730 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7731 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7732 | (pci_resource_start(pdev, 4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7733 | /* |
| 7734 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 7735 | * virtual address and setup the registers. |
| 7736 | */ |
| 7737 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
| 7738 | bar2map_len = pci_resource_len(pdev, 4); |
| 7739 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7740 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7741 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 7742 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7743 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7744 | goto out_iounmap_ctrl; |
| 7745 | } |
| 7746 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 7747 | if (error) |
| 7748 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7749 | } |
| 7750 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7751 | return 0; |
| 7752 | |
| 7753 | out_iounmap_all: |
| 7754 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7755 | out_iounmap_ctrl: |
| 7756 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7757 | out_iounmap_conf: |
| 7758 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7759 | out: |
| 7760 | return error; |
| 7761 | } |
| 7762 | |
| 7763 | /** |
| 7764 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 7765 | * @phba: pointer to lpfc hba data structure. |
| 7766 | * |
| 7767 | * This routine is invoked to unset the PCI device memory space for device |
| 7768 | * with SLI-4 interface spec. |
| 7769 | **/ |
| 7770 | static void |
| 7771 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 7772 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7773 | uint32_t if_type; |
| 7774 | 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] | 7775 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7776 | switch (if_type) { |
| 7777 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7778 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7779 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7780 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7781 | break; |
| 7782 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7783 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7784 | break; |
| 7785 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7786 | default: |
| 7787 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 7788 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7789 | if_type); |
| 7790 | break; |
| 7791 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7792 | } |
| 7793 | |
| 7794 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7795 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 7796 | * @phba: pointer to lpfc hba data structure. |
| 7797 | * |
| 7798 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 7799 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 7800 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 7801 | * invoked, enables either all or nothing, depending on the current |
| 7802 | * availability of PCI vector resources. The device driver is responsible |
| 7803 | * for calling the individual request_irq() to register each MSI-X vector |
| 7804 | * with a interrupt handler, which is done in this function. Note that |
| 7805 | * later when device is unloading, the driver should always call free_irq() |
| 7806 | * on all MSI-X vectors it has done request_irq() on before calling |
| 7807 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 7808 | * will be left with MSI-X enabled and leaks its vectors. |
| 7809 | * |
| 7810 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7811 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7812 | * other values - error |
| 7813 | **/ |
| 7814 | static int |
| 7815 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 7816 | { |
| 7817 | int rc, i; |
| 7818 | LPFC_MBOXQ_t *pmb; |
| 7819 | |
| 7820 | /* Set up MSI-X multi-message vectors */ |
| 7821 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7822 | phba->msix_entries[i].entry = i; |
| 7823 | |
| 7824 | /* Configure MSI-X capability structure */ |
| 7825 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 7826 | ARRAY_SIZE(phba->msix_entries)); |
| 7827 | if (rc) { |
| 7828 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7829 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 7830 | goto msi_fail_out; |
| 7831 | } |
| 7832 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7833 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7834 | "0477 MSI-X entry[%d]: vector=x%x " |
| 7835 | "message=%d\n", i, |
| 7836 | phba->msix_entries[i].vector, |
| 7837 | phba->msix_entries[i].entry); |
| 7838 | /* |
| 7839 | * Assign MSI-X vectors to interrupt handlers |
| 7840 | */ |
| 7841 | |
| 7842 | /* vector-0 is associated to slow-path handler */ |
| 7843 | rc = request_irq(phba->msix_entries[0].vector, |
| 7844 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 7845 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 7846 | if (rc) { |
| 7847 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7848 | "0421 MSI-X slow-path request_irq failed " |
| 7849 | "(%d)\n", rc); |
| 7850 | goto msi_fail_out; |
| 7851 | } |
| 7852 | |
| 7853 | /* vector-1 is associated to fast-path handler */ |
| 7854 | rc = request_irq(phba->msix_entries[1].vector, |
| 7855 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 7856 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 7857 | |
| 7858 | if (rc) { |
| 7859 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7860 | "0429 MSI-X fast-path request_irq failed " |
| 7861 | "(%d)\n", rc); |
| 7862 | goto irq_fail_out; |
| 7863 | } |
| 7864 | |
| 7865 | /* |
| 7866 | * Configure HBA MSI-X attention conditions to messages |
| 7867 | */ |
| 7868 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7869 | |
| 7870 | if (!pmb) { |
| 7871 | rc = -ENOMEM; |
| 7872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7873 | "0474 Unable to allocate memory for issuing " |
| 7874 | "MBOX_CONFIG_MSI command\n"); |
| 7875 | goto mem_fail_out; |
| 7876 | } |
| 7877 | rc = lpfc_config_msi(phba, pmb); |
| 7878 | if (rc) |
| 7879 | goto mbx_fail_out; |
| 7880 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 7881 | if (rc != MBX_SUCCESS) { |
| 7882 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 7883 | "0351 Config MSI mailbox command failed, " |
| 7884 | "mbxCmd x%x, mbxStatus x%x\n", |
| 7885 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 7886 | goto mbx_fail_out; |
| 7887 | } |
| 7888 | |
| 7889 | /* Free memory allocated for mailbox command */ |
| 7890 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7891 | return rc; |
| 7892 | |
| 7893 | mbx_fail_out: |
| 7894 | /* Free memory allocated for mailbox command */ |
| 7895 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7896 | |
| 7897 | mem_fail_out: |
| 7898 | /* free the irq already requested */ |
| 7899 | free_irq(phba->msix_entries[1].vector, phba); |
| 7900 | |
| 7901 | irq_fail_out: |
| 7902 | /* free the irq already requested */ |
| 7903 | free_irq(phba->msix_entries[0].vector, phba); |
| 7904 | |
| 7905 | msi_fail_out: |
| 7906 | /* Unconfigure MSI-X capability structure */ |
| 7907 | pci_disable_msix(phba->pcidev); |
| 7908 | return rc; |
| 7909 | } |
| 7910 | |
| 7911 | /** |
| 7912 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 7913 | * @phba: pointer to lpfc hba data structure. |
| 7914 | * |
| 7915 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 7916 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 7917 | **/ |
| 7918 | static void |
| 7919 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 7920 | { |
| 7921 | int i; |
| 7922 | |
| 7923 | /* Free up MSI-X multi-message vectors */ |
| 7924 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7925 | free_irq(phba->msix_entries[i].vector, phba); |
| 7926 | /* Disable MSI-X */ |
| 7927 | pci_disable_msix(phba->pcidev); |
| 7928 | |
| 7929 | return; |
| 7930 | } |
| 7931 | |
| 7932 | /** |
| 7933 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 7934 | * @phba: pointer to lpfc hba data structure. |
| 7935 | * |
| 7936 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 7937 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 7938 | * enable the MSI vector. The device driver is responsible for calling the |
| 7939 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 7940 | * is done in this function. |
| 7941 | * |
| 7942 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7943 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7944 | * other values - error |
| 7945 | */ |
| 7946 | static int |
| 7947 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 7948 | { |
| 7949 | int rc; |
| 7950 | |
| 7951 | rc = pci_enable_msi(phba->pcidev); |
| 7952 | if (!rc) |
| 7953 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7954 | "0462 PCI enable MSI mode success.\n"); |
| 7955 | else { |
| 7956 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7957 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 7958 | return rc; |
| 7959 | } |
| 7960 | |
| 7961 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 7962 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 7963 | if (rc) { |
| 7964 | pci_disable_msi(phba->pcidev); |
| 7965 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7966 | "0478 MSI request_irq failed (%d)\n", rc); |
| 7967 | } |
| 7968 | return rc; |
| 7969 | } |
| 7970 | |
| 7971 | /** |
| 7972 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 7973 | * @phba: pointer to lpfc hba data structure. |
| 7974 | * |
| 7975 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 7976 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 7977 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 7978 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 7979 | * its vector. |
| 7980 | */ |
| 7981 | static void |
| 7982 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 7983 | { |
| 7984 | free_irq(phba->pcidev->irq, phba); |
| 7985 | pci_disable_msi(phba->pcidev); |
| 7986 | return; |
| 7987 | } |
| 7988 | |
| 7989 | /** |
| 7990 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 7991 | * @phba: pointer to lpfc hba data structure. |
| 7992 | * |
| 7993 | * This routine is invoked to enable device interrupt and associate driver's |
| 7994 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 7995 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 7996 | * will try to fallback from the configured interrupt mode to an interrupt |
| 7997 | * mode which is supported by the platform, kernel, and device in the order |
| 7998 | * of: |
| 7999 | * MSI-X -> MSI -> IRQ. |
| 8000 | * |
| 8001 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8002 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8003 | * other values - error |
| 8004 | **/ |
| 8005 | static uint32_t |
| 8006 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8007 | { |
| 8008 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8009 | int retval; |
| 8010 | |
| 8011 | if (cfg_mode == 2) { |
| 8012 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8013 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8014 | if (!retval) { |
| 8015 | /* Now, try to enable MSI-X interrupt mode */ |
| 8016 | retval = lpfc_sli_enable_msix(phba); |
| 8017 | if (!retval) { |
| 8018 | /* Indicate initialization to MSI-X mode */ |
| 8019 | phba->intr_type = MSIX; |
| 8020 | intr_mode = 2; |
| 8021 | } |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8026 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8027 | retval = lpfc_sli_enable_msi(phba); |
| 8028 | if (!retval) { |
| 8029 | /* Indicate initialization to MSI mode */ |
| 8030 | phba->intr_type = MSI; |
| 8031 | intr_mode = 1; |
| 8032 | } |
| 8033 | } |
| 8034 | |
| 8035 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8036 | if (phba->intr_type == NONE) { |
| 8037 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8038 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8039 | if (!retval) { |
| 8040 | /* Indicate initialization to INTx mode */ |
| 8041 | phba->intr_type = INTx; |
| 8042 | intr_mode = 0; |
| 8043 | } |
| 8044 | } |
| 8045 | return intr_mode; |
| 8046 | } |
| 8047 | |
| 8048 | /** |
| 8049 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8050 | * @phba: pointer to lpfc hba data structure. |
| 8051 | * |
| 8052 | * This routine is invoked to disable device interrupt and disassociate the |
| 8053 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8054 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8055 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8056 | **/ |
| 8057 | static void |
| 8058 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8059 | { |
| 8060 | /* Disable the currently initialized interrupt mode */ |
| 8061 | if (phba->intr_type == MSIX) |
| 8062 | lpfc_sli_disable_msix(phba); |
| 8063 | else if (phba->intr_type == MSI) |
| 8064 | lpfc_sli_disable_msi(phba); |
| 8065 | else if (phba->intr_type == INTx) |
| 8066 | free_irq(phba->pcidev->irq, phba); |
| 8067 | |
| 8068 | /* Reset interrupt management states */ |
| 8069 | phba->intr_type = NONE; |
| 8070 | phba->sli.slistat.sli_intr = 0; |
| 8071 | |
| 8072 | return; |
| 8073 | } |
| 8074 | |
| 8075 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8076 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8077 | * @phba: pointer to lpfc hba data structure. |
| 8078 | * |
| 8079 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8080 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 8081 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 8082 | * enables either all or nothing, depending on the current availability of |
| 8083 | * PCI vector resources. The device driver is responsible for calling the |
| 8084 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 8085 | * handler, which is done in this function. Note that later when device is |
| 8086 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 8087 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 8088 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 8089 | * enabled and leaks its vectors. |
| 8090 | * |
| 8091 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8092 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8093 | * other values - error |
| 8094 | **/ |
| 8095 | static int |
| 8096 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8097 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8098 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8099 | |
| 8100 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8101 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8102 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8103 | |
| 8104 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8105 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8106 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8107 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8108 | vectors); |
| 8109 | if (rc > 1) { |
| 8110 | vectors = rc; |
| 8111 | goto enable_msix_vectors; |
| 8112 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8113 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8114 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 8115 | goto msi_fail_out; |
| 8116 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8117 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8118 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8119 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8120 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8121 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8122 | "message=%d\n", index, |
| 8123 | phba->sli4_hba.msix_entries[index].vector, |
| 8124 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8125 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8126 | /* |
| 8127 | * Assign MSI-X vectors to interrupt handlers |
| 8128 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8129 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8130 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
| 8131 | sprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8132 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8134 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8135 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8136 | 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] | 8137 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8138 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8139 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8140 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8141 | if (rc) { |
| 8142 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8143 | "0486 MSI-X fast-path (%d) " |
| 8144 | "request_irq failed (%d)\n", index, rc); |
| 8145 | goto cfg_fail_out; |
| 8146 | } |
| 8147 | } |
| 8148 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8149 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8151 | "3238 Reducing IO channels to match number of " |
| 8152 | "MSI-X vectors, requested %d got %d\n", |
| 8153 | phba->cfg_fcp_io_channel, vectors); |
| 8154 | phba->cfg_fcp_io_channel = vectors; |
| 8155 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8156 | return rc; |
| 8157 | |
| 8158 | cfg_fail_out: |
| 8159 | /* free the irq already requested */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8160 | for (--index; index >= 0; index--) |
| 8161 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8162 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8163 | |
| 8164 | msi_fail_out: |
| 8165 | /* Unconfigure MSI-X capability structure */ |
| 8166 | pci_disable_msix(phba->pcidev); |
| 8167 | return rc; |
| 8168 | } |
| 8169 | |
| 8170 | /** |
| 8171 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 8172 | * @phba: pointer to lpfc hba data structure. |
| 8173 | * |
| 8174 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8175 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 8176 | **/ |
| 8177 | static void |
| 8178 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 8179 | { |
| 8180 | int index; |
| 8181 | |
| 8182 | /* Free up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8183 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8184 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8185 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8186 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8187 | /* Disable MSI-X */ |
| 8188 | pci_disable_msix(phba->pcidev); |
| 8189 | |
| 8190 | return; |
| 8191 | } |
| 8192 | |
| 8193 | /** |
| 8194 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8195 | * @phba: pointer to lpfc hba data structure. |
| 8196 | * |
| 8197 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8198 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8199 | * to enable the MSI vector. The device driver is responsible for calling |
| 8200 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8201 | * which is done in this function. |
| 8202 | * |
| 8203 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8204 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8205 | * other values - error |
| 8206 | **/ |
| 8207 | static int |
| 8208 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8209 | { |
| 8210 | int rc, index; |
| 8211 | |
| 8212 | rc = pci_enable_msi(phba->pcidev); |
| 8213 | if (!rc) |
| 8214 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8215 | "0487 PCI enable MSI mode success.\n"); |
| 8216 | else { |
| 8217 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8218 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8219 | return rc; |
| 8220 | } |
| 8221 | |
| 8222 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8223 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8224 | if (rc) { |
| 8225 | pci_disable_msi(phba->pcidev); |
| 8226 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8227 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8228 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8229 | } |
| 8230 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8231 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8232 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8233 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8234 | } |
| 8235 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8236 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8237 | } |
| 8238 | |
| 8239 | /** |
| 8240 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8241 | * @phba: pointer to lpfc hba data structure. |
| 8242 | * |
| 8243 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8244 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8245 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8246 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8247 | * its vector. |
| 8248 | **/ |
| 8249 | static void |
| 8250 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8251 | { |
| 8252 | free_irq(phba->pcidev->irq, phba); |
| 8253 | pci_disable_msi(phba->pcidev); |
| 8254 | return; |
| 8255 | } |
| 8256 | |
| 8257 | /** |
| 8258 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8259 | * @phba: pointer to lpfc hba data structure. |
| 8260 | * |
| 8261 | * This routine is invoked to enable device interrupt and associate driver's |
| 8262 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8263 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8264 | * the driver will try to fallback from the configured interrupt mode to an |
| 8265 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8266 | * the order of: |
| 8267 | * MSI-X -> MSI -> IRQ. |
| 8268 | * |
| 8269 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8270 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8271 | * other values - error |
| 8272 | **/ |
| 8273 | static uint32_t |
| 8274 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8275 | { |
| 8276 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8277 | int retval, index; |
| 8278 | |
| 8279 | if (cfg_mode == 2) { |
| 8280 | /* Preparation before conf_msi mbox cmd */ |
| 8281 | retval = 0; |
| 8282 | if (!retval) { |
| 8283 | /* Now, try to enable MSI-X interrupt mode */ |
| 8284 | retval = lpfc_sli4_enable_msix(phba); |
| 8285 | if (!retval) { |
| 8286 | /* Indicate initialization to MSI-X mode */ |
| 8287 | phba->intr_type = MSIX; |
| 8288 | intr_mode = 2; |
| 8289 | } |
| 8290 | } |
| 8291 | } |
| 8292 | |
| 8293 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8294 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8295 | retval = lpfc_sli4_enable_msi(phba); |
| 8296 | if (!retval) { |
| 8297 | /* Indicate initialization to MSI mode */ |
| 8298 | phba->intr_type = MSI; |
| 8299 | intr_mode = 1; |
| 8300 | } |
| 8301 | } |
| 8302 | |
| 8303 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8304 | if (phba->intr_type == NONE) { |
| 8305 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8306 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8307 | if (!retval) { |
| 8308 | /* Indicate initialization to INTx mode */ |
| 8309 | phba->intr_type = INTx; |
| 8310 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8311 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8312 | index++) { |
| 8313 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8314 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8315 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8316 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8317 | } |
| 8318 | } |
| 8319 | } |
| 8320 | return intr_mode; |
| 8321 | } |
| 8322 | |
| 8323 | /** |
| 8324 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8325 | * @phba: pointer to lpfc hba data structure. |
| 8326 | * |
| 8327 | * This routine is invoked to disable device interrupt and disassociate |
| 8328 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8329 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8330 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8331 | **/ |
| 8332 | static void |
| 8333 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 8334 | { |
| 8335 | /* Disable the currently initialized interrupt mode */ |
| 8336 | if (phba->intr_type == MSIX) |
| 8337 | lpfc_sli4_disable_msix(phba); |
| 8338 | else if (phba->intr_type == MSI) |
| 8339 | lpfc_sli4_disable_msi(phba); |
| 8340 | else if (phba->intr_type == INTx) |
| 8341 | free_irq(phba->pcidev->irq, phba); |
| 8342 | |
| 8343 | /* Reset interrupt management states */ |
| 8344 | phba->intr_type = NONE; |
| 8345 | phba->sli.slistat.sli_intr = 0; |
| 8346 | |
| 8347 | return; |
| 8348 | } |
| 8349 | |
| 8350 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8351 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 8352 | * @phba: pointer to lpfc hba data structure. |
| 8353 | * |
| 8354 | * This routine is invoked to unset the HBA device initialization steps to |
| 8355 | * a device with SLI-3 interface spec. |
| 8356 | **/ |
| 8357 | static void |
| 8358 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 8359 | { |
| 8360 | struct lpfc_vport *vport = phba->pport; |
| 8361 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8362 | |
| 8363 | spin_lock_irq(shost->host_lock); |
| 8364 | vport->load_flag |= FC_UNLOADING; |
| 8365 | spin_unlock_irq(shost->host_lock); |
| 8366 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8367 | kfree(phba->vpi_bmask); |
| 8368 | kfree(phba->vpi_ids); |
| 8369 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8370 | lpfc_stop_hba_timers(phba); |
| 8371 | |
| 8372 | phba->pport->work_port_events = 0; |
| 8373 | |
| 8374 | lpfc_sli_hba_down(phba); |
| 8375 | |
| 8376 | lpfc_sli_brdrestart(phba); |
| 8377 | |
| 8378 | lpfc_sli_disable_intr(phba); |
| 8379 | |
| 8380 | return; |
| 8381 | } |
| 8382 | |
| 8383 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8384 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. |
| 8385 | * @phba: pointer to lpfc hba data structure. |
| 8386 | * |
| 8387 | * This routine is invoked to unset the HBA device initialization steps to |
| 8388 | * a device with SLI-4 interface spec. |
| 8389 | **/ |
| 8390 | static void |
| 8391 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) |
| 8392 | { |
| 8393 | struct lpfc_vport *vport = phba->pport; |
| 8394 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8395 | |
| 8396 | spin_lock_irq(shost->host_lock); |
| 8397 | vport->load_flag |= FC_UNLOADING; |
| 8398 | spin_unlock_irq(shost->host_lock); |
| 8399 | |
| 8400 | phba->pport->work_port_events = 0; |
| 8401 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8402 | /* Stop the SLI4 device port */ |
| 8403 | lpfc_stop_port(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8404 | |
| 8405 | lpfc_sli4_disable_intr(phba); |
| 8406 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8407 | /* Reset SLI4 HBA FCoE function */ |
| 8408 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8409 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8410 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8411 | return; |
| 8412 | } |
| 8413 | |
| 8414 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8415 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 8416 | * @phba: Pointer to HBA context object. |
| 8417 | * |
| 8418 | * This function is called in the SLI4 code path to wait for completion |
| 8419 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 8420 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 8421 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 8422 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 8423 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 8424 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 8425 | * the rest of the driver unload resource release. |
| 8426 | **/ |
| 8427 | static void |
| 8428 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 8429 | { |
| 8430 | int wait_time = 0; |
| 8431 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8432 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8433 | |
| 8434 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 8435 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 8436 | if (!fcp_xri_cmpl) |
| 8437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8438 | "2877 FCP XRI exchange busy " |
| 8439 | "wait time: %d seconds.\n", |
| 8440 | wait_time/1000); |
| 8441 | if (!els_xri_cmpl) |
| 8442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8443 | "2878 ELS XRI exchange busy " |
| 8444 | "wait time: %d seconds.\n", |
| 8445 | wait_time/1000); |
| 8446 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 8447 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 8448 | } else { |
| 8449 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 8450 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 8451 | } |
| 8452 | fcp_xri_cmpl = |
| 8453 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8454 | els_xri_cmpl = |
| 8455 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8460 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 8461 | * @phba: Pointer to HBA context object. |
| 8462 | * |
| 8463 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 8464 | * function. The caller is not required to hold any lock. This routine |
| 8465 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 8466 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 8467 | * free any pending commands. |
| 8468 | **/ |
| 8469 | static void |
| 8470 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 8471 | { |
| 8472 | int wait_cnt = 0; |
| 8473 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8474 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8475 | |
| 8476 | lpfc_stop_hba_timers(phba); |
| 8477 | phba->sli4_hba.intr_enable = 0; |
| 8478 | |
| 8479 | /* |
| 8480 | * Gracefully wait out the potential current outstanding asynchronous |
| 8481 | * mailbox command. |
| 8482 | */ |
| 8483 | |
| 8484 | /* First, block any pending async mailbox command from posted */ |
| 8485 | spin_lock_irq(&phba->hbalock); |
| 8486 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 8487 | spin_unlock_irq(&phba->hbalock); |
| 8488 | /* Now, trying to wait it out if we can */ |
| 8489 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8490 | msleep(10); |
| 8491 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 8492 | break; |
| 8493 | } |
| 8494 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 8495 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8496 | spin_lock_irq(&phba->hbalock); |
| 8497 | mboxq = phba->sli.mbox_active; |
| 8498 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8499 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8500 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8501 | phba->sli.mbox_active = NULL; |
| 8502 | spin_unlock_irq(&phba->hbalock); |
| 8503 | } |
| 8504 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8505 | /* Abort all iocbs associated with the hba */ |
| 8506 | lpfc_sli_hba_iocb_abort(phba); |
| 8507 | |
| 8508 | /* Wait for completion of device XRI exchange busy */ |
| 8509 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 8510 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8511 | /* Disable PCI subsystem interrupt */ |
| 8512 | lpfc_sli4_disable_intr(phba); |
| 8513 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8514 | /* Disable SR-IOV if enabled */ |
| 8515 | if (phba->cfg_sriov_nr_virtfn) |
| 8516 | pci_disable_sriov(pdev); |
| 8517 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8518 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8519 | kthread_stop(phba->worker_thread); |
| 8520 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8521 | /* Reset SLI4 HBA FCoE function */ |
| 8522 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8523 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8524 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8525 | /* Stop the SLI4 device port */ |
| 8526 | phba->pport->work_port_events = 0; |
| 8527 | } |
| 8528 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8529 | /** |
| 8530 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 8531 | * @phba: Pointer to HBA context object. |
| 8532 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8533 | * |
| 8534 | * This function is called in the SLI4 code path to read the port's |
| 8535 | * sli4 capabilities. |
| 8536 | * |
| 8537 | * This function may be be called from any context that can block-wait |
| 8538 | * for the completion. The expectation is that this routine is called |
| 8539 | * typically from probe_one or from the online routine. |
| 8540 | **/ |
| 8541 | int |
| 8542 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8543 | { |
| 8544 | int rc; |
| 8545 | struct lpfc_mqe *mqe; |
| 8546 | struct lpfc_pc_sli4_params *sli4_params; |
| 8547 | uint32_t mbox_tmo; |
| 8548 | |
| 8549 | rc = 0; |
| 8550 | mqe = &mboxq->u.mqe; |
| 8551 | |
| 8552 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8553 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8554 | if (!phba->sli4_hba.intr_enable) |
| 8555 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8556 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8557 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8558 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8559 | } |
| 8560 | |
| 8561 | if (unlikely(rc)) |
| 8562 | return 1; |
| 8563 | |
| 8564 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8565 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 8566 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 8567 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 8568 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 8569 | &mqe->un.sli4_params); |
| 8570 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 8571 | &mqe->un.sli4_params); |
| 8572 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 8573 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 8574 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 8575 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 8576 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 8577 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 8578 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 8579 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 8580 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 8581 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 8582 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 8583 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 8584 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 8585 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 8586 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 8587 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 8588 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 8589 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 8590 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 8591 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 8592 | 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] | 8593 | |
| 8594 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8595 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8596 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8597 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8598 | return rc; |
| 8599 | } |
| 8600 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8602 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 8603 | * @phba: Pointer to HBA context object. |
| 8604 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8605 | * |
| 8606 | * This function is called in the SLI4 code path to read the port's |
| 8607 | * sli4 capabilities. |
| 8608 | * |
| 8609 | * This function may be be called from any context that can block-wait |
| 8610 | * for the completion. The expectation is that this routine is called |
| 8611 | * typically from probe_one or from the online routine. |
| 8612 | **/ |
| 8613 | int |
| 8614 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8615 | { |
| 8616 | int rc; |
| 8617 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 8618 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8619 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8620 | int length; |
| 8621 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 8622 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8623 | /* |
| 8624 | * By default, the driver assumes the SLI4 port requires RPI |
| 8625 | * header postings. The SLI4_PARAM response will correct this |
| 8626 | * assumption. |
| 8627 | */ |
| 8628 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 8629 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8630 | /* Read the port's SLI4 Config Parameters */ |
| 8631 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 8632 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8633 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8634 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 8635 | length, LPFC_SLI4_MBX_EMBED); |
| 8636 | if (!phba->sli4_hba.intr_enable) |
| 8637 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8638 | else { |
| 8639 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 8640 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8641 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8642 | if (unlikely(rc)) |
| 8643 | return rc; |
| 8644 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8645 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 8646 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 8647 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 8648 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 8649 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 8650 | mbx_sli4_parameters); |
| 8651 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 8652 | mbx_sli4_parameters); |
| 8653 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 8654 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 8655 | else |
| 8656 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 8657 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 8658 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
| 8659 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 8660 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 8661 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 8662 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
| 8663 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 8664 | mbx_sli4_parameters); |
| 8665 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 8666 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8667 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 8668 | 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] | 8669 | |
| 8670 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8671 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8672 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8673 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8674 | return 0; |
| 8675 | } |
| 8676 | |
| 8677 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8678 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 8679 | * @pdev: pointer to PCI device |
| 8680 | * @pid: pointer to PCI device identifier |
| 8681 | * |
| 8682 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 8683 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8684 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 8685 | * information of the device and driver to see if the driver state that it can |
| 8686 | * support this kind of device. If the match is successful, the driver core |
| 8687 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 8688 | * does all the initialization that it needs to do to handle the HBA properly. |
| 8689 | * |
| 8690 | * Return code |
| 8691 | * 0 - driver can claim the device |
| 8692 | * negative value - driver can not claim the device |
| 8693 | **/ |
| 8694 | static int __devinit |
| 8695 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 8696 | { |
| 8697 | struct lpfc_hba *phba; |
| 8698 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8699 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8700 | int error; |
| 8701 | uint32_t cfg_mode, intr_mode; |
| 8702 | |
| 8703 | /* Allocate memory for HBA structure */ |
| 8704 | phba = lpfc_hba_alloc(pdev); |
| 8705 | if (!phba) |
| 8706 | return -ENOMEM; |
| 8707 | |
| 8708 | /* Perform generic PCI device enabling operation */ |
| 8709 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8710 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8711 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8712 | |
| 8713 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 8714 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 8715 | if (error) |
| 8716 | goto out_disable_pci_dev; |
| 8717 | |
| 8718 | /* Set up SLI-3 specific device PCI memory space */ |
| 8719 | error = lpfc_sli_pci_mem_setup(phba); |
| 8720 | if (error) { |
| 8721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8722 | "1402 Failed to set up pci memory space.\n"); |
| 8723 | goto out_disable_pci_dev; |
| 8724 | } |
| 8725 | |
| 8726 | /* Set up phase-1 common device driver resources */ |
| 8727 | error = lpfc_setup_driver_resource_phase1(phba); |
| 8728 | if (error) { |
| 8729 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8730 | "1403 Failed to set up driver resource.\n"); |
| 8731 | goto out_unset_pci_mem_s3; |
| 8732 | } |
| 8733 | |
| 8734 | /* Set up SLI-3 specific device driver resources */ |
| 8735 | error = lpfc_sli_driver_resource_setup(phba); |
| 8736 | if (error) { |
| 8737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8738 | "1404 Failed to set up driver resource.\n"); |
| 8739 | goto out_unset_pci_mem_s3; |
| 8740 | } |
| 8741 | |
| 8742 | /* Initialize and populate the iocb list per host */ |
| 8743 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 8744 | if (error) { |
| 8745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8746 | "1405 Failed to initialize iocb list.\n"); |
| 8747 | goto out_unset_driver_resource_s3; |
| 8748 | } |
| 8749 | |
| 8750 | /* Set up common device driver resources */ |
| 8751 | error = lpfc_setup_driver_resource_phase2(phba); |
| 8752 | if (error) { |
| 8753 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8754 | "1406 Failed to set up driver resource.\n"); |
| 8755 | goto out_free_iocb_list; |
| 8756 | } |
| 8757 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8758 | /* Get the default values for Model Name and Description */ |
| 8759 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 8760 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8761 | /* Create SCSI host to the physical port */ |
| 8762 | error = lpfc_create_shost(phba); |
| 8763 | if (error) { |
| 8764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8765 | "1407 Failed to create scsi host.\n"); |
| 8766 | goto out_unset_driver_resource; |
| 8767 | } |
| 8768 | |
| 8769 | /* Configure sysfs attributes */ |
| 8770 | vport = phba->pport; |
| 8771 | error = lpfc_alloc_sysfs_attr(vport); |
| 8772 | if (error) { |
| 8773 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8774 | "1476 Failed to allocate sysfs attr\n"); |
| 8775 | goto out_destroy_shost; |
| 8776 | } |
| 8777 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8778 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8779 | /* Now, trying to enable interrupt and bring up the device */ |
| 8780 | cfg_mode = phba->cfg_use_msi; |
| 8781 | while (true) { |
| 8782 | /* Put device to a known state before enabling interrupt */ |
| 8783 | lpfc_stop_port(phba); |
| 8784 | /* Configure and enable interrupt */ |
| 8785 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 8786 | if (intr_mode == LPFC_INTR_ERROR) { |
| 8787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8788 | "0431 Failed to enable interrupt.\n"); |
| 8789 | error = -ENODEV; |
| 8790 | goto out_free_sysfs_attr; |
| 8791 | } |
| 8792 | /* SLI-3 HBA setup */ |
| 8793 | if (lpfc_sli_hba_setup(phba)) { |
| 8794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8795 | "1477 Failed to set up hba\n"); |
| 8796 | error = -ENODEV; |
| 8797 | goto out_remove_device; |
| 8798 | } |
| 8799 | |
| 8800 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 8801 | msleep(50); |
| 8802 | /* Check active interrupts on message signaled interrupts */ |
| 8803 | if (intr_mode == 0 || |
| 8804 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 8805 | /* Log the current active interrupt mode */ |
| 8806 | phba->intr_mode = intr_mode; |
| 8807 | lpfc_log_intr_mode(phba, intr_mode); |
| 8808 | break; |
| 8809 | } else { |
| 8810 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8811 | "0447 Configure interrupt mode (%d) " |
| 8812 | "failed active interrupt test.\n", |
| 8813 | intr_mode); |
| 8814 | /* Disable the current interrupt mode */ |
| 8815 | lpfc_sli_disable_intr(phba); |
| 8816 | /* Try next level of interrupt mode */ |
| 8817 | cfg_mode = --intr_mode; |
| 8818 | } |
| 8819 | } |
| 8820 | |
| 8821 | /* Perform post initialization setup */ |
| 8822 | lpfc_post_init_setup(phba); |
| 8823 | |
| 8824 | /* Check if there are static vports to be created. */ |
| 8825 | lpfc_create_static_vport(phba); |
| 8826 | |
| 8827 | return 0; |
| 8828 | |
| 8829 | out_remove_device: |
| 8830 | lpfc_unset_hba(phba); |
| 8831 | out_free_sysfs_attr: |
| 8832 | lpfc_free_sysfs_attr(vport); |
| 8833 | out_destroy_shost: |
| 8834 | lpfc_destroy_shost(phba); |
| 8835 | out_unset_driver_resource: |
| 8836 | lpfc_unset_driver_resource_phase2(phba); |
| 8837 | out_free_iocb_list: |
| 8838 | lpfc_free_iocb_list(phba); |
| 8839 | out_unset_driver_resource_s3: |
| 8840 | lpfc_sli_driver_resource_unset(phba); |
| 8841 | out_unset_pci_mem_s3: |
| 8842 | lpfc_sli_pci_mem_unset(phba); |
| 8843 | out_disable_pci_dev: |
| 8844 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8845 | if (shost) |
| 8846 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8847 | out_free_phba: |
| 8848 | lpfc_hba_free(phba); |
| 8849 | return error; |
| 8850 | } |
| 8851 | |
| 8852 | /** |
| 8853 | * 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] | 8854 | * @pdev: pointer to PCI device |
| 8855 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8856 | * This routine is to be called to disattach a device with SLI-3 interface |
| 8857 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8858 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 8859 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8860 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8861 | static void __devexit |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8862 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8863 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8864 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8865 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8866 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8867 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8868 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8869 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 8870 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8871 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8872 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8873 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8874 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8875 | lpfc_free_sysfs_attr(vport); |
| 8876 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8877 | /* Release all the vports against this physical port */ |
| 8878 | vports = lpfc_create_vport_work_array(phba); |
| 8879 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 8880 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 8881 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 8882 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8883 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 8884 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8885 | lpfc_destroy_vport_work_array(phba, vports); |
| 8886 | |
| 8887 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8888 | fc_remove_host(shost); |
| 8889 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8890 | lpfc_cleanup(vport); |
| 8891 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8892 | /* |
| 8893 | * Bring down the SLI Layer. This step disable all interrupts, |
| 8894 | * clears the rings, discards all mailbox commands, and resets |
| 8895 | * the HBA. |
| 8896 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8897 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 8898 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8899 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8900 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8901 | kthread_stop(phba->worker_thread); |
| 8902 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8903 | lpfc_sli_brdrestart(phba); |
| 8904 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8905 | kfree(phba->vpi_bmask); |
| 8906 | kfree(phba->vpi_ids); |
| 8907 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8908 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8909 | spin_lock_irq(&phba->hbalock); |
| 8910 | list_del_init(&vport->listentry); |
| 8911 | spin_unlock_irq(&phba->hbalock); |
| 8912 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8913 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8914 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8915 | /* Disable SR-IOV if enabled */ |
| 8916 | if (phba->cfg_sriov_nr_virtfn) |
| 8917 | pci_disable_sriov(pdev); |
| 8918 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8919 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8920 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8921 | |
| 8922 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8923 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8924 | |
| 8925 | /* |
| 8926 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 8927 | * corresponding pools here. |
| 8928 | */ |
| 8929 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8930 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8931 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8932 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 8933 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8934 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8935 | /* Free resources associated with SLI2 interface */ |
| 8936 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8937 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8938 | |
| 8939 | /* unmap adapter SLIM and Control Registers */ |
| 8940 | iounmap(phba->ctrl_regs_memmap_p); |
| 8941 | iounmap(phba->slim_memmap_p); |
| 8942 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8943 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8944 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8945 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8946 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8947 | } |
| 8948 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8949 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8950 | * 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] | 8951 | * @pdev: pointer to PCI device |
| 8952 | * @msg: power management message |
| 8953 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8954 | * This routine is to be called from the kernel's PCI subsystem to support |
| 8955 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 8956 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 8957 | * worker thread for the device, turning off device's interrupt and DMA, |
| 8958 | * and bring the device offline. Note that as the driver implements the |
| 8959 | * minimum PM requirements to a power-aware driver's PM support for the |
| 8960 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 8961 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 8962 | * fully reinitialize its device during resume() method call, the driver will |
| 8963 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 8964 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8965 | * |
| 8966 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8967 | * 0 - driver suspended the device |
| 8968 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8969 | **/ |
| 8970 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8971 | 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] | 8972 | { |
| 8973 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8974 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 8975 | |
| 8976 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8977 | "0473 PCI device Power Management suspend.\n"); |
| 8978 | |
| 8979 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 8980 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8981 | lpfc_offline(phba); |
| 8982 | kthread_stop(phba->worker_thread); |
| 8983 | |
| 8984 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8985 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8986 | |
| 8987 | /* Save device state to PCI config space */ |
| 8988 | pci_save_state(pdev); |
| 8989 | pci_set_power_state(pdev, PCI_D3hot); |
| 8990 | |
| 8991 | return 0; |
| 8992 | } |
| 8993 | |
| 8994 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8995 | * 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] | 8996 | * @pdev: pointer to PCI device |
| 8997 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8998 | * This routine is to be called from the kernel's PCI subsystem to support |
| 8999 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9000 | * invokes this method, it restores the device's PCI config space state and |
| 9001 | * fully reinitializes the device and brings it online. Note that as the |
| 9002 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9003 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9004 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9005 | * driver will fully reinitialize its device during resume() method call, |
| 9006 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9007 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9008 | * |
| 9009 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9010 | * 0 - driver suspended the device |
| 9011 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9012 | **/ |
| 9013 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9014 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9015 | { |
| 9016 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9017 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9018 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9019 | int error; |
| 9020 | |
| 9021 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9022 | "0452 PCI device Power Management resume.\n"); |
| 9023 | |
| 9024 | /* Restore device state from PCI config space */ |
| 9025 | pci_set_power_state(pdev, PCI_D0); |
| 9026 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9027 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9028 | /* |
| 9029 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9030 | * device saved_state flag, need to save the restored state again. |
| 9031 | */ |
| 9032 | pci_save_state(pdev); |
| 9033 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9034 | if (pdev->is_busmaster) |
| 9035 | pci_set_master(pdev); |
| 9036 | |
| 9037 | /* Startup the kernel thread for this host adapter. */ |
| 9038 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9039 | "lpfc_worker_%d", phba->brd_no); |
| 9040 | if (IS_ERR(phba->worker_thread)) { |
| 9041 | error = PTR_ERR(phba->worker_thread); |
| 9042 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9043 | "0434 PM resume failed to start worker " |
| 9044 | "thread: error=x%x.\n", error); |
| 9045 | return error; |
| 9046 | } |
| 9047 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9048 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9049 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9050 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9051 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9052 | "0430 PM resume Failed to enable interrupt\n"); |
| 9053 | return -EIO; |
| 9054 | } else |
| 9055 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9056 | |
| 9057 | /* Restart HBA and bring it online */ |
| 9058 | lpfc_sli_brdrestart(phba); |
| 9059 | lpfc_online(phba); |
| 9060 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9061 | /* Log the current active interrupt mode */ |
| 9062 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9063 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9064 | return 0; |
| 9065 | } |
| 9066 | |
| 9067 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9068 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9069 | * @phba: pointer to lpfc hba data structure. |
| 9070 | * |
| 9071 | * 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] | 9072 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9073 | **/ |
| 9074 | static void |
| 9075 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9076 | { |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9077 | struct lpfc_sli *psli = &phba->sli; |
| 9078 | struct lpfc_sli_ring *pring; |
| 9079 | |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9081 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9082 | |
| 9083 | /* |
| 9084 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9085 | * and let the SCSI mid-layer to retry them to recover. |
| 9086 | */ |
| 9087 | pring = &psli->ring[psli->fcp_ring]; |
| 9088 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9089 | } |
| 9090 | |
| 9091 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9092 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9093 | * @phba: pointer to lpfc hba data structure. |
| 9094 | * |
| 9095 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9096 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9097 | * pending I/Os. |
| 9098 | **/ |
| 9099 | static void |
| 9100 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9101 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9102 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9103 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9104 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9105 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9106 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9107 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9108 | /* Block all SCSI devices' I/Os on the host */ |
| 9109 | lpfc_scsi_dev_block(phba); |
| 9110 | |
| 9111 | /* stop all timers */ |
| 9112 | lpfc_stop_hba_timers(phba); |
| 9113 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9114 | /* Disable interrupt and pci device */ |
| 9115 | lpfc_sli_disable_intr(phba); |
| 9116 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9117 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9118 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9119 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9120 | } |
| 9121 | |
| 9122 | /** |
| 9123 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9124 | * @phba: pointer to lpfc hba data structure. |
| 9125 | * |
| 9126 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9127 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9128 | * pending I/Os. |
| 9129 | **/ |
| 9130 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9131 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9132 | { |
| 9133 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9134 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9135 | /* Block all SCSI devices' I/Os on the host */ |
| 9136 | lpfc_scsi_dev_block(phba); |
| 9137 | |
| 9138 | /* stop all timers */ |
| 9139 | lpfc_stop_hba_timers(phba); |
| 9140 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9141 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9142 | lpfc_sli_flush_fcp_rings(phba); |
| 9143 | } |
| 9144 | |
| 9145 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9146 | * 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] | 9147 | * @pdev: pointer to PCI device. |
| 9148 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9149 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9150 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9151 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9152 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9153 | * When this function is invoked, it will need to stop all the I/Os and |
| 9154 | * interrupt(s) to the device. Once that is done, it will return |
| 9155 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9156 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9157 | * |
| 9158 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9159 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9160 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9161 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9162 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9163 | static pci_ers_result_t |
| 9164 | 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] | 9165 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9166 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9167 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9168 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9169 | switch (state) { |
| 9170 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9171 | /* Non-fatal error, prepare for recovery */ |
| 9172 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9173 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9174 | case pci_channel_io_frozen: |
| 9175 | /* Fatal error, prepare for slot reset */ |
| 9176 | lpfc_sli_prep_dev_for_reset(phba); |
| 9177 | return PCI_ERS_RESULT_NEED_RESET; |
| 9178 | case pci_channel_io_perm_failure: |
| 9179 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9180 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9181 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9182 | default: |
| 9183 | /* Unknown state, prepare and request slot reset */ |
| 9184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9185 | "0472 Unknown PCI error state: x%x\n", state); |
| 9186 | lpfc_sli_prep_dev_for_reset(phba); |
| 9187 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9188 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9189 | } |
| 9190 | |
| 9191 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9192 | * 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] | 9193 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9194 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9195 | * This routine is called from the PCI subsystem for error handling to |
| 9196 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9197 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9198 | * During the PCI subsystem error recovery, after driver returns |
| 9199 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9200 | * recovery and then call this routine before calling the .resume method |
| 9201 | * to recover the device. This function will initialize the HBA device, |
| 9202 | * enable the interrupt, but it will just put the HBA to offline state |
| 9203 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9204 | * |
| 9205 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9206 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9207 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9208 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9209 | static pci_ers_result_t |
| 9210 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9211 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9212 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9213 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9214 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9215 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9216 | |
| 9217 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9218 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9219 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9220 | "PCI device after reset.\n"); |
| 9221 | return PCI_ERS_RESULT_DISCONNECT; |
| 9222 | } |
| 9223 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9224 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9225 | |
| 9226 | /* |
| 9227 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9228 | * device saved_state flag, need to save the restored state again. |
| 9229 | */ |
| 9230 | pci_save_state(pdev); |
| 9231 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9232 | if (pdev->is_busmaster) |
| 9233 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9234 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9235 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9236 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9237 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9238 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9239 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9240 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9241 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9243 | "0427 Cannot re-enable interrupt after " |
| 9244 | "slot reset.\n"); |
| 9245 | return PCI_ERS_RESULT_DISCONNECT; |
| 9246 | } else |
| 9247 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9248 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9249 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9250 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9251 | lpfc_offline(phba); |
| 9252 | lpfc_sli_brdrestart(phba); |
| 9253 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9254 | /* Log the current active interrupt mode */ |
| 9255 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9256 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9257 | return PCI_ERS_RESULT_RECOVERED; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9261 | * 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] | 9262 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9263 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9264 | * This routine is called from the PCI subsystem for error handling to device |
| 9265 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9266 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9267 | * error recovery. After this call, traffic can start to flow from this device |
| 9268 | * again. |
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 | static void |
| 9271 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9272 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9273 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9274 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9275 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9276 | /* 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] | 9277 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9278 | |
| 9279 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9280 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9281 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9282 | } |
| 9283 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9284 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9285 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9286 | * @phba: pointer to lpfc hba data structure. |
| 9287 | * |
| 9288 | * returns the number of ELS/CT IOCBs to reserve |
| 9289 | **/ |
| 9290 | int |
| 9291 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9292 | { |
| 9293 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9294 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9295 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9296 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9297 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9298 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9299 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9300 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9301 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9302 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9303 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9304 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9305 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9306 | else if (max_xri <= 2048) |
| 9307 | return 200; |
| 9308 | else |
| 9309 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9310 | } else |
| 9311 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9312 | } |
| 9313 | |
| 9314 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9315 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9316 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9317 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9318 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9319 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9320 | static void |
| 9321 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9322 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9323 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9324 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9325 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9326 | struct list_head dma_buffer_list; |
| 9327 | int i, rc = 0; |
| 9328 | struct lpfc_dmabuf *dmabuf, *next; |
| 9329 | uint32_t offset = 0, temp_offset = 0; |
| 9330 | |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9331 | /* It can be null, sanity check */ |
| 9332 | if (!fw) { |
| 9333 | rc = -ENXIO; |
| 9334 | goto out; |
| 9335 | } |
| 9336 | image = (struct lpfc_grp_hdr *)fw->data; |
| 9337 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9338 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9339 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9340 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9341 | LPFC_FILE_TYPE_GROUP) || |
| 9342 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9343 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9344 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9345 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9346 | "Magic:%x Type:%x ID:%x\n", |
| 9347 | be32_to_cpu(image->magic_number), |
| 9348 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9349 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9350 | rc = -EINVAL; |
| 9351 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9352 | } |
| 9353 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9354 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9356 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9357 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9358 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9359 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9360 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9361 | GFP_KERNEL); |
| 9362 | if (!dmabuf) { |
| 9363 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9364 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9365 | } |
| 9366 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 9367 | SLI4_PAGE_SIZE, |
| 9368 | &dmabuf->phys, |
| 9369 | GFP_KERNEL); |
| 9370 | if (!dmabuf->virt) { |
| 9371 | kfree(dmabuf); |
| 9372 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9373 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9374 | } |
| 9375 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 9376 | } |
| 9377 | while (offset < fw->size) { |
| 9378 | temp_offset = offset; |
| 9379 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9380 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9381 | memcpy(dmabuf->virt, |
| 9382 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9383 | fw->size - temp_offset); |
| 9384 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9385 | break; |
| 9386 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9387 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 9388 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9389 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9390 | } |
| 9391 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 9392 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9393 | if (rc) |
| 9394 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9395 | } |
| 9396 | rc = offset; |
| 9397 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9398 | |
| 9399 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9400 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 9401 | list_del(&dmabuf->list); |
| 9402 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 9403 | dmabuf->virt, dmabuf->phys); |
| 9404 | kfree(dmabuf); |
| 9405 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9406 | release_firmware(fw); |
| 9407 | out: |
| 9408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9409 | "3024 Firmware update done: %d.", rc); |
| 9410 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9411 | } |
| 9412 | |
| 9413 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9414 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 9415 | * @pdev: pointer to PCI device |
| 9416 | * @pid: pointer to PCI device identifier |
| 9417 | * |
| 9418 | * This routine is called from the kernel's PCI subsystem to device with |
| 9419 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9420 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9421 | * information of the device and driver to see if the driver state that it |
| 9422 | * can support this kind of device. If the match is successful, the driver |
| 9423 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 9424 | * it does all the initialization that it needs to do to handle the HBA |
| 9425 | * properly. |
| 9426 | * |
| 9427 | * Return code |
| 9428 | * 0 - driver can claim the device |
| 9429 | * negative value - driver can not claim the device |
| 9430 | **/ |
| 9431 | static int __devinit |
| 9432 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9433 | { |
| 9434 | struct lpfc_hba *phba; |
| 9435 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9436 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9437 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9438 | uint32_t cfg_mode, intr_mode; |
| 9439 | int mcnt; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9440 | int adjusted_fcp_io_channel; |
James Smart | 5402a31 | 2012-09-29 11:30:06 -0400 | [diff] [blame] | 9441 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9442 | |
| 9443 | /* Allocate memory for HBA structure */ |
| 9444 | phba = lpfc_hba_alloc(pdev); |
| 9445 | if (!phba) |
| 9446 | return -ENOMEM; |
| 9447 | |
| 9448 | /* Perform generic PCI device enabling operation */ |
| 9449 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9450 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9451 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9452 | |
| 9453 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 9454 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 9455 | if (error) |
| 9456 | goto out_disable_pci_dev; |
| 9457 | |
| 9458 | /* Set up SLI-4 specific device PCI memory space */ |
| 9459 | error = lpfc_sli4_pci_mem_setup(phba); |
| 9460 | if (error) { |
| 9461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9462 | "1410 Failed to set up pci memory space.\n"); |
| 9463 | goto out_disable_pci_dev; |
| 9464 | } |
| 9465 | |
| 9466 | /* Set up phase-1 common device driver resources */ |
| 9467 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9468 | if (error) { |
| 9469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9470 | "1411 Failed to set up driver resource.\n"); |
| 9471 | goto out_unset_pci_mem_s4; |
| 9472 | } |
| 9473 | |
| 9474 | /* Set up SLI-4 Specific device driver resources */ |
| 9475 | error = lpfc_sli4_driver_resource_setup(phba); |
| 9476 | if (error) { |
| 9477 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9478 | "1412 Failed to set up driver resource.\n"); |
| 9479 | goto out_unset_pci_mem_s4; |
| 9480 | } |
| 9481 | |
| 9482 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9483 | |
| 9484 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9485 | "2821 initialize iocb list %d.\n", |
| 9486 | phba->cfg_iocb_cnt*1024); |
| 9487 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 9488 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9489 | if (error) { |
| 9490 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9491 | "1413 Failed to initialize iocb list.\n"); |
| 9492 | goto out_unset_driver_resource_s4; |
| 9493 | } |
| 9494 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9495 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 9496 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9497 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9498 | /* Set up common device driver resources */ |
| 9499 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9500 | if (error) { |
| 9501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9502 | "1414 Failed to set up driver resource.\n"); |
| 9503 | goto out_free_iocb_list; |
| 9504 | } |
| 9505 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9506 | /* Get the default values for Model Name and Description */ |
| 9507 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9508 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9509 | /* Create SCSI host to the physical port */ |
| 9510 | error = lpfc_create_shost(phba); |
| 9511 | if (error) { |
| 9512 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9513 | "1415 Failed to create scsi host.\n"); |
| 9514 | goto out_unset_driver_resource; |
| 9515 | } |
| 9516 | |
| 9517 | /* Configure sysfs attributes */ |
| 9518 | vport = phba->pport; |
| 9519 | error = lpfc_alloc_sysfs_attr(vport); |
| 9520 | if (error) { |
| 9521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9522 | "1416 Failed to allocate sysfs attr\n"); |
| 9523 | goto out_destroy_shost; |
| 9524 | } |
| 9525 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9526 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9527 | /* Now, trying to enable interrupt and bring up the device */ |
| 9528 | cfg_mode = phba->cfg_use_msi; |
| 9529 | while (true) { |
| 9530 | /* Put device to a known state before enabling interrupt */ |
| 9531 | lpfc_stop_port(phba); |
| 9532 | /* Configure and enable interrupt */ |
| 9533 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 9534 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9536 | "0426 Failed to enable interrupt.\n"); |
| 9537 | error = -ENODEV; |
| 9538 | goto out_free_sysfs_attr; |
| 9539 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9540 | /* Default to single EQ for non-MSI-X */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 9541 | if (phba->intr_type != MSIX) |
James Smart | 1c13bf6 | 2012-08-14 14:26:20 -0400 | [diff] [blame] | 9542 | adjusted_fcp_io_channel = 1; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9543 | else |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9544 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 9545 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9546 | /* Set up SLI-4 HBA */ |
| 9547 | if (lpfc_sli4_hba_setup(phba)) { |
| 9548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9549 | "1421 Failed to set up hba\n"); |
| 9550 | error = -ENODEV; |
| 9551 | goto out_disable_intr; |
| 9552 | } |
| 9553 | |
| 9554 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
| 9555 | if (intr_mode != 0) |
| 9556 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, |
| 9557 | LPFC_ACT_INTR_CNT); |
| 9558 | |
| 9559 | /* Check active interrupts received only for MSI/MSI-X */ |
| 9560 | if (intr_mode == 0 || |
| 9561 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
| 9562 | /* Log the current active interrupt mode */ |
| 9563 | phba->intr_mode = intr_mode; |
| 9564 | lpfc_log_intr_mode(phba, intr_mode); |
| 9565 | break; |
| 9566 | } |
| 9567 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9568 | "0451 Configure interrupt mode (%d) " |
| 9569 | "failed active interrupt test.\n", |
| 9570 | intr_mode); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9571 | /* Unset the previous SLI-4 HBA setup. */ |
| 9572 | /* |
| 9573 | * TODO: Is this operation compatible with IF TYPE 2 |
| 9574 | * devices? All port state is deleted and cleared. |
| 9575 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9576 | lpfc_sli4_unset_hba(phba); |
| 9577 | /* Try next level of interrupt mode */ |
| 9578 | cfg_mode = --intr_mode; |
| 9579 | } |
| 9580 | |
| 9581 | /* Perform post initialization setup */ |
| 9582 | lpfc_post_init_setup(phba); |
| 9583 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 9584 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
| 9585 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 9586 | LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 5402a31 | 2012-09-29 11:30:06 -0400 | [diff] [blame] | 9587 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", |
| 9588 | phba->ModelName); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9589 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 9590 | file_name, &phba->pcidev->dev, |
| 9591 | GFP_KERNEL, (void *)phba, |
| 9592 | lpfc_write_firmware); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9593 | } |
| 9594 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 9595 | /* Check if there are static vports to be created. */ |
| 9596 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9597 | return 0; |
| 9598 | |
| 9599 | out_disable_intr: |
| 9600 | lpfc_sli4_disable_intr(phba); |
| 9601 | out_free_sysfs_attr: |
| 9602 | lpfc_free_sysfs_attr(vport); |
| 9603 | out_destroy_shost: |
| 9604 | lpfc_destroy_shost(phba); |
| 9605 | out_unset_driver_resource: |
| 9606 | lpfc_unset_driver_resource_phase2(phba); |
| 9607 | out_free_iocb_list: |
| 9608 | lpfc_free_iocb_list(phba); |
| 9609 | out_unset_driver_resource_s4: |
| 9610 | lpfc_sli4_driver_resource_unset(phba); |
| 9611 | out_unset_pci_mem_s4: |
| 9612 | lpfc_sli4_pci_mem_unset(phba); |
| 9613 | out_disable_pci_dev: |
| 9614 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9615 | if (shost) |
| 9616 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9617 | out_free_phba: |
| 9618 | lpfc_hba_free(phba); |
| 9619 | return error; |
| 9620 | } |
| 9621 | |
| 9622 | /** |
| 9623 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 9624 | * @pdev: pointer to PCI device |
| 9625 | * |
| 9626 | * This routine is called from the kernel's PCI subsystem to device with |
| 9627 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9628 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9629 | * device to be removed from the PCI subsystem properly. |
| 9630 | **/ |
| 9631 | static void __devexit |
| 9632 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 9633 | { |
| 9634 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9635 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 9636 | struct lpfc_vport **vports; |
| 9637 | struct lpfc_hba *phba = vport->phba; |
| 9638 | int i; |
| 9639 | |
| 9640 | /* Mark the device unloading flag */ |
| 9641 | spin_lock_irq(&phba->hbalock); |
| 9642 | vport->load_flag |= FC_UNLOADING; |
| 9643 | spin_unlock_irq(&phba->hbalock); |
| 9644 | |
| 9645 | /* Free the HBA sysfs attributes */ |
| 9646 | lpfc_free_sysfs_attr(vport); |
| 9647 | |
| 9648 | /* Release all the vports against this physical port */ |
| 9649 | vports = lpfc_create_vport_work_array(phba); |
| 9650 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9651 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9652 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9653 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9654 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9655 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9656 | lpfc_destroy_vport_work_array(phba, vports); |
| 9657 | |
| 9658 | /* Remove FC host and then SCSI host with the physical port */ |
| 9659 | fc_remove_host(shost); |
| 9660 | scsi_remove_host(shost); |
| 9661 | |
| 9662 | /* Perform cleanup on the physical port */ |
| 9663 | lpfc_cleanup(vport); |
| 9664 | |
| 9665 | /* |
| 9666 | * Bring down the SLI Layer. This step disables all interrupts, |
| 9667 | * clears the rings, discards all mailbox commands, and resets |
| 9668 | * the HBA FCoE function. |
| 9669 | */ |
| 9670 | lpfc_debugfs_terminate(vport); |
| 9671 | lpfc_sli4_hba_unset(phba); |
| 9672 | |
| 9673 | spin_lock_irq(&phba->hbalock); |
| 9674 | list_del_init(&vport->listentry); |
| 9675 | spin_unlock_irq(&phba->hbalock); |
| 9676 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9677 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9678 | * buffers are released to their corresponding pools here. |
| 9679 | */ |
| 9680 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9681 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9682 | lpfc_sli4_driver_resource_unset(phba); |
| 9683 | |
| 9684 | /* Unmap adapter Control and Doorbell registers */ |
| 9685 | lpfc_sli4_pci_mem_unset(phba); |
| 9686 | |
| 9687 | /* Release PCI resources and disable device's PCI function */ |
| 9688 | scsi_host_put(shost); |
| 9689 | lpfc_disable_pci_dev(phba); |
| 9690 | |
| 9691 | /* Finally, free the driver's device data structure */ |
| 9692 | lpfc_hba_free(phba); |
| 9693 | |
| 9694 | return; |
| 9695 | } |
| 9696 | |
| 9697 | /** |
| 9698 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 9699 | * @pdev: pointer to PCI device |
| 9700 | * @msg: power management message |
| 9701 | * |
| 9702 | * This routine is called from the kernel's PCI subsystem to support system |
| 9703 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 9704 | * this method, it quiesces the device by stopping the driver's worker |
| 9705 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 9706 | * the device offline. Note that as the driver implements the minimum PM |
| 9707 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 9708 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 9709 | * method call will be treated as SUSPEND and the driver will fully |
| 9710 | * reinitialize its device during resume() method call, the driver will set |
| 9711 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 9712 | * according to the @msg provided by the PM. |
| 9713 | * |
| 9714 | * Return code |
| 9715 | * 0 - driver suspended the device |
| 9716 | * Error otherwise |
| 9717 | **/ |
| 9718 | static int |
| 9719 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 9720 | { |
| 9721 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9722 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9723 | |
| 9724 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9725 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9726 | |
| 9727 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9728 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9729 | lpfc_offline(phba); |
| 9730 | kthread_stop(phba->worker_thread); |
| 9731 | |
| 9732 | /* Disable interrupt from device */ |
| 9733 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9734 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9735 | |
| 9736 | /* Save device state to PCI config space */ |
| 9737 | pci_save_state(pdev); |
| 9738 | pci_set_power_state(pdev, PCI_D3hot); |
| 9739 | |
| 9740 | return 0; |
| 9741 | } |
| 9742 | |
| 9743 | /** |
| 9744 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 9745 | * @pdev: pointer to PCI device |
| 9746 | * |
| 9747 | * This routine is called from the kernel's PCI subsystem to support system |
| 9748 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 9749 | * this method, it restores the device's PCI config space state and fully |
| 9750 | * reinitializes the device and brings it online. Note that as the driver |
| 9751 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 9752 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9753 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 9754 | * will fully reinitialize its device during resume() method call, the device |
| 9755 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 9756 | * state. |
| 9757 | * |
| 9758 | * Return code |
| 9759 | * 0 - driver suspended the device |
| 9760 | * Error otherwise |
| 9761 | **/ |
| 9762 | static int |
| 9763 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 9764 | { |
| 9765 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9766 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9767 | uint32_t intr_mode; |
| 9768 | int error; |
| 9769 | |
| 9770 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9771 | "0292 PCI device Power Management resume.\n"); |
| 9772 | |
| 9773 | /* Restore device state from PCI config space */ |
| 9774 | pci_set_power_state(pdev, PCI_D0); |
| 9775 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9776 | |
| 9777 | /* |
| 9778 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9779 | * device saved_state flag, need to save the restored state again. |
| 9780 | */ |
| 9781 | pci_save_state(pdev); |
| 9782 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9783 | if (pdev->is_busmaster) |
| 9784 | pci_set_master(pdev); |
| 9785 | |
| 9786 | /* Startup the kernel thread for this host adapter. */ |
| 9787 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9788 | "lpfc_worker_%d", phba->brd_no); |
| 9789 | if (IS_ERR(phba->worker_thread)) { |
| 9790 | error = PTR_ERR(phba->worker_thread); |
| 9791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9792 | "0293 PM resume failed to start worker " |
| 9793 | "thread: error=x%x.\n", error); |
| 9794 | return error; |
| 9795 | } |
| 9796 | |
| 9797 | /* Configure and enable interrupt */ |
| 9798 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9799 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9801 | "0294 PM resume Failed to enable interrupt\n"); |
| 9802 | return -EIO; |
| 9803 | } else |
| 9804 | phba->intr_mode = intr_mode; |
| 9805 | |
| 9806 | /* Restart HBA and bring it online */ |
| 9807 | lpfc_sli_brdrestart(phba); |
| 9808 | lpfc_online(phba); |
| 9809 | |
| 9810 | /* Log the current active interrupt mode */ |
| 9811 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9812 | |
| 9813 | return 0; |
| 9814 | } |
| 9815 | |
| 9816 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9817 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 9818 | * @phba: pointer to lpfc hba data structure. |
| 9819 | * |
| 9820 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 9821 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 9822 | **/ |
| 9823 | static void |
| 9824 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9825 | { |
| 9826 | struct lpfc_sli *psli = &phba->sli; |
| 9827 | struct lpfc_sli_ring *pring; |
| 9828 | |
| 9829 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9830 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 9831 | /* |
| 9832 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9833 | * and let the SCSI mid-layer to retry them to recover. |
| 9834 | */ |
| 9835 | pring = &psli->ring[psli->fcp_ring]; |
| 9836 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 9837 | } |
| 9838 | |
| 9839 | /** |
| 9840 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 9841 | * @phba: pointer to lpfc hba data structure. |
| 9842 | * |
| 9843 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 9844 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9845 | * pending I/Os. |
| 9846 | **/ |
| 9847 | static void |
| 9848 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9849 | { |
| 9850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9851 | "2826 PCI channel disable preparing for reset\n"); |
| 9852 | |
| 9853 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9854 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9855 | |
| 9856 | /* Block all SCSI devices' I/Os on the host */ |
| 9857 | lpfc_scsi_dev_block(phba); |
| 9858 | |
| 9859 | /* stop all timers */ |
| 9860 | lpfc_stop_hba_timers(phba); |
| 9861 | |
| 9862 | /* Disable interrupt and pci device */ |
| 9863 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9864 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9865 | pci_disable_device(phba->pcidev); |
| 9866 | |
| 9867 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9868 | lpfc_sli_flush_fcp_rings(phba); |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 9873 | * @phba: pointer to lpfc hba data structure. |
| 9874 | * |
| 9875 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 9876 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9877 | * pending I/Os. |
| 9878 | **/ |
| 9879 | static void |
| 9880 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 9881 | { |
| 9882 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9883 | "2827 PCI channel permanent disable for failure\n"); |
| 9884 | |
| 9885 | /* Block all SCSI devices' I/Os on the host */ |
| 9886 | lpfc_scsi_dev_block(phba); |
| 9887 | |
| 9888 | /* stop all timers */ |
| 9889 | lpfc_stop_hba_timers(phba); |
| 9890 | |
| 9891 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9892 | lpfc_sli_flush_fcp_rings(phba); |
| 9893 | } |
| 9894 | |
| 9895 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9896 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 9897 | * @pdev: pointer to PCI device. |
| 9898 | * @state: the current PCI connection state. |
| 9899 | * |
| 9900 | * This routine is called from the PCI subsystem for error handling to device |
| 9901 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 9902 | * after a PCI bus error affecting this device has been detected. When this |
| 9903 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 9904 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 9905 | * for the PCI subsystem to perform proper recovery as desired. |
| 9906 | * |
| 9907 | * Return codes |
| 9908 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9909 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9910 | **/ |
| 9911 | static pci_ers_result_t |
| 9912 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 9913 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9914 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9915 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9916 | |
| 9917 | switch (state) { |
| 9918 | case pci_channel_io_normal: |
| 9919 | /* Non-fatal error, prepare for recovery */ |
| 9920 | lpfc_sli4_prep_dev_for_recover(phba); |
| 9921 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9922 | case pci_channel_io_frozen: |
| 9923 | /* Fatal error, prepare for slot reset */ |
| 9924 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9925 | return PCI_ERS_RESULT_NEED_RESET; |
| 9926 | case pci_channel_io_perm_failure: |
| 9927 | /* Permanent failure, prepare for device down */ |
| 9928 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 9929 | return PCI_ERS_RESULT_DISCONNECT; |
| 9930 | default: |
| 9931 | /* Unknown state, prepare and request slot reset */ |
| 9932 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9933 | "2825 Unknown PCI error state: x%x\n", state); |
| 9934 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9935 | return PCI_ERS_RESULT_NEED_RESET; |
| 9936 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9937 | } |
| 9938 | |
| 9939 | /** |
| 9940 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 9941 | * @pdev: pointer to PCI device. |
| 9942 | * |
| 9943 | * This routine is called from the PCI subsystem for error handling to device |
| 9944 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 9945 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 9946 | * PCI subsystem error recovery, after the driver returns |
| 9947 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9948 | * recovery and then call this routine before calling the .resume method to |
| 9949 | * recover the device. This function will initialize the HBA device, enable |
| 9950 | * the interrupt, but it will just put the HBA to offline state without |
| 9951 | * passing any I/O traffic. |
| 9952 | * |
| 9953 | * Return codes |
| 9954 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9955 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9956 | */ |
| 9957 | static pci_ers_result_t |
| 9958 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 9959 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9960 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9961 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9962 | struct lpfc_sli *psli = &phba->sli; |
| 9963 | uint32_t intr_mode; |
| 9964 | |
| 9965 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 9966 | if (pci_enable_device_mem(pdev)) { |
| 9967 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9968 | "PCI device after reset.\n"); |
| 9969 | return PCI_ERS_RESULT_DISCONNECT; |
| 9970 | } |
| 9971 | |
| 9972 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 9973 | |
| 9974 | /* |
| 9975 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9976 | * device saved_state flag, need to save the restored state again. |
| 9977 | */ |
| 9978 | pci_save_state(pdev); |
| 9979 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9980 | if (pdev->is_busmaster) |
| 9981 | pci_set_master(pdev); |
| 9982 | |
| 9983 | spin_lock_irq(&phba->hbalock); |
| 9984 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 9985 | spin_unlock_irq(&phba->hbalock); |
| 9986 | |
| 9987 | /* Configure and enable interrupt */ |
| 9988 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9989 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9991 | "2824 Cannot re-enable interrupt after " |
| 9992 | "slot reset.\n"); |
| 9993 | return PCI_ERS_RESULT_DISCONNECT; |
| 9994 | } else |
| 9995 | phba->intr_mode = intr_mode; |
| 9996 | |
| 9997 | /* Log the current active interrupt mode */ |
| 9998 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9999 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10000 | return PCI_ERS_RESULT_RECOVERED; |
| 10001 | } |
| 10002 | |
| 10003 | /** |
| 10004 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10005 | * @pdev: pointer to PCI device |
| 10006 | * |
| 10007 | * This routine is called from the PCI subsystem for error handling to device |
| 10008 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10009 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10010 | * error recovery. After this call, traffic can start to flow from this device |
| 10011 | * again. |
| 10012 | **/ |
| 10013 | static void |
| 10014 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10015 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10016 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10017 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10018 | |
| 10019 | /* |
| 10020 | * In case of slot reset, as function reset is performed through |
| 10021 | * mailbox command which needs DMA to be enabled, this operation |
| 10022 | * has to be moved to the io resume phase. Taking device offline |
| 10023 | * will perform the necessary cleanup. |
| 10024 | */ |
| 10025 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10026 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10027 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10028 | lpfc_offline(phba); |
| 10029 | lpfc_sli_brdrestart(phba); |
| 10030 | /* Bring the device back online */ |
| 10031 | lpfc_online(phba); |
| 10032 | } |
| 10033 | |
| 10034 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10035 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10036 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10037 | } |
| 10038 | |
| 10039 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10040 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10041 | * @pdev: pointer to PCI device |
| 10042 | * @pid: pointer to PCI device identifier |
| 10043 | * |
| 10044 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10045 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10046 | * at PCI device-specific information of the device and driver to see if the |
| 10047 | * driver state that it can support this kind of device. If the match is |
| 10048 | * successful, the driver core invokes this routine. This routine dispatches |
| 10049 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10050 | * do all the initialization that it needs to do to handle the HBA device |
| 10051 | * properly. |
| 10052 | * |
| 10053 | * Return code |
| 10054 | * 0 - driver can claim the device |
| 10055 | * negative value - driver can not claim the device |
| 10056 | **/ |
| 10057 | static int __devinit |
| 10058 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10059 | { |
| 10060 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10061 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10062 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10063 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10064 | return -ENODEV; |
| 10065 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10066 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10067 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10068 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10069 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10070 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10071 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10072 | return rc; |
| 10073 | } |
| 10074 | |
| 10075 | /** |
| 10076 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10077 | * @pdev: pointer to PCI device |
| 10078 | * |
| 10079 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10080 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10081 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10082 | * remove routine, which will perform all the necessary cleanup for the |
| 10083 | * device to be removed from the PCI subsystem properly. |
| 10084 | **/ |
| 10085 | static void __devexit |
| 10086 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10087 | { |
| 10088 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10089 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10090 | |
| 10091 | switch (phba->pci_dev_grp) { |
| 10092 | case LPFC_PCI_DEV_LP: |
| 10093 | lpfc_pci_remove_one_s3(pdev); |
| 10094 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10095 | case LPFC_PCI_DEV_OC: |
| 10096 | lpfc_pci_remove_one_s4(pdev); |
| 10097 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10098 | default: |
| 10099 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10100 | "1424 Invalid PCI device group: 0x%x\n", |
| 10101 | phba->pci_dev_grp); |
| 10102 | break; |
| 10103 | } |
| 10104 | return; |
| 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10109 | * @pdev: pointer to PCI device |
| 10110 | * @msg: power management message |
| 10111 | * |
| 10112 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10113 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10114 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10115 | * suspend the device. |
| 10116 | * |
| 10117 | * Return code |
| 10118 | * 0 - driver suspended the device |
| 10119 | * Error otherwise |
| 10120 | **/ |
| 10121 | static int |
| 10122 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10123 | { |
| 10124 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10125 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10126 | int rc = -ENODEV; |
| 10127 | |
| 10128 | switch (phba->pci_dev_grp) { |
| 10129 | case LPFC_PCI_DEV_LP: |
| 10130 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10131 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10132 | case LPFC_PCI_DEV_OC: |
| 10133 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10134 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10135 | default: |
| 10136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10137 | "1425 Invalid PCI device group: 0x%x\n", |
| 10138 | phba->pci_dev_grp); |
| 10139 | break; |
| 10140 | } |
| 10141 | return rc; |
| 10142 | } |
| 10143 | |
| 10144 | /** |
| 10145 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10146 | * @pdev: pointer to PCI device |
| 10147 | * |
| 10148 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10149 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10150 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10151 | * resume the device. |
| 10152 | * |
| 10153 | * Return code |
| 10154 | * 0 - driver suspended the device |
| 10155 | * Error otherwise |
| 10156 | **/ |
| 10157 | static int |
| 10158 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10159 | { |
| 10160 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10161 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10162 | int rc = -ENODEV; |
| 10163 | |
| 10164 | switch (phba->pci_dev_grp) { |
| 10165 | case LPFC_PCI_DEV_LP: |
| 10166 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10167 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10168 | case LPFC_PCI_DEV_OC: |
| 10169 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10170 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10171 | default: |
| 10172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10173 | "1426 Invalid PCI device group: 0x%x\n", |
| 10174 | phba->pci_dev_grp); |
| 10175 | break; |
| 10176 | } |
| 10177 | return rc; |
| 10178 | } |
| 10179 | |
| 10180 | /** |
| 10181 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10182 | * @pdev: pointer to PCI device. |
| 10183 | * @state: the current PCI connection state. |
| 10184 | * |
| 10185 | * This routine is registered to the PCI subsystem for error handling. This |
| 10186 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10187 | * this device has been detected. When this routine is invoked, it dispatches |
| 10188 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 10189 | * routine, which will perform the proper error detected operation. |
| 10190 | * |
| 10191 | * Return codes |
| 10192 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10193 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10194 | **/ |
| 10195 | static pci_ers_result_t |
| 10196 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 10197 | { |
| 10198 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10199 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10200 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10201 | |
| 10202 | switch (phba->pci_dev_grp) { |
| 10203 | case LPFC_PCI_DEV_LP: |
| 10204 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10205 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10206 | case LPFC_PCI_DEV_OC: |
| 10207 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10208 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10209 | default: |
| 10210 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10211 | "1427 Invalid PCI device group: 0x%x\n", |
| 10212 | phba->pci_dev_grp); |
| 10213 | break; |
| 10214 | } |
| 10215 | return rc; |
| 10216 | } |
| 10217 | |
| 10218 | /** |
| 10219 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10220 | * @pdev: pointer to PCI device. |
| 10221 | * |
| 10222 | * This routine is registered to the PCI subsystem for error handling. This |
| 10223 | * function is called after PCI bus has been reset to restart the PCI card |
| 10224 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10225 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10226 | * routine, which will perform the proper device reset. |
| 10227 | * |
| 10228 | * Return codes |
| 10229 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10230 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10231 | **/ |
| 10232 | static pci_ers_result_t |
| 10233 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10234 | { |
| 10235 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10236 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10237 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10238 | |
| 10239 | switch (phba->pci_dev_grp) { |
| 10240 | case LPFC_PCI_DEV_LP: |
| 10241 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10242 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10243 | case LPFC_PCI_DEV_OC: |
| 10244 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10245 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10246 | default: |
| 10247 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10248 | "1428 Invalid PCI device group: 0x%x\n", |
| 10249 | phba->pci_dev_grp); |
| 10250 | break; |
| 10251 | } |
| 10252 | return rc; |
| 10253 | } |
| 10254 | |
| 10255 | /** |
| 10256 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10257 | * @pdev: pointer to PCI device |
| 10258 | * |
| 10259 | * This routine is registered to the PCI subsystem for error handling. It |
| 10260 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10261 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10262 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10263 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10264 | **/ |
| 10265 | static void |
| 10266 | lpfc_io_resume(struct pci_dev *pdev) |
| 10267 | { |
| 10268 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10269 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10270 | |
| 10271 | switch (phba->pci_dev_grp) { |
| 10272 | case LPFC_PCI_DEV_LP: |
| 10273 | lpfc_io_resume_s3(pdev); |
| 10274 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10275 | case LPFC_PCI_DEV_OC: |
| 10276 | lpfc_io_resume_s4(pdev); |
| 10277 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10278 | default: |
| 10279 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10280 | "1429 Invalid PCI device group: 0x%x\n", |
| 10281 | phba->pci_dev_grp); |
| 10282 | break; |
| 10283 | } |
| 10284 | return; |
| 10285 | } |
| 10286 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10287 | /** |
| 10288 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace |
| 10289 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10290 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10291 | * |
| 10292 | * This routine puts a reference count on the lpfc module whenever the |
| 10293 | * character device is opened |
| 10294 | **/ |
| 10295 | static int |
| 10296 | lpfc_mgmt_open(struct inode *inode, struct file *filep) |
| 10297 | { |
| 10298 | try_module_get(THIS_MODULE); |
| 10299 | return 0; |
| 10300 | } |
| 10301 | |
| 10302 | /** |
| 10303 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace |
| 10304 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10305 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10306 | * |
| 10307 | * This routine removes a reference count from the lpfc module when the |
| 10308 | * character device is closed |
| 10309 | **/ |
| 10310 | static int |
| 10311 | lpfc_mgmt_release(struct inode *inode, struct file *filep) |
| 10312 | { |
| 10313 | module_put(THIS_MODULE); |
| 10314 | return 0; |
| 10315 | } |
| 10316 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10317 | static struct pci_device_id lpfc_id_table[] = { |
| 10318 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 10319 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 10320 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 10321 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10322 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 10323 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10324 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 10325 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10326 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 10327 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10328 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 10329 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10330 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 10331 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10332 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 10333 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10334 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 10335 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10336 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 10337 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10338 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 10339 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10340 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 10341 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10342 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 10343 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10344 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 10345 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10346 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_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_BMID, |
| 10349 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10350 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 10351 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10352 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 10353 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10354 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 10355 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10356 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 10357 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10358 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 10359 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10360 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 10361 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10362 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 10363 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10364 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 10365 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10366 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 10367 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10368 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 10369 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10370 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 10371 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10372 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 10373 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 10374 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 10375 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10376 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 10377 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10378 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 10379 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10380 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 10381 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10382 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 10383 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10384 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 10385 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10386 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 10387 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10388 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 10389 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10390 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 10391 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10392 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 10393 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10394 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 10395 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10396 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10397 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 10398 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 10399 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 10400 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 10401 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10402 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 10403 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 10404 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 10405 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10406 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 10407 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 10408 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 10409 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10410 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 10411 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10412 | { 0 } |
| 10413 | }; |
| 10414 | |
| 10415 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 10416 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 10417 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10418 | .error_detected = lpfc_io_error_detected, |
| 10419 | .slot_reset = lpfc_io_slot_reset, |
| 10420 | .resume = lpfc_io_resume, |
| 10421 | }; |
| 10422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10423 | static struct pci_driver lpfc_driver = { |
| 10424 | .name = LPFC_DRIVER_NAME, |
| 10425 | .id_table = lpfc_id_table, |
| 10426 | .probe = lpfc_pci_probe_one, |
| 10427 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10428 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10429 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10430 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10431 | }; |
| 10432 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10433 | static const struct file_operations lpfc_mgmt_fop = { |
| 10434 | .open = lpfc_mgmt_open, |
| 10435 | .release = lpfc_mgmt_release, |
| 10436 | }; |
| 10437 | |
| 10438 | static struct miscdevice lpfc_mgmt_dev = { |
| 10439 | .minor = MISC_DYNAMIC_MINOR, |
| 10440 | .name = "lpfcmgmt", |
| 10441 | .fops = &lpfc_mgmt_fop, |
| 10442 | }; |
| 10443 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10444 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10445 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10446 | * |
| 10447 | * This routine is to be invoked when the lpfc module is loaded into the |
| 10448 | * kernel. The special kernel macro module_init() is used to indicate the |
| 10449 | * role of this routine to the kernel as lpfc module entry point. |
| 10450 | * |
| 10451 | * Return codes |
| 10452 | * 0 - successful |
| 10453 | * -ENOMEM - FC attach transport failed |
| 10454 | * all others - failed |
| 10455 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10456 | static int __init |
| 10457 | lpfc_init(void) |
| 10458 | { |
| 10459 | int error = 0; |
| 10460 | |
| 10461 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10462 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10463 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10464 | error = misc_register(&lpfc_mgmt_dev); |
| 10465 | if (error) |
| 10466 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 10467 | "misc_register returned with status %d", error); |
| 10468 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10469 | if (lpfc_enable_npiv) { |
| 10470 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 10471 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 10472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10473 | lpfc_transport_template = |
| 10474 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10475 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10476 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10477 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10478 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10479 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 10480 | if (lpfc_vport_transport_template == NULL) { |
| 10481 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10482 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10483 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10484 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10485 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10486 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10487 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10488 | if (lpfc_enable_npiv) |
| 10489 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10490 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10491 | |
| 10492 | return error; |
| 10493 | } |
| 10494 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10495 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10496 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10497 | * |
| 10498 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 10499 | * The special kernel macro module_exit() is used to indicate the role of |
| 10500 | * this routine to the kernel as lpfc module exit point. |
| 10501 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10502 | static void __exit |
| 10503 | lpfc_exit(void) |
| 10504 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10505 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10506 | pci_unregister_driver(&lpfc_driver); |
| 10507 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10508 | if (lpfc_enable_npiv) |
| 10509 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10510 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10511 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 10512 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10513 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 10514 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 10515 | } |
| 10516 | |
| 10517 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10518 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 10519 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10520 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 10521 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 10522 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10523 | } |
| 10524 | |
| 10525 | module_init(lpfc_init); |
| 10526 | module_exit(lpfc_exit); |
| 10527 | MODULE_LICENSE("GPL"); |
| 10528 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 10529 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 10530 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |