| 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 | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 544 | mod_timer(&vport->els_tmofunc, |
| 545 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 546 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 547 | mod_timer(&phba->hb_tmofunc, |
| 548 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 549 | phba->hb_outstanding = 0; |
| 550 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 551 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 552 | mod_timer(&phba->eratt_poll, |
| 553 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 554 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 555 | if (phba->hba_flag & LINK_DISABLED) { |
| 556 | lpfc_printf_log(phba, |
| 557 | KERN_ERR, LOG_INIT, |
| 558 | "2598 Adapter Link is disabled.\n"); |
| 559 | lpfc_down_link(phba, pmb); |
| 560 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 561 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 562 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 563 | lpfc_printf_log(phba, |
| 564 | KERN_ERR, LOG_INIT, |
| 565 | "2599 Adapter failed to issue DOWN_LINK" |
| 566 | " mbox command rc 0x%x\n", rc); |
| 567 | |
| 568 | mempool_free(pmb, phba->mbox_mem_pool); |
| 569 | return -EIO; |
| 570 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 571 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 572 | mempool_free(pmb, phba->mbox_mem_pool); |
| 573 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 574 | if (rc) |
| 575 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 576 | } |
| 577 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 578 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 579 | if (!pmb) { |
| 580 | phba->link_state = LPFC_HBA_ERROR; |
| 581 | return -ENOMEM; |
| 582 | } |
| 583 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 584 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 585 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 586 | pmb->vport = phba->pport; |
| 587 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 589 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 590 | lpfc_printf_log(phba, |
| 591 | KERN_ERR, |
| 592 | LOG_INIT, |
| 593 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 594 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 595 | rc); |
| 596 | mempool_free(pmb, phba->mbox_mem_pool); |
| 597 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 598 | |
| 599 | /* Get Option rom version */ |
| 600 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 601 | if (!pmb) { |
| 602 | phba->link_state = LPFC_HBA_ERROR; |
| 603 | return -ENOMEM; |
| 604 | } |
| 605 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 606 | lpfc_dump_wakeup_param(phba, pmb); |
| 607 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 608 | pmb->vport = phba->pport; |
| 609 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 610 | |
| 611 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 612 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 613 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 614 | mempool_free(pmb, phba->mbox_mem_pool); |
| 615 | } |
| 616 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 617 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 618 | } |
| 619 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 620 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 621 | * lpfc_hba_init_link - Initialize the FC link |
| 622 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 623 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 624 | * |
| 625 | * This routine will issue the INIT_LINK mailbox command call. |
| 626 | * It is available to other drivers through the lpfc_hba data |
| 627 | * structure for use as a delayed link up mechanism with the |
| 628 | * module parameter lpfc_suppress_link_up. |
| 629 | * |
| 630 | * Return code |
| 631 | * 0 - success |
| 632 | * Any other value - error |
| 633 | **/ |
| 634 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 635 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 636 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 637 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 642 | * @phba: pointer to lpfc hba data structure. |
| 643 | * @fc_topology: desired fc topology. |
| 644 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 645 | * |
| 646 | * This routine will issue the INIT_LINK mailbox command call. |
| 647 | * It is available to other drivers through the lpfc_hba data |
| 648 | * structure for use as a delayed link up mechanism with the |
| 649 | * module parameter lpfc_suppress_link_up. |
| 650 | * |
| 651 | * Return code |
| 652 | * 0 - success |
| 653 | * Any other value - error |
| 654 | **/ |
| 655 | int |
| 656 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 657 | uint32_t flag) |
| 658 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 659 | struct lpfc_vport *vport = phba->pport; |
| 660 | LPFC_MBOXQ_t *pmb; |
| 661 | MAILBOX_t *mb; |
| 662 | int rc; |
| 663 | |
| 664 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 665 | if (!pmb) { |
| 666 | phba->link_state = LPFC_HBA_ERROR; |
| 667 | return -ENOMEM; |
| 668 | } |
| 669 | mb = &pmb->u.mb; |
| 670 | pmb->vport = vport; |
| 671 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 672 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 673 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 674 | !(phba->lmt & LMT_1Gb)) || |
| 675 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 676 | !(phba->lmt & LMT_2Gb)) || |
| 677 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 678 | !(phba->lmt & LMT_4Gb)) || |
| 679 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 680 | !(phba->lmt & LMT_8Gb)) || |
| 681 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 682 | !(phba->lmt & LMT_10Gb)) || |
| 683 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
| 684 | !(phba->lmt & LMT_16Gb))) { |
| 685 | /* Reset link speed to auto */ |
| 686 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 687 | "1302 Invalid speed for this board:%d " |
| 688 | "Reset link speed to auto.\n", |
| 689 | phba->cfg_link_speed); |
| 690 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 691 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 692 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 693 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 694 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 695 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 696 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 697 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 698 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 699 | "0498 Adapter failed to init, mbxCmd x%x " |
| 700 | "INIT_LINK, mbxStatus x%x\n", |
| 701 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 702 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 703 | /* Clear all interrupt enable conditions */ |
| 704 | writel(0, phba->HCregaddr); |
| 705 | readl(phba->HCregaddr); /* flush */ |
| 706 | /* Clear all pending interrupts */ |
| 707 | writel(0xffffffff, phba->HAregaddr); |
| 708 | readl(phba->HAregaddr); /* flush */ |
| 709 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 710 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 711 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 712 | mempool_free(pmb, phba->mbox_mem_pool); |
| 713 | return -EIO; |
| 714 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 715 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 716 | if (flag == MBX_POLL) |
| 717 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 724 | * @phba: pointer to lpfc hba data structure. |
| 725 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 726 | * |
| 727 | * This routine will issue the DOWN_LINK mailbox command call. |
| 728 | * It is available to other drivers through the lpfc_hba data |
| 729 | * structure for use to stop the link. |
| 730 | * |
| 731 | * Return code |
| 732 | * 0 - success |
| 733 | * Any other value - error |
| 734 | **/ |
| 735 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 736 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 737 | { |
| 738 | LPFC_MBOXQ_t *pmb; |
| 739 | int rc; |
| 740 | |
| 741 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 742 | if (!pmb) { |
| 743 | phba->link_state = LPFC_HBA_ERROR; |
| 744 | return -ENOMEM; |
| 745 | } |
| 746 | |
| 747 | lpfc_printf_log(phba, |
| 748 | KERN_ERR, LOG_INIT, |
| 749 | "0491 Adapter Link is disabled.\n"); |
| 750 | lpfc_down_link(phba, pmb); |
| 751 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 752 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 753 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 754 | lpfc_printf_log(phba, |
| 755 | KERN_ERR, LOG_INIT, |
| 756 | "2522 Adapter failed to issue DOWN_LINK" |
| 757 | " mbox command rc 0x%x\n", rc); |
| 758 | |
| 759 | mempool_free(pmb, phba->mbox_mem_pool); |
| 760 | return -EIO; |
| 761 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 762 | if (flag == MBX_POLL) |
| 763 | mempool_free(pmb, phba->mbox_mem_pool); |
| 764 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 769 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 770 | * @phba: pointer to lpfc HBA data structure. |
| 771 | * |
| 772 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 773 | * bringing down the SLI Layer. |
| 774 | * |
| 775 | * Return codes |
| 776 | * 0 - success. |
| 777 | * Any other value - error. |
| 778 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 779 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 780 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 782 | struct lpfc_vport **vports; |
| 783 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 784 | |
| 785 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 786 | /* Disable interrupts */ |
| 787 | writel(0, phba->HCregaddr); |
| 788 | readl(phba->HCregaddr); /* flush */ |
| 789 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 790 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 791 | if (phba->pport->load_flag & FC_UNLOADING) |
| 792 | lpfc_cleanup_discovery_resources(phba->pport); |
| 793 | else { |
| 794 | vports = lpfc_create_vport_work_array(phba); |
| 795 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 796 | for (i = 0; i <= phba->max_vports && |
| 797 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 798 | lpfc_cleanup_discovery_resources(vports[i]); |
| 799 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 800 | } |
| 801 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 802 | } |
| 803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 804 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 805 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 806 | * @phba: pointer to lpfc HBA data structure. |
| 807 | * |
| 808 | * This routine will do uninitialization after the HBA is reset when bring |
| 809 | * down the SLI Layer. |
| 810 | * |
| 811 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 812 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 813 | * Any other value - error. |
| 814 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 815 | static int |
| 816 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 817 | { |
| 818 | struct lpfc_sli *psli = &phba->sli; |
| 819 | struct lpfc_sli_ring *pring; |
| 820 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 821 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 822 | int i; |
| 823 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 824 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 825 | lpfc_sli_hbqbuf_free_all(phba); |
| 826 | else { |
| 827 | /* Cleanup preposted buffers on the ELS ring */ |
| 828 | pring = &psli->ring[LPFC_ELS_RING]; |
| 829 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 830 | list_del(&mp->list); |
| 831 | pring->postbufq_cnt--; |
| 832 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 833 | kfree(mp); |
| 834 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 835 | } |
| 836 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 837 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 838 | for (i = 0; i < psli->num_rings; i++) { |
| 839 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 840 | |
| 841 | /* At this point in time the HBA is either reset or DOA. Either |
| 842 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 843 | */ |
| 844 | list_splice_init(&pring->txcmplq, &completions); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 845 | spin_unlock_irq(&phba->hbalock); |
| 846 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 847 | /* Cancel all the IOCBs from the completions list */ |
| 848 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 849 | IOERR_SLI_ABORTED); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 850 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 851 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 852 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 853 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 854 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 855 | |
| 856 | return 0; |
| 857 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 858 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 859 | /** |
| 860 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 861 | * @phba: pointer to lpfc HBA data structure. |
| 862 | * |
| 863 | * This routine will do uninitialization after the HBA is reset when bring |
| 864 | * down the SLI Layer. |
| 865 | * |
| 866 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 867 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 868 | * Any other value - error. |
| 869 | **/ |
| 870 | static int |
| 871 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 872 | { |
| 873 | struct lpfc_scsi_buf *psb, *psb_next; |
| 874 | LIST_HEAD(aborts); |
| 875 | int ret; |
| 876 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 877 | struct lpfc_sglq *sglq_entry = NULL; |
| 878 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 879 | ret = lpfc_hba_down_post_s3(phba); |
| 880 | if (ret) |
| 881 | return ret; |
| 882 | /* At this point in time the HBA is either reset or DOA. Either |
| 883 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 884 | * on the lpfc_sgl_list so that it can either be freed if the |
| 885 | * driver is unloading or reposted if the driver is restarting |
| 886 | * the port. |
| 887 | */ |
| 888 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 889 | /* scsl_buf_list */ |
| 890 | /* abts_sgl_list_lock required because worker thread uses this |
| 891 | * list. |
| 892 | */ |
| 893 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 894 | list_for_each_entry(sglq_entry, |
| 895 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 896 | sglq_entry->state = SGL_FREED; |
| 897 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 898 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 899 | &phba->sli4_hba.lpfc_sgl_list); |
| 900 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 901 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 902 | * list. |
| 903 | */ |
| 904 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 905 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 906 | &aborts); |
| 907 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 908 | spin_unlock_irq(&phba->hbalock); |
| 909 | |
| 910 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 911 | psb->pCmd = NULL; |
| 912 | psb->status = IOSTAT_SUCCESS; |
| 913 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 914 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 915 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 916 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 922 | * @phba: pointer to lpfc HBA data structure. |
| 923 | * |
| 924 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 925 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 926 | * |
| 927 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 928 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 929 | * Any other value - error. |
| 930 | **/ |
| 931 | int |
| 932 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 933 | { |
| 934 | return (*phba->lpfc_hba_down_post)(phba); |
| 935 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 936 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 937 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 938 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 939 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 940 | * |
| 941 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 942 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 943 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 944 | * event will be used by the worker thread to invoke the actual timeout |
| 945 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 946 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 947 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 948 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 949 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 950 | lpfc_hb_timeout(unsigned long ptr) |
| 951 | { |
| 952 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 953 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 954 | unsigned long iflag; |
| 955 | |
| 956 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 957 | |
| 958 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 959 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 960 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 961 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 962 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 963 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 964 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 965 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 966 | if (!tmo_posted) |
| 967 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 971 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 972 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 973 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 974 | * |
| 975 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 976 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 977 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 978 | * event will be used by the worker thread to invoke the actual timeout |
| 979 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 980 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 981 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 982 | **/ |
| 983 | static void |
| 984 | lpfc_rrq_timeout(unsigned long ptr) |
| 985 | { |
| 986 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 987 | unsigned long iflag; |
| 988 | |
| 989 | phba = (struct lpfc_hba *)ptr; |
| 990 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 991 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 992 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 993 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 997 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 998 | * @phba: pointer to lpfc hba data structure. |
| 999 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1000 | * |
| 1001 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1002 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1003 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1004 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1005 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1006 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1007 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1008 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1009 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1010 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1011 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1012 | static void |
| 1013 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1014 | { |
| 1015 | unsigned long drvr_flag; |
| 1016 | |
| 1017 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1018 | phba->hb_outstanding = 0; |
| 1019 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1020 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1021 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1022 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1023 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1024 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1025 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1026 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1027 | jiffies + |
| 1028 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1029 | return; |
| 1030 | } |
| 1031 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1032 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1033 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1034 | * @phba: pointer to lpfc hba data structure. |
| 1035 | * |
| 1036 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1037 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1038 | * handler performs any periodic operations needed for the device. If such |
| 1039 | * periodic event has already been attended to either in the interrupt handler |
| 1040 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1041 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1042 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1043 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1044 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1045 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1046 | * to offline. |
| 1047 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1048 | void |
| 1049 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1050 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1051 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1052 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1053 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1054 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1055 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1056 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1057 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1058 | vports = lpfc_create_vport_work_array(phba); |
| 1059 | if (vports != NULL) |
| 1060 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1061 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1062 | lpfc_destroy_vport_work_array(phba, vports); |
| 1063 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1064 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1065 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1066 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1067 | return; |
| 1068 | |
| 1069 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1070 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1071 | if (time_after(phba->last_completion_time + |
| 1072 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1073 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1074 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1075 | if (!phba->hb_outstanding) |
| 1076 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1077 | jiffies + |
| 1078 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1079 | else |
| 1080 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1081 | jiffies + |
| 1082 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1086 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1087 | if (phba->elsbuf_cnt && |
| 1088 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1089 | spin_lock_irq(&phba->hbalock); |
| 1090 | list_splice_init(&phba->elsbuf, &completions); |
| 1091 | phba->elsbuf_cnt = 0; |
| 1092 | phba->elsbuf_prev_cnt = 0; |
| 1093 | spin_unlock_irq(&phba->hbalock); |
| 1094 | |
| 1095 | while (!list_empty(&completions)) { |
| 1096 | list_remove_head(&completions, buf_ptr, |
| 1097 | struct lpfc_dmabuf, list); |
| 1098 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1099 | kfree(buf_ptr); |
| 1100 | } |
| 1101 | } |
| 1102 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1103 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1104 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1105 | if (phba->cfg_enable_hba_heartbeat) { |
| 1106 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1107 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1108 | (list_empty(&psli->mboxq))) { |
| 1109 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1110 | GFP_KERNEL); |
| 1111 | if (!pmboxq) { |
| 1112 | mod_timer(&phba->hb_tmofunc, |
| 1113 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1114 | msecs_to_jiffies(1000 * |
| 1115 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1116 | return; |
| 1117 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1118 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1119 | lpfc_heart_beat(phba, pmboxq); |
| 1120 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1121 | pmboxq->vport = phba->pport; |
| 1122 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1123 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1124 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1125 | if (retval != MBX_BUSY && |
| 1126 | retval != MBX_SUCCESS) { |
| 1127 | mempool_free(pmboxq, |
| 1128 | phba->mbox_mem_pool); |
| 1129 | mod_timer(&phba->hb_tmofunc, |
| 1130 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1131 | msecs_to_jiffies(1000 * |
| 1132 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1133 | return; |
| 1134 | } |
| 1135 | phba->skipped_hb = 0; |
| 1136 | phba->hb_outstanding = 1; |
| 1137 | } else if (time_before_eq(phba->last_completion_time, |
| 1138 | phba->skipped_hb)) { |
| 1139 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1140 | "2857 Last completion time not " |
| 1141 | " updated in %d ms\n", |
| 1142 | jiffies_to_msecs(jiffies |
| 1143 | - phba->last_completion_time)); |
| 1144 | } else |
| 1145 | phba->skipped_hb = jiffies; |
| 1146 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1147 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1148 | jiffies + |
| 1149 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1150 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1151 | } else { |
| 1152 | /* |
| 1153 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1154 | * we need to give the hb mailbox cmd a chance to |
| 1155 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1156 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1157 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1158 | "0459 Adapter heartbeat still out" |
| 1159 | "standing:last compl time was %d ms.\n", |
| 1160 | jiffies_to_msecs(jiffies |
| 1161 | - phba->last_completion_time)); |
| 1162 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1163 | jiffies + |
| 1164 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1165 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1169 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1170 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1171 | * @phba: pointer to lpfc hba data structure. |
| 1172 | * |
| 1173 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1174 | * other than Port Error 6 has been detected. |
| 1175 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1176 | static void |
| 1177 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1178 | { |
| 1179 | struct lpfc_sli *psli = &phba->sli; |
| 1180 | |
| 1181 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1182 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1183 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1184 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1185 | |
| 1186 | lpfc_offline(phba); |
| 1187 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1188 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1189 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1190 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1191 | lpfc_hba_down_post(phba); |
| 1192 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1193 | lpfc_unblock_mgmt_io(phba); |
| 1194 | phba->link_state = LPFC_HBA_ERROR; |
| 1195 | return; |
| 1196 | } |
| 1197 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1198 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1199 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1200 | * @phba: pointer to lpfc hba data structure. |
| 1201 | * |
| 1202 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1203 | * other than Port Error 6 has been detected. |
| 1204 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1205 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1206 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1207 | { |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1208 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1209 | lpfc_offline(phba); |
| 1210 | lpfc_sli4_brdreset(phba); |
| 1211 | lpfc_hba_down_post(phba); |
| 1212 | lpfc_sli4_post_status_check(phba); |
| 1213 | lpfc_unblock_mgmt_io(phba); |
| 1214 | phba->link_state = LPFC_HBA_ERROR; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1218 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1219 | * @phba: pointer to lpfc hba data structure. |
| 1220 | * |
| 1221 | * This routine is invoked to handle the deferred HBA hardware error |
| 1222 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1223 | * and another ER bit in the host status register. The driver will |
| 1224 | * wait until the ER1 bit clears before handling the error condition. |
| 1225 | **/ |
| 1226 | static void |
| 1227 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1228 | { |
| 1229 | uint32_t old_host_status = phba->work_hs; |
| 1230 | struct lpfc_sli_ring *pring; |
| 1231 | struct lpfc_sli *psli = &phba->sli; |
| 1232 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1233 | /* If the pci channel is offline, ignore possible errors, |
| 1234 | * since we cannot communicate with the pci card anyway. |
| 1235 | */ |
| 1236 | if (pci_channel_offline(phba->pcidev)) { |
| 1237 | spin_lock_irq(&phba->hbalock); |
| 1238 | phba->hba_flag &= ~DEFER_ERATT; |
| 1239 | spin_unlock_irq(&phba->hbalock); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1243 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1244 | "0479 Deferred Adapter Hardware Error " |
| 1245 | "Data: x%x x%x x%x\n", |
| 1246 | phba->work_hs, |
| 1247 | phba->work_status[0], phba->work_status[1]); |
| 1248 | |
| 1249 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1250 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1251 | spin_unlock_irq(&phba->hbalock); |
| 1252 | |
| 1253 | |
| 1254 | /* |
| 1255 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1256 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1257 | * SCSI layer retry it after re-establishing link. |
| 1258 | */ |
| 1259 | pring = &psli->ring[psli->fcp_ring]; |
| 1260 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1261 | |
| 1262 | /* |
| 1263 | * There was a firmware error. Take the hba offline and then |
| 1264 | * attempt to restart it. |
| 1265 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1266 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1267 | lpfc_offline(phba); |
| 1268 | |
| 1269 | /* Wait for the ER1 bit to clear.*/ |
| 1270 | while (phba->work_hs & HS_FFER1) { |
| 1271 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1272 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1273 | phba->work_hs = UNPLUG_ERR ; |
| 1274 | break; |
| 1275 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1276 | /* If driver is unloading let the worker thread continue */ |
| 1277 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1278 | phba->work_hs = 0; |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | /* |
| 1284 | * This is to ptrotect against a race condition in which |
| 1285 | * first write to the host attention register clear the |
| 1286 | * host status register. |
| 1287 | */ |
| 1288 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1289 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1290 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1291 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1292 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1293 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1294 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1295 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1296 | } |
| 1297 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1298 | static void |
| 1299 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1300 | { |
| 1301 | struct lpfc_board_event_header board_event; |
| 1302 | struct Scsi_Host *shost; |
| 1303 | |
| 1304 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1305 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1306 | shost = lpfc_shost_from_vport(phba->pport); |
| 1307 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1308 | sizeof(board_event), |
| 1309 | (char *) &board_event, |
| 1310 | LPFC_NL_VENDOR_ID); |
| 1311 | } |
| 1312 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1313 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1314 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1315 | * @phba: pointer to lpfc hba data structure. |
| 1316 | * |
| 1317 | * This routine is invoked to handle the following HBA hardware error |
| 1318 | * conditions: |
| 1319 | * 1 - HBA error attention interrupt |
| 1320 | * 2 - DMA ring index out of range |
| 1321 | * 3 - Mailbox command came back as unknown |
| 1322 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1323 | static void |
| 1324 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1326 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1327 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1329 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1330 | unsigned long temperature; |
| 1331 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1332 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1334 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1335 | * since we cannot communicate with the pci card anyway. |
| 1336 | */ |
| 1337 | if (pci_channel_offline(phba->pcidev)) { |
| 1338 | spin_lock_irq(&phba->hbalock); |
| 1339 | phba->hba_flag &= ~DEFER_ERATT; |
| 1340 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1341 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1344 | /* If resets are disabled then leave the HBA alone and return */ |
| 1345 | if (!phba->cfg_enable_hba_reset) |
| 1346 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1348 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1349 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1350 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1351 | if (phba->hba_flag & DEFER_ERATT) |
| 1352 | lpfc_handle_deferred_eratt(phba); |
| 1353 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1354 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1355 | if (phba->work_hs & HS_FFER6) |
| 1356 | /* Re-establishing Link */ |
| 1357 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1358 | "1301 Re-establishing Link " |
| 1359 | "Data: x%x x%x x%x\n", |
| 1360 | phba->work_hs, phba->work_status[0], |
| 1361 | phba->work_status[1]); |
| 1362 | if (phba->work_hs & HS_FFER8) |
| 1363 | /* Device Zeroization */ |
| 1364 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1365 | "2861 Host Authentication device " |
| 1366 | "zeroization Data:x%x x%x x%x\n", |
| 1367 | phba->work_hs, phba->work_status[0], |
| 1368 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1369 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1370 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1371 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1372 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | |
| 1374 | /* |
| 1375 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1376 | * That could cause the I/Os dropped by the firmware. |
| 1377 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1378 | * retry it after re-establishing link. |
| 1379 | */ |
| 1380 | pring = &psli->ring[psli->fcp_ring]; |
| 1381 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1382 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | /* |
| 1384 | * There was a firmware error. Take the hba offline and then |
| 1385 | * attempt to restart it. |
| 1386 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1387 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1389 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1390 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1391 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | return; |
| 1393 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1394 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1395 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1396 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1397 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1398 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1399 | temp_event_data.data = (uint32_t)temperature; |
| 1400 | |
| 1401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1402 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1403 | "(%ld), taking this port offline " |
| 1404 | "Data: x%x x%x x%x\n", |
| 1405 | temperature, phba->work_hs, |
| 1406 | phba->work_status[0], phba->work_status[1]); |
| 1407 | |
| 1408 | shost = lpfc_shost_from_vport(phba->pport); |
| 1409 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1410 | sizeof(temp_event_data), |
| 1411 | (char *) &temp_event_data, |
| 1412 | SCSI_NL_VID_TYPE_PCI |
| 1413 | | PCI_VENDOR_ID_EMULEX); |
| 1414 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1415 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1416 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1417 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1418 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1419 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1420 | } else { |
| 1421 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1422 | * failure is a value other than FFER6. Do not call the offline |
| 1423 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | */ |
| 1425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1426 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1428 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | phba->work_status[0], phba->work_status[1]); |
| 1430 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1431 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1432 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1434 | sizeof(event_data), (char *) &event_data, |
| 1435 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1436 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1437 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1439 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | } |
| 1441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1442 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1443 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1444 | * @phba: pointer to lpfc hba data structure. |
| 1445 | * @mbx_action: flag for mailbox shutdown action. |
| 1446 | * |
| 1447 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1448 | * response to port status register polling attention. It waits for port |
| 1449 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1450 | * During this process, interrupt vectors are freed and later requested |
| 1451 | * for handling possible port resource change. |
| 1452 | **/ |
| 1453 | static int |
| 1454 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action) |
| 1455 | { |
| 1456 | int rc; |
| 1457 | uint32_t intr_mode; |
| 1458 | |
| 1459 | /* |
| 1460 | * On error status condition, driver need to wait for port |
| 1461 | * ready before performing reset. |
| 1462 | */ |
| 1463 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1464 | if (!rc) { |
| 1465 | /* need reset: attempt for port recovery */ |
| 1466 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1467 | "2887 Reset Needed: Attempting Port " |
| 1468 | "Recovery...\n"); |
| 1469 | lpfc_offline_prep(phba, mbx_action); |
| 1470 | lpfc_offline(phba); |
| 1471 | /* release interrupt for possible resource change */ |
| 1472 | lpfc_sli4_disable_intr(phba); |
| 1473 | lpfc_sli_brdrestart(phba); |
| 1474 | /* request and enable interrupt */ |
| 1475 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1476 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1477 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1478 | "3175 Failed to enable interrupt\n"); |
| 1479 | return -EIO; |
| 1480 | } else { |
| 1481 | phba->intr_mode = intr_mode; |
| 1482 | } |
| 1483 | rc = lpfc_online(phba); |
| 1484 | if (rc == 0) |
| 1485 | lpfc_unblock_mgmt_io(phba); |
| 1486 | } |
| 1487 | return rc; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1491 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1492 | * @phba: pointer to lpfc hba data structure. |
| 1493 | * |
| 1494 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1495 | * conditions. |
| 1496 | **/ |
| 1497 | static void |
| 1498 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1499 | { |
| 1500 | struct lpfc_vport *vport = phba->pport; |
| 1501 | uint32_t event_data; |
| 1502 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1503 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1504 | struct lpfc_register portstat_reg = {0}; |
| 1505 | uint32_t reg_err1, reg_err2; |
| 1506 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1507 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1508 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1509 | |
| 1510 | /* If the pci channel is offline, ignore possible errors, since |
| 1511 | * we cannot communicate with the pci card anyway. |
| 1512 | */ |
| 1513 | if (pci_channel_offline(phba->pcidev)) |
| 1514 | return; |
| 1515 | /* If resets are disabled then leave the HBA alone and return */ |
| 1516 | if (!phba->cfg_enable_hba_reset) |
| 1517 | return; |
| 1518 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1519 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1520 | switch (if_type) { |
| 1521 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1522 | pci_rd_rc1 = lpfc_readl( |
| 1523 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1524 | &uerrlo_reg); |
| 1525 | pci_rd_rc2 = lpfc_readl( |
| 1526 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1527 | &uemasklo_reg); |
| 1528 | /* consider PCI bus read error as pci_channel_offline */ |
| 1529 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1530 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1531 | lpfc_sli4_offline_eratt(phba); |
| 1532 | break; |
| 1533 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1534 | pci_rd_rc1 = lpfc_readl( |
| 1535 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1536 | &portstat_reg.word0); |
| 1537 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1538 | if (pci_rd_rc1 == -EIO) { |
| 1539 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1540 | "3151 PCI bus read access failure: x%x\n", |
| 1541 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1542 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1543 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1544 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1545 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1546 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
| 1547 | /* TODO: Register for Overtemp async events. */ |
| 1548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1549 | "2889 Port Overtemperature event, " |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 1550 | "taking port offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1551 | spin_lock_irq(&phba->hbalock); |
| 1552 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1553 | spin_unlock_irq(&phba->hbalock); |
| 1554 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1555 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1556 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1557 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1558 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) |
| 1559 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1560 | "3143 Port Down: Firmware Restarted\n"); |
| 1561 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1562 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1563 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1564 | "3144 Port Down: Debug Dump\n"); |
| 1565 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1566 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1568 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1569 | |
| 1570 | /* Check port status register for function reset */ |
| 1571 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT); |
| 1572 | if (rc == 0) { |
| 1573 | /* don't report event on forced debug dump */ |
| 1574 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1575 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1576 | return; |
| 1577 | else |
| 1578 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1579 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1580 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1581 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1582 | "3152 Unrecoverable error, bring the port " |
| 1583 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1584 | lpfc_sli4_offline_eratt(phba); |
| 1585 | break; |
| 1586 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1587 | default: |
| 1588 | break; |
| 1589 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1590 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1591 | "3123 Report dump event to upper layer\n"); |
| 1592 | /* Send an internal error event to mgmt application */ |
| 1593 | lpfc_board_errevt_to_mgmt(phba); |
| 1594 | |
| 1595 | event_data = FC_REG_DUMP_EVENT; |
| 1596 | shost = lpfc_shost_from_vport(vport); |
| 1597 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1598 | sizeof(event_data), (char *) &event_data, |
| 1599 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1604 | * @phba: pointer to lpfc HBA data structure. |
| 1605 | * |
| 1606 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1607 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1608 | * |
| 1609 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1610 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1611 | * Any other value - error. |
| 1612 | **/ |
| 1613 | void |
| 1614 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1615 | { |
| 1616 | (*phba->lpfc_handle_eratt)(phba); |
| 1617 | } |
| 1618 | |
| 1619 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1620 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1621 | * @phba: pointer to lpfc hba data structure. |
| 1622 | * |
| 1623 | * This routine is invoked from the worker thread to handle a HBA host |
| 1624 | * attention link event. |
| 1625 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1627 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1629 | struct lpfc_vport *vport = phba->pport; |
| 1630 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | LPFC_MBOXQ_t *pmb; |
| 1632 | volatile uint32_t control; |
| 1633 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1634 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | |
| 1636 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1637 | if (!pmb) { |
| 1638 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1640 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1641 | |
| 1642 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1643 | if (!mp) { |
| 1644 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1645 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1646 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | |
| 1648 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1649 | if (!mp->virt) { |
| 1650 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1652 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1654 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1655 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | |
| 1657 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1658 | lpfc_read_topology(phba, pmb, mp); |
| 1659 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1660 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1661 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1662 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1663 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1664 | if (rc == MBX_NOT_FINISHED) { |
| 1665 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1666 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1667 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | |
| 1669 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1670 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | writel(HA_LATT, phba->HAregaddr); |
| 1672 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | |
| 1675 | return; |
| 1676 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1677 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1678 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1679 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1680 | lpfc_handle_latt_free_mp: |
| 1681 | kfree(mp); |
| 1682 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1683 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | lpfc_handle_latt_err_exit: |
| 1685 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1686 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1688 | control = readl(phba->HCregaddr); |
| 1689 | control |= HC_LAINT_ENA; |
| 1690 | writel(control, phba->HCregaddr); |
| 1691 | readl(phba->HCregaddr); /* flush */ |
| 1692 | |
| 1693 | /* Clear Link Attention in HA REG */ |
| 1694 | writel(HA_LATT, phba->HAregaddr); |
| 1695 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1696 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1700 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1701 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | |
| 1703 | return; |
| 1704 | } |
| 1705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1707 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1708 | * @phba: pointer to lpfc hba data structure. |
| 1709 | * @vpd: pointer to the vital product data. |
| 1710 | * @len: length of the vital product data in bytes. |
| 1711 | * |
| 1712 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1713 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1714 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1715 | * |
| 1716 | * Return codes |
| 1717 | * 0 - pointer to the VPD passed in is NULL |
| 1718 | * 1 - success |
| 1719 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1720 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | { |
| 1723 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1724 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | int i, j; |
| 1726 | int finished = 0; |
| 1727 | int index = 0; |
| 1728 | |
| 1729 | if (!vpd) |
| 1730 | return 0; |
| 1731 | |
| 1732 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1733 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1734 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1736 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1737 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | switch (vpd[index]) { |
| 1739 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1740 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | index += 1; |
| 1742 | lenlo = vpd[index]; |
| 1743 | index += 1; |
| 1744 | lenhi = vpd[index]; |
| 1745 | index += 1; |
| 1746 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1747 | index += i; |
| 1748 | break; |
| 1749 | case 0x90: |
| 1750 | index += 1; |
| 1751 | lenlo = vpd[index]; |
| 1752 | index += 1; |
| 1753 | lenhi = vpd[index]; |
| 1754 | index += 1; |
| 1755 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1756 | if (Length > len - index) |
| 1757 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | while (Length > 0) { |
| 1759 | /* Look for Serial Number */ |
| 1760 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1761 | index += 2; |
| 1762 | i = vpd[index]; |
| 1763 | index += 1; |
| 1764 | j = 0; |
| 1765 | Length -= (3+i); |
| 1766 | while(i--) { |
| 1767 | phba->SerialNumber[j++] = vpd[index++]; |
| 1768 | if (j == 31) |
| 1769 | break; |
| 1770 | } |
| 1771 | phba->SerialNumber[j] = 0; |
| 1772 | continue; |
| 1773 | } |
| 1774 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1775 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1776 | index += 2; |
| 1777 | i = vpd[index]; |
| 1778 | index += 1; |
| 1779 | j = 0; |
| 1780 | Length -= (3+i); |
| 1781 | while(i--) { |
| 1782 | phba->ModelDesc[j++] = vpd[index++]; |
| 1783 | if (j == 255) |
| 1784 | break; |
| 1785 | } |
| 1786 | phba->ModelDesc[j] = 0; |
| 1787 | continue; |
| 1788 | } |
| 1789 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1790 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1791 | index += 2; |
| 1792 | i = vpd[index]; |
| 1793 | index += 1; |
| 1794 | j = 0; |
| 1795 | Length -= (3+i); |
| 1796 | while(i--) { |
| 1797 | phba->ModelName[j++] = vpd[index++]; |
| 1798 | if (j == 79) |
| 1799 | break; |
| 1800 | } |
| 1801 | phba->ModelName[j] = 0; |
| 1802 | continue; |
| 1803 | } |
| 1804 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1805 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1806 | index += 2; |
| 1807 | i = vpd[index]; |
| 1808 | index += 1; |
| 1809 | j = 0; |
| 1810 | Length -= (3+i); |
| 1811 | while(i--) { |
| 1812 | phba->ProgramType[j++] = vpd[index++]; |
| 1813 | if (j == 255) |
| 1814 | break; |
| 1815 | } |
| 1816 | phba->ProgramType[j] = 0; |
| 1817 | continue; |
| 1818 | } |
| 1819 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1820 | phba->vpd_flag |= VPD_PORT; |
| 1821 | index += 2; |
| 1822 | i = vpd[index]; |
| 1823 | index += 1; |
| 1824 | j = 0; |
| 1825 | Length -= (3+i); |
| 1826 | while(i--) { |
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_GET)) { |
| 1830 | j++; |
| 1831 | index++; |
| 1832 | } else |
| 1833 | phba->Port[j++] = vpd[index++]; |
| 1834 | if (j == 19) |
| 1835 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1837 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1838 | (phba->sli4_hba.pport_name_sta == |
| 1839 | LPFC_SLI4_PPNAME_NON)) |
| 1840 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | continue; |
| 1842 | } |
| 1843 | else { |
| 1844 | index += 2; |
| 1845 | i = vpd[index]; |
| 1846 | index += 1; |
| 1847 | index += i; |
| 1848 | Length -= (3 + i); |
| 1849 | } |
| 1850 | } |
| 1851 | finished = 0; |
| 1852 | break; |
| 1853 | case 0x78: |
| 1854 | finished = 1; |
| 1855 | break; |
| 1856 | default: |
| 1857 | index ++; |
| 1858 | break; |
| 1859 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1860 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | |
| 1862 | return(1); |
| 1863 | } |
| 1864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1866 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1867 | * @phba: pointer to lpfc hba data structure. |
| 1868 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1869 | * @descp: pointer to the data structure to hold the derived description. |
| 1870 | * |
| 1871 | * This routine retrieves HBA's description based on its registered PCI device |
| 1872 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1873 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1874 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1875 | * function returns, the @mdp will be filled with the model name. |
| 1876 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1878 | 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] | 1879 | { |
| 1880 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1881 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1882 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1883 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1884 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1885 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1886 | char *name; |
| 1887 | char *bus; |
| 1888 | char *function; |
| 1889 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1890 | |
| 1891 | if (mdp && mdp[0] != '\0' |
| 1892 | && descp && descp[0] != '\0') |
| 1893 | return; |
| 1894 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 1895 | if (phba->lmt & LMT_16Gb) |
| 1896 | max_speed = 16; |
| 1897 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1898 | max_speed = 10; |
| 1899 | else if (phba->lmt & LMT_8Gb) |
| 1900 | max_speed = 8; |
| 1901 | else if (phba->lmt & LMT_4Gb) |
| 1902 | max_speed = 4; |
| 1903 | else if (phba->lmt & LMT_2Gb) |
| 1904 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1905 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1906 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 1907 | else |
| 1908 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | |
| 1910 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1912 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1913 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1914 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1915 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | case PCI_DEVICE_ID_SUPERFLY: |
| 1917 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1918 | m = (typeof(m)){"LP7000", "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)){"LP7000E", "PCI", |
| 1922 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | break; |
| 1924 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1925 | m = (typeof(m)){"LP8000", "PCI", |
| 1926 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | break; |
| 1928 | case PCI_DEVICE_ID_CENTAUR: |
| 1929 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1930 | m = (typeof(m)){"LP9002", "PCI", |
| 1931 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1933 | m = (typeof(m)){"LP9000", "PCI", |
| 1934 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | break; |
| 1936 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1937 | m = (typeof(m)){"LP952", "PCI", |
| 1938 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | break; |
| 1940 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1941 | m = (typeof(m)){"LP9802", "PCI-X", |
| 1942 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1943 | break; |
| 1944 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1945 | m = (typeof(m)){"LP10000", "PCI-X", |
| 1946 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | break; |
| 1948 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1949 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 1950 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1951 | break; |
| 1952 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1953 | m = (typeof(m)){"LP982", "PCI-X", |
| 1954 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | break; |
| 1956 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1957 | m = (typeof(m)){"LP1050", "PCI-X", |
| 1958 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1959 | break; |
| 1960 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1961 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 1962 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1964 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1965 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 1966 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1967 | break; |
| 1968 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1969 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 1970 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1971 | break; |
| 1972 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1973 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1974 | break; |
| 1975 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1976 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1977 | break; |
| 1978 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1979 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1980 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1982 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | break; |
| 1984 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1985 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | break; |
| 1987 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1988 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1990 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1991 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1992 | break; |
| 1993 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1994 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1995 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1996 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1998 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | break; |
| 2000 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2001 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2002 | break; |
| 2003 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2004 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2005 | break; |
| 2006 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2007 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2008 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2009 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2010 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2011 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2012 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2013 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2014 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2015 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2016 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2017 | break; |
| 2018 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2019 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2020 | break; |
| 2021 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2022 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2023 | break; |
| 2024 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2025 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2026 | break; |
| 2027 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2028 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2029 | break; |
| 2030 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2031 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2032 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2033 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2034 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2035 | GE = 1; |
| 2036 | break; |
| 2037 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2038 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2039 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2040 | break; |
| 2041 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2042 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 2043 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2044 | break; |
| 2045 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2046 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 2047 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2048 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2049 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2050 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2051 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2052 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2053 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2054 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2055 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2056 | break; |
| 2057 | case PCI_DEVICE_ID_FALCON: |
| 2058 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2059 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2060 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2061 | case PCI_DEVICE_ID_BALIUS: |
| 2062 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2063 | "Fibre Channel Adapter"}; |
| 2064 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2065 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2066 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2067 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2068 | break; |
| 2069 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2070 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2071 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2072 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2073 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2074 | case PCI_DEVICE_ID_SKYHAWK: |
| 2075 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2076 | oneConnect = 1; |
| 2077 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2078 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2079 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2080 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2081 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2083 | |
| 2084 | if (mdp && mdp[0] == '\0') |
| 2085 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2086 | /* |
| 2087 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2088 | * and we put the port number on the end |
| 2089 | */ |
| 2090 | if (descp && descp[0] == '\0') { |
| 2091 | if (oneConnect) |
| 2092 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2093 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2094 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2095 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2096 | else if (max_speed == 0) |
| 2097 | snprintf(descp, 255, |
| 2098 | "Emulex %s %s %s ", |
| 2099 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2100 | else |
| 2101 | snprintf(descp, 255, |
| 2102 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2103 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2104 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2105 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | } |
| 2107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2109 | * 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] | 2110 | * @phba: pointer to lpfc hba data structure. |
| 2111 | * @pring: pointer to a IOCB ring. |
| 2112 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2113 | * |
| 2114 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2115 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2116 | * |
| 2117 | * Return codes |
| 2118 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2119 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2121 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | { |
| 2123 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2124 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | struct lpfc_dmabuf *mp1, *mp2; |
| 2126 | |
| 2127 | cnt += pring->missbufcnt; |
| 2128 | |
| 2129 | /* While there are buffers to post */ |
| 2130 | while (cnt > 0) { |
| 2131 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2132 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | if (iocb == NULL) { |
| 2134 | pring->missbufcnt = cnt; |
| 2135 | return cnt; |
| 2136 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | icmd = &iocb->iocb; |
| 2138 | |
| 2139 | /* 2 buffers can be posted per command */ |
| 2140 | /* Allocate buffer to post */ |
| 2141 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2142 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2143 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2144 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 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(&mp1->list); |
| 2152 | /* Allocate buffer to post */ |
| 2153 | if (cnt > 1) { |
| 2154 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2155 | if (mp2) |
| 2156 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2157 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2158 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2159 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2160 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2161 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2162 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2163 | pring->missbufcnt = cnt; |
| 2164 | return cnt; |
| 2165 | } |
| 2166 | |
| 2167 | INIT_LIST_HEAD(&mp2->list); |
| 2168 | } else { |
| 2169 | mp2 = NULL; |
| 2170 | } |
| 2171 | |
| 2172 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2173 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2174 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2175 | icmd->ulpBdeCount = 1; |
| 2176 | cnt--; |
| 2177 | if (mp2) { |
| 2178 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2179 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2180 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2181 | cnt--; |
| 2182 | icmd->ulpBdeCount = 2; |
| 2183 | } |
| 2184 | |
| 2185 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2186 | icmd->ulpLe = 1; |
| 2187 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2188 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2189 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2191 | kfree(mp1); |
| 2192 | cnt++; |
| 2193 | if (mp2) { |
| 2194 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2195 | kfree(mp2); |
| 2196 | cnt++; |
| 2197 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2198 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2200 | return cnt; |
| 2201 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2202 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2203 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2204 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2205 | } |
| 2206 | pring->missbufcnt = 0; |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2211 | * 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] | 2212 | * @phba: pointer to lpfc hba data structure. |
| 2213 | * |
| 2214 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2215 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2216 | * set to 64 IOCBs. |
| 2217 | * |
| 2218 | * Return codes |
| 2219 | * 0 - success (currently always success) |
| 2220 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2222 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2223 | { |
| 2224 | struct lpfc_sli *psli = &phba->sli; |
| 2225 | |
| 2226 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2227 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | /* Ring 2 - FCP no buffers needed */ |
| 2229 | |
| 2230 | return 0; |
| 2231 | } |
| 2232 | |
| 2233 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2234 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2235 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2236 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2237 | * @HashResultPointer: pointer to an array as hash table. |
| 2238 | * |
| 2239 | * This routine sets up the initial values to the array of hash table entries |
| 2240 | * for the LC HBAs. |
| 2241 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | static void |
| 2243 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2244 | { |
| 2245 | HashResultPointer[0] = 0x67452301; |
| 2246 | HashResultPointer[1] = 0xEFCDAB89; |
| 2247 | HashResultPointer[2] = 0x98BADCFE; |
| 2248 | HashResultPointer[3] = 0x10325476; |
| 2249 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2250 | } |
| 2251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2253 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2254 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2255 | * @HashWorkingPointer: pointer to an working hash table. |
| 2256 | * |
| 2257 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2258 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2259 | * The results are putting back to the initial hash table, returned through |
| 2260 | * the @HashResultPointer as the result hash table. |
| 2261 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2262 | static void |
| 2263 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2264 | { |
| 2265 | int t; |
| 2266 | uint32_t TEMP; |
| 2267 | uint32_t A, B, C, D, E; |
| 2268 | t = 16; |
| 2269 | do { |
| 2270 | HashWorkingPointer[t] = |
| 2271 | S(1, |
| 2272 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2273 | 8] ^ |
| 2274 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2275 | } while (++t <= 79); |
| 2276 | t = 0; |
| 2277 | A = HashResultPointer[0]; |
| 2278 | B = HashResultPointer[1]; |
| 2279 | C = HashResultPointer[2]; |
| 2280 | D = HashResultPointer[3]; |
| 2281 | E = HashResultPointer[4]; |
| 2282 | |
| 2283 | do { |
| 2284 | if (t < 20) { |
| 2285 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2286 | } else if (t < 40) { |
| 2287 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2288 | } else if (t < 60) { |
| 2289 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2290 | } else { |
| 2291 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2292 | } |
| 2293 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2294 | E = D; |
| 2295 | D = C; |
| 2296 | C = S(30, B); |
| 2297 | B = A; |
| 2298 | A = TEMP; |
| 2299 | } while (++t <= 79); |
| 2300 | |
| 2301 | HashResultPointer[0] += A; |
| 2302 | HashResultPointer[1] += B; |
| 2303 | HashResultPointer[2] += C; |
| 2304 | HashResultPointer[3] += D; |
| 2305 | HashResultPointer[4] += E; |
| 2306 | |
| 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_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2311 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2312 | * @HashWorking: pointer to the entry of the working hash array. |
| 2313 | * |
| 2314 | * This routine calculates the working hash array referred by @HashWorking |
| 2315 | * from the challenge random numbers associated with the host, referred by |
| 2316 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2317 | * array and returned by reference through @HashWorking. |
| 2318 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | static void |
| 2320 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2321 | { |
| 2322 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2323 | } |
| 2324 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2326 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2327 | * @phba: pointer to lpfc hba data structure. |
| 2328 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2329 | * |
| 2330 | * This routine performs the special handling for LC HBA initialization. |
| 2331 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | void |
| 2333 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2334 | { |
| 2335 | int t; |
| 2336 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2337 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2339 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | if (!HashWorking) |
| 2341 | return; |
| 2342 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2344 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2345 | |
| 2346 | for (t = 0; t < 7; t++) |
| 2347 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2348 | |
| 2349 | lpfc_sha_init(hbainit); |
| 2350 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2351 | kfree(HashWorking); |
| 2352 | } |
| 2353 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2354 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2355 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2356 | * @vport: pointer to a virtual N_Port data structure. |
| 2357 | * |
| 2358 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2359 | * It invokes the discovery state machine to perform necessary state |
| 2360 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2361 | * the physical port is treated as @vport 0. |
| 2362 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2363 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2366 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2368 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2370 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2371 | lpfc_port_link_failure(vport); |
| 2372 | |
| 2373 | 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] | 2374 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2375 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2376 | NLP_STE_UNUSED_NODE); |
| 2377 | if (!ndlp) |
| 2378 | continue; |
| 2379 | spin_lock_irq(&phba->ndlp_lock); |
| 2380 | NLP_SET_FREE_REQ(ndlp); |
| 2381 | spin_unlock_irq(&phba->ndlp_lock); |
| 2382 | /* Trigger the release of the ndlp memory */ |
| 2383 | lpfc_nlp_put(ndlp); |
| 2384 | continue; |
| 2385 | } |
| 2386 | spin_lock_irq(&phba->ndlp_lock); |
| 2387 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2388 | /* The ndlp should not be in memory free mode already */ |
| 2389 | spin_unlock_irq(&phba->ndlp_lock); |
| 2390 | continue; |
| 2391 | } else |
| 2392 | /* Indicate request for freeing ndlp memory */ |
| 2393 | NLP_SET_FREE_REQ(ndlp); |
| 2394 | spin_unlock_irq(&phba->ndlp_lock); |
| 2395 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2396 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2397 | ndlp->nlp_DID == Fabric_DID) { |
| 2398 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2399 | lpfc_nlp_put(ndlp); |
| 2400 | continue; |
| 2401 | } |
| 2402 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2403 | /* take care of nodes in unused state before the state |
| 2404 | * machine taking action. |
| 2405 | */ |
| 2406 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2407 | lpfc_nlp_put(ndlp); |
| 2408 | continue; |
| 2409 | } |
| 2410 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2411 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2412 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2413 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2414 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2415 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2416 | NLP_EVT_DEVICE_RM); |
| 2417 | } |
| 2418 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2419 | /* At this point, ALL ndlp's should be gone |
| 2420 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2421 | * Lets wait for this to happen, if needed. |
| 2422 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2423 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2424 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2425 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2426 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2427 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2428 | &vport->fc_nodes, nlp_listp) { |
| 2429 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2430 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2431 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2432 | "usgmap:x%x refcnt:%d\n", |
| 2433 | ndlp->nlp_DID, (void *)ndlp, |
| 2434 | ndlp->nlp_usg_map, |
| 2435 | atomic_read( |
| 2436 | &ndlp->kref.refcount)); |
| 2437 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2438 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2439 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2440 | |
| 2441 | /* Wait for any activity on ndlps to settle */ |
| 2442 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2443 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2444 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | } |
| 2446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2448 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2449 | * @vport: pointer to a virtual N_Port data structure. |
| 2450 | * |
| 2451 | * This routine stops all the timers associated with a @vport. This function |
| 2452 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2453 | * port is treated as @vport 0. |
| 2454 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2455 | void |
| 2456 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2458 | del_timer_sync(&vport->els_tmofunc); |
| 2459 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2460 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2461 | lpfc_can_disctmo(vport); |
| 2462 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | } |
| 2464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2465 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2466 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2467 | * @phba: pointer to lpfc hba data structure. |
| 2468 | * |
| 2469 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2470 | * caller of this routine should already hold the host lock. |
| 2471 | **/ |
| 2472 | void |
| 2473 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2474 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2475 | /* Clear pending FCF rediscovery wait flag */ |
| 2476 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2477 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2478 | /* Now, try to stop the timer */ |
| 2479 | del_timer(&phba->fcf.redisc_wait); |
| 2480 | } |
| 2481 | |
| 2482 | /** |
| 2483 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2484 | * @phba: pointer to lpfc hba data structure. |
| 2485 | * |
| 2486 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2487 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2488 | * lock held before proceeding with disabling the timer and clearing the |
| 2489 | * wait timer pendig flag. |
| 2490 | **/ |
| 2491 | void |
| 2492 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2493 | { |
| 2494 | spin_lock_irq(&phba->hbalock); |
| 2495 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2496 | /* FCF rediscovery timer already fired or stopped */ |
| 2497 | spin_unlock_irq(&phba->hbalock); |
| 2498 | return; |
| 2499 | } |
| 2500 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2501 | /* Clear failover in progress flags */ |
| 2502 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2503 | spin_unlock_irq(&phba->hbalock); |
| 2504 | } |
| 2505 | |
| 2506 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2507 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2508 | * @phba: pointer to lpfc hba data structure. |
| 2509 | * |
| 2510 | * This routine stops all the timers associated with a HBA. This function is |
| 2511 | * invoked before either putting a HBA offline or unloading the driver. |
| 2512 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2513 | void |
| 2514 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2516 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2517 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2518 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2519 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2520 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2521 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2522 | del_timer_sync(&phba->rrq_tmr); |
| 2523 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2524 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2525 | phba->hb_outstanding = 0; |
| 2526 | |
| 2527 | switch (phba->pci_dev_grp) { |
| 2528 | case LPFC_PCI_DEV_LP: |
| 2529 | /* Stop any LightPulse device specific driver timers */ |
| 2530 | del_timer_sync(&phba->fcp_poll_timer); |
| 2531 | break; |
| 2532 | case LPFC_PCI_DEV_OC: |
| 2533 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2534 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2535 | break; |
| 2536 | default: |
| 2537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2538 | "0297 Invalid device group (x%x)\n", |
| 2539 | phba->pci_dev_grp); |
| 2540 | break; |
| 2541 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2542 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | } |
| 2544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2546 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2547 | * @phba: pointer to lpfc hba data structure. |
| 2548 | * |
| 2549 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2550 | * management interface is marked as blocked, all the user space access to |
| 2551 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2552 | * all be blocked. The HBA is set to block the management interface when the |
| 2553 | * driver prepares the HBA interface for online or offline. |
| 2554 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2555 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2556 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2557 | { |
| 2558 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2559 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2560 | unsigned long timeout; |
| 2561 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2562 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2563 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2564 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2565 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2566 | return; |
| 2567 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2568 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2569 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2570 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2571 | /* Determine how long we might wait for the active mailbox |
| 2572 | * command to be gracefully completed by firmware. |
| 2573 | */ |
| 2574 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2575 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2576 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2577 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2578 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2579 | /* Wait for the outstnading mailbox command to complete */ |
| 2580 | while (phba->sli.mbox_active) { |
| 2581 | /* Check active mailbox complete status every 2ms */ |
| 2582 | msleep(2); |
| 2583 | if (time_after(jiffies, timeout)) { |
| 2584 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2585 | "2813 Mgmt IO is Blocked %x " |
| 2586 | "- mbox cmd %x still active\n", |
| 2587 | phba->sli.sli_flag, actcmd); |
| 2588 | break; |
| 2589 | } |
| 2590 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2591 | } |
| 2592 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2593 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2594 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2595 | * @phba: pointer to lpfc hba data structure. |
| 2596 | * |
| 2597 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2598 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2599 | * is to fixup the temporary rpi assignments. |
| 2600 | **/ |
| 2601 | void |
| 2602 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2603 | { |
| 2604 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2605 | struct lpfc_vport **vports; |
| 2606 | int i; |
| 2607 | |
| 2608 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2609 | return; |
| 2610 | |
| 2611 | vports = lpfc_create_vport_work_array(phba); |
| 2612 | if (vports != NULL) { |
| 2613 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2614 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2615 | continue; |
| 2616 | |
| 2617 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2618 | &vports[i]->fc_nodes, |
| 2619 | nlp_listp) { |
| 2620 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2621 | ndlp->nlp_rpi = |
| 2622 | lpfc_sli4_alloc_rpi(phba); |
| 2623 | } |
| 2624 | } |
| 2625 | } |
| 2626 | lpfc_destroy_vport_work_array(phba, vports); |
| 2627 | } |
| 2628 | |
| 2629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2630 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2631 | * @phba: pointer to lpfc hba data structure. |
| 2632 | * |
| 2633 | * This routine initializes the HBA and brings a HBA online. During this |
| 2634 | * process, the management interface is blocked to prevent user space access |
| 2635 | * to the HBA interfering with the driver initialization. |
| 2636 | * |
| 2637 | * Return codes |
| 2638 | * 0 - successful |
| 2639 | * 1 - failed |
| 2640 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2642 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2644 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2645 | struct lpfc_vport **vports; |
| 2646 | int i; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2647 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | if (!phba) |
| 2650 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2651 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2653 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2654 | return 0; |
| 2655 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2656 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2657 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2659 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2661 | if (!lpfc_sli_queue_setup(phba)) { |
| 2662 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2664 | } |
| 2665 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2666 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2667 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2668 | lpfc_unblock_mgmt_io(phba); |
| 2669 | return 1; |
| 2670 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2671 | spin_lock_irq(&phba->hbalock); |
| 2672 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 2673 | vpis_cleared = true; |
| 2674 | spin_unlock_irq(&phba->hbalock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2675 | } else { |
| 2676 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2677 | lpfc_unblock_mgmt_io(phba); |
| 2678 | return 1; |
| 2679 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2680 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2682 | vports = lpfc_create_vport_work_array(phba); |
| 2683 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2684 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2685 | struct Scsi_Host *shost; |
| 2686 | shost = lpfc_shost_from_vport(vports[i]); |
| 2687 | spin_lock_irq(shost->host_lock); |
| 2688 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2689 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2690 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2691 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2692 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 2693 | if ((vpis_cleared) && |
| 2694 | (vports[i]->port_type != |
| 2695 | LPFC_PHYSICAL_PORT)) |
| 2696 | vports[i]->vpi = 0; |
| 2697 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2698 | spin_unlock_irq(shost->host_lock); |
| 2699 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2700 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2702 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | return 0; |
| 2704 | } |
| 2705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2707 | * 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] | 2708 | * @phba: pointer to lpfc hba data structure. |
| 2709 | * |
| 2710 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2711 | * HBA's management interface is marked as not blocked, all the user space |
| 2712 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2713 | * interface will be allowed. The HBA is set to block the management interface |
| 2714 | * when the driver prepares the HBA interface for online or offline and then |
| 2715 | * set to unblock the management interface afterwards. |
| 2716 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2717 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2718 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2719 | { |
| 2720 | unsigned long iflag; |
| 2721 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2722 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2723 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2724 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2725 | } |
| 2726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2728 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2729 | * @phba: pointer to lpfc hba data structure. |
| 2730 | * |
| 2731 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2732 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2733 | * queue to make it ready to be brought offline. |
| 2734 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2735 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2736 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2737 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2739 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2740 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2741 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2742 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2744 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2745 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2747 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | |
| 2749 | lpfc_linkdown(phba); |
| 2750 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2751 | /* Issue an unreg_login to all nodes on all vports */ |
| 2752 | vports = lpfc_create_vport_work_array(phba); |
| 2753 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2754 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2755 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2756 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2757 | shost = lpfc_shost_from_vport(vports[i]); |
| 2758 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2759 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2760 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2761 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2762 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2763 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2764 | shost = lpfc_shost_from_vport(vports[i]); |
| 2765 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2766 | &vports[i]->fc_nodes, |
| 2767 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2768 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2769 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2770 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2771 | continue; |
| 2772 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2773 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2774 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2775 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2776 | NULL, NLP_EVT_DEVICE_RM); |
| 2777 | } |
| 2778 | spin_lock_irq(shost->host_lock); |
| 2779 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2780 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2781 | /* |
| 2782 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2783 | * RPI. Get a new RPI when the adapter port |
| 2784 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2785 | */ |
| 2786 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2787 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2788 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2789 | } |
| 2790 | } |
| 2791 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2792 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2794 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2795 | } |
| 2796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2798 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2799 | * @phba: pointer to lpfc hba data structure. |
| 2800 | * |
| 2801 | * This routine actually brings a HBA offline. It stops all the timers |
| 2802 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2803 | * marks the HBA as in offline state for the upper layer protocol. |
| 2804 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2805 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2807 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2808 | struct Scsi_Host *shost; |
| 2809 | struct lpfc_vport **vports; |
| 2810 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2811 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2812 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2813 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2814 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2815 | /* stop port and all timers associated with this hba */ |
| 2816 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2817 | vports = lpfc_create_vport_work_array(phba); |
| 2818 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2819 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2820 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2821 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2822 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2823 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2825 | now. */ |
| 2826 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2827 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2828 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2829 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2830 | vports = lpfc_create_vport_work_array(phba); |
| 2831 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2832 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2833 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2834 | spin_lock_irq(shost->host_lock); |
| 2835 | vports[i]->work_port_events = 0; |
| 2836 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2837 | spin_unlock_irq(shost->host_lock); |
| 2838 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2839 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2840 | } |
| 2841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2842 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2843 | * 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] | 2844 | * @phba: pointer to lpfc hba data structure. |
| 2845 | * |
| 2846 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2847 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2848 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2849 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2850 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2851 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2852 | { |
| 2853 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2854 | struct lpfc_iocbq *io, *io_next; |
| 2855 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2856 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2857 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2859 | |
| 2860 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 2861 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 2862 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2863 | list_del(&sb->list); |
| 2864 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2865 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | kfree(sb); |
| 2867 | phba->total_scsi_bufs--; |
| 2868 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 2869 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 2870 | |
| 2871 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 2872 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 2873 | list) { |
| 2874 | list_del(&sb->list); |
| 2875 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
| 2876 | sb->dma_handle); |
| 2877 | kfree(sb); |
| 2878 | phba->total_scsi_bufs--; |
| 2879 | } |
| 2880 | spin_unlock(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2881 | |
| 2882 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2883 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2884 | list_del(&io->list); |
| 2885 | kfree(io); |
| 2886 | phba->total_iocbq_bufs--; |
| 2887 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2888 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2889 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | /** |
| 2893 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping |
| 2894 | * @phba: pointer to lpfc hba data structure. |
| 2895 | * |
| 2896 | * This routine first calculates the sizes of the current els and allocated |
| 2897 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 2898 | * XRIs assigned due to port function reset. During port initialization, the |
| 2899 | * current els and allocated scsi sgl lists are 0s. |
| 2900 | * |
| 2901 | * Return codes |
| 2902 | * 0 - successful (for now, it always returns 0) |
| 2903 | **/ |
| 2904 | int |
| 2905 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) |
| 2906 | { |
| 2907 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 2908 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; |
| 2909 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; |
| 2910 | LIST_HEAD(els_sgl_list); |
| 2911 | LIST_HEAD(scsi_sgl_list); |
| 2912 | int rc; |
| 2913 | |
| 2914 | /* |
| 2915 | * update on pci function's els xri-sgl list |
| 2916 | */ |
| 2917 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 2918 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 2919 | /* els xri-sgl expanded */ |
| 2920 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 2921 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2922 | "3157 ELS xri-sgl count increased from " |
| 2923 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2924 | els_xri_cnt); |
| 2925 | /* allocate the additional els sgls */ |
| 2926 | for (i = 0; i < xri_cnt; i++) { |
| 2927 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 2928 | GFP_KERNEL); |
| 2929 | if (sglq_entry == NULL) { |
| 2930 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2931 | "2562 Failure to allocate an " |
| 2932 | "ELS sgl entry:%d\n", i); |
| 2933 | rc = -ENOMEM; |
| 2934 | goto out_free_mem; |
| 2935 | } |
| 2936 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 2937 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 2938 | &sglq_entry->phys); |
| 2939 | if (sglq_entry->virt == NULL) { |
| 2940 | kfree(sglq_entry); |
| 2941 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2942 | "2563 Failure to allocate an " |
| 2943 | "ELS mbuf:%d\n", i); |
| 2944 | rc = -ENOMEM; |
| 2945 | goto out_free_mem; |
| 2946 | } |
| 2947 | sglq_entry->sgl = sglq_entry->virt; |
| 2948 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 2949 | sglq_entry->state = SGL_FREED; |
| 2950 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 2951 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 2952 | spin_lock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2953 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 2954 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 2955 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 2956 | /* els xri-sgl shrinked */ |
| 2957 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 2958 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2959 | "3158 ELS xri-sgl count decreased from " |
| 2960 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 2961 | els_xri_cnt); |
| 2962 | spin_lock_irq(&phba->hbalock); |
| 2963 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); |
| 2964 | spin_unlock_irq(&phba->hbalock); |
| 2965 | /* release extra els sgls from list */ |
| 2966 | for (i = 0; i < xri_cnt; i++) { |
| 2967 | list_remove_head(&els_sgl_list, |
| 2968 | sglq_entry, struct lpfc_sglq, list); |
| 2969 | if (sglq_entry) { |
| 2970 | lpfc_mbuf_free(phba, sglq_entry->virt, |
| 2971 | sglq_entry->phys); |
| 2972 | kfree(sglq_entry); |
| 2973 | } |
| 2974 | } |
| 2975 | spin_lock_irq(&phba->hbalock); |
| 2976 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
| 2977 | spin_unlock_irq(&phba->hbalock); |
| 2978 | } else |
| 2979 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 2980 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 2981 | els_xri_cnt); |
| 2982 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 2983 | |
| 2984 | /* update xris to els sgls on the list */ |
| 2985 | sglq_entry = NULL; |
| 2986 | sglq_entry_next = NULL; |
| 2987 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 2988 | &phba->sli4_hba.lpfc_sgl_list, list) { |
| 2989 | lxri = lpfc_sli4_next_xritag(phba); |
| 2990 | if (lxri == NO_XRI) { |
| 2991 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2992 | "2400 Failed to allocate xri for " |
| 2993 | "ELS sgl\n"); |
| 2994 | rc = -ENOMEM; |
| 2995 | goto out_free_mem; |
| 2996 | } |
| 2997 | sglq_entry->sli4_lxritag = lxri; |
| 2998 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 2999 | } |
| 3000 | |
| 3001 | /* |
| 3002 | * update on pci function's allocated scsi xri-sgl list |
| 3003 | */ |
| 3004 | phba->total_scsi_bufs = 0; |
| 3005 | |
| 3006 | /* maximum number of xris available for scsi buffers */ |
| 3007 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3008 | els_xri_cnt; |
| 3009 | |
| 3010 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3011 | "2401 Current allocated SCSI xri-sgl count:%d, " |
| 3012 | "maximum SCSI xri count:%d\n", |
| 3013 | phba->sli4_hba.scsi_xri_cnt, |
| 3014 | phba->sli4_hba.scsi_xri_max); |
| 3015 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3016 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
| 3017 | spin_lock_irq(&phba->scsi_buf_list_put_lock); |
| 3018 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3019 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
| 3020 | spin_unlock_irq(&phba->scsi_buf_list_put_lock); |
| 3021 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3022 | |
| 3023 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3024 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3025 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3026 | phba->sli4_hba.scsi_xri_max; |
| 3027 | /* release the extra allocated scsi buffers */ |
| 3028 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3029 | list_remove_head(&scsi_sgl_list, psb, |
| 3030 | struct lpfc_scsi_buf, list); |
| 3031 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, |
| 3032 | psb->dma_handle); |
| 3033 | kfree(psb); |
| 3034 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3035 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3036 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3037 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | /* update xris associated to remaining allocated scsi buffers */ |
| 3041 | psb = NULL; |
| 3042 | psb_next = NULL; |
| 3043 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3044 | lxri = lpfc_sli4_next_xritag(phba); |
| 3045 | if (lxri == NO_XRI) { |
| 3046 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3047 | "2560 Failed to allocate xri for " |
| 3048 | "scsi buffer\n"); |
| 3049 | rc = -ENOMEM; |
| 3050 | goto out_free_mem; |
| 3051 | } |
| 3052 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3053 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3054 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3055 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
| 3056 | spin_lock_irq(&phba->scsi_buf_list_put_lock); |
| 3057 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3058 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 3059 | spin_unlock_irq(&phba->scsi_buf_list_put_lock); |
| 3060 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3063 | |
| 3064 | out_free_mem: |
| 3065 | lpfc_free_els_sgl_list(phba); |
| 3066 | lpfc_scsi_free(phba); |
| 3067 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | } |
| 3069 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3070 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3071 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3072 | * @phba: pointer to lpfc hba data structure. |
| 3073 | * @instance: a unique integer ID to this FC port. |
| 3074 | * @dev: pointer to the device data structure. |
| 3075 | * |
| 3076 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3077 | * can be created on top of either a physical port or a virtual port provided |
| 3078 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3079 | * and associates the FC port created before adding the shost into the SCSI |
| 3080 | * layer. |
| 3081 | * |
| 3082 | * Return codes |
| 3083 | * @vport - pointer to the virtual N_Port data structure. |
| 3084 | * NULL - port create failed. |
| 3085 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3086 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3087 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3088 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3089 | struct lpfc_vport *vport; |
| 3090 | struct Scsi_Host *shost; |
| 3091 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3092 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3093 | if (dev != &phba->pcidev->dev) |
| 3094 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3095 | sizeof(struct lpfc_vport)); |
| 3096 | else |
| 3097 | shost = scsi_host_alloc(&lpfc_template, |
| 3098 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3099 | if (!shost) |
| 3100 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3101 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3102 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3103 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3104 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3105 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3106 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3107 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3108 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | shost->unique_id = instance; |
| 3110 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3111 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3112 | shost->this_id = -1; |
| 3113 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3114 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3115 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3116 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3117 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3118 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3119 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3120 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3121 | * Set initial can_queue value since 0 is no longer supported and |
| 3122 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3123 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3124 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3125 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3126 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3127 | shost->transportt = lpfc_vport_transport_template; |
| 3128 | vport->port_type = LPFC_NPIV_PORT; |
| 3129 | } else { |
| 3130 | shost->transportt = lpfc_transport_template; |
| 3131 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3132 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3133 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3134 | /* Initialize all internally managed lists. */ |
| 3135 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3136 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3137 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3138 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3139 | init_timer(&vport->fc_disctmo); |
| 3140 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3142 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3143 | init_timer(&vport->fc_fdmitmo); |
| 3144 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3145 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3146 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3147 | init_timer(&vport->els_tmofunc); |
| 3148 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3150 | |
| 3151 | init_timer(&vport->delayed_disc_tmo); |
| 3152 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 3153 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 3154 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3155 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3156 | if (error) |
| 3157 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3158 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3159 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3161 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3162 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3163 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3164 | out_put_shost: |
| 3165 | scsi_host_put(shost); |
| 3166 | out: |
| 3167 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3168 | } |
| 3169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3171 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3172 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3173 | * |
| 3174 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3175 | * resources associated with the port are released. |
| 3176 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3177 | void |
| 3178 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3179 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3180 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3181 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3182 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3183 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3184 | fc_remove_host(shost); |
| 3185 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3186 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3187 | spin_lock_irq(&phba->hbalock); |
| 3188 | list_del_init(&vport->listentry); |
| 3189 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3190 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3191 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3192 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3193 | } |
| 3194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3196 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3197 | * |
| 3198 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 3199 | * uses the kernel idr facility to perform the task. |
| 3200 | * |
| 3201 | * Return codes: |
| 3202 | * instance - a unique integer ID allocated as the new instance. |
| 3203 | * -1 - lpfc get instance failed. |
| 3204 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3205 | int |
| 3206 | lpfc_get_instance(void) |
| 3207 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3208 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3209 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 3210 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 3211 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3212 | } |
| 3213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3215 | * 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] | 3216 | * @shost: pointer to SCSI host data structure. |
| 3217 | * @time: elapsed time of the scan in jiffies. |
| 3218 | * |
| 3219 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 3220 | * whether the scan host is finished. |
| 3221 | * |
| 3222 | * Note: there is no scan_start function as adapter initialization will have |
| 3223 | * asynchronously kicked off the link initialization. |
| 3224 | * |
| 3225 | * Return codes |
| 3226 | * 0 - SCSI host scan is not over yet. |
| 3227 | * 1 - SCSI host scan is over. |
| 3228 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3229 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3230 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3231 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3232 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3233 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3234 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3235 | spin_lock_irq(shost->host_lock); |
| 3236 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3237 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3238 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3239 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3240 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3241 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3242 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3243 | "0461 Scanning longer than 30 " |
| 3244 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3245 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3246 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3247 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3248 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 3249 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3251 | "0465 Link down longer than 15 " |
| 3252 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3253 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3254 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3255 | } |
| 3256 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3257 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3258 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3259 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3260 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3261 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3262 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3263 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3264 | goto finished; |
| 3265 | |
| 3266 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3267 | |
| 3268 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3269 | spin_unlock_irq(shost->host_lock); |
| 3270 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3271 | } |
| 3272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3274 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3275 | * @shost: pointer to SCSI host data structure. |
| 3276 | * |
| 3277 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3278 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3279 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3280 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3281 | { |
| 3282 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3283 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3284 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3285 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3286 | */ |
| 3287 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3288 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3289 | 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] | 3290 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3291 | |
| 3292 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3293 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3294 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3295 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3296 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3297 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3298 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3299 | |
| 3300 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3301 | if (phba->lmt & LMT_16Gb) |
| 3302 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3303 | if (phba->lmt & LMT_10Gb) |
| 3304 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3305 | if (phba->lmt & LMT_8Gb) |
| 3306 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3307 | if (phba->lmt & LMT_4Gb) |
| 3308 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3309 | if (phba->lmt & LMT_2Gb) |
| 3310 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3311 | if (phba->lmt & LMT_1Gb) |
| 3312 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3313 | |
| 3314 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3315 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3316 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3317 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3318 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3319 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3320 | /* This value is also unchanging */ |
| 3321 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3322 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3323 | fc_host_active_fc4s(shost)[2] = 1; |
| 3324 | fc_host_active_fc4s(shost)[7] = 1; |
| 3325 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3326 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3327 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3328 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3329 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3330 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3332 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3333 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3334 | * @phba: pointer to lpfc hba data structure. |
| 3335 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3336 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3337 | * from generating interrupts and stops the device driver's timers for the |
| 3338 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3339 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3340 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3341 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3342 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3343 | /* Clear all interrupt enable conditions */ |
| 3344 | writel(0, phba->HCregaddr); |
| 3345 | readl(phba->HCregaddr); /* flush */ |
| 3346 | /* Clear all pending interrupts */ |
| 3347 | writel(0xffffffff, phba->HAregaddr); |
| 3348 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3349 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3350 | /* Reset some HBA SLI setup states */ |
| 3351 | lpfc_stop_hba_timers(phba); |
| 3352 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3353 | } |
| 3354 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3355 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3356 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3357 | * @phba: pointer to lpfc hba data structure. |
| 3358 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3359 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3360 | * from generating interrupts and stops the device driver's timers for the |
| 3361 | * device. |
| 3362 | **/ |
| 3363 | static void |
| 3364 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3365 | { |
| 3366 | /* Reset some HBA SLI4 setup states */ |
| 3367 | lpfc_stop_hba_timers(phba); |
| 3368 | phba->pport->work_port_events = 0; |
| 3369 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | /** |
| 3373 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3374 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3375 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3376 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3377 | * the API jump table function pointer from the lpfc_hba struct. |
| 3378 | **/ |
| 3379 | void |
| 3380 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3381 | { |
| 3382 | phba->lpfc_stop_port(phba); |
| 3383 | } |
| 3384 | |
| 3385 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3386 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3387 | * @phba: Pointer to hba for which this call is being executed. |
| 3388 | * |
| 3389 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3390 | **/ |
| 3391 | void |
| 3392 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3393 | { |
| 3394 | unsigned long fcf_redisc_wait_tmo = |
| 3395 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3396 | /* Start fcf rediscovery wait period timer */ |
| 3397 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3398 | spin_lock_irq(&phba->hbalock); |
| 3399 | /* Allow action to new fcf asynchronous event */ |
| 3400 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3401 | /* Mark the FCF rediscovery pending state */ |
| 3402 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3403 | spin_unlock_irq(&phba->hbalock); |
| 3404 | } |
| 3405 | |
| 3406 | /** |
| 3407 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3408 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3409 | * |
| 3410 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3411 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3412 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3413 | * list, and then worker thread shall be waked up for processing from the |
| 3414 | * worker thread context. |
| 3415 | **/ |
| 3416 | void |
| 3417 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3418 | { |
| 3419 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3420 | |
| 3421 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3422 | spin_lock_irq(&phba->hbalock); |
| 3423 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3424 | spin_unlock_irq(&phba->hbalock); |
| 3425 | return; |
| 3426 | } |
| 3427 | /* Clear FCF rediscovery timer pending flag */ |
| 3428 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3429 | /* FCF rediscovery event to worker thread */ |
| 3430 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3431 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3432 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3433 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3434 | /* wake up worker thread */ |
| 3435 | lpfc_worker_wake_up(phba); |
| 3436 | } |
| 3437 | |
| 3438 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3439 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3440 | * @phba: pointer to lpfc hba data structure. |
| 3441 | * @acqe_link: pointer to the async link completion queue entry. |
| 3442 | * |
| 3443 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3444 | * translate it into the base driver's read link attention mailbox command |
| 3445 | * status. |
| 3446 | * |
| 3447 | * Return: Link-attention status in terms of base driver's coding. |
| 3448 | **/ |
| 3449 | static uint16_t |
| 3450 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3451 | struct lpfc_acqe_link *acqe_link) |
| 3452 | { |
| 3453 | uint16_t latt_fault; |
| 3454 | |
| 3455 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3456 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3457 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3458 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3459 | latt_fault = 0; |
| 3460 | break; |
| 3461 | default: |
| 3462 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3463 | "0398 Invalid link fault code: x%x\n", |
| 3464 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3465 | latt_fault = MBXERR_ERROR; |
| 3466 | break; |
| 3467 | } |
| 3468 | return latt_fault; |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3473 | * @phba: pointer to lpfc hba data structure. |
| 3474 | * @acqe_link: pointer to the async link completion queue entry. |
| 3475 | * |
| 3476 | * This routine is to parse the SLI4 link attention type and translate it |
| 3477 | * into the base driver's link attention type coding. |
| 3478 | * |
| 3479 | * Return: Link attention type in terms of base driver's coding. |
| 3480 | **/ |
| 3481 | static uint8_t |
| 3482 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3483 | struct lpfc_acqe_link *acqe_link) |
| 3484 | { |
| 3485 | uint8_t att_type; |
| 3486 | |
| 3487 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3488 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3489 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3490 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3491 | break; |
| 3492 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3493 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3494 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3495 | break; |
| 3496 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3497 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3498 | break; |
| 3499 | default: |
| 3500 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3501 | "0399 Invalid link attention type: x%x\n", |
| 3502 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3503 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3504 | break; |
| 3505 | } |
| 3506 | return att_type; |
| 3507 | } |
| 3508 | |
| 3509 | /** |
| 3510 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3511 | * @phba: pointer to lpfc hba data structure. |
| 3512 | * @acqe_link: pointer to the async link completion queue entry. |
| 3513 | * |
| 3514 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3515 | * it into the base driver's link-attention link speed coding. |
| 3516 | * |
| 3517 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3518 | **/ |
| 3519 | static uint8_t |
| 3520 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3521 | struct lpfc_acqe_link *acqe_link) |
| 3522 | { |
| 3523 | uint8_t link_speed; |
| 3524 | |
| 3525 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3526 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3527 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3528 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3529 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3530 | break; |
| 3531 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3532 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3533 | break; |
| 3534 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3535 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3536 | break; |
| 3537 | default: |
| 3538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3539 | "0483 Invalid link-attention link speed: x%x\n", |
| 3540 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3541 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | return link_speed; |
| 3545 | } |
| 3546 | |
| 3547 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3548 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 3549 | * @phba: pointer to lpfc hba data structure. |
| 3550 | * |
| 3551 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 3552 | * |
| 3553 | * Return: link speed in terms of Mbps. |
| 3554 | **/ |
| 3555 | uint32_t |
| 3556 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 3557 | { |
| 3558 | uint32_t link_speed; |
| 3559 | |
| 3560 | if (!lpfc_is_link_up(phba)) |
| 3561 | return 0; |
| 3562 | |
| 3563 | switch (phba->fc_linkspeed) { |
| 3564 | case LPFC_LINK_SPEED_1GHZ: |
| 3565 | link_speed = 1000; |
| 3566 | break; |
| 3567 | case LPFC_LINK_SPEED_2GHZ: |
| 3568 | link_speed = 2000; |
| 3569 | break; |
| 3570 | case LPFC_LINK_SPEED_4GHZ: |
| 3571 | link_speed = 4000; |
| 3572 | break; |
| 3573 | case LPFC_LINK_SPEED_8GHZ: |
| 3574 | link_speed = 8000; |
| 3575 | break; |
| 3576 | case LPFC_LINK_SPEED_10GHZ: |
| 3577 | link_speed = 10000; |
| 3578 | break; |
| 3579 | case LPFC_LINK_SPEED_16GHZ: |
| 3580 | link_speed = 16000; |
| 3581 | break; |
| 3582 | default: |
| 3583 | link_speed = 0; |
| 3584 | } |
| 3585 | return link_speed; |
| 3586 | } |
| 3587 | |
| 3588 | /** |
| 3589 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 3590 | * @phba: pointer to lpfc hba data structure. |
| 3591 | * @evt_code: asynchronous event code. |
| 3592 | * @speed_code: asynchronous event link speed code. |
| 3593 | * |
| 3594 | * This routine is to parse the giving SLI4 async event link speed code into |
| 3595 | * value of Mbps for the link speed. |
| 3596 | * |
| 3597 | * Return: link speed in terms of Mbps. |
| 3598 | **/ |
| 3599 | static uint32_t |
| 3600 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 3601 | uint8_t speed_code) |
| 3602 | { |
| 3603 | uint32_t port_speed; |
| 3604 | |
| 3605 | switch (evt_code) { |
| 3606 | case LPFC_TRAILER_CODE_LINK: |
| 3607 | switch (speed_code) { |
| 3608 | case LPFC_EVT_CODE_LINK_NO_LINK: |
| 3609 | port_speed = 0; |
| 3610 | break; |
| 3611 | case LPFC_EVT_CODE_LINK_10_MBIT: |
| 3612 | port_speed = 10; |
| 3613 | break; |
| 3614 | case LPFC_EVT_CODE_LINK_100_MBIT: |
| 3615 | port_speed = 100; |
| 3616 | break; |
| 3617 | case LPFC_EVT_CODE_LINK_1_GBIT: |
| 3618 | port_speed = 1000; |
| 3619 | break; |
| 3620 | case LPFC_EVT_CODE_LINK_10_GBIT: |
| 3621 | port_speed = 10000; |
| 3622 | break; |
| 3623 | default: |
| 3624 | port_speed = 0; |
| 3625 | } |
| 3626 | break; |
| 3627 | case LPFC_TRAILER_CODE_FC: |
| 3628 | switch (speed_code) { |
| 3629 | case LPFC_EVT_CODE_FC_NO_LINK: |
| 3630 | port_speed = 0; |
| 3631 | break; |
| 3632 | case LPFC_EVT_CODE_FC_1_GBAUD: |
| 3633 | port_speed = 1000; |
| 3634 | break; |
| 3635 | case LPFC_EVT_CODE_FC_2_GBAUD: |
| 3636 | port_speed = 2000; |
| 3637 | break; |
| 3638 | case LPFC_EVT_CODE_FC_4_GBAUD: |
| 3639 | port_speed = 4000; |
| 3640 | break; |
| 3641 | case LPFC_EVT_CODE_FC_8_GBAUD: |
| 3642 | port_speed = 8000; |
| 3643 | break; |
| 3644 | case LPFC_EVT_CODE_FC_10_GBAUD: |
| 3645 | port_speed = 10000; |
| 3646 | break; |
| 3647 | case LPFC_EVT_CODE_FC_16_GBAUD: |
| 3648 | port_speed = 16000; |
| 3649 | break; |
| 3650 | default: |
| 3651 | port_speed = 0; |
| 3652 | } |
| 3653 | break; |
| 3654 | default: |
| 3655 | port_speed = 0; |
| 3656 | } |
| 3657 | return port_speed; |
| 3658 | } |
| 3659 | |
| 3660 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3661 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3662 | * @phba: pointer to lpfc hba data structure. |
| 3663 | * @acqe_link: pointer to the async link completion queue entry. |
| 3664 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3665 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3666 | **/ |
| 3667 | static void |
| 3668 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3669 | struct lpfc_acqe_link *acqe_link) |
| 3670 | { |
| 3671 | struct lpfc_dmabuf *mp; |
| 3672 | LPFC_MBOXQ_t *pmb; |
| 3673 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3674 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3675 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3676 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3677 | |
| 3678 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3679 | 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] | 3680 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3681 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3682 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3683 | if (!pmb) { |
| 3684 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3685 | "0395 The mboxq allocation failed\n"); |
| 3686 | return; |
| 3687 | } |
| 3688 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3689 | if (!mp) { |
| 3690 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3691 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3692 | goto out_free_pmb; |
| 3693 | } |
| 3694 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3695 | if (!mp->virt) { |
| 3696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3697 | "0397 The mbuf allocation failed\n"); |
| 3698 | goto out_free_dmabuf; |
| 3699 | } |
| 3700 | |
| 3701 | /* Cleanup any outstanding ELS commands */ |
| 3702 | lpfc_els_flush_all_cmd(phba); |
| 3703 | |
| 3704 | /* Block ELS IOCBs until we have done process link event */ |
| 3705 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3706 | |
| 3707 | /* Update link event statistics */ |
| 3708 | phba->sli.slistat.link_event++; |
| 3709 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3710 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3711 | lpfc_read_topology(phba, pmb, mp); |
| 3712 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3713 | pmb->vport = phba->pport; |
| 3714 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3715 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3716 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3717 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 3718 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3719 | phba->sli4_hba.link_state.duplex = |
| 3720 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3721 | phba->sli4_hba.link_state.status = |
| 3722 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3723 | phba->sli4_hba.link_state.type = |
| 3724 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3725 | phba->sli4_hba.link_state.number = |
| 3726 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3727 | phba->sli4_hba.link_state.fault = |
| 3728 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3729 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3730 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 3731 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3732 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3733 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3734 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3735 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3736 | phba->sli4_hba.link_state.speed, |
| 3737 | phba->sli4_hba.link_state.topology, |
| 3738 | phba->sli4_hba.link_state.status, |
| 3739 | phba->sli4_hba.link_state.type, |
| 3740 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3741 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3742 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3743 | /* |
| 3744 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3745 | * topology info. Note: Optional for non FC-AL ports. |
| 3746 | */ |
| 3747 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3748 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3749 | if (rc == MBX_NOT_FINISHED) |
| 3750 | goto out_free_dmabuf; |
| 3751 | return; |
| 3752 | } |
| 3753 | /* |
| 3754 | * For FCoE Mode: fill in all the topology information we need and call |
| 3755 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3756 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3757 | */ |
| 3758 | /* Parse and translate status field */ |
| 3759 | mb = &pmb->u.mb; |
| 3760 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3761 | |
| 3762 | /* Parse and translate link attention fields */ |
| 3763 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3764 | la->eventTag = acqe_link->event_tag; |
| 3765 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3766 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3767 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3768 | |
| 3769 | /* Fake the the following irrelvant fields */ |
| 3770 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3771 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3772 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3773 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3774 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3775 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3776 | |
| 3777 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3778 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3779 | |
| 3780 | return; |
| 3781 | |
| 3782 | out_free_dmabuf: |
| 3783 | kfree(mp); |
| 3784 | out_free_pmb: |
| 3785 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3786 | } |
| 3787 | |
| 3788 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3789 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3790 | * @phba: pointer to lpfc hba data structure. |
| 3791 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3792 | * |
| 3793 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3794 | * that the event was received and then issue a read_topology mailbox command so |
| 3795 | * that the rest of the driver will treat it the same as SLI3. |
| 3796 | **/ |
| 3797 | static void |
| 3798 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3799 | { |
| 3800 | struct lpfc_dmabuf *mp; |
| 3801 | LPFC_MBOXQ_t *pmb; |
| 3802 | int rc; |
| 3803 | |
| 3804 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3805 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3806 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3807 | "2895 Non FC link Event detected.(%d)\n", |
| 3808 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3809 | return; |
| 3810 | } |
| 3811 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3812 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3813 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 3814 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3815 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3816 | phba->sli4_hba.link_state.topology = |
| 3817 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3818 | phba->sli4_hba.link_state.status = |
| 3819 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3820 | phba->sli4_hba.link_state.type = |
| 3821 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3822 | phba->sli4_hba.link_state.number = |
| 3823 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3824 | phba->sli4_hba.link_state.fault = |
| 3825 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3826 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3827 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3828 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3829 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3830 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3831 | "%dMbps Fault:%d\n", |
| 3832 | phba->sli4_hba.link_state.speed, |
| 3833 | phba->sli4_hba.link_state.topology, |
| 3834 | phba->sli4_hba.link_state.status, |
| 3835 | phba->sli4_hba.link_state.type, |
| 3836 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 3837 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3838 | phba->sli4_hba.link_state.fault); |
| 3839 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3840 | if (!pmb) { |
| 3841 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3842 | "2897 The mboxq allocation failed\n"); |
| 3843 | return; |
| 3844 | } |
| 3845 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3846 | if (!mp) { |
| 3847 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3848 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3849 | goto out_free_pmb; |
| 3850 | } |
| 3851 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3852 | if (!mp->virt) { |
| 3853 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3854 | "2899 The mbuf allocation failed\n"); |
| 3855 | goto out_free_dmabuf; |
| 3856 | } |
| 3857 | |
| 3858 | /* Cleanup any outstanding ELS commands */ |
| 3859 | lpfc_els_flush_all_cmd(phba); |
| 3860 | |
| 3861 | /* Block ELS IOCBs until we have done process link event */ |
| 3862 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3863 | |
| 3864 | /* Update link event statistics */ |
| 3865 | phba->sli.slistat.link_event++; |
| 3866 | |
| 3867 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3868 | lpfc_read_topology(phba, pmb, mp); |
| 3869 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3870 | pmb->vport = phba->pport; |
| 3871 | |
| 3872 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3873 | if (rc == MBX_NOT_FINISHED) |
| 3874 | goto out_free_dmabuf; |
| 3875 | return; |
| 3876 | |
| 3877 | out_free_dmabuf: |
| 3878 | kfree(mp); |
| 3879 | out_free_pmb: |
| 3880 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3885 | * @phba: pointer to lpfc hba data structure. |
| 3886 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3887 | * |
| 3888 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3889 | **/ |
| 3890 | static void |
| 3891 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3892 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3893 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 3894 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3895 | uint8_t status; |
| 3896 | struct lpfc_acqe_misconfigured_event *misconfigured; |
| 3897 | |
| 3898 | /* special case misconfigured event as it contains data for all ports */ |
| 3899 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3900 | LPFC_SLI_INTF_IF_TYPE_2) || |
| 3901 | (bf_get(lpfc_trailer_type, acqe_sli) != |
| 3902 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { |
| 3903 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3904 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3905 | "x%08x SLI Event Type:%d\n", |
| 3906 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3907 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3908 | return; |
| 3909 | } |
| 3910 | |
| 3911 | port_name = phba->Port[0]; |
| 3912 | if (port_name == 0x00) |
| 3913 | port_name = '?'; /* get port name is empty */ |
| 3914 | |
| 3915 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
| 3916 | &acqe_sli->event_data1; |
| 3917 | |
| 3918 | /* fetch the status for this port */ |
| 3919 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 3920 | case LPFC_LINK_NUMBER_0: |
| 3921 | status = bf_get(lpfc_sli_misconfigured_port0, |
| 3922 | &misconfigured->theEvent); |
| 3923 | break; |
| 3924 | case LPFC_LINK_NUMBER_1: |
| 3925 | status = bf_get(lpfc_sli_misconfigured_port1, |
| 3926 | &misconfigured->theEvent); |
| 3927 | break; |
| 3928 | case LPFC_LINK_NUMBER_2: |
| 3929 | status = bf_get(lpfc_sli_misconfigured_port2, |
| 3930 | &misconfigured->theEvent); |
| 3931 | break; |
| 3932 | case LPFC_LINK_NUMBER_3: |
| 3933 | status = bf_get(lpfc_sli_misconfigured_port3, |
| 3934 | &misconfigured->theEvent); |
| 3935 | break; |
| 3936 | default: |
| 3937 | status = ~LPFC_SLI_EVENT_STATUS_VALID; |
| 3938 | break; |
| 3939 | } |
| 3940 | |
| 3941 | switch (status) { |
| 3942 | case LPFC_SLI_EVENT_STATUS_VALID: |
| 3943 | return; /* no message if the sfp is okay */ |
| 3944 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3945 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
| 3946 | "installed - Reseat optics, if issue not " |
| 3947 | "resolved, replace."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3948 | break; |
| 3949 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 3950 | sprintf(message, |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3951 | "Optics of two types installed - Remove one optic or " \ |
| 3952 | "install matching pair of optics."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3953 | break; |
| 3954 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 3955 | sprintf(message, "Incompatible optics - Replace with " \ |
| 3956 | "compatible optics for card to function."); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 3957 | break; |
| 3958 | default: |
| 3959 | /* firmware is reporting a status we don't know about */ |
| 3960 | sprintf(message, "Unknown event status x%02x", status); |
| 3961 | break; |
| 3962 | } |
| 3963 | |
| 3964 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3965 | "3176 Misconfigured Physical Port - " |
| 3966 | "Port Name %c %s\n", port_name, message); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3970 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 3971 | * @vport: pointer to vport data structure. |
| 3972 | * |
| 3973 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 3974 | * response to a CVL event. |
| 3975 | * |
| 3976 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 3977 | * return NULL. |
| 3978 | **/ |
| 3979 | static struct lpfc_nodelist * |
| 3980 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 3981 | { |
| 3982 | struct lpfc_nodelist *ndlp; |
| 3983 | struct Scsi_Host *shost; |
| 3984 | struct lpfc_hba *phba; |
| 3985 | |
| 3986 | if (!vport) |
| 3987 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3988 | phba = vport->phba; |
| 3989 | if (!phba) |
| 3990 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3991 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 3992 | if (!ndlp) { |
| 3993 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 3994 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3995 | if (!ndlp) |
| 3996 | return 0; |
| 3997 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 3998 | /* Set the node type */ |
| 3999 | ndlp->nlp_type |= NLP_FABRIC; |
| 4000 | /* Put ndlp onto node list */ |
| 4001 | lpfc_enqueue_node(vport, ndlp); |
| 4002 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4003 | /* re-setup ndlp without removing from node list */ |
| 4004 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4005 | if (!ndlp) |
| 4006 | return 0; |
| 4007 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4008 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4009 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4010 | return NULL; |
| 4011 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4012 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4013 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4014 | return NULL; |
| 4015 | shost = lpfc_shost_from_vport(vport); |
| 4016 | if (!shost) |
| 4017 | return NULL; |
| 4018 | lpfc_linkdown_port(vport); |
| 4019 | lpfc_cleanup_pending_mbox(vport); |
| 4020 | spin_lock_irq(shost->host_lock); |
| 4021 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4022 | spin_unlock_irq(shost->host_lock); |
| 4023 | |
| 4024 | return ndlp; |
| 4025 | } |
| 4026 | |
| 4027 | /** |
| 4028 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4029 | * @vport: pointer to lpfc hba data structure. |
| 4030 | * |
| 4031 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4032 | * response to a FCF dead event. |
| 4033 | **/ |
| 4034 | static void |
| 4035 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4036 | { |
| 4037 | struct lpfc_vport **vports; |
| 4038 | int i; |
| 4039 | |
| 4040 | vports = lpfc_create_vport_work_array(phba); |
| 4041 | if (vports) |
| 4042 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4043 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4044 | lpfc_destroy_vport_work_array(phba, vports); |
| 4045 | } |
| 4046 | |
| 4047 | /** |
James Smart | 25aee40 | 2013-03-01 16:36:34 -0500 | [diff] [blame] | 4048 | * lpfc_sli4_perform_inuse_fcf_recovery - Perform inuse fcf recovery |
| 4049 | * @vport: pointer to lpfc hba data structure. |
| 4050 | * |
| 4051 | * This routine is to perform FCF recovery when the in-use FCF either dead or |
| 4052 | * got modified. |
| 4053 | **/ |
| 4054 | static void |
| 4055 | lpfc_sli4_perform_inuse_fcf_recovery(struct lpfc_hba *phba, |
| 4056 | struct lpfc_acqe_fip *acqe_fip) |
| 4057 | { |
| 4058 | int rc; |
| 4059 | |
| 4060 | spin_lock_irq(&phba->hbalock); |
| 4061 | /* Mark the fast failover process in progress */ |
| 4062 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 4063 | spin_unlock_irq(&phba->hbalock); |
| 4064 | |
| 4065 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 4066 | "2771 Start FCF fast failover process due to in-use " |
| 4067 | "FCF DEAD/MODIFIED event: evt_tag:x%x, index:x%x\n", |
| 4068 | acqe_fip->event_tag, acqe_fip->index); |
| 4069 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 4070 | if (rc) { |
| 4071 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4072 | "2772 Issue FCF rediscover mabilbox command " |
| 4073 | "failed, fail through to FCF dead event\n"); |
| 4074 | spin_lock_irq(&phba->hbalock); |
| 4075 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 4076 | spin_unlock_irq(&phba->hbalock); |
| 4077 | /* |
| 4078 | * Last resort will fail over by treating this as a link |
| 4079 | * down to FCF registration. |
| 4080 | */ |
| 4081 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 4082 | } else { |
| 4083 | /* Reset FCF roundrobin bmask for new discovery */ |
| 4084 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 4085 | /* |
| 4086 | * Handling fast FCF failover to a DEAD FCF event is |
| 4087 | * considered equalivant to receiving CVL to all vports. |
| 4088 | */ |
| 4089 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4094 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4095 | * @phba: pointer to lpfc hba data structure. |
| 4096 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4097 | * |
| 4098 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4099 | **/ |
| 4100 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4101 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4102 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4103 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4104 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4105 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4106 | struct lpfc_vport *vport; |
| 4107 | struct lpfc_nodelist *ndlp; |
| 4108 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4109 | int active_vlink_present; |
| 4110 | struct lpfc_vport **vports; |
| 4111 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4112 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4113 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4114 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4115 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4116 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4117 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4118 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4119 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4120 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4121 | "2546 New FCF event, evt_tag:x%x, " |
| 4122 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4123 | acqe_fip->event_tag, |
| 4124 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4125 | else |
| 4126 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4127 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4128 | "2788 FCF param modified event, " |
| 4129 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4130 | acqe_fip->event_tag, |
| 4131 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4132 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4133 | /* |
| 4134 | * During period of FCF discovery, read the FCF |
| 4135 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4136 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4137 | */ |
| 4138 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4139 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4140 | "2779 Read FCF (x%x) for updating " |
| 4141 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4142 | acqe_fip->index); |
| 4143 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4144 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4145 | |
| 4146 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4147 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4148 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4149 | spin_unlock_irq(&phba->hbalock); |
| 4150 | break; |
| 4151 | } |
| 4152 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 4153 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 4154 | spin_unlock_irq(&phba->hbalock); |
| 4155 | break; |
| 4156 | } |
| 4157 | |
James Smart | 25aee40 | 2013-03-01 16:36:34 -0500 | [diff] [blame] | 4158 | /* If FCF has been in discovered state, perform rediscovery |
| 4159 | * only if the FCF with the same index of the in-use FCF got |
| 4160 | * modified during normal operation. Otherwise, do nothing. |
| 4161 | */ |
| 4162 | if (phba->pport->port_state > LPFC_FLOGI) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4163 | spin_unlock_irq(&phba->hbalock); |
James Smart | 25aee40 | 2013-03-01 16:36:34 -0500 | [diff] [blame] | 4164 | if (phba->fcf.current_rec.fcf_indx == |
| 4165 | acqe_fip->index) { |
| 4166 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 4167 | "3300 In-use FCF (%d) " |
| 4168 | "modified, perform FCF " |
| 4169 | "rediscovery\n", |
| 4170 | acqe_fip->index); |
| 4171 | lpfc_sli4_perform_inuse_fcf_recovery(phba, |
| 4172 | acqe_fip); |
| 4173 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 4174 | break; |
| 4175 | } |
| 4176 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4177 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4178 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 4179 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4180 | "2770 Start FCF table scan per async FCF " |
| 4181 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4182 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4183 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 4184 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4185 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4186 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4187 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4188 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4189 | break; |
| 4190 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4191 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4192 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 4193 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4194 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 4195 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4196 | break; |
| 4197 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4198 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4199 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4200 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4201 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4202 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4203 | /* |
| 4204 | * If we are in the middle of FCF failover process, clear |
| 4205 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4206 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4207 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4208 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4209 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4210 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4211 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4212 | break; |
| 4213 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4214 | spin_unlock_irq(&phba->hbalock); |
| 4215 | |
| 4216 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4217 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4218 | break; |
| 4219 | |
| 4220 | /* |
| 4221 | * Otherwise, request the port to rediscover the entire FCF |
| 4222 | * table for a fast recovery from case that the current FCF |
| 4223 | * is no longer valid as we are not in the middle of FCF |
| 4224 | * failover process already. |
| 4225 | */ |
James Smart | 25aee40 | 2013-03-01 16:36:34 -0500 | [diff] [blame] | 4226 | lpfc_sli4_perform_inuse_fcf_recovery(phba, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4227 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4228 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 4229 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4230 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4231 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4232 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4233 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4234 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4235 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4236 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4237 | if (!ndlp) |
| 4238 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4239 | active_vlink_present = 0; |
| 4240 | |
| 4241 | vports = lpfc_create_vport_work_array(phba); |
| 4242 | if (vports) { |
| 4243 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 4244 | i++) { |
| 4245 | if ((!(vports[i]->fc_flag & |
| 4246 | FC_VPORT_CVL_RCVD)) && |
| 4247 | (vports[i]->port_state > LPFC_FDISC)) { |
| 4248 | active_vlink_present = 1; |
| 4249 | break; |
| 4250 | } |
| 4251 | } |
| 4252 | lpfc_destroy_vport_work_array(phba, vports); |
| 4253 | } |
| 4254 | |
| 4255 | if (active_vlink_present) { |
| 4256 | /* |
| 4257 | * If there are other active VLinks present, |
| 4258 | * re-instantiate the Vlink using FDISC. |
| 4259 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4260 | mod_timer(&ndlp->nlp_delayfunc, |
| 4261 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4262 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4263 | spin_lock_irq(shost->host_lock); |
| 4264 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 4265 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4266 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 4267 | vport->port_state = LPFC_FDISC; |
| 4268 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4269 | /* |
| 4270 | * Otherwise, we request port to rediscover |
| 4271 | * the entire FCF table for a fast recovery |
| 4272 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4273 | * is no longer valid if we are not already |
| 4274 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4275 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4276 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4277 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4278 | spin_unlock_irq(&phba->hbalock); |
| 4279 | break; |
| 4280 | } |
| 4281 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4282 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4283 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4284 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 4285 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4286 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4287 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4288 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4289 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4290 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4291 | LOG_DISCOVERY, |
| 4292 | "2774 Issue FCF rediscover " |
| 4293 | "mabilbox command failed, " |
| 4294 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4295 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4296 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4297 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4298 | /* |
| 4299 | * Last resort will be re-try on the |
| 4300 | * the current registered FCF entry. |
| 4301 | */ |
| 4302 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4303 | } else |
| 4304 | /* |
| 4305 | * Reset FCF roundrobin bmask for new |
| 4306 | * discovery. |
| 4307 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 4308 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4309 | } |
| 4310 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4311 | default: |
| 4312 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4313 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4314 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4315 | break; |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | /** |
| 4320 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 4321 | * @phba: pointer to lpfc hba data structure. |
| 4322 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 4323 | * |
| 4324 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 4325 | **/ |
| 4326 | static void |
| 4327 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 4328 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 4329 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4330 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4331 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4332 | "0290 The SLI4 DCBX asynchronous event is not " |
| 4333 | "handled yet\n"); |
| 4334 | } |
| 4335 | |
| 4336 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4337 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 4338 | * @phba: pointer to lpfc hba data structure. |
| 4339 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 4340 | * |
| 4341 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 4342 | * is an asynchronous notified of a logical link speed change. The Port |
| 4343 | * reports the logical link speed in units of 10Mbps. |
| 4344 | **/ |
| 4345 | static void |
| 4346 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 4347 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 4348 | { |
| 4349 | uint16_t prev_ll_spd; |
| 4350 | |
| 4351 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 4352 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 4353 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 4354 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4355 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4356 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4357 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4358 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 4359 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4363 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 4364 | * @phba: pointer to lpfc hba data structure. |
| 4365 | * |
| 4366 | * This routine is invoked by the worker thread to process all the pending |
| 4367 | * SLI4 asynchronous events. |
| 4368 | **/ |
| 4369 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 4370 | { |
| 4371 | struct lpfc_cq_event *cq_event; |
| 4372 | |
| 4373 | /* First, declare the async event has been handled */ |
| 4374 | spin_lock_irq(&phba->hbalock); |
| 4375 | phba->hba_flag &= ~ASYNC_EVENT; |
| 4376 | spin_unlock_irq(&phba->hbalock); |
| 4377 | /* Now, handle all the async events */ |
| 4378 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 4379 | /* Get the first event from the head of the event queue */ |
| 4380 | spin_lock_irq(&phba->hbalock); |
| 4381 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 4382 | cq_event, struct lpfc_cq_event, list); |
| 4383 | spin_unlock_irq(&phba->hbalock); |
| 4384 | /* Process the asynchronous event */ |
| 4385 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 4386 | case LPFC_TRAILER_CODE_LINK: |
| 4387 | lpfc_sli4_async_link_evt(phba, |
| 4388 | &cq_event->cqe.acqe_link); |
| 4389 | break; |
| 4390 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4391 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4392 | break; |
| 4393 | case LPFC_TRAILER_CODE_DCBX: |
| 4394 | lpfc_sli4_async_dcbx_evt(phba, |
| 4395 | &cq_event->cqe.acqe_dcbx); |
| 4396 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 4397 | case LPFC_TRAILER_CODE_GRP5: |
| 4398 | lpfc_sli4_async_grp5_evt(phba, |
| 4399 | &cq_event->cqe.acqe_grp5); |
| 4400 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4401 | case LPFC_TRAILER_CODE_FC: |
| 4402 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 4403 | break; |
| 4404 | case LPFC_TRAILER_CODE_SLI: |
| 4405 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 4406 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4407 | default: |
| 4408 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4409 | "1804 Invalid asynchrous event code: " |
| 4410 | "x%x\n", bf_get(lpfc_trailer_code, |
| 4411 | &cq_event->cqe.mcqe_cmpl)); |
| 4412 | break; |
| 4413 | } |
| 4414 | /* Free the completion event processed to the free pool */ |
| 4415 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4420 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 4421 | * @phba: pointer to lpfc hba data structure. |
| 4422 | * |
| 4423 | * This routine is invoked by the worker thread to process FCF table |
| 4424 | * rediscovery pending completion event. |
| 4425 | **/ |
| 4426 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 4427 | { |
| 4428 | int rc; |
| 4429 | |
| 4430 | spin_lock_irq(&phba->hbalock); |
| 4431 | /* Clear FCF rediscovery timeout event */ |
| 4432 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 4433 | /* Clear driver fast failover FCF record flag */ |
| 4434 | phba->fcf.failover_rec.flag = 0; |
| 4435 | /* Set state for FCF fast failover */ |
| 4436 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 4437 | spin_unlock_irq(&phba->hbalock); |
| 4438 | |
| 4439 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4440 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4441 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4442 | 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] | 4443 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4444 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4445 | "2747 Issue FCF scan read FCF mailbox " |
| 4446 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4450 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4451 | * @phba: pointer to lpfc hba data structure. |
| 4452 | * @dev_grp: The HBA PCI-Device group number. |
| 4453 | * |
| 4454 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4455 | * API jump table entries. |
| 4456 | * |
| 4457 | * Return: 0 if success, otherwise -ENODEV |
| 4458 | **/ |
| 4459 | int |
| 4460 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4461 | { |
| 4462 | int rc; |
| 4463 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4464 | /* Set up lpfc PCI-device group */ |
| 4465 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4466 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4467 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4468 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4469 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4470 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4471 | /* Set up device INIT API function jump table */ |
| 4472 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4473 | if (rc) |
| 4474 | return -ENODEV; |
| 4475 | /* Set up SCSI API function jump table */ |
| 4476 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4477 | if (rc) |
| 4478 | return -ENODEV; |
| 4479 | /* Set up SLI API function jump table */ |
| 4480 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4481 | if (rc) |
| 4482 | return -ENODEV; |
| 4483 | /* Set up MBOX API function jump table */ |
| 4484 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4485 | if (rc) |
| 4486 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4487 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4488 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4492 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4493 | * @phba: pointer to lpfc hba data structure. |
| 4494 | * @intr_mode: active interrupt mode adopted. |
| 4495 | * |
| 4496 | * This routine it invoked to log the currently used active interrupt mode |
| 4497 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4498 | **/ |
| 4499 | 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] | 4500 | { |
| 4501 | switch (intr_mode) { |
| 4502 | case 0: |
| 4503 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4504 | "0470 Enable INTx interrupt mode.\n"); |
| 4505 | break; |
| 4506 | case 1: |
| 4507 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4508 | "0481 Enabled MSI interrupt mode.\n"); |
| 4509 | break; |
| 4510 | case 2: |
| 4511 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4512 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4513 | break; |
| 4514 | default: |
| 4515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4516 | "0482 Illegal interrupt mode.\n"); |
| 4517 | break; |
| 4518 | } |
| 4519 | return; |
| 4520 | } |
| 4521 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4522 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4523 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4524 | * @phba: pointer to lpfc hba data structure. |
| 4525 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4526 | * This routine is invoked to enable the PCI device that is common to all |
| 4527 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4528 | * |
| 4529 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4530 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4531 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4532 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4533 | static int |
| 4534 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4535 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4536 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4537 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4538 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4539 | /* Obtain PCI device reference */ |
| 4540 | if (!phba->pcidev) |
| 4541 | goto out_error; |
| 4542 | else |
| 4543 | pdev = phba->pcidev; |
| 4544 | /* Select PCI BARs */ |
| 4545 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4546 | /* Enable PCI device */ |
| 4547 | if (pci_enable_device_mem(pdev)) |
| 4548 | goto out_error; |
| 4549 | /* Request PCI resource for the device */ |
| 4550 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4551 | goto out_disable_device; |
| 4552 | /* Set up device as PCI master and save state for EEH */ |
| 4553 | pci_set_master(pdev); |
| 4554 | pci_try_set_mwi(pdev); |
| 4555 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4556 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4557 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
| 4558 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) |
| 4559 | pdev->needs_freset = 1; |
| 4560 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4561 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4562 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4563 | out_disable_device: |
| 4564 | pci_disable_device(pdev); |
| 4565 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4567 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4568 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4572 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4573 | * @phba: pointer to lpfc hba data structure. |
| 4574 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4575 | * This routine is invoked to disable the PCI device that is common to all |
| 4576 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4577 | **/ |
| 4578 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4579 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4580 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4581 | struct pci_dev *pdev; |
| 4582 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4583 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4584 | /* Obtain PCI device reference */ |
| 4585 | if (!phba->pcidev) |
| 4586 | return; |
| 4587 | else |
| 4588 | pdev = phba->pcidev; |
| 4589 | /* Select PCI BARs */ |
| 4590 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4591 | /* Release PCI resource and disable PCI device */ |
| 4592 | pci_release_selected_regions(pdev, bars); |
| 4593 | pci_disable_device(pdev); |
| 4594 | /* Null out PCI private reference to driver */ |
| 4595 | pci_set_drvdata(pdev, NULL); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4596 | |
| 4597 | return; |
| 4598 | } |
| 4599 | |
| 4600 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4601 | * lpfc_reset_hba - Reset a hba |
| 4602 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4603 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4604 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4605 | * offline, performs a board restart, and then brings the board back |
| 4606 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4607 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4608 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4609 | void |
| 4610 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4612 | /* If resets are disabled then set error state and return. */ |
| 4613 | if (!phba->cfg_enable_hba_reset) { |
| 4614 | phba->link_state = LPFC_HBA_ERROR; |
| 4615 | return; |
| 4616 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 4617 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4618 | lpfc_offline(phba); |
| 4619 | lpfc_sli_brdrestart(phba); |
| 4620 | lpfc_online(phba); |
| 4621 | lpfc_unblock_mgmt_io(phba); |
| 4622 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4623 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4624 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4625 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4626 | * @phba: pointer to lpfc hba data structure. |
| 4627 | * |
| 4628 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4629 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4630 | * enable the number of virtual functions to the physical function. As |
| 4631 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4632 | * API call does not considered as an error condition for most of the device. |
| 4633 | **/ |
| 4634 | uint16_t |
| 4635 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4636 | { |
| 4637 | struct pci_dev *pdev = phba->pcidev; |
| 4638 | uint16_t nr_virtfn; |
| 4639 | int pos; |
| 4640 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4641 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4642 | if (pos == 0) |
| 4643 | return 0; |
| 4644 | |
| 4645 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4646 | return nr_virtfn; |
| 4647 | } |
| 4648 | |
| 4649 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4650 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4651 | * @phba: pointer to lpfc hba data structure. |
| 4652 | * @nr_vfn: number of virtual functions to be enabled. |
| 4653 | * |
| 4654 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4655 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4656 | * enable the number of virtual functions to the physical function. As |
| 4657 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4658 | * API call does not considered as an error condition for most of the device. |
| 4659 | **/ |
| 4660 | int |
| 4661 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4662 | { |
| 4663 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4664 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4665 | int rc; |
| 4666 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4667 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4668 | if (nr_vfn > max_nr_vfn) { |
| 4669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4670 | "3057 Requested vfs (%d) greater than " |
| 4671 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4672 | return -EINVAL; |
| 4673 | } |
| 4674 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4675 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4676 | if (rc) { |
| 4677 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4678 | "2806 Failed to enable sriov on this device " |
| 4679 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4680 | nr_vfn, rc); |
| 4681 | } else |
| 4682 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4683 | "2807 Successful enable sriov on this device " |
| 4684 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4685 | return rc; |
| 4686 | } |
| 4687 | |
| 4688 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4689 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4690 | * @phba: pointer to lpfc hba data structure. |
| 4691 | * |
| 4692 | * This routine is invoked to set up the driver internal resources specific to |
| 4693 | * support the SLI-3 HBA device it attached to. |
| 4694 | * |
| 4695 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4696 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4697 | * other values - error |
| 4698 | **/ |
| 4699 | static int |
| 4700 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4701 | { |
| 4702 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4703 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4704 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4705 | /* |
| 4706 | * Initialize timers used by driver |
| 4707 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4708 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4709 | /* Heartbeat timer */ |
| 4710 | init_timer(&phba->hb_tmofunc); |
| 4711 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4712 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4713 | |
| 4714 | psli = &phba->sli; |
| 4715 | /* MBOX heartbeat timer */ |
| 4716 | init_timer(&psli->mbox_tmo); |
| 4717 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4718 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4719 | /* FCP polling mode timer */ |
| 4720 | init_timer(&phba->fcp_poll_timer); |
| 4721 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4722 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4723 | /* Fabric block timer */ |
| 4724 | init_timer(&phba->fabric_block_timer); |
| 4725 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4726 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4727 | /* EA polling mode timer */ |
| 4728 | init_timer(&phba->eratt_poll); |
| 4729 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4730 | phba->eratt_poll.data = (unsigned long) phba; |
| 4731 | |
| 4732 | /* Host attention work mask setup */ |
| 4733 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4734 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4735 | |
| 4736 | /* Get all the module params for configuring this host */ |
| 4737 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4738 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4739 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4740 | /* check for menlo minimum sg count */ |
| 4741 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4742 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4743 | } |
| 4744 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4745 | if (!phba->sli.ring) |
| 4746 | phba->sli.ring = (struct lpfc_sli_ring *) |
| 4747 | kzalloc(LPFC_SLI3_MAX_RING * |
| 4748 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4749 | if (!phba->sli.ring) |
| 4750 | return -ENOMEM; |
| 4751 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4752 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4753 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4754 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4755 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4756 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4757 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4758 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4759 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4760 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4761 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 4762 | if (phba->cfg_enable_bg) { |
| 4763 | /* |
| 4764 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 4765 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 4766 | * over how many protection data segments the SCSI Layer |
| 4767 | * will hand us (ie: there could be one for every block |
| 4768 | * in the IO), we just allocate enough BDEs to accomidate |
| 4769 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 4770 | * minimize the risk of running out. |
| 4771 | */ |
| 4772 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4773 | sizeof(struct fcp_rsp) + |
| 4774 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 4775 | |
| 4776 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 4777 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 4778 | |
| 4779 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 4780 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4781 | } else { |
| 4782 | /* |
| 4783 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 4784 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 4785 | * cfg_sg_seg_cnt data segments. |
| 4786 | */ |
| 4787 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4788 | sizeof(struct fcp_rsp) + |
| 4789 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4790 | |
| 4791 | /* Total BDEs in BPL for scsi_sg_list */ |
| 4792 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 4793 | } |
| 4794 | |
| 4795 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4796 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 4797 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 4798 | phba->cfg_total_seg_cnt); |
| 4799 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4800 | phba->max_vpi = LPFC_MAX_VPI; |
| 4801 | /* This will be set to correct value after config_port mbox */ |
| 4802 | phba->max_vports = 0; |
| 4803 | |
| 4804 | /* |
| 4805 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4806 | */ |
| 4807 | lpfc_sli_setup(phba); |
| 4808 | lpfc_sli_queue_setup(phba); |
| 4809 | |
| 4810 | /* Allocate device driver memory */ |
| 4811 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4812 | return -ENOMEM; |
| 4813 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4814 | /* |
| 4815 | * Enable sr-iov virtual functions if supported and configured |
| 4816 | * through the module parameter. |
| 4817 | */ |
| 4818 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4819 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4820 | phba->cfg_sriov_nr_virtfn); |
| 4821 | if (rc) { |
| 4822 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4823 | "2808 Requested number of SR-IOV " |
| 4824 | "virtual functions (%d) is not " |
| 4825 | "supported\n", |
| 4826 | phba->cfg_sriov_nr_virtfn); |
| 4827 | phba->cfg_sriov_nr_virtfn = 0; |
| 4828 | } |
| 4829 | } |
| 4830 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4831 | return 0; |
| 4832 | } |
| 4833 | |
| 4834 | /** |
| 4835 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4836 | * @phba: pointer to lpfc hba data structure. |
| 4837 | * |
| 4838 | * This routine is invoked to unset the driver internal resources set up |
| 4839 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4840 | **/ |
| 4841 | static void |
| 4842 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4843 | { |
| 4844 | /* Free device driver memory allocated */ |
| 4845 | lpfc_mem_free_all(phba); |
| 4846 | |
| 4847 | return; |
| 4848 | } |
| 4849 | |
| 4850 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4851 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4852 | * @phba: pointer to lpfc hba data structure. |
| 4853 | * |
| 4854 | * This routine is invoked to set up the driver internal resources specific to |
| 4855 | * support the SLI-4 HBA device it attached to. |
| 4856 | * |
| 4857 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4858 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4859 | * other values - error |
| 4860 | **/ |
| 4861 | static int |
| 4862 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4863 | { |
| 4864 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4865 | LPFC_MBOXQ_t *mboxq; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4866 | int rc, i, hbq_count, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4867 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4868 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4869 | int longs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4870 | |
| 4871 | /* Before proceed, wait for POST done and device ready */ |
| 4872 | rc = lpfc_sli4_post_status_check(phba); |
| 4873 | if (rc) |
| 4874 | return -ENODEV; |
| 4875 | |
| 4876 | /* |
| 4877 | * Initialize timers used by driver |
| 4878 | */ |
| 4879 | |
| 4880 | /* Heartbeat timer */ |
| 4881 | init_timer(&phba->hb_tmofunc); |
| 4882 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4883 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4884 | init_timer(&phba->rrq_tmr); |
| 4885 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4886 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4887 | |
| 4888 | psli = &phba->sli; |
| 4889 | /* MBOX heartbeat timer */ |
| 4890 | init_timer(&psli->mbox_tmo); |
| 4891 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4892 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4893 | /* Fabric block timer */ |
| 4894 | init_timer(&phba->fabric_block_timer); |
| 4895 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4896 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4897 | /* EA polling mode timer */ |
| 4898 | init_timer(&phba->eratt_poll); |
| 4899 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4900 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4901 | /* FCF rediscover timer */ |
| 4902 | init_timer(&phba->fcf.redisc_wait); |
| 4903 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4904 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4905 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4906 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4907 | * Control structure for handling external multi-buffer mailbox |
| 4908 | * command pass-through. |
| 4909 | */ |
| 4910 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4911 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4912 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4913 | |
| 4914 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4915 | * We need to do a READ_CONFIG mailbox command here before |
| 4916 | * calling lpfc_get_cfgparam. For VFs this will report the |
| 4917 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. |
| 4918 | * All of the resources allocated |
| 4919 | * for this Port are tied to these values. |
| 4920 | */ |
| 4921 | /* Get all the module params for configuring this host */ |
| 4922 | lpfc_get_cfgparam(phba); |
| 4923 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4924 | |
| 4925 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 4926 | phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count; |
| 4927 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4928 | /* This will be set to correct value after the read_config mbox */ |
| 4929 | phba->max_vports = 0; |
| 4930 | |
| 4931 | /* Program the default value of vlan_id and fc_map */ |
| 4932 | phba->valid_vlan = 0; |
| 4933 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4934 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4935 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4936 | |
| 4937 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4938 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
| 4939 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. |
| 4940 | */ |
| 4941 | if (!phba->sli.ring) |
| 4942 | phba->sli.ring = kzalloc( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4943 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4944 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 4945 | if (!phba->sli.ring) |
| 4946 | return -ENOMEM; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4947 | |
| 4948 | /* |
| 4949 | * It doesn't matter what family our adapter is in, we are |
| 4950 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 4951 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 4952 | */ |
| 4953 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 4954 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) |
| 4955 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 4956 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 4957 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4958 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4959 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4960 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4961 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 4962 | if (phba->cfg_enable_bg) { |
| 4963 | /* |
| 4964 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 4965 | * the FCP rsp, and a SGE for each. Sice we have no control |
| 4966 | * over how many protection data segments the SCSI Layer |
| 4967 | * will hand us (ie: there could be one for every block |
| 4968 | * in the IO), we just allocate enough SGEs to accomidate |
| 4969 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 4970 | * minimize the risk of running out. |
| 4971 | */ |
| 4972 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4973 | sizeof(struct fcp_rsp) + max_buf_size; |
| 4974 | |
| 4975 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 4976 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 4977 | |
| 4978 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
| 4979 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
| 4980 | } else { |
| 4981 | /* |
| 4982 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 4983 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 4984 | * cfg_sg_seg_cnt data segments. |
| 4985 | */ |
| 4986 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4987 | sizeof(struct fcp_rsp) + |
| 4988 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); |
| 4989 | |
| 4990 | /* Total SGEs for scsi_sg_list */ |
| 4991 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 4992 | /* |
| 4993 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need |
| 4994 | * to post 1 page for the SGL. |
| 4995 | */ |
| 4996 | } |
| 4997 | |
| 4998 | /* Initialize the host templates with the updated values. */ |
| 4999 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5000 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5001 | |
| 5002 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5003 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5004 | else |
| 5005 | phba->cfg_sg_dma_buf_size = |
| 5006 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5007 | |
| 5008 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5009 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5010 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5011 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5012 | |
| 5013 | /* Initialize buffer queue management fields */ |
| 5014 | hbq_count = lpfc_sli_hbq_count(); |
| 5015 | for (i = 0; i < hbq_count; ++i) |
| 5016 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5017 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5018 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5019 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5020 | |
| 5021 | /* |
| 5022 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5023 | */ |
| 5024 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5025 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5026 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5027 | /* This abort list used by worker thread */ |
| 5028 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 5029 | |
| 5030 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5031 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5032 | */ |
| 5033 | |
| 5034 | /* Driver internel slow-path CQ Event pool */ |
| 5035 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5036 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5037 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5038 | /* Asynchronous event CQ Event work queue list */ |
| 5039 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5040 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5041 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5042 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5043 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5044 | /* Receive queue CQ Event work queue list */ |
| 5045 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5046 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5047 | /* Initialize extent block lists. */ |
| 5048 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 5049 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 5050 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 5051 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 5052 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5053 | /* Initialize the driver internal SLI layer lists. */ |
| 5054 | lpfc_sli_setup(phba); |
| 5055 | lpfc_sli_queue_setup(phba); |
| 5056 | |
| 5057 | /* Allocate device driver memory */ |
| 5058 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 5059 | if (rc) |
| 5060 | return -ENOMEM; |
| 5061 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5062 | /* IF Type 2 ports get initialized now. */ |
| 5063 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5064 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 5065 | rc = lpfc_pci_function_reset(phba); |
| 5066 | if (unlikely(rc)) |
| 5067 | return -ENODEV; |
| 5068 | } |
| 5069 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5070 | /* Create the bootstrap mailbox command */ |
| 5071 | rc = lpfc_create_bootstrap_mbox(phba); |
| 5072 | if (unlikely(rc)) |
| 5073 | goto out_free_mem; |
| 5074 | |
| 5075 | /* Set up the host's endian order with the device. */ |
| 5076 | rc = lpfc_setup_endian_order(phba); |
| 5077 | if (unlikely(rc)) |
| 5078 | goto out_free_bsmbx; |
| 5079 | |
| 5080 | /* Set up the hba's configuration parameters. */ |
| 5081 | rc = lpfc_sli4_read_config(phba); |
| 5082 | if (unlikely(rc)) |
| 5083 | goto out_free_bsmbx; |
| 5084 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5085 | /* IF Type 0 ports get initialized now. */ |
| 5086 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 5087 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 5088 | rc = lpfc_pci_function_reset(phba); |
| 5089 | if (unlikely(rc)) |
| 5090 | goto out_free_bsmbx; |
| 5091 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5092 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5093 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 5094 | GFP_KERNEL); |
| 5095 | if (!mboxq) { |
| 5096 | rc = -ENOMEM; |
| 5097 | goto out_free_bsmbx; |
| 5098 | } |
| 5099 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5100 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5101 | lpfc_supported_pages(mboxq); |
| 5102 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5103 | if (!rc) { |
| 5104 | mqe = &mboxq->u.mqe; |
| 5105 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 5106 | LPFC_MAX_SUPPORTED_PAGES); |
| 5107 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 5108 | switch (pn_page[i]) { |
| 5109 | case LPFC_SLI4_PARAMETERS: |
| 5110 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 5111 | break; |
| 5112 | default: |
| 5113 | break; |
| 5114 | } |
| 5115 | } |
| 5116 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 5117 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 5118 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 5119 | if (rc) { |
| 5120 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5121 | rc = -EIO; |
| 5122 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5123 | } |
| 5124 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5125 | /* |
| 5126 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5127 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 5128 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 5129 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5130 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 5131 | if (rc) { |
| 5132 | if (phba->sli4_hba.extents_in_use && |
| 5133 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 5134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5135 | "2999 Unsupported SLI4 Parameters " |
| 5136 | "Extents and RPI headers enabled.\n"); |
| 5137 | goto out_free_bsmbx; |
| 5138 | } |
| 5139 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 5140 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5141 | /* Verify all the SLI4 queues */ |
| 5142 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5143 | if (rc) |
| 5144 | goto out_free_bsmbx; |
| 5145 | |
| 5146 | /* Create driver internal CQE event pool */ |
| 5147 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 5148 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 5149 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5150 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5151 | /* Initialize sgl lists per host */ |
| 5152 | lpfc_init_sgl_list(phba); |
| 5153 | |
| 5154 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5155 | rc = lpfc_init_active_sgl_array(phba); |
| 5156 | if (rc) { |
| 5157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5158 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5159 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5160 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5161 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 5162 | if (rc) { |
| 5163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5164 | "1432 Failed to initialize rpi headers.\n"); |
| 5165 | goto out_free_active_sgl; |
| 5166 | } |
| 5167 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5168 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5169 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 5170 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 5171 | GFP_KERNEL); |
| 5172 | if (!phba->fcf.fcf_rr_bmask) { |
| 5173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5174 | "2759 Failed allocate memory for FCF round " |
| 5175 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5176 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5177 | goto out_remove_rpi_hdrs; |
| 5178 | } |
| 5179 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5180 | phba->sli4_hba.fcp_eq_hdl = |
| 5181 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
| 5182 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 5183 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 5184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5185 | "2572 Failed allocate memory for " |
| 5186 | "fast-path per-EQ handle array\n"); |
| 5187 | rc = -ENOMEM; |
| 5188 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 5192 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5193 | if (!phba->sli4_hba.msix_entries) { |
| 5194 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5195 | "2573 Failed allocate memory for msi-x " |
| 5196 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5197 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5198 | goto out_free_fcp_eq_hdl; |
| 5199 | } |
| 5200 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5201 | /* |
| 5202 | * Enable sr-iov virtual functions if supported and configured |
| 5203 | * through the module parameter. |
| 5204 | */ |
| 5205 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5206 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5207 | phba->cfg_sriov_nr_virtfn); |
| 5208 | if (rc) { |
| 5209 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5210 | "3020 Requested number of SR-IOV " |
| 5211 | "virtual functions (%d) is not " |
| 5212 | "supported\n", |
| 5213 | phba->cfg_sriov_nr_virtfn); |
| 5214 | phba->cfg_sriov_nr_virtfn = 0; |
| 5215 | } |
| 5216 | } |
| 5217 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5218 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5219 | |
| 5220 | out_free_fcp_eq_hdl: |
| 5221 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5222 | out_free_fcf_rr_bmask: |
| 5223 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5224 | out_remove_rpi_hdrs: |
| 5225 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 5226 | out_free_active_sgl: |
| 5227 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5228 | out_destroy_cq_event_pool: |
| 5229 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5230 | out_free_bsmbx: |
| 5231 | lpfc_destroy_bootstrap_mbox(phba); |
| 5232 | out_free_mem: |
| 5233 | lpfc_mem_free(phba); |
| 5234 | return rc; |
| 5235 | } |
| 5236 | |
| 5237 | /** |
| 5238 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 5239 | * @phba: pointer to lpfc hba data structure. |
| 5240 | * |
| 5241 | * This routine is invoked to unset the driver internal resources set up |
| 5242 | * specific for supporting the SLI-4 HBA device it attached to. |
| 5243 | **/ |
| 5244 | static void |
| 5245 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 5246 | { |
| 5247 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 5248 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5249 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 5250 | kfree(phba->sli4_hba.msix_entries); |
| 5251 | |
| 5252 | /* Free memory allocated for fast-path work queue handles */ |
| 5253 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 5254 | |
| 5255 | /* Free the allocated rpi headers. */ |
| 5256 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5257 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5258 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5259 | /* Free eligible FCF index bmask */ |
| 5260 | kfree(phba->fcf.fcf_rr_bmask); |
| 5261 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5262 | /* Free the ELS sgl list */ |
| 5263 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5264 | lpfc_free_els_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5265 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5266 | /* Free the completion queue EQ event pool */ |
| 5267 | lpfc_sli4_cq_event_release_all(phba); |
| 5268 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 5269 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5270 | /* Release resource identifiers. */ |
| 5271 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 5272 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5273 | /* Free the bsmbx region. */ |
| 5274 | lpfc_destroy_bootstrap_mbox(phba); |
| 5275 | |
| 5276 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 5277 | lpfc_mem_free_all(phba); |
| 5278 | |
| 5279 | /* Free the current connect table */ |
| 5280 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5281 | &phba->fcf_conn_rec_list, list) { |
| 5282 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5283 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5284 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5285 | |
| 5286 | return; |
| 5287 | } |
| 5288 | |
| 5289 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5290 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5291 | * @phba: The hba struct for which this call is being executed. |
| 5292 | * @dev_grp: The HBA PCI-Device group number. |
| 5293 | * |
| 5294 | * This routine sets up the device INIT interface API function jump table |
| 5295 | * in @phba struct. |
| 5296 | * |
| 5297 | * Returns: 0 - success, -ENODEV - failure. |
| 5298 | **/ |
| 5299 | int |
| 5300 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 5301 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 5302 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 5303 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 5304 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5305 | switch (dev_grp) { |
| 5306 | case LPFC_PCI_DEV_LP: |
| 5307 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 5308 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 5309 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 5310 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5311 | case LPFC_PCI_DEV_OC: |
| 5312 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 5313 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 5314 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 5315 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5316 | default: |
| 5317 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5318 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 5319 | dev_grp); |
| 5320 | return -ENODEV; |
| 5321 | break; |
| 5322 | } |
| 5323 | return 0; |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 5328 | * @phba: pointer to lpfc hba data structure. |
| 5329 | * |
| 5330 | * This routine is invoked to set up the driver internal resources before the |
| 5331 | * device specific resource setup to support the HBA device it attached to. |
| 5332 | * |
| 5333 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5334 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5335 | * other values - error |
| 5336 | **/ |
| 5337 | static int |
| 5338 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 5339 | { |
| 5340 | /* |
| 5341 | * Driver resources common to all SLI revisions |
| 5342 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5343 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5344 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5345 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 5346 | /* Initialize ndlp management spinlock */ |
| 5347 | spin_lock_init(&phba->ndlp_lock); |
| 5348 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5349 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5350 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 5351 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5352 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5353 | /* Initialize the wait queue head for the kernel thread */ |
| 5354 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5355 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5356 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 5357 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5358 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5359 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5360 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5361 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5362 | /* Initialize the fabric iocb list */ |
| 5363 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5364 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5365 | /* Initialize list to save ELS buffers */ |
| 5366 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5367 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5368 | /* Initialize FCF connection rec list */ |
| 5369 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5370 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5371 | return 0; |
| 5372 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5373 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5374 | /** |
| 5375 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 5376 | * @phba: pointer to lpfc hba data structure. |
| 5377 | * |
| 5378 | * This routine is invoked to set up the driver internal resources after the |
| 5379 | * device specific resource setup to support the HBA device it attached to. |
| 5380 | * |
| 5381 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5382 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5383 | * other values - error |
| 5384 | **/ |
| 5385 | static int |
| 5386 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 5387 | { |
| 5388 | int error; |
| 5389 | |
| 5390 | /* Startup the kernel thread for this host adapter. */ |
| 5391 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 5392 | "lpfc_worker_%d", phba->brd_no); |
| 5393 | if (IS_ERR(phba->worker_thread)) { |
| 5394 | error = PTR_ERR(phba->worker_thread); |
| 5395 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5396 | } |
| 5397 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5398 | return 0; |
| 5399 | } |
| 5400 | |
| 5401 | /** |
| 5402 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 5403 | * @phba: pointer to lpfc hba data structure. |
| 5404 | * |
| 5405 | * This routine is invoked to unset the driver internal resources set up after |
| 5406 | * the device specific resource setup for supporting the HBA device it |
| 5407 | * attached to. |
| 5408 | **/ |
| 5409 | static void |
| 5410 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 5411 | { |
| 5412 | /* Stop kernel worker thread */ |
| 5413 | kthread_stop(phba->worker_thread); |
| 5414 | } |
| 5415 | |
| 5416 | /** |
| 5417 | * lpfc_free_iocb_list - Free iocb list. |
| 5418 | * @phba: pointer to lpfc hba data structure. |
| 5419 | * |
| 5420 | * This routine is invoked to free the driver's IOCB list and memory. |
| 5421 | **/ |
| 5422 | static void |
| 5423 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 5424 | { |
| 5425 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 5426 | |
| 5427 | spin_lock_irq(&phba->hbalock); |
| 5428 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 5429 | &phba->lpfc_iocb_list, list) { |
| 5430 | list_del(&iocbq_entry->list); |
| 5431 | kfree(iocbq_entry); |
| 5432 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5433 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5434 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5435 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5436 | return; |
| 5437 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5438 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5439 | /** |
| 5440 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 5441 | * @phba: pointer to lpfc hba data structure. |
| 5442 | * |
| 5443 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 5444 | * list and set up the IOCB tag array accordingly. |
| 5445 | * |
| 5446 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5447 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5448 | * other values - error |
| 5449 | **/ |
| 5450 | static int |
| 5451 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 5452 | { |
| 5453 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 5454 | uint16_t iotag; |
| 5455 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5456 | |
| 5457 | /* Initialize and populate the iocb list per host. */ |
| 5458 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5459 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5460 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5461 | if (iocbq_entry == NULL) { |
| 5462 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 5463 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 5464 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5465 | goto out_free_iocbq; |
| 5466 | } |
| 5467 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5468 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 5469 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5470 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5471 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5472 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 5473 | goto out_free_iocbq; |
| 5474 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5475 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5476 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5477 | |
| 5478 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5479 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 5480 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5481 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5482 | } |
| 5483 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5484 | return 0; |
| 5485 | |
| 5486 | out_free_iocbq: |
| 5487 | lpfc_free_iocb_list(phba); |
| 5488 | |
| 5489 | return -ENOMEM; |
| 5490 | } |
| 5491 | |
| 5492 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5493 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5494 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5495 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5496 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5497 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5498 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5499 | void |
| 5500 | 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] | 5501 | { |
| 5502 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5503 | |
| 5504 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 5505 | list_del(&sglq_entry->list); |
| 5506 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5507 | kfree(sglq_entry); |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | /** |
| 5512 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 5513 | * @phba: pointer to lpfc hba data structure. |
| 5514 | * |
| 5515 | * This routine is invoked to free the driver's els sgl list and memory. |
| 5516 | **/ |
| 5517 | static void |
| 5518 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 5519 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5520 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5521 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5522 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5523 | spin_lock_irq(&phba->hbalock); |
| 5524 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5525 | spin_unlock_irq(&phba->hbalock); |
| 5526 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5527 | /* Now free the sgl list */ |
| 5528 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | /** |
| 5532 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5533 | * @phba: pointer to lpfc hba data structure. |
| 5534 | * |
| 5535 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5536 | * This array will hold the sglq_entry's for active IOs. |
| 5537 | **/ |
| 5538 | static int |
| 5539 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5540 | { |
| 5541 | int size; |
| 5542 | size = sizeof(struct lpfc_sglq *); |
| 5543 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5544 | |
| 5545 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5546 | kzalloc(size, GFP_KERNEL); |
| 5547 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5548 | return -ENOMEM; |
| 5549 | return 0; |
| 5550 | } |
| 5551 | |
| 5552 | /** |
| 5553 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5554 | * @phba: pointer to lpfc hba data structure. |
| 5555 | * |
| 5556 | * This routine is invoked to walk through the array of active sglq entries |
| 5557 | * and free all of the resources. |
| 5558 | * This is just a place holder for now. |
| 5559 | **/ |
| 5560 | static void |
| 5561 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5562 | { |
| 5563 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5564 | } |
| 5565 | |
| 5566 | /** |
| 5567 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5568 | * @phba: pointer to lpfc hba data structure. |
| 5569 | * |
| 5570 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5571 | * list and set up the sgl xritag tag array accordingly. |
| 5572 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5573 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5574 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5575 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5576 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5577 | /* Initialize and populate the sglq list per host/VF. */ |
| 5578 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5579 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5580 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5581 | /* els xri-sgl book keeping */ |
| 5582 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5583 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5584 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5585 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | /** |
| 5589 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5590 | * @phba: pointer to lpfc hba data structure. |
| 5591 | * |
| 5592 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5593 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5594 | * 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] | 5595 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5596 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5597 | * |
| 5598 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5599 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5600 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5601 | **/ |
| 5602 | int |
| 5603 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5604 | { |
| 5605 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5606 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5607 | |
| 5608 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5609 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5610 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5611 | if (phba->sli4_hba.extents_in_use) |
| 5612 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5613 | |
| 5614 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5615 | if (!rpi_hdr) { |
| 5616 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5617 | "0391 Error during rpi post operation\n"); |
| 5618 | lpfc_sli4_remove_rpis(phba); |
| 5619 | rc = -ENODEV; |
| 5620 | } |
| 5621 | |
| 5622 | return rc; |
| 5623 | } |
| 5624 | |
| 5625 | /** |
| 5626 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5627 | * @phba: pointer to lpfc hba data structure. |
| 5628 | * |
| 5629 | * This routine is invoked to allocate a single 4KB memory region to |
| 5630 | * support rpis and stores them in the phba. This single region |
| 5631 | * provides support for up to 64 rpis. The region is used globally |
| 5632 | * by the device. |
| 5633 | * |
| 5634 | * Returns: |
| 5635 | * A valid rpi hdr on success. |
| 5636 | * A NULL pointer on any failure. |
| 5637 | **/ |
| 5638 | struct lpfc_rpi_hdr * |
| 5639 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5640 | { |
| 5641 | uint16_t rpi_limit, curr_rpi_range; |
| 5642 | struct lpfc_dmabuf *dmabuf; |
| 5643 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5644 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5645 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5646 | /* |
| 5647 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5648 | * required. Set the expected maximum count and let the actual value |
| 5649 | * get set when extents are fully allocated. |
| 5650 | */ |
| 5651 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5652 | return NULL; |
| 5653 | if (phba->sli4_hba.extents_in_use) |
| 5654 | return NULL; |
| 5655 | |
| 5656 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5657 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5658 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5659 | |
| 5660 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5661 | /* |
| 5662 | * Establish the starting RPI in this header block. The starting |
| 5663 | * rpi is normalized to a zero base because the physical rpi is |
| 5664 | * port based. |
| 5665 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5666 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5667 | spin_unlock_irq(&phba->hbalock); |
| 5668 | |
| 5669 | /* |
| 5670 | * The port has a limited number of rpis. The increment here |
| 5671 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5672 | * and to allow the full max_rpi range per port. |
| 5673 | */ |
| 5674 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5675 | rpi_count = rpi_limit - curr_rpi_range; |
| 5676 | else |
| 5677 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5678 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5679 | if (!rpi_count) |
| 5680 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5681 | /* |
| 5682 | * First allocate the protocol header region for the port. The |
| 5683 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5684 | */ |
| 5685 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5686 | if (!dmabuf) |
| 5687 | return NULL; |
| 5688 | |
| 5689 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5690 | LPFC_HDR_TEMPLATE_SIZE, |
| 5691 | &dmabuf->phys, |
| 5692 | GFP_KERNEL); |
| 5693 | if (!dmabuf->virt) { |
| 5694 | rpi_hdr = NULL; |
| 5695 | goto err_free_dmabuf; |
| 5696 | } |
| 5697 | |
| 5698 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5699 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5700 | rpi_hdr = NULL; |
| 5701 | goto err_free_coherent; |
| 5702 | } |
| 5703 | |
| 5704 | /* Save the rpi header data for cleanup later. */ |
| 5705 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5706 | if (!rpi_hdr) |
| 5707 | goto err_free_coherent; |
| 5708 | |
| 5709 | rpi_hdr->dmabuf = dmabuf; |
| 5710 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5711 | rpi_hdr->page_count = 1; |
| 5712 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5713 | |
| 5714 | /* The rpi_hdr stores the logical index only. */ |
| 5715 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5716 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5717 | |
| 5718 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5719 | * The next_rpi stores the next logical module-64 rpi value used |
| 5720 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5721 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5722 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5723 | spin_unlock_irq(&phba->hbalock); |
| 5724 | return rpi_hdr; |
| 5725 | |
| 5726 | err_free_coherent: |
| 5727 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5728 | dmabuf->virt, dmabuf->phys); |
| 5729 | err_free_dmabuf: |
| 5730 | kfree(dmabuf); |
| 5731 | return NULL; |
| 5732 | } |
| 5733 | |
| 5734 | /** |
| 5735 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5736 | * @phba: pointer to lpfc hba data structure. |
| 5737 | * |
| 5738 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5739 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5740 | * presumes the caller has released all rpis consumed by fabric or port |
| 5741 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5742 | **/ |
| 5743 | void |
| 5744 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5745 | { |
| 5746 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5747 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5748 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5749 | goto exit; |
| 5750 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5751 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5752 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5753 | list_del(&rpi_hdr->list); |
| 5754 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5755 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5756 | kfree(rpi_hdr->dmabuf); |
| 5757 | kfree(rpi_hdr); |
| 5758 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5759 | exit: |
| 5760 | /* There are no rpis available to the port now. */ |
| 5761 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5765 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5766 | * @pdev: pointer to pci device data structure. |
| 5767 | * |
| 5768 | * This routine is invoked to allocate the driver hba data structure for an |
| 5769 | * HBA device. If the allocation is successful, the phba reference to the |
| 5770 | * PCI device data structure is set. |
| 5771 | * |
| 5772 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5773 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5774 | * NULL - error |
| 5775 | **/ |
| 5776 | static struct lpfc_hba * |
| 5777 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5778 | { |
| 5779 | struct lpfc_hba *phba; |
| 5780 | |
| 5781 | /* Allocate memory for HBA structure */ |
| 5782 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5783 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5784 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5785 | return NULL; |
| 5786 | } |
| 5787 | |
| 5788 | /* Set reference to PCI device in HBA structure */ |
| 5789 | phba->pcidev = pdev; |
| 5790 | |
| 5791 | /* Assign an unused board number */ |
| 5792 | phba->brd_no = lpfc_get_instance(); |
| 5793 | if (phba->brd_no < 0) { |
| 5794 | kfree(phba); |
| 5795 | return NULL; |
| 5796 | } |
| 5797 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5798 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5799 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5800 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5801 | return phba; |
| 5802 | } |
| 5803 | |
| 5804 | /** |
| 5805 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5806 | * @phba: pointer to lpfc hba data structure. |
| 5807 | * |
| 5808 | * This routine is invoked to free the driver hba data structure with an |
| 5809 | * HBA device. |
| 5810 | **/ |
| 5811 | static void |
| 5812 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5813 | { |
| 5814 | /* Release the driver assigned board number */ |
| 5815 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5816 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5817 | /* Free memory allocated with sli rings */ |
| 5818 | kfree(phba->sli.ring); |
| 5819 | phba->sli.ring = NULL; |
| 5820 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5821 | kfree(phba); |
| 5822 | return; |
| 5823 | } |
| 5824 | |
| 5825 | /** |
| 5826 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5827 | * @phba: pointer to lpfc hba data structure. |
| 5828 | * |
| 5829 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5830 | * host with it. |
| 5831 | * |
| 5832 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5833 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5834 | * other values - error |
| 5835 | **/ |
| 5836 | static int |
| 5837 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5838 | { |
| 5839 | struct lpfc_vport *vport; |
| 5840 | struct Scsi_Host *shost; |
| 5841 | |
| 5842 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5843 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5844 | phba->fc_ratov = FF_DEF_RATOV; |
| 5845 | phba->fc_altov = FF_DEF_ALTOV; |
| 5846 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5847 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5848 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5849 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5850 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5851 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5852 | |
| 5853 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5854 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5855 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5856 | /* Put reference to SCSI host to driver's device private data */ |
| 5857 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5858 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5859 | return 0; |
| 5860 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5861 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5862 | /** |
| 5863 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5864 | * @phba: pointer to lpfc hba data structure. |
| 5865 | * |
| 5866 | * This routine is invoked to destroy HBA physical port and the associated |
| 5867 | * SCSI host. |
| 5868 | **/ |
| 5869 | static void |
| 5870 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5871 | { |
| 5872 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5873 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5874 | /* Destroy physical port that associated with the SCSI host */ |
| 5875 | destroy_port(vport); |
| 5876 | |
| 5877 | return; |
| 5878 | } |
| 5879 | |
| 5880 | /** |
| 5881 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5882 | * @phba: pointer to lpfc hba data structure. |
| 5883 | * @shost: the shost to be used to detect Block guard settings. |
| 5884 | * |
| 5885 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5886 | * This routine also allocates memory for debugging bg buffers. |
| 5887 | **/ |
| 5888 | static void |
| 5889 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5890 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5891 | uint32_t old_mask; |
| 5892 | uint32_t old_guard; |
| 5893 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5894 | int pagecnt = 10; |
| 5895 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5896 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5897 | "1478 Registering BlockGuard with the " |
| 5898 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5899 | |
| 5900 | old_mask = lpfc_prot_mask; |
| 5901 | old_guard = lpfc_prot_guard; |
| 5902 | |
| 5903 | /* Only allow supported values */ |
| 5904 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
| 5905 | SHOST_DIX_TYPE0_PROTECTION | |
| 5906 | SHOST_DIX_TYPE1_PROTECTION); |
| 5907 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); |
| 5908 | |
| 5909 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
| 5910 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 5911 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
| 5912 | |
| 5913 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5914 | if ((old_mask != lpfc_prot_mask) || |
| 5915 | (old_guard != lpfc_prot_guard)) |
| 5916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5917 | "1475 Registering BlockGuard with the " |
| 5918 | "SCSI layer: mask %d guard %d\n", |
| 5919 | lpfc_prot_mask, lpfc_prot_guard); |
| 5920 | |
| 5921 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 5922 | scsi_host_set_guard(shost, lpfc_prot_guard); |
| 5923 | } else |
| 5924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5925 | "1479 Not Registering BlockGuard with the SCSI " |
| 5926 | "layer, Bad protection parameters: %d %d\n", |
| 5927 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5928 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 5929 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5930 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5931 | while (pagecnt) { |
| 5932 | spin_lock_init(&_dump_buf_lock); |
| 5933 | _dump_buf_data = |
| 5934 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5935 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5936 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5937 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5938 | "_dump_buf_data at 0x%p\n", |
| 5939 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5940 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5941 | memset(_dump_buf_data, 0, |
| 5942 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5943 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5944 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5945 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5946 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5947 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5948 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5949 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5950 | "memory for hexdump\n"); |
| 5951 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5952 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5953 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5954 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5955 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5956 | while (pagecnt) { |
| 5957 | _dump_buf_dif = |
| 5958 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5959 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5960 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5961 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5962 | "_dump_buf_dif at 0x%p\n", |
| 5963 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5964 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5965 | memset(_dump_buf_dif, 0, |
| 5966 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5967 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5968 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5969 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5970 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5971 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5972 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5973 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5974 | "memory for hexdump\n"); |
| 5975 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5976 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5977 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5978 | _dump_buf_dif); |
| 5979 | } |
| 5980 | |
| 5981 | /** |
| 5982 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 5983 | * @phba: pointer to lpfc hba data structure. |
| 5984 | * |
| 5985 | * This routine is invoked to perform all the necessary post initialization |
| 5986 | * setup for the device. |
| 5987 | **/ |
| 5988 | static void |
| 5989 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 5990 | { |
| 5991 | struct Scsi_Host *shost; |
| 5992 | struct lpfc_adapter_event_header adapter_event; |
| 5993 | |
| 5994 | /* Get the default values for Model Name and Description */ |
| 5995 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 5996 | |
| 5997 | /* |
| 5998 | * hba setup may have changed the hba_queue_depth so we need to |
| 5999 | * adjust the value of can_queue. |
| 6000 | */ |
| 6001 | shost = pci_get_drvdata(phba->pcidev); |
| 6002 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 6003 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 6004 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6005 | |
| 6006 | lpfc_host_attrib_init(shost); |
| 6007 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6008 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 6009 | spin_lock_irq(shost->host_lock); |
| 6010 | lpfc_poll_start_timer(phba); |
| 6011 | spin_unlock_irq(shost->host_lock); |
| 6012 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 6013 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6014 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6015 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6016 | /* Send board arrival event to upper layer */ |
| 6017 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 6018 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 6019 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6020 | sizeof(adapter_event), |
| 6021 | (char *) &adapter_event, |
| 6022 | LPFC_NL_VENDOR_ID); |
| 6023 | return; |
| 6024 | } |
| 6025 | |
| 6026 | /** |
| 6027 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 6028 | * @phba: pointer to lpfc hba data structure. |
| 6029 | * |
| 6030 | * This routine is invoked to set up the PCI device memory space for device |
| 6031 | * with SLI-3 interface spec. |
| 6032 | * |
| 6033 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6034 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6035 | * other values - error |
| 6036 | **/ |
| 6037 | static int |
| 6038 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 6039 | { |
| 6040 | struct pci_dev *pdev; |
| 6041 | unsigned long bar0map_len, bar2map_len; |
| 6042 | int i, hbq_count; |
| 6043 | void *ptr; |
| 6044 | int error = -ENODEV; |
| 6045 | |
| 6046 | /* Obtain PCI device reference */ |
| 6047 | if (!phba->pcidev) |
| 6048 | return error; |
| 6049 | else |
| 6050 | pdev = phba->pcidev; |
| 6051 | |
| 6052 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6053 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 6054 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 6055 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 6056 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6057 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 6058 | } |
| 6059 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6060 | |
| 6061 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 6062 | * required by each mapping. |
| 6063 | */ |
| 6064 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 6065 | bar0map_len = pci_resource_len(pdev, 0); |
| 6066 | |
| 6067 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 6068 | bar2map_len = pci_resource_len(pdev, 2); |
| 6069 | |
| 6070 | /* Map HBA SLIM to a kernel virtual address. */ |
| 6071 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 6072 | if (!phba->slim_memmap_p) { |
| 6073 | dev_printk(KERN_ERR, &pdev->dev, |
| 6074 | "ioremap failed for SLIM memory.\n"); |
| 6075 | goto out; |
| 6076 | } |
| 6077 | |
| 6078 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 6079 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 6080 | if (!phba->ctrl_regs_memmap_p) { |
| 6081 | dev_printk(KERN_ERR, &pdev->dev, |
| 6082 | "ioremap failed for HBA control registers.\n"); |
| 6083 | goto out_iounmap_slim; |
| 6084 | } |
| 6085 | |
| 6086 | /* Allocate memory for SLI-2 structures */ |
| 6087 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 6088 | SLI2_SLIM_SIZE, |
| 6089 | &phba->slim2p.phys, |
| 6090 | GFP_KERNEL); |
| 6091 | if (!phba->slim2p.virt) |
| 6092 | goto out_iounmap; |
| 6093 | |
| 6094 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 6095 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 6096 | phba->mbox_ext = (phba->slim2p.virt + |
| 6097 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6098 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 6099 | phba->IOCBs = (phba->slim2p.virt + |
| 6100 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 6101 | |
| 6102 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 6103 | lpfc_sli_hbq_size(), |
| 6104 | &phba->hbqslimp.phys, |
| 6105 | GFP_KERNEL); |
| 6106 | if (!phba->hbqslimp.virt) |
| 6107 | goto out_free_slim; |
| 6108 | |
| 6109 | hbq_count = lpfc_sli_hbq_count(); |
| 6110 | ptr = phba->hbqslimp.virt; |
| 6111 | for (i = 0; i < hbq_count; ++i) { |
| 6112 | phba->hbqs[i].hbq_virt = ptr; |
| 6113 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 6114 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 6115 | sizeof(struct lpfc_hbq_entry)); |
| 6116 | } |
| 6117 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 6118 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 6119 | |
| 6120 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 6121 | |
| 6122 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 6123 | |
| 6124 | phba->MBslimaddr = phba->slim_memmap_p; |
| 6125 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 6126 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 6127 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 6128 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 6129 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6130 | return 0; |
| 6131 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6132 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 6133 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6134 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6135 | out_iounmap: |
| 6136 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6137 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6138 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6139 | out: |
| 6140 | return error; |
| 6141 | } |
| 6142 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6143 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6144 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 6145 | * @phba: pointer to lpfc hba data structure. |
| 6146 | * |
| 6147 | * This routine is invoked to unset the PCI device memory space for device |
| 6148 | * with SLI-3 interface spec. |
| 6149 | **/ |
| 6150 | static void |
| 6151 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 6152 | { |
| 6153 | struct pci_dev *pdev; |
| 6154 | |
| 6155 | /* Obtain PCI device reference */ |
| 6156 | if (!phba->pcidev) |
| 6157 | return; |
| 6158 | else |
| 6159 | pdev = phba->pcidev; |
| 6160 | |
| 6161 | /* Free coherent DMA memory allocated */ |
| 6162 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 6163 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 6164 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 6165 | phba->slim2p.virt, phba->slim2p.phys); |
| 6166 | |
| 6167 | /* I/O memory unmap */ |
| 6168 | iounmap(phba->ctrl_regs_memmap_p); |
| 6169 | iounmap(phba->slim_memmap_p); |
| 6170 | |
| 6171 | return; |
| 6172 | } |
| 6173 | |
| 6174 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6175 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 6176 | * @phba: pointer to lpfc hba data structure. |
| 6177 | * |
| 6178 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 6179 | * done and check status. |
| 6180 | * |
| 6181 | * Return 0 if successful, otherwise -ENODEV. |
| 6182 | **/ |
| 6183 | int |
| 6184 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 6185 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6186 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 6187 | struct lpfc_register reg_data; |
| 6188 | int i, port_error = 0; |
| 6189 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6190 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6191 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 6192 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6193 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6194 | return -ENODEV; |
| 6195 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6196 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 6197 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6198 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 6199 | &portsmphr_reg.word0) || |
| 6200 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6201 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6202 | port_error = -ENODEV; |
| 6203 | break; |
| 6204 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6205 | if (LPFC_POST_STAGE_PORT_READY == |
| 6206 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6207 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6208 | msleep(10); |
| 6209 | } |
| 6210 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6211 | /* |
| 6212 | * If there was a port error during POST, then don't proceed with |
| 6213 | * other register reads as the data may not be valid. Just exit. |
| 6214 | */ |
| 6215 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6217 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 6218 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 6219 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 6220 | portsmphr_reg.word0, |
| 6221 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 6222 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 6223 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 6224 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 6225 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 6226 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 6227 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 6228 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 6229 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6231 | "2534 Device Info: SLIFamily=0x%x, " |
| 6232 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 6233 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6234 | bf_get(lpfc_sli_intf_sli_family, |
| 6235 | &phba->sli4_hba.sli_intf), |
| 6236 | bf_get(lpfc_sli_intf_slirev, |
| 6237 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6238 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6239 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6240 | bf_get(lpfc_sli_intf_sli_hint1, |
| 6241 | &phba->sli4_hba.sli_intf), |
| 6242 | bf_get(lpfc_sli_intf_sli_hint2, |
| 6243 | &phba->sli4_hba.sli_intf), |
| 6244 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6245 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6246 | /* |
| 6247 | * Check for other Port errors during the initialization |
| 6248 | * process. Fail the load if the port did not come up |
| 6249 | * correctly. |
| 6250 | */ |
| 6251 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6252 | &phba->sli4_hba.sli_intf); |
| 6253 | switch (if_type) { |
| 6254 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6255 | phba->sli4_hba.ue_mask_lo = |
| 6256 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 6257 | phba->sli4_hba.ue_mask_hi = |
| 6258 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 6259 | uerrlo_reg.word0 = |
| 6260 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 6261 | uerrhi_reg.word0 = |
| 6262 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 6263 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 6264 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 6265 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6266 | "1422 Unrecoverable Error " |
| 6267 | "Detected during POST " |
| 6268 | "uerr_lo_reg=0x%x, " |
| 6269 | "uerr_hi_reg=0x%x, " |
| 6270 | "ue_mask_lo_reg=0x%x, " |
| 6271 | "ue_mask_hi_reg=0x%x\n", |
| 6272 | uerrlo_reg.word0, |
| 6273 | uerrhi_reg.word0, |
| 6274 | phba->sli4_hba.ue_mask_lo, |
| 6275 | phba->sli4_hba.ue_mask_hi); |
| 6276 | port_error = -ENODEV; |
| 6277 | } |
| 6278 | break; |
| 6279 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6280 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 6281 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 6282 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6283 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 6284 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6285 | phba->work_status[0] = |
| 6286 | readl(phba->sli4_hba.u.if_type2. |
| 6287 | ERR1regaddr); |
| 6288 | phba->work_status[1] = |
| 6289 | readl(phba->sli4_hba.u.if_type2. |
| 6290 | ERR2regaddr); |
| 6291 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 6292 | "2888 Unrecoverable port error " |
| 6293 | "following POST: port status reg " |
| 6294 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6295 | "error 1=0x%x, error 2=0x%x\n", |
| 6296 | reg_data.word0, |
| 6297 | portsmphr_reg.word0, |
| 6298 | phba->work_status[0], |
| 6299 | phba->work_status[1]); |
| 6300 | port_error = -ENODEV; |
| 6301 | } |
| 6302 | break; |
| 6303 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6304 | default: |
| 6305 | break; |
| 6306 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6307 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6308 | return port_error; |
| 6309 | } |
| 6310 | |
| 6311 | /** |
| 6312 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 6313 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6314 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6315 | * |
| 6316 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 6317 | * memory map. |
| 6318 | **/ |
| 6319 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6320 | 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] | 6321 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6322 | switch (if_type) { |
| 6323 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6324 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 6325 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 6326 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 6327 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 6328 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 6329 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 6330 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 6331 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 6332 | phba->sli4_hba.SLIINTFregaddr = |
| 6333 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6334 | break; |
| 6335 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6336 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6337 | phba->sli4_hba.conf_regs_memmap_p + |
| 6338 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6339 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6340 | phba->sli4_hba.conf_regs_memmap_p + |
| 6341 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6342 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6343 | phba->sli4_hba.conf_regs_memmap_p + |
| 6344 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6345 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6346 | phba->sli4_hba.conf_regs_memmap_p + |
| 6347 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6348 | phba->sli4_hba.SLIINTFregaddr = |
| 6349 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 6350 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6351 | phba->sli4_hba.conf_regs_memmap_p + |
| 6352 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6353 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6354 | phba->sli4_hba.conf_regs_memmap_p + |
| 6355 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6356 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6357 | phba->sli4_hba.conf_regs_memmap_p + |
| 6358 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6359 | phba->sli4_hba.EQCQDBregaddr = |
| 6360 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 6361 | phba->sli4_hba.MQDBregaddr = |
| 6362 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 6363 | phba->sli4_hba.BMBXregaddr = |
| 6364 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 6365 | break; |
| 6366 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6367 | default: |
| 6368 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 6369 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 6370 | if_type); |
| 6371 | break; |
| 6372 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | /** |
| 6376 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 6377 | * @phba: pointer to lpfc hba data structure. |
| 6378 | * |
| 6379 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 6380 | * memory map. |
| 6381 | **/ |
| 6382 | static void |
| 6383 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 6384 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6385 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 6386 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6387 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6388 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6389 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6390 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6391 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6392 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /** |
| 6396 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 6397 | * @phba: pointer to lpfc hba data structure. |
| 6398 | * @vf: virtual function number |
| 6399 | * |
| 6400 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 6401 | * based on the given viftual function number, @vf. |
| 6402 | * |
| 6403 | * Return 0 if successful, otherwise -ENODEV. |
| 6404 | **/ |
| 6405 | static int |
| 6406 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 6407 | { |
| 6408 | if (vf > LPFC_VIR_FUNC_MAX) |
| 6409 | return -ENODEV; |
| 6410 | |
| 6411 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6412 | vf * LPFC_VFR_PAGE_SIZE + |
| 6413 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6414 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 6415 | vf * LPFC_VFR_PAGE_SIZE + |
| 6416 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6417 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6418 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 6419 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6420 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 6421 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 6422 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 6423 | return 0; |
| 6424 | } |
| 6425 | |
| 6426 | /** |
| 6427 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 6428 | * @phba: pointer to lpfc hba data structure. |
| 6429 | * |
| 6430 | * This routine is invoked to create the bootstrap mailbox |
| 6431 | * region consistent with the SLI-4 interface spec. This |
| 6432 | * routine allocates all memory necessary to communicate |
| 6433 | * mailbox commands to the port and sets up all alignment |
| 6434 | * needs. No locks are expected to be held when calling |
| 6435 | * this routine. |
| 6436 | * |
| 6437 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6438 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6439 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6440 | **/ |
| 6441 | static int |
| 6442 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 6443 | { |
| 6444 | uint32_t bmbx_size; |
| 6445 | struct lpfc_dmabuf *dmabuf; |
| 6446 | struct dma_address *dma_address; |
| 6447 | uint32_t pa_addr; |
| 6448 | uint64_t phys_addr; |
| 6449 | |
| 6450 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6451 | if (!dmabuf) |
| 6452 | return -ENOMEM; |
| 6453 | |
| 6454 | /* |
| 6455 | * The bootstrap mailbox region is comprised of 2 parts |
| 6456 | * plus an alignment restriction of 16 bytes. |
| 6457 | */ |
| 6458 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 6459 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6460 | bmbx_size, |
| 6461 | &dmabuf->phys, |
| 6462 | GFP_KERNEL); |
| 6463 | if (!dmabuf->virt) { |
| 6464 | kfree(dmabuf); |
| 6465 | return -ENOMEM; |
| 6466 | } |
| 6467 | memset(dmabuf->virt, 0, bmbx_size); |
| 6468 | |
| 6469 | /* |
| 6470 | * Initialize the bootstrap mailbox pointers now so that the register |
| 6471 | * operations are simple later. The mailbox dma address is required |
| 6472 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6473 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6474 | * command to the port. |
| 6475 | */ |
| 6476 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6477 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6478 | |
| 6479 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6480 | LPFC_ALIGN_16_BYTE); |
| 6481 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6482 | LPFC_ALIGN_16_BYTE); |
| 6483 | |
| 6484 | /* |
| 6485 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6486 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6487 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6488 | * the 30-bit address is the high or low address. |
| 6489 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6490 | * clean on 32 bit machines. |
| 6491 | */ |
| 6492 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6493 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6494 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6495 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6496 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6497 | |
| 6498 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6499 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6500 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6501 | return 0; |
| 6502 | } |
| 6503 | |
| 6504 | /** |
| 6505 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6506 | * @phba: pointer to lpfc hba data structure. |
| 6507 | * |
| 6508 | * This routine is invoked to teardown the bootstrap mailbox |
| 6509 | * region and release all host resources. This routine requires |
| 6510 | * the caller to ensure all mailbox commands recovered, no |
| 6511 | * additional mailbox comands are sent, and interrupts are disabled |
| 6512 | * before calling this routine. |
| 6513 | * |
| 6514 | **/ |
| 6515 | static void |
| 6516 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6517 | { |
| 6518 | dma_free_coherent(&phba->pcidev->dev, |
| 6519 | phba->sli4_hba.bmbx.bmbx_size, |
| 6520 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6521 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6522 | |
| 6523 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6524 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6525 | } |
| 6526 | |
| 6527 | /** |
| 6528 | * lpfc_sli4_read_config - Get the config parameters. |
| 6529 | * @phba: pointer to lpfc hba data structure. |
| 6530 | * |
| 6531 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6532 | * The configuration parameters are used to set the base and maximum values |
| 6533 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6534 | * allocation for the port. |
| 6535 | * |
| 6536 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6537 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6538 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6539 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6540 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6541 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6542 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6543 | { |
| 6544 | LPFC_MBOXQ_t *pmb; |
| 6545 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6546 | union lpfc_sli4_cfg_shdr *shdr; |
| 6547 | uint32_t shdr_status, shdr_add_status; |
| 6548 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6549 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6550 | char *pdesc_0; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6551 | uint32_t desc_count; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6552 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6553 | |
| 6554 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6555 | if (!pmb) { |
| 6556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6557 | "2011 Unable to allocate memory for issuing " |
| 6558 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6559 | return -ENOMEM; |
| 6560 | } |
| 6561 | |
| 6562 | lpfc_read_config(phba, pmb); |
| 6563 | |
| 6564 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6565 | if (rc != MBX_SUCCESS) { |
| 6566 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6567 | "2012 Mailbox failed , mbxCmd x%x " |
| 6568 | "READ_CONFIG, mbxStatus x%x\n", |
| 6569 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6570 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6571 | rc = -EIO; |
| 6572 | } else { |
| 6573 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6574 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6575 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6576 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6577 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6578 | phba->sli4_hba.lnk_info.lnk_no = |
| 6579 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6580 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6581 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6582 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6583 | phba->sli4_hba.lnk_info.lnk_no); |
| 6584 | } else |
| 6585 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6586 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6587 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6588 | phba->sli4_hba.extents_in_use = |
| 6589 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6590 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6591 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6592 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6593 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6594 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6595 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6596 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6597 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6598 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6599 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6600 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6601 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6602 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6603 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6604 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6605 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6606 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6607 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6608 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6609 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6610 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6611 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6612 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6613 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6614 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6615 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6616 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6617 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6618 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6619 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6620 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6621 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6622 | phba->max_vports = phba->max_vpi; |
| 6623 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6624 | "2003 cfg params Extents? %d " |
| 6625 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6626 | "VPI(B:%d M:%d) " |
| 6627 | "VFI(B:%d M:%d) " |
| 6628 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6629 | "FCFI(Count:%d)\n", |
| 6630 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6631 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6632 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6633 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6634 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6635 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6636 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6637 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6638 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6639 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6640 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6641 | |
| 6642 | if (rc) |
| 6643 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6644 | |
| 6645 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6646 | if (phba->cfg_hba_queue_depth > |
| 6647 | (phba->sli4_hba.max_cfg_param.max_xri - |
| 6648 | lpfc_sli4_get_els_iocb_cnt(phba))) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6649 | phba->cfg_hba_queue_depth = |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6650 | phba->sli4_hba.max_cfg_param.max_xri - |
| 6651 | lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6652 | |
| 6653 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6654 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6655 | goto read_cfg_out; |
| 6656 | |
| 6657 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6658 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6659 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6660 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6661 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6662 | length, LPFC_SLI4_MBX_EMBED); |
| 6663 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6664 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6665 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6666 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6667 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6668 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6669 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6670 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6671 | "3026 Mailbox failed , mbxCmd x%x " |
| 6672 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6673 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6674 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6675 | goto read_cfg_out; |
| 6676 | } |
| 6677 | |
| 6678 | /* search for fc_fcoe resrouce descriptor */ |
| 6679 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6680 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6681 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6682 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 6683 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 6684 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 6685 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 6686 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 6687 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 6688 | goto read_cfg_out; |
| 6689 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6690 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6691 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6692 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6693 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6694 | phba->sli4_hba.iov.pf_number = |
| 6695 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6696 | phba->sli4_hba.iov.vf_number = |
| 6697 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6698 | break; |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6703 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6704 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6705 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6706 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 6707 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6708 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6709 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6710 | "Resrouce Descriptor:x%x\n", |
| 6711 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6712 | |
| 6713 | read_cfg_out: |
| 6714 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6715 | return rc; |
| 6716 | } |
| 6717 | |
| 6718 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6719 | * 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] | 6720 | * @phba: pointer to lpfc hba data structure. |
| 6721 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6722 | * This routine is invoked to setup the port-side endian order when |
| 6723 | * the port if_type is 0. This routine has no function for other |
| 6724 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6725 | * |
| 6726 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6727 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6728 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6729 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6730 | **/ |
| 6731 | static int |
| 6732 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6733 | { |
| 6734 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6735 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6736 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6737 | HOST_ENDIAN_HIGH_WORD1}; |
| 6738 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6739 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6740 | switch (if_type) { |
| 6741 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6742 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6743 | GFP_KERNEL); |
| 6744 | if (!mboxq) { |
| 6745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6746 | "0492 Unable to allocate memory for " |
| 6747 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6748 | "command\n"); |
| 6749 | return -ENOMEM; |
| 6750 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6751 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6752 | /* |
| 6753 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6754 | * two words to contain special data values and no other data. |
| 6755 | */ |
| 6756 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6757 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6758 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6759 | if (rc != MBX_SUCCESS) { |
| 6760 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6761 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6762 | "failed with status x%x\n", |
| 6763 | rc); |
| 6764 | rc = -EIO; |
| 6765 | } |
| 6766 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6767 | break; |
| 6768 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6769 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6770 | default: |
| 6771 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6772 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6773 | return rc; |
| 6774 | } |
| 6775 | |
| 6776 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6777 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6778 | * @phba: pointer to lpfc hba data structure. |
| 6779 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6780 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6781 | * CQs. after this routine is called the counts will be set to valid values that |
| 6782 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6783 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6784 | * |
| 6785 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6786 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6787 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6788 | **/ |
| 6789 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6790 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6791 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6792 | int cfg_fcp_io_channel; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6793 | uint32_t cpu; |
| 6794 | uint32_t i = 0; |
| 6795 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6796 | |
| 6797 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6798 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6799 | * device parameters |
| 6800 | */ |
| 6801 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6802 | /* Sanity check on HBA EQ parameters */ |
| 6803 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6804 | |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6805 | /* It doesn't make sense to have more io channels then CPUs */ |
| 6806 | for_each_online_cpu(cpu) { |
| 6807 | i++; |
| 6808 | } |
| 6809 | if (i < cfg_fcp_io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6810 | lpfc_printf_log(phba, |
| 6811 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 6812 | "3188 Reducing IO channels to match number of " |
| 6813 | "CPUs: from %d to %d\n", cfg_fcp_io_channel, i); |
| 6814 | cfg_fcp_io_channel = i; |
| 6815 | } |
| 6816 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6817 | if (cfg_fcp_io_channel > |
| 6818 | phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6819 | if (phba->sli4_hba.max_cfg_param.max_eq < |
| 6820 | LPFC_FCP_IO_CHAN_MIN) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6822 | "2574 Not enough EQs (%d) from the " |
| 6823 | "pci function for supporting FCP " |
| 6824 | "EQs (%d)\n", |
| 6825 | phba->sli4_hba.max_cfg_param.max_eq, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6826 | phba->cfg_fcp_io_channel); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6827 | goto out_error; |
| 6828 | } |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 6829 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6830 | "2575 Reducing IO channels to match number of " |
| 6831 | "available EQs: from %d to %d\n", |
| 6832 | cfg_fcp_io_channel, |
| 6833 | phba->sli4_hba.max_cfg_param.max_eq); |
| 6834 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6835 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6836 | |
| 6837 | /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */ |
| 6838 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6839 | /* The actual number of FCP event queues adopted */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6840 | phba->cfg_fcp_eq_count = cfg_fcp_io_channel; |
| 6841 | phba->cfg_fcp_wq_count = cfg_fcp_io_channel; |
| 6842 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6843 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6844 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6845 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6846 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6847 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6848 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6849 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6850 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6851 | |
| 6852 | return 0; |
| 6853 | out_error: |
| 6854 | return -ENOMEM; |
| 6855 | } |
| 6856 | |
| 6857 | /** |
| 6858 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6859 | * @phba: pointer to lpfc hba data structure. |
| 6860 | * |
| 6861 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6862 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6863 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6864 | * we just use some constant number as place holder. |
| 6865 | * |
| 6866 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 6867 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6868 | * -ENOMEM - No availble memory |
| 6869 | * -EIO - The mailbox failed to complete successfully. |
| 6870 | **/ |
| 6871 | int |
| 6872 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6873 | { |
| 6874 | struct lpfc_queue *qdesc; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6875 | int idx; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6876 | |
| 6877 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6878 | * Create HBA Record arrays. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6879 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6880 | if (!phba->cfg_fcp_io_channel) |
| 6881 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6882 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6883 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6884 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6885 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6886 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6887 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6888 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6889 | |
| 6890 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6891 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6892 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6894 | "2576 Failed allocate memory for " |
| 6895 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6896 | goto out_error; |
| 6897 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6898 | |
| 6899 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6900 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6901 | if (!phba->sli4_hba.fcp_cq) { |
| 6902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6903 | "2577 Failed allocate memory for fast-path " |
| 6904 | "CQ record array\n"); |
| 6905 | goto out_error; |
| 6906 | } |
| 6907 | |
| 6908 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6909 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6910 | if (!phba->sli4_hba.fcp_wq) { |
| 6911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6912 | "2578 Failed allocate memory for fast-path " |
| 6913 | "WQ record array\n"); |
| 6914 | goto out_error; |
| 6915 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6916 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6917 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6918 | * Since the first EQ can have multiple CQs associated with it, |
| 6919 | * this array is used to quickly see if we have a FCP fast-path |
| 6920 | * CQ match. |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6921 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6922 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
| 6923 | phba->cfg_fcp_io_channel), GFP_KERNEL); |
| 6924 | if (!phba->sli4_hba.fcp_cq_map) { |
| 6925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6926 | "2545 Failed allocate memory for fast-path " |
| 6927 | "CQ map\n"); |
| 6928 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6929 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6930 | |
| 6931 | /* |
| 6932 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies |
| 6933 | * how many EQs to create. |
| 6934 | */ |
| 6935 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 6936 | |
| 6937 | /* Create EQs */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6938 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6939 | phba->sli4_hba.eq_ecount); |
| 6940 | if (!qdesc) { |
| 6941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6942 | "0497 Failed allocate EQ (%d)\n", idx); |
| 6943 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6944 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6945 | phba->sli4_hba.hba_eq[idx] = qdesc; |
| 6946 | |
| 6947 | /* Create Fast Path FCP CQs */ |
| 6948 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6949 | phba->sli4_hba.cq_ecount); |
| 6950 | if (!qdesc) { |
| 6951 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6952 | "0499 Failed allocate fast-path FCP " |
| 6953 | "CQ (%d)\n", idx); |
| 6954 | goto out_error; |
| 6955 | } |
| 6956 | phba->sli4_hba.fcp_cq[idx] = qdesc; |
| 6957 | |
| 6958 | /* Create Fast Path FCP WQs */ |
| 6959 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6960 | phba->sli4_hba.wq_ecount); |
| 6961 | if (!qdesc) { |
| 6962 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6963 | "0503 Failed allocate fast-path FCP " |
| 6964 | "WQ (%d)\n", idx); |
| 6965 | goto out_error; |
| 6966 | } |
| 6967 | phba->sli4_hba.fcp_wq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6968 | } |
| 6969 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6970 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6971 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6972 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6973 | */ |
| 6974 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6975 | /* Create slow-path Mailbox Command Complete Queue */ |
| 6976 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6977 | phba->sli4_hba.cq_ecount); |
| 6978 | if (!qdesc) { |
| 6979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6980 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6981 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6982 | } |
| 6983 | phba->sli4_hba.mbx_cq = qdesc; |
| 6984 | |
| 6985 | /* Create slow-path ELS Complete Queue */ |
| 6986 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6987 | phba->sli4_hba.cq_ecount); |
| 6988 | if (!qdesc) { |
| 6989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6990 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6991 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6992 | } |
| 6993 | phba->sli4_hba.els_cq = qdesc; |
| 6994 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6995 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6996 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6997 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6998 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6999 | |
| 7000 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7001 | |
| 7002 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 7003 | phba->sli4_hba.mq_ecount); |
| 7004 | if (!qdesc) { |
| 7005 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7006 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7007 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7008 | } |
| 7009 | phba->sli4_hba.mbx_wq = qdesc; |
| 7010 | |
| 7011 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7012 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7013 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7014 | |
| 7015 | /* Create slow-path ELS Work Queue */ |
| 7016 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 7017 | phba->sli4_hba.wq_ecount); |
| 7018 | if (!qdesc) { |
| 7019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7020 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7021 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7022 | } |
| 7023 | phba->sli4_hba.els_wq = qdesc; |
| 7024 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7025 | /* |
| 7026 | * Create Receive Queue (RQ) |
| 7027 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7028 | |
| 7029 | /* Create Receive Queue for header */ |
| 7030 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7031 | phba->sli4_hba.rq_ecount); |
| 7032 | if (!qdesc) { |
| 7033 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7034 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7035 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7036 | } |
| 7037 | phba->sli4_hba.hdr_rq = qdesc; |
| 7038 | |
| 7039 | /* Create Receive Queue for data */ |
| 7040 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 7041 | phba->sli4_hba.rq_ecount); |
| 7042 | if (!qdesc) { |
| 7043 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7044 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7045 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7046 | } |
| 7047 | phba->sli4_hba.dat_rq = qdesc; |
| 7048 | |
| 7049 | return 0; |
| 7050 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7051 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7052 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7053 | return -ENOMEM; |
| 7054 | } |
| 7055 | |
| 7056 | /** |
| 7057 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 7058 | * @phba: pointer to lpfc hba data structure. |
| 7059 | * |
| 7060 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 7061 | * operation. |
| 7062 | * |
| 7063 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7064 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7065 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7066 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7067 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7068 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7069 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 7070 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7071 | int idx; |
| 7072 | |
| 7073 | if (phba->sli4_hba.hba_eq != NULL) { |
| 7074 | /* Release HBA event queue */ |
| 7075 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7076 | if (phba->sli4_hba.hba_eq[idx] != NULL) { |
| 7077 | lpfc_sli4_queue_free( |
| 7078 | phba->sli4_hba.hba_eq[idx]); |
| 7079 | phba->sli4_hba.hba_eq[idx] = NULL; |
| 7080 | } |
| 7081 | } |
| 7082 | kfree(phba->sli4_hba.hba_eq); |
| 7083 | phba->sli4_hba.hba_eq = NULL; |
| 7084 | } |
| 7085 | |
| 7086 | if (phba->sli4_hba.fcp_cq != NULL) { |
| 7087 | /* Release FCP completion queue */ |
| 7088 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7089 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { |
| 7090 | lpfc_sli4_queue_free( |
| 7091 | phba->sli4_hba.fcp_cq[idx]); |
| 7092 | phba->sli4_hba.fcp_cq[idx] = NULL; |
| 7093 | } |
| 7094 | } |
| 7095 | kfree(phba->sli4_hba.fcp_cq); |
| 7096 | phba->sli4_hba.fcp_cq = NULL; |
| 7097 | } |
| 7098 | |
| 7099 | if (phba->sli4_hba.fcp_wq != NULL) { |
| 7100 | /* Release FCP work queue */ |
| 7101 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { |
| 7102 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { |
| 7103 | lpfc_sli4_queue_free( |
| 7104 | phba->sli4_hba.fcp_wq[idx]); |
| 7105 | phba->sli4_hba.fcp_wq[idx] = NULL; |
| 7106 | } |
| 7107 | } |
| 7108 | kfree(phba->sli4_hba.fcp_wq); |
| 7109 | phba->sli4_hba.fcp_wq = NULL; |
| 7110 | } |
| 7111 | |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7112 | if (phba->pci_bar0_memmap_p) { |
| 7113 | iounmap(phba->pci_bar0_memmap_p); |
| 7114 | phba->pci_bar0_memmap_p = NULL; |
| 7115 | } |
| 7116 | if (phba->pci_bar2_memmap_p) { |
| 7117 | iounmap(phba->pci_bar2_memmap_p); |
| 7118 | phba->pci_bar2_memmap_p = NULL; |
| 7119 | } |
| 7120 | if (phba->pci_bar4_memmap_p) { |
| 7121 | iounmap(phba->pci_bar4_memmap_p); |
| 7122 | phba->pci_bar4_memmap_p = NULL; |
| 7123 | } |
| 7124 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7125 | /* Release FCP CQ mapping array */ |
| 7126 | if (phba->sli4_hba.fcp_cq_map != NULL) { |
| 7127 | kfree(phba->sli4_hba.fcp_cq_map); |
| 7128 | phba->sli4_hba.fcp_cq_map = NULL; |
| 7129 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7130 | |
| 7131 | /* Release mailbox command work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7132 | if (phba->sli4_hba.mbx_wq != NULL) { |
| 7133 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 7134 | phba->sli4_hba.mbx_wq = NULL; |
| 7135 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7136 | |
| 7137 | /* Release ELS work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7138 | if (phba->sli4_hba.els_wq != NULL) { |
| 7139 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 7140 | phba->sli4_hba.els_wq = NULL; |
| 7141 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7142 | |
| 7143 | /* Release unsolicited receive queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7144 | if (phba->sli4_hba.hdr_rq != NULL) { |
| 7145 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 7146 | phba->sli4_hba.hdr_rq = NULL; |
| 7147 | } |
| 7148 | if (phba->sli4_hba.dat_rq != NULL) { |
| 7149 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 7150 | phba->sli4_hba.dat_rq = NULL; |
| 7151 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7152 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7153 | /* Release ELS complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7154 | if (phba->sli4_hba.els_cq != NULL) { |
| 7155 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 7156 | phba->sli4_hba.els_cq = NULL; |
| 7157 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7158 | |
| 7159 | /* Release mailbox command complete queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7160 | if (phba->sli4_hba.mbx_cq != NULL) { |
| 7161 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 7162 | phba->sli4_hba.mbx_cq = NULL; |
| 7163 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7164 | |
| 7165 | return; |
| 7166 | } |
| 7167 | |
| 7168 | /** |
| 7169 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 7170 | * @phba: pointer to lpfc hba data structure. |
| 7171 | * |
| 7172 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 7173 | * operation. |
| 7174 | * |
| 7175 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7176 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7177 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7178 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7179 | **/ |
| 7180 | int |
| 7181 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 7182 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7183 | struct lpfc_sli *psli = &phba->sli; |
| 7184 | struct lpfc_sli_ring *pring; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7185 | int rc = -ENOMEM; |
| 7186 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 7187 | int fcp_cq_index = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7188 | uint32_t shdr_status, shdr_add_status; |
| 7189 | union lpfc_sli4_cfg_shdr *shdr; |
| 7190 | LPFC_MBOXQ_t *mboxq; |
| 7191 | uint32_t length; |
| 7192 | |
| 7193 | /* Check for dual-ULP support */ |
| 7194 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7195 | if (!mboxq) { |
| 7196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7197 | "3249 Unable to allocate memory for " |
| 7198 | "QUERY_FW_CFG mailbox command\n"); |
| 7199 | return -ENOMEM; |
| 7200 | } |
| 7201 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 7202 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7203 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7204 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 7205 | length, LPFC_SLI4_MBX_EMBED); |
| 7206 | |
| 7207 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7208 | |
| 7209 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7210 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7211 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7212 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 7213 | if (shdr_status || shdr_add_status || rc) { |
| 7214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7215 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 7216 | "x%x add_status x%x, mbx status x%x\n", |
| 7217 | shdr_status, shdr_add_status, rc); |
| 7218 | if (rc != MBX_TIMEOUT) |
| 7219 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7220 | rc = -ENXIO; |
| 7221 | goto out_error; |
| 7222 | } |
| 7223 | |
| 7224 | phba->sli4_hba.fw_func_mode = |
| 7225 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 7226 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 7227 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; |
| 7228 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7229 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 7230 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 7231 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 7232 | |
| 7233 | if (rc != MBX_TIMEOUT) |
| 7234 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7235 | |
| 7236 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7237 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7238 | */ |
| 7239 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7240 | /* Set up HBA event queue */ |
| 7241 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7243 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7244 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7245 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7246 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7247 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
| 7248 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7249 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7250 | "0522 Fast-path EQ (%d) not " |
| 7251 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7252 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7253 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7254 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7255 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
James Smart | bf8dae8 | 2012-08-03 12:36:24 -0400 | [diff] [blame] | 7256 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7257 | if (rc) { |
| 7258 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7259 | "0523 Failed setup of fast-path EQ " |
| 7260 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7261 | goto out_destroy_hba_eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7262 | } |
| 7263 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7264 | "2584 HBA EQ setup: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7265 | "queue[%d]-id=%d\n", fcp_eqidx, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7266 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7267 | } |
| 7268 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7269 | /* Set up fast-path FCP Response Complete Queue */ |
| 7270 | if (!phba->sli4_hba.fcp_cq) { |
| 7271 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7272 | "3148 Fast-path FCP CQ array not " |
| 7273 | "allocated\n"); |
| 7274 | rc = -ENOMEM; |
| 7275 | goto out_destroy_hba_eq; |
| 7276 | } |
| 7277 | |
| 7278 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { |
| 7279 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 7280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7281 | "0526 Fast-path FCP CQ (%d) not " |
| 7282 | "allocated\n", fcp_cqidx); |
| 7283 | rc = -ENOMEM; |
| 7284 | goto out_destroy_fcp_cq; |
| 7285 | } |
| 7286 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 7287 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); |
| 7288 | if (rc) { |
| 7289 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7290 | "0527 Failed setup of fast-path FCP " |
| 7291 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 7292 | goto out_destroy_fcp_cq; |
| 7293 | } |
| 7294 | |
| 7295 | /* Setup fcp_cq_map for fast lookup */ |
| 7296 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = |
| 7297 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; |
| 7298 | |
| 7299 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7300 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
| 7301 | "parent seq[%d]-id=%d\n", |
| 7302 | fcp_cqidx, |
| 7303 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
| 7304 | fcp_cqidx, |
| 7305 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); |
| 7306 | } |
| 7307 | |
| 7308 | /* Set up fast-path FCP Work Queue */ |
| 7309 | if (!phba->sli4_hba.fcp_wq) { |
| 7310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7311 | "3149 Fast-path FCP WQ array not " |
| 7312 | "allocated\n"); |
| 7313 | rc = -ENOMEM; |
| 7314 | goto out_destroy_fcp_cq; |
| 7315 | } |
| 7316 | |
| 7317 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { |
| 7318 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 7319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7320 | "0534 Fast-path FCP WQ (%d) not " |
| 7321 | "allocated\n", fcp_wqidx); |
| 7322 | rc = -ENOMEM; |
| 7323 | goto out_destroy_fcp_wq; |
| 7324 | } |
| 7325 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 7326 | phba->sli4_hba.fcp_cq[fcp_wqidx], |
| 7327 | LPFC_FCP); |
| 7328 | if (rc) { |
| 7329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7330 | "0535 Failed setup of fast-path FCP " |
| 7331 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 7332 | goto out_destroy_fcp_wq; |
| 7333 | } |
| 7334 | |
| 7335 | /* Bind this WQ to the next FCP ring */ |
| 7336 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; |
| 7337 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; |
| 7338 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; |
| 7339 | |
| 7340 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7341 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 7342 | "parent cq[%d]-id=%d\n", |
| 7343 | fcp_wqidx, |
| 7344 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 7345 | fcp_cq_index, |
| 7346 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); |
| 7347 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7348 | /* |
| 7349 | * Set up Complete Queues (CQs) |
| 7350 | */ |
| 7351 | |
| 7352 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 7353 | if (!phba->sli4_hba.mbx_cq) { |
| 7354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7355 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7356 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7357 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7358 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7359 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
| 7360 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7361 | if (rc) { |
| 7362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7363 | "0529 Failed setup of slow-path mailbox CQ: " |
| 7364 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7365 | goto out_destroy_fcp_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7366 | } |
| 7367 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7368 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7369 | phba->sli4_hba.mbx_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7370 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7371 | |
| 7372 | /* Set up slow-path ELS Complete Queue */ |
| 7373 | if (!phba->sli4_hba.els_cq) { |
| 7374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7375 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7376 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7377 | goto out_destroy_mbx_cq; |
| 7378 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7379 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
| 7380 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7381 | if (rc) { |
| 7382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7383 | "0531 Failed setup of slow-path ELS CQ: " |
| 7384 | "rc = 0x%x\n", rc); |
| 7385 | goto out_destroy_mbx_cq; |
| 7386 | } |
| 7387 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7388 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 7389 | phba->sli4_hba.els_cq->queue_id, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7390 | phba->sli4_hba.hba_eq[0]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7391 | |
| 7392 | /* |
| 7393 | * Set up all the Work Queues (WQs) |
| 7394 | */ |
| 7395 | |
| 7396 | /* Set up Mailbox Command Queue */ |
| 7397 | if (!phba->sli4_hba.mbx_wq) { |
| 7398 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7399 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7400 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7401 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7402 | } |
| 7403 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 7404 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 7405 | if (rc) { |
| 7406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7407 | "0539 Failed setup of slow-path MQ: " |
| 7408 | "rc = 0x%x\n", rc); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7409 | goto out_destroy_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7410 | } |
| 7411 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7412 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7413 | phba->sli4_hba.mbx_wq->queue_id, |
| 7414 | phba->sli4_hba.mbx_cq->queue_id); |
| 7415 | |
| 7416 | /* Set up slow-path ELS Work Queue */ |
| 7417 | if (!phba->sli4_hba.els_wq) { |
| 7418 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7419 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7420 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7421 | goto out_destroy_mbx_wq; |
| 7422 | } |
| 7423 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 7424 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 7425 | if (rc) { |
| 7426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7427 | "0537 Failed setup of slow-path ELS WQ: " |
| 7428 | "rc = 0x%x\n", rc); |
| 7429 | goto out_destroy_mbx_wq; |
| 7430 | } |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7431 | |
| 7432 | /* Bind this WQ to the ELS ring */ |
| 7433 | pring = &psli->ring[LPFC_ELS_RING]; |
| 7434 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; |
| 7435 | phba->sli4_hba.els_cq->pring = pring; |
| 7436 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7437 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7438 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 7439 | phba->sli4_hba.els_wq->queue_id, |
| 7440 | phba->sli4_hba.els_cq->queue_id); |
| 7441 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7442 | /* |
| 7443 | * Create Receive Queue (RQ) |
| 7444 | */ |
| 7445 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 7446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7447 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7448 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7449 | goto out_destroy_els_wq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7450 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7451 | |
| 7452 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 7453 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 7454 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7455 | 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] | 7456 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7457 | if (rc) { |
| 7458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7459 | "0541 Failed setup of Receive Queue: " |
| 7460 | "rc = 0x%x\n", rc); |
| 7461 | goto out_destroy_fcp_wq; |
| 7462 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7463 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7464 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7465 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 7466 | "parent cq-id=%d\n", |
| 7467 | phba->sli4_hba.hdr_rq->queue_id, |
| 7468 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7469 | phba->sli4_hba.els_cq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7470 | return 0; |
| 7471 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7472 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7473 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7474 | out_destroy_mbx_wq: |
| 7475 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7476 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7477 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 7478 | out_destroy_mbx_cq: |
| 7479 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7480 | out_destroy_fcp_wq: |
| 7481 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 7482 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 7483 | out_destroy_fcp_cq: |
| 7484 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 7485 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 7486 | out_destroy_hba_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7487 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7488 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7489 | out_error: |
| 7490 | return rc; |
| 7491 | } |
| 7492 | |
| 7493 | /** |
| 7494 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7495 | * @phba: pointer to lpfc hba data structure. |
| 7496 | * |
| 7497 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7498 | * operation. |
| 7499 | * |
| 7500 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7501 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7502 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7503 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7504 | **/ |
| 7505 | void |
| 7506 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7507 | { |
| 7508 | int fcp_qidx; |
| 7509 | |
| 7510 | /* Unset mailbox command work queue */ |
| 7511 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7512 | /* Unset ELS work queue */ |
| 7513 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7514 | /* Unset unsolicited receive queue */ |
| 7515 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7516 | /* Unset FCP work queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7517 | if (phba->sli4_hba.fcp_wq) { |
| 7518 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7519 | fcp_qidx++) |
| 7520 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7521 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7522 | /* Unset mailbox command complete queue */ |
| 7523 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7524 | /* Unset ELS complete queue */ |
| 7525 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7526 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7527 | if (phba->sli4_hba.fcp_cq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7528 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
| 7529 | fcp_qidx++) |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7530 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7531 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7532 | /* Unset fast-path event queue */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7533 | if (phba->sli4_hba.hba_eq) { |
| 7534 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7535 | fcp_qidx++) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7536 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7537 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | /** |
| 7541 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7542 | * @phba: pointer to lpfc hba data structure. |
| 7543 | * |
| 7544 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7545 | * events. The body of the completion queue event is a completion queue entry |
| 7546 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7547 | * the following HBA completion queue events for the worker thread to process: |
| 7548 | * - Mailbox asynchronous events |
| 7549 | * - Receive queue completion unsolicited events |
| 7550 | * Later, this can be used for all the slow-path events. |
| 7551 | * |
| 7552 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7553 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7554 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7555 | **/ |
| 7556 | static int |
| 7557 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7558 | { |
| 7559 | struct lpfc_cq_event *cq_event; |
| 7560 | int i; |
| 7561 | |
| 7562 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7563 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7564 | if (!cq_event) |
| 7565 | goto out_pool_create_fail; |
| 7566 | list_add_tail(&cq_event->list, |
| 7567 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7568 | } |
| 7569 | return 0; |
| 7570 | |
| 7571 | out_pool_create_fail: |
| 7572 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7573 | return -ENOMEM; |
| 7574 | } |
| 7575 | |
| 7576 | /** |
| 7577 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7578 | * @phba: pointer to lpfc hba data structure. |
| 7579 | * |
| 7580 | * This routine is invoked to free the pool of completion queue events at |
| 7581 | * driver unload time. Note that, it is the responsibility of the driver |
| 7582 | * cleanup routine to free all the outstanding completion-queue events |
| 7583 | * allocated from this pool back into the pool before invoking this routine |
| 7584 | * to destroy the pool. |
| 7585 | **/ |
| 7586 | static void |
| 7587 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7588 | { |
| 7589 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7590 | |
| 7591 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7592 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7593 | list_del(&cq_event->list); |
| 7594 | kfree(cq_event); |
| 7595 | } |
| 7596 | } |
| 7597 | |
| 7598 | /** |
| 7599 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7600 | * @phba: pointer to lpfc hba data structure. |
| 7601 | * |
| 7602 | * This routine is the lock free version of the API invoked to allocate a |
| 7603 | * completion-queue event from the free pool. |
| 7604 | * |
| 7605 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7606 | * NULL otherwise. |
| 7607 | **/ |
| 7608 | struct lpfc_cq_event * |
| 7609 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7610 | { |
| 7611 | struct lpfc_cq_event *cq_event = NULL; |
| 7612 | |
| 7613 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7614 | struct lpfc_cq_event, list); |
| 7615 | return cq_event; |
| 7616 | } |
| 7617 | |
| 7618 | /** |
| 7619 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7620 | * @phba: pointer to lpfc hba data structure. |
| 7621 | * |
| 7622 | * This routine is the lock version of the API invoked to allocate a |
| 7623 | * completion-queue event from the free pool. |
| 7624 | * |
| 7625 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7626 | * NULL otherwise. |
| 7627 | **/ |
| 7628 | struct lpfc_cq_event * |
| 7629 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7630 | { |
| 7631 | struct lpfc_cq_event *cq_event; |
| 7632 | unsigned long iflags; |
| 7633 | |
| 7634 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7635 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7636 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7637 | return cq_event; |
| 7638 | } |
| 7639 | |
| 7640 | /** |
| 7641 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7642 | * @phba: pointer to lpfc hba data structure. |
| 7643 | * @cq_event: pointer to the completion queue event to be freed. |
| 7644 | * |
| 7645 | * This routine is the lock free version of the API invoked to release a |
| 7646 | * completion-queue event back into the free pool. |
| 7647 | **/ |
| 7648 | void |
| 7649 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7650 | struct lpfc_cq_event *cq_event) |
| 7651 | { |
| 7652 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7653 | } |
| 7654 | |
| 7655 | /** |
| 7656 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7657 | * @phba: pointer to lpfc hba data structure. |
| 7658 | * @cq_event: pointer to the completion queue event to be freed. |
| 7659 | * |
| 7660 | * This routine is the lock version of the API invoked to release a |
| 7661 | * completion-queue event back into the free pool. |
| 7662 | **/ |
| 7663 | void |
| 7664 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7665 | struct lpfc_cq_event *cq_event) |
| 7666 | { |
| 7667 | unsigned long iflags; |
| 7668 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7669 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7670 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7671 | } |
| 7672 | |
| 7673 | /** |
| 7674 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7675 | * @phba: pointer to lpfc hba data structure. |
| 7676 | * |
| 7677 | * This routine is to free all the pending completion-queue events to the |
| 7678 | * back into the free pool for device reset. |
| 7679 | **/ |
| 7680 | static void |
| 7681 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7682 | { |
| 7683 | LIST_HEAD(cqelist); |
| 7684 | struct lpfc_cq_event *cqe; |
| 7685 | unsigned long iflags; |
| 7686 | |
| 7687 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7688 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7689 | /* Pending FCP XRI abort events */ |
| 7690 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7691 | &cqelist); |
| 7692 | /* Pending ELS XRI abort events */ |
| 7693 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7694 | &cqelist); |
| 7695 | /* Pending asynnc events */ |
| 7696 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7697 | &cqelist); |
| 7698 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7699 | |
| 7700 | while (!list_empty(&cqelist)) { |
| 7701 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7702 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7703 | } |
| 7704 | } |
| 7705 | |
| 7706 | /** |
| 7707 | * lpfc_pci_function_reset - Reset pci function. |
| 7708 | * @phba: pointer to lpfc hba data structure. |
| 7709 | * |
| 7710 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7711 | * all resources assigned to the PCI function which originates this request. |
| 7712 | * |
| 7713 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7714 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7715 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7716 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7717 | **/ |
| 7718 | int |
| 7719 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7720 | { |
| 7721 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7722 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7723 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7724 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7725 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7726 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7727 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7728 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7729 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7730 | switch (if_type) { |
| 7731 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7732 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7733 | GFP_KERNEL); |
| 7734 | if (!mboxq) { |
| 7735 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7736 | "0494 Unable to allocate memory for " |
| 7737 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7738 | "command\n"); |
| 7739 | return -ENOMEM; |
| 7740 | } |
| 7741 | |
| 7742 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7743 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7744 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7745 | LPFC_SLI4_MBX_EMBED); |
| 7746 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7747 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7748 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7749 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7750 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7751 | &shdr->response); |
| 7752 | if (rc != MBX_TIMEOUT) |
| 7753 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7754 | if (shdr_status || shdr_add_status || rc) { |
| 7755 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7756 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7757 | "failed with status x%x add_status x%x," |
| 7758 | " mbx status x%x\n", |
| 7759 | shdr_status, shdr_add_status, rc); |
| 7760 | rc = -ENXIO; |
| 7761 | } |
| 7762 | break; |
| 7763 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7764 | for (num_resets = 0; |
| 7765 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7766 | num_resets++) { |
| 7767 | reg_data.word0 = 0; |
| 7768 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7769 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7770 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7771 | LPFC_SLIPORT_INIT_PORT); |
| 7772 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7773 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7774 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 7775 | pci_read_config_word(phba->pcidev, |
| 7776 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7777 | /* |
| 7778 | * Poll the Port Status Register and wait for RDY for |
| 7779 | * up to 10 seconds. If the port doesn't respond, treat |
| 7780 | * it as an error. If the port responds with RN, start |
| 7781 | * the loop again. |
| 7782 | */ |
| 7783 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7784 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7785 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7786 | STATUSregaddr, ®_data.word0)) { |
| 7787 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7788 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7789 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7790 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7791 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7792 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7793 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7794 | } |
| 7795 | |
| 7796 | /* |
| 7797 | * If the port responds to the init request with |
| 7798 | * reset needed, delay for a bit and restart the loop. |
| 7799 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7800 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7801 | msleep(10); |
| 7802 | reset_again = 0; |
| 7803 | continue; |
| 7804 | } |
| 7805 | |
| 7806 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7807 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7808 | (rdy_chk >= 1000)) { |
| 7809 | phba->work_status[0] = readl( |
| 7810 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7811 | phba->work_status[1] = readl( |
| 7812 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7813 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7814 | "2890 Port error detected during port " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7815 | "reset(%d): wait_tmo:%d ms, " |
| 7816 | "port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7817 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7818 | num_resets, rdy_chk*10, |
| 7819 | reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7820 | phba->work_status[0], |
| 7821 | phba->work_status[1]); |
| 7822 | rc = -ENODEV; |
| 7823 | } |
| 7824 | |
| 7825 | /* |
| 7826 | * Terminate the outer loop provided the Port indicated |
| 7827 | * ready within 10 seconds. |
| 7828 | */ |
| 7829 | if (rdy_chk < 1000) |
| 7830 | break; |
| 7831 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7832 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7833 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7834 | break; |
| 7835 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7836 | default: |
| 7837 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7838 | } |
| 7839 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7840 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7841 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7842 | if (num_resets >= MAX_IF_TYPE_2_RESETS) { |
| 7843 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7844 | "3317 HBA not functional: IP Reset Failed " |
| 7845 | "after (%d) retries, try: " |
| 7846 | "echo fw_reset > board_mode\n", num_resets); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7847 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 7848 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7849 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7850 | return rc; |
| 7851 | } |
| 7852 | |
| 7853 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7854 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7855 | * @phba: pointer to lpfc hba data structure. |
| 7856 | * |
| 7857 | * This routine is invoked to set up the PCI device memory space for device |
| 7858 | * with SLI-4 interface spec. |
| 7859 | * |
| 7860 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7861 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7862 | * other values - error |
| 7863 | **/ |
| 7864 | static int |
| 7865 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7866 | { |
| 7867 | struct pci_dev *pdev; |
| 7868 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7869 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7870 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7871 | |
| 7872 | /* Obtain PCI device reference */ |
| 7873 | if (!phba->pcidev) |
| 7874 | return error; |
| 7875 | else |
| 7876 | pdev = phba->pcidev; |
| 7877 | |
| 7878 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7879 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7880 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7881 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7882 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7883 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7884 | } |
| 7885 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7886 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7887 | /* |
| 7888 | * The BARs and register set definitions and offset locations are |
| 7889 | * dependent on the if_type. |
| 7890 | */ |
| 7891 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 7892 | &phba->sli4_hba.sli_intf.word0)) { |
| 7893 | return error; |
| 7894 | } |
| 7895 | |
| 7896 | /* There is no SLI3 failback for SLI4 devices. */ |
| 7897 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 7898 | LPFC_SLI_INTF_VALID) { |
| 7899 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7900 | "2894 SLI_INTF reg contents invalid " |
| 7901 | "sli_intf reg 0x%x\n", |
| 7902 | phba->sli4_hba.sli_intf.word0); |
| 7903 | return error; |
| 7904 | } |
| 7905 | |
| 7906 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7907 | /* |
| 7908 | * Get the bus address of SLI4 device Bar regions and the |
| 7909 | * number of bytes required by each mapping. The mapping of the |
| 7910 | * particular PCI BARs regions is dependent on the type of |
| 7911 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7912 | */ |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7913 | if (pci_resource_start(pdev, 0)) { |
| 7914 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7915 | bar0map_len = pci_resource_len(pdev, 0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7916 | |
| 7917 | /* |
| 7918 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 7919 | * addr |
| 7920 | */ |
| 7921 | phba->sli4_hba.conf_regs_memmap_p = |
| 7922 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 7923 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7924 | dev_printk(KERN_ERR, &pdev->dev, |
| 7925 | "ioremap failed for SLI4 PCI config " |
| 7926 | "registers.\n"); |
| 7927 | goto out; |
| 7928 | } |
| 7929 | /* Set up BAR0 PCI config space register memory map */ |
| 7930 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7931 | } else { |
| 7932 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 7933 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7934 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7935 | dev_printk(KERN_ERR, &pdev->dev, |
| 7936 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 7937 | goto out; |
| 7938 | } |
| 7939 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7940 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7941 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7942 | dev_printk(KERN_ERR, &pdev->dev, |
| 7943 | "ioremap failed for SLI4 PCI config " |
| 7944 | "registers.\n"); |
| 7945 | goto out; |
| 7946 | } |
| 7947 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7948 | } |
| 7949 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7950 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7951 | (pci_resource_start(pdev, 2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7952 | /* |
| 7953 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 7954 | * virtual address and setup the registers. |
| 7955 | */ |
| 7956 | phba->pci_bar1_map = pci_resource_start(pdev, 2); |
| 7957 | bar1map_len = pci_resource_len(pdev, 2); |
| 7958 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7959 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7960 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 7961 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7962 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7963 | goto out_iounmap_conf; |
| 7964 | } |
| 7965 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7966 | } |
| 7967 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7968 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7969 | (pci_resource_start(pdev, 4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7970 | /* |
| 7971 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 7972 | * virtual address and setup the registers. |
| 7973 | */ |
| 7974 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
| 7975 | bar2map_len = pci_resource_len(pdev, 4); |
| 7976 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7977 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7978 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 7979 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7980 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7981 | goto out_iounmap_ctrl; |
| 7982 | } |
| 7983 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 7984 | if (error) |
| 7985 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7986 | } |
| 7987 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7988 | return 0; |
| 7989 | |
| 7990 | out_iounmap_all: |
| 7991 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7992 | out_iounmap_ctrl: |
| 7993 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7994 | out_iounmap_conf: |
| 7995 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7996 | out: |
| 7997 | return error; |
| 7998 | } |
| 7999 | |
| 8000 | /** |
| 8001 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 8002 | * @phba: pointer to lpfc hba data structure. |
| 8003 | * |
| 8004 | * This routine is invoked to unset the PCI device memory space for device |
| 8005 | * with SLI-4 interface spec. |
| 8006 | **/ |
| 8007 | static void |
| 8008 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 8009 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8010 | uint32_t if_type; |
| 8011 | 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] | 8012 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8013 | switch (if_type) { |
| 8014 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8015 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 8016 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 8017 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8018 | break; |
| 8019 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8020 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 8021 | break; |
| 8022 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8023 | default: |
| 8024 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8025 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8026 | if_type); |
| 8027 | break; |
| 8028 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8032 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 8033 | * @phba: pointer to lpfc hba data structure. |
| 8034 | * |
| 8035 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8036 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 8037 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 8038 | * invoked, enables either all or nothing, depending on the current |
| 8039 | * availability of PCI vector resources. The device driver is responsible |
| 8040 | * for calling the individual request_irq() to register each MSI-X vector |
| 8041 | * with a interrupt handler, which is done in this function. Note that |
| 8042 | * later when device is unloading, the driver should always call free_irq() |
| 8043 | * on all MSI-X vectors it has done request_irq() on before calling |
| 8044 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 8045 | * will be left with MSI-X enabled and leaks its vectors. |
| 8046 | * |
| 8047 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8048 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8049 | * other values - error |
| 8050 | **/ |
| 8051 | static int |
| 8052 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 8053 | { |
| 8054 | int rc, i; |
| 8055 | LPFC_MBOXQ_t *pmb; |
| 8056 | |
| 8057 | /* Set up MSI-X multi-message vectors */ |
| 8058 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8059 | phba->msix_entries[i].entry = i; |
| 8060 | |
| 8061 | /* Configure MSI-X capability structure */ |
| 8062 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 8063 | ARRAY_SIZE(phba->msix_entries)); |
| 8064 | if (rc) { |
| 8065 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8066 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 8067 | goto msi_fail_out; |
| 8068 | } |
| 8069 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8070 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8071 | "0477 MSI-X entry[%d]: vector=x%x " |
| 8072 | "message=%d\n", i, |
| 8073 | phba->msix_entries[i].vector, |
| 8074 | phba->msix_entries[i].entry); |
| 8075 | /* |
| 8076 | * Assign MSI-X vectors to interrupt handlers |
| 8077 | */ |
| 8078 | |
| 8079 | /* vector-0 is associated to slow-path handler */ |
| 8080 | rc = request_irq(phba->msix_entries[0].vector, |
| 8081 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 8082 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 8083 | if (rc) { |
| 8084 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8085 | "0421 MSI-X slow-path request_irq failed " |
| 8086 | "(%d)\n", rc); |
| 8087 | goto msi_fail_out; |
| 8088 | } |
| 8089 | |
| 8090 | /* vector-1 is associated to fast-path handler */ |
| 8091 | rc = request_irq(phba->msix_entries[1].vector, |
| 8092 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 8093 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 8094 | |
| 8095 | if (rc) { |
| 8096 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8097 | "0429 MSI-X fast-path request_irq failed " |
| 8098 | "(%d)\n", rc); |
| 8099 | goto irq_fail_out; |
| 8100 | } |
| 8101 | |
| 8102 | /* |
| 8103 | * Configure HBA MSI-X attention conditions to messages |
| 8104 | */ |
| 8105 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8106 | |
| 8107 | if (!pmb) { |
| 8108 | rc = -ENOMEM; |
| 8109 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8110 | "0474 Unable to allocate memory for issuing " |
| 8111 | "MBOX_CONFIG_MSI command\n"); |
| 8112 | goto mem_fail_out; |
| 8113 | } |
| 8114 | rc = lpfc_config_msi(phba, pmb); |
| 8115 | if (rc) |
| 8116 | goto mbx_fail_out; |
| 8117 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8118 | if (rc != MBX_SUCCESS) { |
| 8119 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 8120 | "0351 Config MSI mailbox command failed, " |
| 8121 | "mbxCmd x%x, mbxStatus x%x\n", |
| 8122 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 8123 | goto mbx_fail_out; |
| 8124 | } |
| 8125 | |
| 8126 | /* Free memory allocated for mailbox command */ |
| 8127 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8128 | return rc; |
| 8129 | |
| 8130 | mbx_fail_out: |
| 8131 | /* Free memory allocated for mailbox command */ |
| 8132 | mempool_free(pmb, phba->mbox_mem_pool); |
| 8133 | |
| 8134 | mem_fail_out: |
| 8135 | /* free the irq already requested */ |
| 8136 | free_irq(phba->msix_entries[1].vector, phba); |
| 8137 | |
| 8138 | irq_fail_out: |
| 8139 | /* free the irq already requested */ |
| 8140 | free_irq(phba->msix_entries[0].vector, phba); |
| 8141 | |
| 8142 | msi_fail_out: |
| 8143 | /* Unconfigure MSI-X capability structure */ |
| 8144 | pci_disable_msix(phba->pcidev); |
| 8145 | return rc; |
| 8146 | } |
| 8147 | |
| 8148 | /** |
| 8149 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 8150 | * @phba: pointer to lpfc hba data structure. |
| 8151 | * |
| 8152 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8153 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 8154 | **/ |
| 8155 | static void |
| 8156 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 8157 | { |
| 8158 | int i; |
| 8159 | |
| 8160 | /* Free up MSI-X multi-message vectors */ |
| 8161 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 8162 | free_irq(phba->msix_entries[i].vector, phba); |
| 8163 | /* Disable MSI-X */ |
| 8164 | pci_disable_msix(phba->pcidev); |
| 8165 | |
| 8166 | return; |
| 8167 | } |
| 8168 | |
| 8169 | /** |
| 8170 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 8171 | * @phba: pointer to lpfc hba data structure. |
| 8172 | * |
| 8173 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8174 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 8175 | * enable the MSI vector. The device driver is responsible for calling the |
| 8176 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 8177 | * is done in this function. |
| 8178 | * |
| 8179 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8180 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8181 | * other values - error |
| 8182 | */ |
| 8183 | static int |
| 8184 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 8185 | { |
| 8186 | int rc; |
| 8187 | |
| 8188 | rc = pci_enable_msi(phba->pcidev); |
| 8189 | if (!rc) |
| 8190 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8191 | "0462 PCI enable MSI mode success.\n"); |
| 8192 | else { |
| 8193 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8194 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 8195 | return rc; |
| 8196 | } |
| 8197 | |
| 8198 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8199 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8200 | if (rc) { |
| 8201 | pci_disable_msi(phba->pcidev); |
| 8202 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8203 | "0478 MSI request_irq failed (%d)\n", rc); |
| 8204 | } |
| 8205 | return rc; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
| 8209 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 8210 | * @phba: pointer to lpfc hba data structure. |
| 8211 | * |
| 8212 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8213 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 8214 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8215 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8216 | * its vector. |
| 8217 | */ |
| 8218 | static void |
| 8219 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 8220 | { |
| 8221 | free_irq(phba->pcidev->irq, phba); |
| 8222 | pci_disable_msi(phba->pcidev); |
| 8223 | return; |
| 8224 | } |
| 8225 | |
| 8226 | /** |
| 8227 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 8228 | * @phba: pointer to lpfc hba data structure. |
| 8229 | * |
| 8230 | * This routine is invoked to enable device interrupt and associate driver's |
| 8231 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 8232 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 8233 | * will try to fallback from the configured interrupt mode to an interrupt |
| 8234 | * mode which is supported by the platform, kernel, and device in the order |
| 8235 | * of: |
| 8236 | * MSI-X -> MSI -> IRQ. |
| 8237 | * |
| 8238 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8239 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8240 | * other values - error |
| 8241 | **/ |
| 8242 | static uint32_t |
| 8243 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8244 | { |
| 8245 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8246 | int retval; |
| 8247 | |
| 8248 | if (cfg_mode == 2) { |
| 8249 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 8250 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 8251 | if (!retval) { |
| 8252 | /* Now, try to enable MSI-X interrupt mode */ |
| 8253 | retval = lpfc_sli_enable_msix(phba); |
| 8254 | if (!retval) { |
| 8255 | /* Indicate initialization to MSI-X mode */ |
| 8256 | phba->intr_type = MSIX; |
| 8257 | intr_mode = 2; |
| 8258 | } |
| 8259 | } |
| 8260 | } |
| 8261 | |
| 8262 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8263 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8264 | retval = lpfc_sli_enable_msi(phba); |
| 8265 | if (!retval) { |
| 8266 | /* Indicate initialization to MSI mode */ |
| 8267 | phba->intr_type = MSI; |
| 8268 | intr_mode = 1; |
| 8269 | } |
| 8270 | } |
| 8271 | |
| 8272 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8273 | if (phba->intr_type == NONE) { |
| 8274 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 8275 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8276 | if (!retval) { |
| 8277 | /* Indicate initialization to INTx mode */ |
| 8278 | phba->intr_type = INTx; |
| 8279 | intr_mode = 0; |
| 8280 | } |
| 8281 | } |
| 8282 | return intr_mode; |
| 8283 | } |
| 8284 | |
| 8285 | /** |
| 8286 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 8287 | * @phba: pointer to lpfc hba data structure. |
| 8288 | * |
| 8289 | * This routine is invoked to disable device interrupt and disassociate the |
| 8290 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 8291 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 8292 | * release the interrupt vector(s) for the message signaled interrupt. |
| 8293 | **/ |
| 8294 | static void |
| 8295 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 8296 | { |
| 8297 | /* Disable the currently initialized interrupt mode */ |
| 8298 | if (phba->intr_type == MSIX) |
| 8299 | lpfc_sli_disable_msix(phba); |
| 8300 | else if (phba->intr_type == MSI) |
| 8301 | lpfc_sli_disable_msi(phba); |
| 8302 | else if (phba->intr_type == INTx) |
| 8303 | free_irq(phba->pcidev->irq, phba); |
| 8304 | |
| 8305 | /* Reset interrupt management states */ |
| 8306 | phba->intr_type = NONE; |
| 8307 | phba->sli.slistat.sli_intr = 0; |
| 8308 | |
| 8309 | return; |
| 8310 | } |
| 8311 | |
| 8312 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8313 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 8314 | * @phba: pointer to lpfc hba data structure. |
| 8315 | * |
| 8316 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 8317 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 8318 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 8319 | * enables either all or nothing, depending on the current availability of |
| 8320 | * PCI vector resources. The device driver is responsible for calling the |
| 8321 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 8322 | * handler, which is done in this function. Note that later when device is |
| 8323 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 8324 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 8325 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 8326 | * enabled and leaks its vectors. |
| 8327 | * |
| 8328 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8329 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8330 | * other values - error |
| 8331 | **/ |
| 8332 | static int |
| 8333 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 8334 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8335 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8336 | |
| 8337 | /* Set up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8338 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8339 | phba->sli4_hba.msix_entries[index].entry = index; |
| 8340 | |
| 8341 | /* Configure MSI-X capability structure */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8342 | vectors = phba->cfg_fcp_io_channel; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8343 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8344 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8345 | vectors); |
| 8346 | if (rc > 1) { |
| 8347 | vectors = rc; |
| 8348 | goto enable_msix_vectors; |
| 8349 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8351 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 8352 | goto msi_fail_out; |
| 8353 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8354 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8355 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8356 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8357 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8358 | "0489 MSI-X entry[%d]: vector=x%x " |
| 8359 | "message=%d\n", index, |
| 8360 | phba->sli4_hba.msix_entries[index].vector, |
| 8361 | phba->sli4_hba.msix_entries[index].entry); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8362 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8363 | /* |
| 8364 | * Assign MSI-X vectors to interrupt handlers |
| 8365 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8366 | for (index = 0; index < vectors; index++) { |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8367 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
| 8368 | sprintf((char *)&phba->sli4_hba.handler_name[index], |
| 8369 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8370 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8371 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8372 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8373 | 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] | 8374 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8375 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 8376 | (char *)&phba->sli4_hba.handler_name[index], |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8377 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8378 | if (rc) { |
| 8379 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8380 | "0486 MSI-X fast-path (%d) " |
| 8381 | "request_irq failed (%d)\n", index, rc); |
| 8382 | goto cfg_fail_out; |
| 8383 | } |
| 8384 | } |
| 8385 | |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8386 | if (vectors != phba->cfg_fcp_io_channel) { |
| 8387 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8388 | "3238 Reducing IO channels to match number of " |
| 8389 | "MSI-X vectors, requested %d got %d\n", |
| 8390 | phba->cfg_fcp_io_channel, vectors); |
| 8391 | phba->cfg_fcp_io_channel = vectors; |
| 8392 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8393 | return rc; |
| 8394 | |
| 8395 | cfg_fail_out: |
| 8396 | /* free the irq already requested */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8397 | for (--index; index >= 0; index--) |
| 8398 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8399 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8400 | |
| 8401 | msi_fail_out: |
| 8402 | /* Unconfigure MSI-X capability structure */ |
| 8403 | pci_disable_msix(phba->pcidev); |
| 8404 | return rc; |
| 8405 | } |
| 8406 | |
| 8407 | /** |
| 8408 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 8409 | * @phba: pointer to lpfc hba data structure. |
| 8410 | * |
| 8411 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 8412 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 8413 | **/ |
| 8414 | static void |
| 8415 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 8416 | { |
| 8417 | int index; |
| 8418 | |
| 8419 | /* Free up MSI-X multi-message vectors */ |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8420 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8421 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8422 | &phba->sli4_hba.fcp_eq_hdl[index]); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8423 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8424 | /* Disable MSI-X */ |
| 8425 | pci_disable_msix(phba->pcidev); |
| 8426 | |
| 8427 | return; |
| 8428 | } |
| 8429 | |
| 8430 | /** |
| 8431 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8432 | * @phba: pointer to lpfc hba data structure. |
| 8433 | * |
| 8434 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8435 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8436 | * to enable the MSI vector. The device driver is responsible for calling |
| 8437 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8438 | * which is done in this function. |
| 8439 | * |
| 8440 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8441 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8442 | * other values - error |
| 8443 | **/ |
| 8444 | static int |
| 8445 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8446 | { |
| 8447 | int rc, index; |
| 8448 | |
| 8449 | rc = pci_enable_msi(phba->pcidev); |
| 8450 | if (!rc) |
| 8451 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8452 | "0487 PCI enable MSI mode success.\n"); |
| 8453 | else { |
| 8454 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8455 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8456 | return rc; |
| 8457 | } |
| 8458 | |
| 8459 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8460 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8461 | if (rc) { |
| 8462 | pci_disable_msi(phba->pcidev); |
| 8463 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8464 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8465 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | } |
| 8467 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8468 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8469 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8470 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8471 | } |
| 8472 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8473 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8474 | } |
| 8475 | |
| 8476 | /** |
| 8477 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8478 | * @phba: pointer to lpfc hba data structure. |
| 8479 | * |
| 8480 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8481 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8482 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8483 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8484 | * its vector. |
| 8485 | **/ |
| 8486 | static void |
| 8487 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8488 | { |
| 8489 | free_irq(phba->pcidev->irq, phba); |
| 8490 | pci_disable_msi(phba->pcidev); |
| 8491 | return; |
| 8492 | } |
| 8493 | |
| 8494 | /** |
| 8495 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8496 | * @phba: pointer to lpfc hba data structure. |
| 8497 | * |
| 8498 | * This routine is invoked to enable device interrupt and associate driver's |
| 8499 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8500 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8501 | * the driver will try to fallback from the configured interrupt mode to an |
| 8502 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8503 | * the order of: |
| 8504 | * MSI-X -> MSI -> IRQ. |
| 8505 | * |
| 8506 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8507 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8508 | * other values - error |
| 8509 | **/ |
| 8510 | static uint32_t |
| 8511 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8512 | { |
| 8513 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8514 | int retval, index; |
| 8515 | |
| 8516 | if (cfg_mode == 2) { |
| 8517 | /* Preparation before conf_msi mbox cmd */ |
| 8518 | retval = 0; |
| 8519 | if (!retval) { |
| 8520 | /* Now, try to enable MSI-X interrupt mode */ |
| 8521 | retval = lpfc_sli4_enable_msix(phba); |
| 8522 | if (!retval) { |
| 8523 | /* Indicate initialization to MSI-X mode */ |
| 8524 | phba->intr_type = MSIX; |
| 8525 | intr_mode = 2; |
| 8526 | } |
| 8527 | } |
| 8528 | } |
| 8529 | |
| 8530 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8531 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8532 | retval = lpfc_sli4_enable_msi(phba); |
| 8533 | if (!retval) { |
| 8534 | /* Indicate initialization to MSI mode */ |
| 8535 | phba->intr_type = MSI; |
| 8536 | intr_mode = 1; |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8541 | if (phba->intr_type == NONE) { |
| 8542 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8543 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8544 | if (!retval) { |
| 8545 | /* Indicate initialization to INTx mode */ |
| 8546 | phba->intr_type = INTx; |
| 8547 | intr_mode = 0; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8548 | for (index = 0; index < phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8549 | index++) { |
| 8550 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8551 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 8552 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
| 8553 | fcp_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8554 | } |
| 8555 | } |
| 8556 | } |
| 8557 | return intr_mode; |
| 8558 | } |
| 8559 | |
| 8560 | /** |
| 8561 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8562 | * @phba: pointer to lpfc hba data structure. |
| 8563 | * |
| 8564 | * This routine is invoked to disable device interrupt and disassociate |
| 8565 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8566 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8567 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8568 | **/ |
| 8569 | static void |
| 8570 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 8571 | { |
| 8572 | /* Disable the currently initialized interrupt mode */ |
| 8573 | if (phba->intr_type == MSIX) |
| 8574 | lpfc_sli4_disable_msix(phba); |
| 8575 | else if (phba->intr_type == MSI) |
| 8576 | lpfc_sli4_disable_msi(phba); |
| 8577 | else if (phba->intr_type == INTx) |
| 8578 | free_irq(phba->pcidev->irq, phba); |
| 8579 | |
| 8580 | /* Reset interrupt management states */ |
| 8581 | phba->intr_type = NONE; |
| 8582 | phba->sli.slistat.sli_intr = 0; |
| 8583 | |
| 8584 | return; |
| 8585 | } |
| 8586 | |
| 8587 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8588 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 8589 | * @phba: pointer to lpfc hba data structure. |
| 8590 | * |
| 8591 | * This routine is invoked to unset the HBA device initialization steps to |
| 8592 | * a device with SLI-3 interface spec. |
| 8593 | **/ |
| 8594 | static void |
| 8595 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 8596 | { |
| 8597 | struct lpfc_vport *vport = phba->pport; |
| 8598 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8599 | |
| 8600 | spin_lock_irq(shost->host_lock); |
| 8601 | vport->load_flag |= FC_UNLOADING; |
| 8602 | spin_unlock_irq(shost->host_lock); |
| 8603 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8604 | kfree(phba->vpi_bmask); |
| 8605 | kfree(phba->vpi_ids); |
| 8606 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8607 | lpfc_stop_hba_timers(phba); |
| 8608 | |
| 8609 | phba->pport->work_port_events = 0; |
| 8610 | |
| 8611 | lpfc_sli_hba_down(phba); |
| 8612 | |
| 8613 | lpfc_sli_brdrestart(phba); |
| 8614 | |
| 8615 | lpfc_sli_disable_intr(phba); |
| 8616 | |
| 8617 | return; |
| 8618 | } |
| 8619 | |
| 8620 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8621 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 8622 | * @phba: Pointer to HBA context object. |
| 8623 | * |
| 8624 | * This function is called in the SLI4 code path to wait for completion |
| 8625 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 8626 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 8627 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 8628 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 8629 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 8630 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 8631 | * the rest of the driver unload resource release. |
| 8632 | **/ |
| 8633 | static void |
| 8634 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 8635 | { |
| 8636 | int wait_time = 0; |
| 8637 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8638 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8639 | |
| 8640 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 8641 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 8642 | if (!fcp_xri_cmpl) |
| 8643 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8644 | "2877 FCP XRI exchange busy " |
| 8645 | "wait time: %d seconds.\n", |
| 8646 | wait_time/1000); |
| 8647 | if (!els_xri_cmpl) |
| 8648 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8649 | "2878 ELS XRI exchange busy " |
| 8650 | "wait time: %d seconds.\n", |
| 8651 | wait_time/1000); |
| 8652 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 8653 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 8654 | } else { |
| 8655 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 8656 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 8657 | } |
| 8658 | fcp_xri_cmpl = |
| 8659 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8660 | els_xri_cmpl = |
| 8661 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8662 | } |
| 8663 | } |
| 8664 | |
| 8665 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8666 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 8667 | * @phba: Pointer to HBA context object. |
| 8668 | * |
| 8669 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 8670 | * function. The caller is not required to hold any lock. This routine |
| 8671 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 8672 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 8673 | * free any pending commands. |
| 8674 | **/ |
| 8675 | static void |
| 8676 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 8677 | { |
| 8678 | int wait_cnt = 0; |
| 8679 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8680 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8681 | |
| 8682 | lpfc_stop_hba_timers(phba); |
| 8683 | phba->sli4_hba.intr_enable = 0; |
| 8684 | |
| 8685 | /* |
| 8686 | * Gracefully wait out the potential current outstanding asynchronous |
| 8687 | * mailbox command. |
| 8688 | */ |
| 8689 | |
| 8690 | /* First, block any pending async mailbox command from posted */ |
| 8691 | spin_lock_irq(&phba->hbalock); |
| 8692 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 8693 | spin_unlock_irq(&phba->hbalock); |
| 8694 | /* Now, trying to wait it out if we can */ |
| 8695 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8696 | msleep(10); |
| 8697 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 8698 | break; |
| 8699 | } |
| 8700 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 8701 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8702 | spin_lock_irq(&phba->hbalock); |
| 8703 | mboxq = phba->sli.mbox_active; |
| 8704 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8705 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8706 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8707 | phba->sli.mbox_active = NULL; |
| 8708 | spin_unlock_irq(&phba->hbalock); |
| 8709 | } |
| 8710 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8711 | /* Abort all iocbs associated with the hba */ |
| 8712 | lpfc_sli_hba_iocb_abort(phba); |
| 8713 | |
| 8714 | /* Wait for completion of device XRI exchange busy */ |
| 8715 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 8716 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8717 | /* Disable PCI subsystem interrupt */ |
| 8718 | lpfc_sli4_disable_intr(phba); |
| 8719 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8720 | /* Disable SR-IOV if enabled */ |
| 8721 | if (phba->cfg_sriov_nr_virtfn) |
| 8722 | pci_disable_sriov(pdev); |
| 8723 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8724 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8725 | kthread_stop(phba->worker_thread); |
| 8726 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8727 | /* Reset SLI4 HBA FCoE function */ |
| 8728 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8729 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8730 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8731 | /* Stop the SLI4 device port */ |
| 8732 | phba->pport->work_port_events = 0; |
| 8733 | } |
| 8734 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8735 | /** |
| 8736 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 8737 | * @phba: Pointer to HBA context object. |
| 8738 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8739 | * |
| 8740 | * This function is called in the SLI4 code path to read the port's |
| 8741 | * sli4 capabilities. |
| 8742 | * |
| 8743 | * This function may be be called from any context that can block-wait |
| 8744 | * for the completion. The expectation is that this routine is called |
| 8745 | * typically from probe_one or from the online routine. |
| 8746 | **/ |
| 8747 | int |
| 8748 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8749 | { |
| 8750 | int rc; |
| 8751 | struct lpfc_mqe *mqe; |
| 8752 | struct lpfc_pc_sli4_params *sli4_params; |
| 8753 | uint32_t mbox_tmo; |
| 8754 | |
| 8755 | rc = 0; |
| 8756 | mqe = &mboxq->u.mqe; |
| 8757 | |
| 8758 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8759 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8760 | if (!phba->sli4_hba.intr_enable) |
| 8761 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8762 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8763 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8764 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8765 | } |
| 8766 | |
| 8767 | if (unlikely(rc)) |
| 8768 | return 1; |
| 8769 | |
| 8770 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8771 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 8772 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 8773 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 8774 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 8775 | &mqe->un.sli4_params); |
| 8776 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 8777 | &mqe->un.sli4_params); |
| 8778 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 8779 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 8780 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 8781 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 8782 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 8783 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 8784 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 8785 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 8786 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 8787 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 8788 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 8789 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 8790 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 8791 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 8792 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 8793 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 8794 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 8795 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 8796 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 8797 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 8798 | 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] | 8799 | |
| 8800 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8801 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8802 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8803 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8804 | return rc; |
| 8805 | } |
| 8806 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8807 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8808 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 8809 | * @phba: Pointer to HBA context object. |
| 8810 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8811 | * |
| 8812 | * This function is called in the SLI4 code path to read the port's |
| 8813 | * sli4 capabilities. |
| 8814 | * |
| 8815 | * This function may be be called from any context that can block-wait |
| 8816 | * for the completion. The expectation is that this routine is called |
| 8817 | * typically from probe_one or from the online routine. |
| 8818 | **/ |
| 8819 | int |
| 8820 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8821 | { |
| 8822 | int rc; |
| 8823 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 8824 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8825 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8826 | int length; |
| 8827 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 8828 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8829 | /* |
| 8830 | * By default, the driver assumes the SLI4 port requires RPI |
| 8831 | * header postings. The SLI4_PARAM response will correct this |
| 8832 | * assumption. |
| 8833 | */ |
| 8834 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 8835 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8836 | /* Read the port's SLI4 Config Parameters */ |
| 8837 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 8838 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8839 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8840 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 8841 | length, LPFC_SLI4_MBX_EMBED); |
| 8842 | if (!phba->sli4_hba.intr_enable) |
| 8843 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8844 | else { |
| 8845 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 8846 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8847 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8848 | if (unlikely(rc)) |
| 8849 | return rc; |
| 8850 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8851 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 8852 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 8853 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 8854 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 8855 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 8856 | mbx_sli4_parameters); |
| 8857 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 8858 | mbx_sli4_parameters); |
| 8859 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 8860 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 8861 | else |
| 8862 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 8863 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 8864 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
| 8865 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 8866 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 8867 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 8868 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
| 8869 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 8870 | mbx_sli4_parameters); |
| 8871 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 8872 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8873 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 8874 | 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] | 8875 | |
| 8876 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8877 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8878 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8879 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8880 | return 0; |
| 8881 | } |
| 8882 | |
| 8883 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8884 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 8885 | * @pdev: pointer to PCI device |
| 8886 | * @pid: pointer to PCI device identifier |
| 8887 | * |
| 8888 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 8889 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8890 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 8891 | * information of the device and driver to see if the driver state that it can |
| 8892 | * support this kind of device. If the match is successful, the driver core |
| 8893 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 8894 | * does all the initialization that it needs to do to handle the HBA properly. |
| 8895 | * |
| 8896 | * Return code |
| 8897 | * 0 - driver can claim the device |
| 8898 | * negative value - driver can not claim the device |
| 8899 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8900 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8901 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 8902 | { |
| 8903 | struct lpfc_hba *phba; |
| 8904 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8905 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8906 | int error; |
| 8907 | uint32_t cfg_mode, intr_mode; |
| 8908 | |
| 8909 | /* Allocate memory for HBA structure */ |
| 8910 | phba = lpfc_hba_alloc(pdev); |
| 8911 | if (!phba) |
| 8912 | return -ENOMEM; |
| 8913 | |
| 8914 | /* Perform generic PCI device enabling operation */ |
| 8915 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8916 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8917 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8918 | |
| 8919 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 8920 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 8921 | if (error) |
| 8922 | goto out_disable_pci_dev; |
| 8923 | |
| 8924 | /* Set up SLI-3 specific device PCI memory space */ |
| 8925 | error = lpfc_sli_pci_mem_setup(phba); |
| 8926 | if (error) { |
| 8927 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8928 | "1402 Failed to set up pci memory space.\n"); |
| 8929 | goto out_disable_pci_dev; |
| 8930 | } |
| 8931 | |
| 8932 | /* Set up phase-1 common device driver resources */ |
| 8933 | error = lpfc_setup_driver_resource_phase1(phba); |
| 8934 | if (error) { |
| 8935 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8936 | "1403 Failed to set up driver resource.\n"); |
| 8937 | goto out_unset_pci_mem_s3; |
| 8938 | } |
| 8939 | |
| 8940 | /* Set up SLI-3 specific device driver resources */ |
| 8941 | error = lpfc_sli_driver_resource_setup(phba); |
| 8942 | if (error) { |
| 8943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8944 | "1404 Failed to set up driver resource.\n"); |
| 8945 | goto out_unset_pci_mem_s3; |
| 8946 | } |
| 8947 | |
| 8948 | /* Initialize and populate the iocb list per host */ |
| 8949 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 8950 | if (error) { |
| 8951 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8952 | "1405 Failed to initialize iocb list.\n"); |
| 8953 | goto out_unset_driver_resource_s3; |
| 8954 | } |
| 8955 | |
| 8956 | /* Set up common device driver resources */ |
| 8957 | error = lpfc_setup_driver_resource_phase2(phba); |
| 8958 | if (error) { |
| 8959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8960 | "1406 Failed to set up driver resource.\n"); |
| 8961 | goto out_free_iocb_list; |
| 8962 | } |
| 8963 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8964 | /* Get the default values for Model Name and Description */ |
| 8965 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 8966 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8967 | /* Create SCSI host to the physical port */ |
| 8968 | error = lpfc_create_shost(phba); |
| 8969 | if (error) { |
| 8970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8971 | "1407 Failed to create scsi host.\n"); |
| 8972 | goto out_unset_driver_resource; |
| 8973 | } |
| 8974 | |
| 8975 | /* Configure sysfs attributes */ |
| 8976 | vport = phba->pport; |
| 8977 | error = lpfc_alloc_sysfs_attr(vport); |
| 8978 | if (error) { |
| 8979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8980 | "1476 Failed to allocate sysfs attr\n"); |
| 8981 | goto out_destroy_shost; |
| 8982 | } |
| 8983 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8984 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8985 | /* Now, trying to enable interrupt and bring up the device */ |
| 8986 | cfg_mode = phba->cfg_use_msi; |
| 8987 | while (true) { |
| 8988 | /* Put device to a known state before enabling interrupt */ |
| 8989 | lpfc_stop_port(phba); |
| 8990 | /* Configure and enable interrupt */ |
| 8991 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 8992 | if (intr_mode == LPFC_INTR_ERROR) { |
| 8993 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8994 | "0431 Failed to enable interrupt.\n"); |
| 8995 | error = -ENODEV; |
| 8996 | goto out_free_sysfs_attr; |
| 8997 | } |
| 8998 | /* SLI-3 HBA setup */ |
| 8999 | if (lpfc_sli_hba_setup(phba)) { |
| 9000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9001 | "1477 Failed to set up hba\n"); |
| 9002 | error = -ENODEV; |
| 9003 | goto out_remove_device; |
| 9004 | } |
| 9005 | |
| 9006 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 9007 | msleep(50); |
| 9008 | /* Check active interrupts on message signaled interrupts */ |
| 9009 | if (intr_mode == 0 || |
| 9010 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 9011 | /* Log the current active interrupt mode */ |
| 9012 | phba->intr_mode = intr_mode; |
| 9013 | lpfc_log_intr_mode(phba, intr_mode); |
| 9014 | break; |
| 9015 | } else { |
| 9016 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9017 | "0447 Configure interrupt mode (%d) " |
| 9018 | "failed active interrupt test.\n", |
| 9019 | intr_mode); |
| 9020 | /* Disable the current interrupt mode */ |
| 9021 | lpfc_sli_disable_intr(phba); |
| 9022 | /* Try next level of interrupt mode */ |
| 9023 | cfg_mode = --intr_mode; |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | /* Perform post initialization setup */ |
| 9028 | lpfc_post_init_setup(phba); |
| 9029 | |
| 9030 | /* Check if there are static vports to be created. */ |
| 9031 | lpfc_create_static_vport(phba); |
| 9032 | |
| 9033 | return 0; |
| 9034 | |
| 9035 | out_remove_device: |
| 9036 | lpfc_unset_hba(phba); |
| 9037 | out_free_sysfs_attr: |
| 9038 | lpfc_free_sysfs_attr(vport); |
| 9039 | out_destroy_shost: |
| 9040 | lpfc_destroy_shost(phba); |
| 9041 | out_unset_driver_resource: |
| 9042 | lpfc_unset_driver_resource_phase2(phba); |
| 9043 | out_free_iocb_list: |
| 9044 | lpfc_free_iocb_list(phba); |
| 9045 | out_unset_driver_resource_s3: |
| 9046 | lpfc_sli_driver_resource_unset(phba); |
| 9047 | out_unset_pci_mem_s3: |
| 9048 | lpfc_sli_pci_mem_unset(phba); |
| 9049 | out_disable_pci_dev: |
| 9050 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9051 | if (shost) |
| 9052 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9053 | out_free_phba: |
| 9054 | lpfc_hba_free(phba); |
| 9055 | return error; |
| 9056 | } |
| 9057 | |
| 9058 | /** |
| 9059 | * 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] | 9060 | * @pdev: pointer to PCI device |
| 9061 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9062 | * This routine is to be called to disattach a device with SLI-3 interface |
| 9063 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 9064 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9065 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9066 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9067 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9068 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9069 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9070 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9071 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9072 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9073 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9074 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9075 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 9076 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9077 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9078 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 9079 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9080 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9081 | lpfc_free_sysfs_attr(vport); |
| 9082 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9083 | /* Release all the vports against this physical port */ |
| 9084 | vports = lpfc_create_vport_work_array(phba); |
| 9085 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9086 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9087 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9088 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9089 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9090 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 9091 | lpfc_destroy_vport_work_array(phba, vports); |
| 9092 | |
| 9093 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9094 | fc_remove_host(shost); |
| 9095 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 9096 | lpfc_cleanup(vport); |
| 9097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9098 | /* |
| 9099 | * Bring down the SLI Layer. This step disable all interrupts, |
| 9100 | * clears the rings, discards all mailbox commands, and resets |
| 9101 | * the HBA. |
| 9102 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9103 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 9104 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9105 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9106 | /* Stop kthread signal shall trigger work_done one more time */ |
| 9107 | kthread_stop(phba->worker_thread); |
| 9108 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9109 | lpfc_sli_brdrestart(phba); |
| 9110 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 9111 | kfree(phba->vpi_bmask); |
| 9112 | kfree(phba->vpi_ids); |
| 9113 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9114 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9115 | spin_lock_irq(&phba->hbalock); |
| 9116 | list_del_init(&vport->listentry); |
| 9117 | spin_unlock_irq(&phba->hbalock); |
| 9118 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9119 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9120 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9121 | /* Disable SR-IOV if enabled */ |
| 9122 | if (phba->cfg_sriov_nr_virtfn) |
| 9123 | pci_disable_sriov(pdev); |
| 9124 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9125 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9126 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9127 | |
| 9128 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9129 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9130 | |
| 9131 | /* |
| 9132 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 9133 | * corresponding pools here. |
| 9134 | */ |
| 9135 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9136 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9137 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9138 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9139 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9140 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9141 | /* Free resources associated with SLI2 interface */ |
| 9142 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9143 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9144 | |
| 9145 | /* unmap adapter SLIM and Control Registers */ |
| 9146 | iounmap(phba->ctrl_regs_memmap_p); |
| 9147 | iounmap(phba->slim_memmap_p); |
| 9148 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9149 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9150 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 9151 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9152 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9153 | } |
| 9154 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9155 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9156 | * 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] | 9157 | * @pdev: pointer to PCI device |
| 9158 | * @msg: power management message |
| 9159 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9160 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9161 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 9162 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 9163 | * worker thread for the device, turning off device's interrupt and DMA, |
| 9164 | * and bring the device offline. Note that as the driver implements the |
| 9165 | * minimum PM requirements to a power-aware driver's PM support for the |
| 9166 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9167 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 9168 | * fully reinitialize its device during resume() method call, the driver will |
| 9169 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 9170 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9171 | * |
| 9172 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9173 | * 0 - driver suspended the device |
| 9174 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9175 | **/ |
| 9176 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9177 | 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] | 9178 | { |
| 9179 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9180 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9181 | |
| 9182 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9183 | "0473 PCI device Power Management suspend.\n"); |
| 9184 | |
| 9185 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9186 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9187 | lpfc_offline(phba); |
| 9188 | kthread_stop(phba->worker_thread); |
| 9189 | |
| 9190 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9191 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9192 | |
| 9193 | /* Save device state to PCI config space */ |
| 9194 | pci_save_state(pdev); |
| 9195 | pci_set_power_state(pdev, PCI_D3hot); |
| 9196 | |
| 9197 | return 0; |
| 9198 | } |
| 9199 | |
| 9200 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9201 | * 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] | 9202 | * @pdev: pointer to PCI device |
| 9203 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9204 | * This routine is to be called from the kernel's PCI subsystem to support |
| 9205 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 9206 | * invokes this method, it restores the device's PCI config space state and |
| 9207 | * fully reinitializes the device and brings it online. Note that as the |
| 9208 | * driver implements the minimum PM requirements to a power-aware driver's |
| 9209 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 9210 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 9211 | * driver will fully reinitialize its device during resume() method call, |
| 9212 | * the device will be set to PCI_D0 directly in PCI config space before |
| 9213 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9214 | * |
| 9215 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9216 | * 0 - driver suspended the device |
| 9217 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9218 | **/ |
| 9219 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9220 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9221 | { |
| 9222 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9223 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9224 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9225 | int error; |
| 9226 | |
| 9227 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9228 | "0452 PCI device Power Management resume.\n"); |
| 9229 | |
| 9230 | /* Restore device state from PCI config space */ |
| 9231 | pci_set_power_state(pdev, PCI_D0); |
| 9232 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9233 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9234 | /* |
| 9235 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9236 | * device saved_state flag, need to save the restored state again. |
| 9237 | */ |
| 9238 | pci_save_state(pdev); |
| 9239 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9240 | if (pdev->is_busmaster) |
| 9241 | pci_set_master(pdev); |
| 9242 | |
| 9243 | /* Startup the kernel thread for this host adapter. */ |
| 9244 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9245 | "lpfc_worker_%d", phba->brd_no); |
| 9246 | if (IS_ERR(phba->worker_thread)) { |
| 9247 | error = PTR_ERR(phba->worker_thread); |
| 9248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9249 | "0434 PM resume failed to start worker " |
| 9250 | "thread: error=x%x.\n", error); |
| 9251 | return error; |
| 9252 | } |
| 9253 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9254 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9255 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9256 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9257 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9258 | "0430 PM resume Failed to enable interrupt\n"); |
| 9259 | return -EIO; |
| 9260 | } else |
| 9261 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9262 | |
| 9263 | /* Restart HBA and bring it online */ |
| 9264 | lpfc_sli_brdrestart(phba); |
| 9265 | lpfc_online(phba); |
| 9266 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9267 | /* Log the current active interrupt mode */ |
| 9268 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9269 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 9270 | return 0; |
| 9271 | } |
| 9272 | |
| 9273 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9274 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 9275 | * @phba: pointer to lpfc hba data structure. |
| 9276 | * |
| 9277 | * 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] | 9278 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9279 | **/ |
| 9280 | static void |
| 9281 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9282 | { |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9283 | struct lpfc_sli *psli = &phba->sli; |
| 9284 | struct lpfc_sli_ring *pring; |
| 9285 | |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9287 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9288 | |
| 9289 | /* |
| 9290 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9291 | * and let the SCSI mid-layer to retry them to recover. |
| 9292 | */ |
| 9293 | pring = &psli->ring[psli->fcp_ring]; |
| 9294 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9295 | } |
| 9296 | |
| 9297 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9298 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 9299 | * @phba: pointer to lpfc hba data structure. |
| 9300 | * |
| 9301 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 9302 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9303 | * pending I/Os. |
| 9304 | **/ |
| 9305 | static void |
| 9306 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9307 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9308 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9309 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9310 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9311 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9312 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9313 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9314 | /* Block all SCSI devices' I/Os on the host */ |
| 9315 | lpfc_scsi_dev_block(phba); |
| 9316 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame^] | 9317 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9318 | lpfc_sli_flush_fcp_rings(phba); |
| 9319 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9320 | /* stop all timers */ |
| 9321 | lpfc_stop_hba_timers(phba); |
| 9322 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9323 | /* Disable interrupt and pci device */ |
| 9324 | lpfc_sli_disable_intr(phba); |
| 9325 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | /** |
| 9329 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 9330 | * @phba: pointer to lpfc hba data structure. |
| 9331 | * |
| 9332 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 9333 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9334 | * pending I/Os. |
| 9335 | **/ |
| 9336 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9337 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9338 | { |
| 9339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9340 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9341 | /* Block all SCSI devices' I/Os on the host */ |
| 9342 | lpfc_scsi_dev_block(phba); |
| 9343 | |
| 9344 | /* stop all timers */ |
| 9345 | lpfc_stop_hba_timers(phba); |
| 9346 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9347 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9348 | lpfc_sli_flush_fcp_rings(phba); |
| 9349 | } |
| 9350 | |
| 9351 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9352 | * 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] | 9353 | * @pdev: pointer to PCI device. |
| 9354 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9355 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9356 | * This routine is called from the PCI subsystem for I/O error handling to |
| 9357 | * device with SLI-3 interface spec. This function is called by the PCI |
| 9358 | * subsystem after a PCI bus error affecting this device has been detected. |
| 9359 | * When this function is invoked, it will need to stop all the I/Os and |
| 9360 | * interrupt(s) to the device. Once that is done, it will return |
| 9361 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 9362 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9363 | * |
| 9364 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9365 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9366 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9367 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9368 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9369 | static pci_ers_result_t |
| 9370 | 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] | 9371 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9372 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9373 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9374 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9375 | switch (state) { |
| 9376 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 9377 | /* Non-fatal error, prepare for recovery */ |
| 9378 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9379 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9380 | case pci_channel_io_frozen: |
| 9381 | /* Fatal error, prepare for slot reset */ |
| 9382 | lpfc_sli_prep_dev_for_reset(phba); |
| 9383 | return PCI_ERS_RESULT_NEED_RESET; |
| 9384 | case pci_channel_io_perm_failure: |
| 9385 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9386 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9387 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9388 | default: |
| 9389 | /* Unknown state, prepare and request slot reset */ |
| 9390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9391 | "0472 Unknown PCI error state: x%x\n", state); |
| 9392 | lpfc_sli_prep_dev_for_reset(phba); |
| 9393 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9394 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9395 | } |
| 9396 | |
| 9397 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9398 | * 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] | 9399 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9400 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9401 | * This routine is called from the PCI subsystem for error handling to |
| 9402 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9403 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9404 | * During the PCI subsystem error recovery, after driver returns |
| 9405 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9406 | * recovery and then call this routine before calling the .resume method |
| 9407 | * to recover the device. This function will initialize the HBA device, |
| 9408 | * enable the interrupt, but it will just put the HBA to offline state |
| 9409 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9410 | * |
| 9411 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9412 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9413 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9414 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9415 | static pci_ers_result_t |
| 9416 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9417 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9418 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9419 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9420 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9421 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9422 | |
| 9423 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9424 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9425 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9426 | "PCI device after reset.\n"); |
| 9427 | return PCI_ERS_RESULT_DISCONNECT; |
| 9428 | } |
| 9429 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9430 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9431 | |
| 9432 | /* |
| 9433 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9434 | * device saved_state flag, need to save the restored state again. |
| 9435 | */ |
| 9436 | pci_save_state(pdev); |
| 9437 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9438 | if (pdev->is_busmaster) |
| 9439 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9440 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9441 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9442 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9443 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9444 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9445 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9446 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9447 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9449 | "0427 Cannot re-enable interrupt after " |
| 9450 | "slot reset.\n"); |
| 9451 | return PCI_ERS_RESULT_DISCONNECT; |
| 9452 | } else |
| 9453 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9454 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9455 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9456 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9457 | lpfc_offline(phba); |
| 9458 | lpfc_sli_brdrestart(phba); |
| 9459 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9460 | /* Log the current active interrupt mode */ |
| 9461 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9462 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9463 | return PCI_ERS_RESULT_RECOVERED; |
| 9464 | } |
| 9465 | |
| 9466 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9467 | * 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] | 9468 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9469 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9470 | * This routine is called from the PCI subsystem for error handling to device |
| 9471 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9472 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9473 | * error recovery. After this call, traffic can start to flow from this device |
| 9474 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9475 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9476 | static void |
| 9477 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9478 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9479 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9480 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9481 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9482 | /* 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] | 9483 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9484 | |
| 9485 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9486 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9487 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9488 | } |
| 9489 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9490 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9491 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9492 | * @phba: pointer to lpfc hba data structure. |
| 9493 | * |
| 9494 | * returns the number of ELS/CT IOCBs to reserve |
| 9495 | **/ |
| 9496 | int |
| 9497 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9498 | { |
| 9499 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9500 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9501 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9502 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9503 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9504 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9505 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9506 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9507 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9508 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9509 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9510 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9511 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 9512 | else if (max_xri <= 2048) |
| 9513 | return 200; |
| 9514 | else |
| 9515 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9516 | } else |
| 9517 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9518 | } |
| 9519 | |
| 9520 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9521 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9522 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9523 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9524 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9525 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9526 | static void |
| 9527 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9528 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9529 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9530 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9531 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9532 | struct list_head dma_buffer_list; |
| 9533 | int i, rc = 0; |
| 9534 | struct lpfc_dmabuf *dmabuf, *next; |
| 9535 | uint32_t offset = 0, temp_offset = 0; |
| 9536 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9537 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9538 | if (!fw) { |
| 9539 | rc = -ENXIO; |
| 9540 | goto out; |
| 9541 | } |
| 9542 | image = (struct lpfc_grp_hdr *)fw->data; |
| 9543 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9544 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9545 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9546 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9547 | LPFC_FILE_TYPE_GROUP) || |
| 9548 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9549 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9550 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9551 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9552 | "Magic:%x Type:%x ID:%x\n", |
| 9553 | be32_to_cpu(image->magic_number), |
| 9554 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9555 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9556 | rc = -EINVAL; |
| 9557 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9558 | } |
| 9559 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9560 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9562 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9563 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9564 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9565 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9566 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9567 | GFP_KERNEL); |
| 9568 | if (!dmabuf) { |
| 9569 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9570 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9571 | } |
| 9572 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 9573 | SLI4_PAGE_SIZE, |
| 9574 | &dmabuf->phys, |
| 9575 | GFP_KERNEL); |
| 9576 | if (!dmabuf->virt) { |
| 9577 | kfree(dmabuf); |
| 9578 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9579 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9580 | } |
| 9581 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 9582 | } |
| 9583 | while (offset < fw->size) { |
| 9584 | temp_offset = offset; |
| 9585 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9586 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9587 | memcpy(dmabuf->virt, |
| 9588 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9589 | fw->size - temp_offset); |
| 9590 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9591 | break; |
| 9592 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9593 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 9594 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9595 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9596 | } |
| 9597 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 9598 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9599 | if (rc) |
| 9600 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9601 | } |
| 9602 | rc = offset; |
| 9603 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9604 | |
| 9605 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9606 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 9607 | list_del(&dmabuf->list); |
| 9608 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 9609 | dmabuf->virt, dmabuf->phys); |
| 9610 | kfree(dmabuf); |
| 9611 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9612 | release_firmware(fw); |
| 9613 | out: |
| 9614 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9615 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9616 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9617 | } |
| 9618 | |
| 9619 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9620 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 9621 | * @phba: pointer to lpfc hba data structure. |
| 9622 | * |
| 9623 | * This routine is called to perform Linux generic firmware upgrade on device |
| 9624 | * that supports such feature. |
| 9625 | **/ |
| 9626 | int |
| 9627 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 9628 | { |
| 9629 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 9630 | int ret; |
| 9631 | const struct firmware *fw; |
| 9632 | |
| 9633 | /* Only supported on SLI4 interface type 2 for now */ |
| 9634 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 9635 | LPFC_SLI_INTF_IF_TYPE_2) |
| 9636 | return -EPERM; |
| 9637 | |
| 9638 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 9639 | |
| 9640 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 9641 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 9642 | file_name, &phba->pcidev->dev, |
| 9643 | GFP_KERNEL, (void *)phba, |
| 9644 | lpfc_write_firmware); |
| 9645 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 9646 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 9647 | if (!ret) |
| 9648 | lpfc_write_firmware(fw, (void *)phba); |
| 9649 | } else { |
| 9650 | ret = -EINVAL; |
| 9651 | } |
| 9652 | |
| 9653 | return ret; |
| 9654 | } |
| 9655 | |
| 9656 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9657 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 9658 | * @pdev: pointer to PCI device |
| 9659 | * @pid: pointer to PCI device identifier |
| 9660 | * |
| 9661 | * This routine is called from the kernel's PCI subsystem to device with |
| 9662 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9663 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9664 | * information of the device and driver to see if the driver state that it |
| 9665 | * can support this kind of device. If the match is successful, the driver |
| 9666 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 9667 | * it does all the initialization that it needs to do to handle the HBA |
| 9668 | * properly. |
| 9669 | * |
| 9670 | * Return code |
| 9671 | * 0 - driver can claim the device |
| 9672 | * negative value - driver can not claim the device |
| 9673 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9674 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9675 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9676 | { |
| 9677 | struct lpfc_hba *phba; |
| 9678 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9679 | struct Scsi_Host *shost = NULL; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 9680 | int error, ret; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9681 | uint32_t cfg_mode, intr_mode; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9682 | int adjusted_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9683 | |
| 9684 | /* Allocate memory for HBA structure */ |
| 9685 | phba = lpfc_hba_alloc(pdev); |
| 9686 | if (!phba) |
| 9687 | return -ENOMEM; |
| 9688 | |
| 9689 | /* Perform generic PCI device enabling operation */ |
| 9690 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9691 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9692 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9693 | |
| 9694 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 9695 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 9696 | if (error) |
| 9697 | goto out_disable_pci_dev; |
| 9698 | |
| 9699 | /* Set up SLI-4 specific device PCI memory space */ |
| 9700 | error = lpfc_sli4_pci_mem_setup(phba); |
| 9701 | if (error) { |
| 9702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9703 | "1410 Failed to set up pci memory space.\n"); |
| 9704 | goto out_disable_pci_dev; |
| 9705 | } |
| 9706 | |
| 9707 | /* Set up phase-1 common device driver resources */ |
| 9708 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9709 | if (error) { |
| 9710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9711 | "1411 Failed to set up driver resource.\n"); |
| 9712 | goto out_unset_pci_mem_s4; |
| 9713 | } |
| 9714 | |
| 9715 | /* Set up SLI-4 Specific device driver resources */ |
| 9716 | error = lpfc_sli4_driver_resource_setup(phba); |
| 9717 | if (error) { |
| 9718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9719 | "1412 Failed to set up driver resource.\n"); |
| 9720 | goto out_unset_pci_mem_s4; |
| 9721 | } |
| 9722 | |
| 9723 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9724 | |
| 9725 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9726 | "2821 initialize iocb list %d.\n", |
| 9727 | phba->cfg_iocb_cnt*1024); |
| 9728 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 9729 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9730 | if (error) { |
| 9731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9732 | "1413 Failed to initialize iocb list.\n"); |
| 9733 | goto out_unset_driver_resource_s4; |
| 9734 | } |
| 9735 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9736 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 9737 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9738 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9739 | /* Set up common device driver resources */ |
| 9740 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9741 | if (error) { |
| 9742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9743 | "1414 Failed to set up driver resource.\n"); |
| 9744 | goto out_free_iocb_list; |
| 9745 | } |
| 9746 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9747 | /* Get the default values for Model Name and Description */ |
| 9748 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9749 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9750 | /* Create SCSI host to the physical port */ |
| 9751 | error = lpfc_create_shost(phba); |
| 9752 | if (error) { |
| 9753 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9754 | "1415 Failed to create scsi host.\n"); |
| 9755 | goto out_unset_driver_resource; |
| 9756 | } |
| 9757 | |
| 9758 | /* Configure sysfs attributes */ |
| 9759 | vport = phba->pport; |
| 9760 | error = lpfc_alloc_sysfs_attr(vport); |
| 9761 | if (error) { |
| 9762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9763 | "1416 Failed to allocate sysfs attr\n"); |
| 9764 | goto out_destroy_shost; |
| 9765 | } |
| 9766 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9767 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9768 | /* Now, trying to enable interrupt and bring up the device */ |
| 9769 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9770 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 9771 | /* Put device to a known state before enabling interrupt */ |
| 9772 | lpfc_stop_port(phba); |
| 9773 | /* Configure and enable interrupt */ |
| 9774 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 9775 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9776 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9777 | "0426 Failed to enable interrupt.\n"); |
| 9778 | error = -ENODEV; |
| 9779 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9780 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 9781 | /* Default to single EQ for non-MSI-X */ |
| 9782 | if (phba->intr_type != MSIX) |
| 9783 | adjusted_fcp_io_channel = 1; |
| 9784 | else |
| 9785 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; |
| 9786 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; |
| 9787 | /* Set up SLI-4 HBA */ |
| 9788 | if (lpfc_sli4_hba_setup(phba)) { |
| 9789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9790 | "1421 Failed to set up hba\n"); |
| 9791 | error = -ENODEV; |
| 9792 | goto out_disable_intr; |
| 9793 | } |
| 9794 | |
| 9795 | /* Log the current active interrupt mode */ |
| 9796 | phba->intr_mode = intr_mode; |
| 9797 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9798 | |
| 9799 | /* Perform post initialization setup */ |
| 9800 | lpfc_post_init_setup(phba); |
| 9801 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 9802 | /* check for firmware upgrade or downgrade */ |
| 9803 | if (phba->cfg_request_firmware_upgrade) |
| 9804 | ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9805 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 9806 | /* Check if there are static vports to be created. */ |
| 9807 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9808 | return 0; |
| 9809 | |
| 9810 | out_disable_intr: |
| 9811 | lpfc_sli4_disable_intr(phba); |
| 9812 | out_free_sysfs_attr: |
| 9813 | lpfc_free_sysfs_attr(vport); |
| 9814 | out_destroy_shost: |
| 9815 | lpfc_destroy_shost(phba); |
| 9816 | out_unset_driver_resource: |
| 9817 | lpfc_unset_driver_resource_phase2(phba); |
| 9818 | out_free_iocb_list: |
| 9819 | lpfc_free_iocb_list(phba); |
| 9820 | out_unset_driver_resource_s4: |
| 9821 | lpfc_sli4_driver_resource_unset(phba); |
| 9822 | out_unset_pci_mem_s4: |
| 9823 | lpfc_sli4_pci_mem_unset(phba); |
| 9824 | out_disable_pci_dev: |
| 9825 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9826 | if (shost) |
| 9827 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9828 | out_free_phba: |
| 9829 | lpfc_hba_free(phba); |
| 9830 | return error; |
| 9831 | } |
| 9832 | |
| 9833 | /** |
| 9834 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 9835 | * @pdev: pointer to PCI device |
| 9836 | * |
| 9837 | * This routine is called from the kernel's PCI subsystem to device with |
| 9838 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9839 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9840 | * device to be removed from the PCI subsystem properly. |
| 9841 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9842 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9843 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 9844 | { |
| 9845 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9846 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 9847 | struct lpfc_vport **vports; |
| 9848 | struct lpfc_hba *phba = vport->phba; |
| 9849 | int i; |
| 9850 | |
| 9851 | /* Mark the device unloading flag */ |
| 9852 | spin_lock_irq(&phba->hbalock); |
| 9853 | vport->load_flag |= FC_UNLOADING; |
| 9854 | spin_unlock_irq(&phba->hbalock); |
| 9855 | |
| 9856 | /* Free the HBA sysfs attributes */ |
| 9857 | lpfc_free_sysfs_attr(vport); |
| 9858 | |
| 9859 | /* Release all the vports against this physical port */ |
| 9860 | vports = lpfc_create_vport_work_array(phba); |
| 9861 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9862 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 9863 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 9864 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9865 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 9866 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9867 | lpfc_destroy_vport_work_array(phba, vports); |
| 9868 | |
| 9869 | /* Remove FC host and then SCSI host with the physical port */ |
| 9870 | fc_remove_host(shost); |
| 9871 | scsi_remove_host(shost); |
| 9872 | |
| 9873 | /* Perform cleanup on the physical port */ |
| 9874 | lpfc_cleanup(vport); |
| 9875 | |
| 9876 | /* |
| 9877 | * Bring down the SLI Layer. This step disables all interrupts, |
| 9878 | * clears the rings, discards all mailbox commands, and resets |
| 9879 | * the HBA FCoE function. |
| 9880 | */ |
| 9881 | lpfc_debugfs_terminate(vport); |
| 9882 | lpfc_sli4_hba_unset(phba); |
| 9883 | |
| 9884 | spin_lock_irq(&phba->hbalock); |
| 9885 | list_del_init(&vport->listentry); |
| 9886 | spin_unlock_irq(&phba->hbalock); |
| 9887 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9888 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9889 | * buffers are released to their corresponding pools here. |
| 9890 | */ |
| 9891 | lpfc_scsi_free(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9892 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9893 | lpfc_sli4_driver_resource_unset(phba); |
| 9894 | |
| 9895 | /* Unmap adapter Control and Doorbell registers */ |
| 9896 | lpfc_sli4_pci_mem_unset(phba); |
| 9897 | |
| 9898 | /* Release PCI resources and disable device's PCI function */ |
| 9899 | scsi_host_put(shost); |
| 9900 | lpfc_disable_pci_dev(phba); |
| 9901 | |
| 9902 | /* Finally, free the driver's device data structure */ |
| 9903 | lpfc_hba_free(phba); |
| 9904 | |
| 9905 | return; |
| 9906 | } |
| 9907 | |
| 9908 | /** |
| 9909 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 9910 | * @pdev: pointer to PCI device |
| 9911 | * @msg: power management message |
| 9912 | * |
| 9913 | * This routine is called from the kernel's PCI subsystem to support system |
| 9914 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 9915 | * this method, it quiesces the device by stopping the driver's worker |
| 9916 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 9917 | * the device offline. Note that as the driver implements the minimum PM |
| 9918 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 9919 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 9920 | * method call will be treated as SUSPEND and the driver will fully |
| 9921 | * reinitialize its device during resume() method call, the driver will set |
| 9922 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 9923 | * according to the @msg provided by the PM. |
| 9924 | * |
| 9925 | * Return code |
| 9926 | * 0 - driver suspended the device |
| 9927 | * Error otherwise |
| 9928 | **/ |
| 9929 | static int |
| 9930 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 9931 | { |
| 9932 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9933 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9934 | |
| 9935 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9936 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9937 | |
| 9938 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 9939 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9940 | lpfc_offline(phba); |
| 9941 | kthread_stop(phba->worker_thread); |
| 9942 | |
| 9943 | /* Disable interrupt from device */ |
| 9944 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9945 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9946 | |
| 9947 | /* Save device state to PCI config space */ |
| 9948 | pci_save_state(pdev); |
| 9949 | pci_set_power_state(pdev, PCI_D3hot); |
| 9950 | |
| 9951 | return 0; |
| 9952 | } |
| 9953 | |
| 9954 | /** |
| 9955 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 9956 | * @pdev: pointer to PCI device |
| 9957 | * |
| 9958 | * This routine is called from the kernel's PCI subsystem to support system |
| 9959 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 9960 | * this method, it restores the device's PCI config space state and fully |
| 9961 | * reinitializes the device and brings it online. Note that as the driver |
| 9962 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 9963 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9964 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 9965 | * will fully reinitialize its device during resume() method call, the device |
| 9966 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 9967 | * state. |
| 9968 | * |
| 9969 | * Return code |
| 9970 | * 0 - driver suspended the device |
| 9971 | * Error otherwise |
| 9972 | **/ |
| 9973 | static int |
| 9974 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 9975 | { |
| 9976 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9977 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9978 | uint32_t intr_mode; |
| 9979 | int error; |
| 9980 | |
| 9981 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9982 | "0292 PCI device Power Management resume.\n"); |
| 9983 | |
| 9984 | /* Restore device state from PCI config space */ |
| 9985 | pci_set_power_state(pdev, PCI_D0); |
| 9986 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9987 | |
| 9988 | /* |
| 9989 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9990 | * device saved_state flag, need to save the restored state again. |
| 9991 | */ |
| 9992 | pci_save_state(pdev); |
| 9993 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9994 | if (pdev->is_busmaster) |
| 9995 | pci_set_master(pdev); |
| 9996 | |
| 9997 | /* Startup the kernel thread for this host adapter. */ |
| 9998 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9999 | "lpfc_worker_%d", phba->brd_no); |
| 10000 | if (IS_ERR(phba->worker_thread)) { |
| 10001 | error = PTR_ERR(phba->worker_thread); |
| 10002 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10003 | "0293 PM resume failed to start worker " |
| 10004 | "thread: error=x%x.\n", error); |
| 10005 | return error; |
| 10006 | } |
| 10007 | |
| 10008 | /* Configure and enable interrupt */ |
| 10009 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10010 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10012 | "0294 PM resume Failed to enable interrupt\n"); |
| 10013 | return -EIO; |
| 10014 | } else |
| 10015 | phba->intr_mode = intr_mode; |
| 10016 | |
| 10017 | /* Restart HBA and bring it online */ |
| 10018 | lpfc_sli_brdrestart(phba); |
| 10019 | lpfc_online(phba); |
| 10020 | |
| 10021 | /* Log the current active interrupt mode */ |
| 10022 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10023 | |
| 10024 | return 0; |
| 10025 | } |
| 10026 | |
| 10027 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10028 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 10029 | * @phba: pointer to lpfc hba data structure. |
| 10030 | * |
| 10031 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 10032 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 10033 | **/ |
| 10034 | static void |
| 10035 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10036 | { |
| 10037 | struct lpfc_sli *psli = &phba->sli; |
| 10038 | struct lpfc_sli_ring *pring; |
| 10039 | |
| 10040 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10041 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 10042 | /* |
| 10043 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10044 | * and let the SCSI mid-layer to retry them to recover. |
| 10045 | */ |
| 10046 | pring = &psli->ring[psli->fcp_ring]; |
| 10047 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 10048 | } |
| 10049 | |
| 10050 | /** |
| 10051 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 10052 | * @phba: pointer to lpfc hba data structure. |
| 10053 | * |
| 10054 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 10055 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10056 | * pending I/Os. |
| 10057 | **/ |
| 10058 | static void |
| 10059 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10060 | { |
| 10061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10062 | "2826 PCI channel disable preparing for reset\n"); |
| 10063 | |
| 10064 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10065 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10066 | |
| 10067 | /* Block all SCSI devices' I/Os on the host */ |
| 10068 | lpfc_scsi_dev_block(phba); |
| 10069 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame^] | 10070 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10071 | lpfc_sli_flush_fcp_rings(phba); |
| 10072 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10073 | /* stop all timers */ |
| 10074 | lpfc_stop_hba_timers(phba); |
| 10075 | |
| 10076 | /* Disable interrupt and pci device */ |
| 10077 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10078 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10079 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10080 | } |
| 10081 | |
| 10082 | /** |
| 10083 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 10084 | * @phba: pointer to lpfc hba data structure. |
| 10085 | * |
| 10086 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 10087 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10088 | * pending I/Os. |
| 10089 | **/ |
| 10090 | static void |
| 10091 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 10092 | { |
| 10093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10094 | "2827 PCI channel permanent disable for failure\n"); |
| 10095 | |
| 10096 | /* Block all SCSI devices' I/Os on the host */ |
| 10097 | lpfc_scsi_dev_block(phba); |
| 10098 | |
| 10099 | /* stop all timers */ |
| 10100 | lpfc_stop_hba_timers(phba); |
| 10101 | |
| 10102 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10103 | lpfc_sli_flush_fcp_rings(phba); |
| 10104 | } |
| 10105 | |
| 10106 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10107 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 10108 | * @pdev: pointer to PCI device. |
| 10109 | * @state: the current PCI connection state. |
| 10110 | * |
| 10111 | * This routine is called from the PCI subsystem for error handling to device |
| 10112 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 10113 | * after a PCI bus error affecting this device has been detected. When this |
| 10114 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 10115 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 10116 | * for the PCI subsystem to perform proper recovery as desired. |
| 10117 | * |
| 10118 | * Return codes |
| 10119 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10120 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10121 | **/ |
| 10122 | static pci_ers_result_t |
| 10123 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 10124 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10125 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10126 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10127 | |
| 10128 | switch (state) { |
| 10129 | case pci_channel_io_normal: |
| 10130 | /* Non-fatal error, prepare for recovery */ |
| 10131 | lpfc_sli4_prep_dev_for_recover(phba); |
| 10132 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 10133 | case pci_channel_io_frozen: |
| 10134 | /* Fatal error, prepare for slot reset */ |
| 10135 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10136 | return PCI_ERS_RESULT_NEED_RESET; |
| 10137 | case pci_channel_io_perm_failure: |
| 10138 | /* Permanent failure, prepare for device down */ |
| 10139 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 10140 | return PCI_ERS_RESULT_DISCONNECT; |
| 10141 | default: |
| 10142 | /* Unknown state, prepare and request slot reset */ |
| 10143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10144 | "2825 Unknown PCI error state: x%x\n", state); |
| 10145 | lpfc_sli4_prep_dev_for_reset(phba); |
| 10146 | return PCI_ERS_RESULT_NEED_RESET; |
| 10147 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10148 | } |
| 10149 | |
| 10150 | /** |
| 10151 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 10152 | * @pdev: pointer to PCI device. |
| 10153 | * |
| 10154 | * This routine is called from the PCI subsystem for error handling to device |
| 10155 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 10156 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 10157 | * PCI subsystem error recovery, after the driver returns |
| 10158 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 10159 | * recovery and then call this routine before calling the .resume method to |
| 10160 | * recover the device. This function will initialize the HBA device, enable |
| 10161 | * the interrupt, but it will just put the HBA to offline state without |
| 10162 | * passing any I/O traffic. |
| 10163 | * |
| 10164 | * Return codes |
| 10165 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10166 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10167 | */ |
| 10168 | static pci_ers_result_t |
| 10169 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 10170 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10171 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10172 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10173 | struct lpfc_sli *psli = &phba->sli; |
| 10174 | uint32_t intr_mode; |
| 10175 | |
| 10176 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 10177 | if (pci_enable_device_mem(pdev)) { |
| 10178 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 10179 | "PCI device after reset.\n"); |
| 10180 | return PCI_ERS_RESULT_DISCONNECT; |
| 10181 | } |
| 10182 | |
| 10183 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 10184 | |
| 10185 | /* |
| 10186 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10187 | * device saved_state flag, need to save the restored state again. |
| 10188 | */ |
| 10189 | pci_save_state(pdev); |
| 10190 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10191 | if (pdev->is_busmaster) |
| 10192 | pci_set_master(pdev); |
| 10193 | |
| 10194 | spin_lock_irq(&phba->hbalock); |
| 10195 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 10196 | spin_unlock_irq(&phba->hbalock); |
| 10197 | |
| 10198 | /* Configure and enable interrupt */ |
| 10199 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 10200 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10201 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10202 | "2824 Cannot re-enable interrupt after " |
| 10203 | "slot reset.\n"); |
| 10204 | return PCI_ERS_RESULT_DISCONNECT; |
| 10205 | } else |
| 10206 | phba->intr_mode = intr_mode; |
| 10207 | |
| 10208 | /* Log the current active interrupt mode */ |
| 10209 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10210 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10211 | return PCI_ERS_RESULT_RECOVERED; |
| 10212 | } |
| 10213 | |
| 10214 | /** |
| 10215 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 10216 | * @pdev: pointer to PCI device |
| 10217 | * |
| 10218 | * This routine is called from the PCI subsystem for error handling to device |
| 10219 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 10220 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 10221 | * error recovery. After this call, traffic can start to flow from this device |
| 10222 | * again. |
| 10223 | **/ |
| 10224 | static void |
| 10225 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 10226 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10227 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10228 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10229 | |
| 10230 | /* |
| 10231 | * In case of slot reset, as function reset is performed through |
| 10232 | * mailbox command which needs DMA to be enabled, this operation |
| 10233 | * has to be moved to the io resume phase. Taking device offline |
| 10234 | * will perform the necessary cleanup. |
| 10235 | */ |
| 10236 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 10237 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10238 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10239 | lpfc_offline(phba); |
| 10240 | lpfc_sli_brdrestart(phba); |
| 10241 | /* Bring the device back online */ |
| 10242 | lpfc_online(phba); |
| 10243 | } |
| 10244 | |
| 10245 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 10246 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 10247 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10248 | } |
| 10249 | |
| 10250 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10251 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 10252 | * @pdev: pointer to PCI device |
| 10253 | * @pid: pointer to PCI device identifier |
| 10254 | * |
| 10255 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10256 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 10257 | * at PCI device-specific information of the device and driver to see if the |
| 10258 | * driver state that it can support this kind of device. If the match is |
| 10259 | * successful, the driver core invokes this routine. This routine dispatches |
| 10260 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 10261 | * do all the initialization that it needs to do to handle the HBA device |
| 10262 | * properly. |
| 10263 | * |
| 10264 | * Return code |
| 10265 | * 0 - driver can claim the device |
| 10266 | * negative value - driver can not claim the device |
| 10267 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10268 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10269 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10270 | { |
| 10271 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10272 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10273 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10274 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10275 | return -ENODEV; |
| 10276 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10277 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10278 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10279 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10280 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10281 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 10282 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10283 | return rc; |
| 10284 | } |
| 10285 | |
| 10286 | /** |
| 10287 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 10288 | * @pdev: pointer to PCI device |
| 10289 | * |
| 10290 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 10291 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 10292 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 10293 | * remove routine, which will perform all the necessary cleanup for the |
| 10294 | * device to be removed from the PCI subsystem properly. |
| 10295 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10296 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10297 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 10298 | { |
| 10299 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10300 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10301 | |
| 10302 | switch (phba->pci_dev_grp) { |
| 10303 | case LPFC_PCI_DEV_LP: |
| 10304 | lpfc_pci_remove_one_s3(pdev); |
| 10305 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10306 | case LPFC_PCI_DEV_OC: |
| 10307 | lpfc_pci_remove_one_s4(pdev); |
| 10308 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10309 | default: |
| 10310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10311 | "1424 Invalid PCI device group: 0x%x\n", |
| 10312 | phba->pci_dev_grp); |
| 10313 | break; |
| 10314 | } |
| 10315 | return; |
| 10316 | } |
| 10317 | |
| 10318 | /** |
| 10319 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 10320 | * @pdev: pointer to PCI device |
| 10321 | * @msg: power management message |
| 10322 | * |
| 10323 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10324 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10325 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 10326 | * suspend the device. |
| 10327 | * |
| 10328 | * Return code |
| 10329 | * 0 - driver suspended the device |
| 10330 | * Error otherwise |
| 10331 | **/ |
| 10332 | static int |
| 10333 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 10334 | { |
| 10335 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10336 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10337 | int rc = -ENODEV; |
| 10338 | |
| 10339 | switch (phba->pci_dev_grp) { |
| 10340 | case LPFC_PCI_DEV_LP: |
| 10341 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 10342 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10343 | case LPFC_PCI_DEV_OC: |
| 10344 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 10345 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10346 | default: |
| 10347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10348 | "1425 Invalid PCI device group: 0x%x\n", |
| 10349 | phba->pci_dev_grp); |
| 10350 | break; |
| 10351 | } |
| 10352 | return rc; |
| 10353 | } |
| 10354 | |
| 10355 | /** |
| 10356 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 10357 | * @pdev: pointer to PCI device |
| 10358 | * |
| 10359 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 10360 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 10361 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 10362 | * resume the device. |
| 10363 | * |
| 10364 | * Return code |
| 10365 | * 0 - driver suspended the device |
| 10366 | * Error otherwise |
| 10367 | **/ |
| 10368 | static int |
| 10369 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 10370 | { |
| 10371 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10372 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10373 | int rc = -ENODEV; |
| 10374 | |
| 10375 | switch (phba->pci_dev_grp) { |
| 10376 | case LPFC_PCI_DEV_LP: |
| 10377 | rc = lpfc_pci_resume_one_s3(pdev); |
| 10378 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10379 | case LPFC_PCI_DEV_OC: |
| 10380 | rc = lpfc_pci_resume_one_s4(pdev); |
| 10381 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10382 | default: |
| 10383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10384 | "1426 Invalid PCI device group: 0x%x\n", |
| 10385 | phba->pci_dev_grp); |
| 10386 | break; |
| 10387 | } |
| 10388 | return rc; |
| 10389 | } |
| 10390 | |
| 10391 | /** |
| 10392 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 10393 | * @pdev: pointer to PCI device. |
| 10394 | * @state: the current PCI connection state. |
| 10395 | * |
| 10396 | * This routine is registered to the PCI subsystem for error handling. This |
| 10397 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 10398 | * this device has been detected. When this routine is invoked, it dispatches |
| 10399 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 10400 | * routine, which will perform the proper error detected operation. |
| 10401 | * |
| 10402 | * Return codes |
| 10403 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 10404 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10405 | **/ |
| 10406 | static pci_ers_result_t |
| 10407 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 10408 | { |
| 10409 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10410 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10411 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10412 | |
| 10413 | switch (phba->pci_dev_grp) { |
| 10414 | case LPFC_PCI_DEV_LP: |
| 10415 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10416 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10417 | case LPFC_PCI_DEV_OC: |
| 10418 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10419 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10420 | default: |
| 10421 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10422 | "1427 Invalid PCI device group: 0x%x\n", |
| 10423 | phba->pci_dev_grp); |
| 10424 | break; |
| 10425 | } |
| 10426 | return rc; |
| 10427 | } |
| 10428 | |
| 10429 | /** |
| 10430 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10431 | * @pdev: pointer to PCI device. |
| 10432 | * |
| 10433 | * This routine is registered to the PCI subsystem for error handling. This |
| 10434 | * function is called after PCI bus has been reset to restart the PCI card |
| 10435 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10436 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10437 | * routine, which will perform the proper device reset. |
| 10438 | * |
| 10439 | * Return codes |
| 10440 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10441 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10442 | **/ |
| 10443 | static pci_ers_result_t |
| 10444 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10445 | { |
| 10446 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10447 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10448 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10449 | |
| 10450 | switch (phba->pci_dev_grp) { |
| 10451 | case LPFC_PCI_DEV_LP: |
| 10452 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10453 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10454 | case LPFC_PCI_DEV_OC: |
| 10455 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10456 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10457 | default: |
| 10458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10459 | "1428 Invalid PCI device group: 0x%x\n", |
| 10460 | phba->pci_dev_grp); |
| 10461 | break; |
| 10462 | } |
| 10463 | return rc; |
| 10464 | } |
| 10465 | |
| 10466 | /** |
| 10467 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10468 | * @pdev: pointer to PCI device |
| 10469 | * |
| 10470 | * This routine is registered to the PCI subsystem for error handling. It |
| 10471 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10472 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10473 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10474 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10475 | **/ |
| 10476 | static void |
| 10477 | lpfc_io_resume(struct pci_dev *pdev) |
| 10478 | { |
| 10479 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10480 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10481 | |
| 10482 | switch (phba->pci_dev_grp) { |
| 10483 | case LPFC_PCI_DEV_LP: |
| 10484 | lpfc_io_resume_s3(pdev); |
| 10485 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10486 | case LPFC_PCI_DEV_OC: |
| 10487 | lpfc_io_resume_s4(pdev); |
| 10488 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10489 | default: |
| 10490 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10491 | "1429 Invalid PCI device group: 0x%x\n", |
| 10492 | phba->pci_dev_grp); |
| 10493 | break; |
| 10494 | } |
| 10495 | return; |
| 10496 | } |
| 10497 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10498 | /** |
| 10499 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace |
| 10500 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10501 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10502 | * |
| 10503 | * This routine puts a reference count on the lpfc module whenever the |
| 10504 | * character device is opened |
| 10505 | **/ |
| 10506 | static int |
| 10507 | lpfc_mgmt_open(struct inode *inode, struct file *filep) |
| 10508 | { |
| 10509 | try_module_get(THIS_MODULE); |
| 10510 | return 0; |
| 10511 | } |
| 10512 | |
| 10513 | /** |
| 10514 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace |
| 10515 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10516 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10517 | * |
| 10518 | * This routine removes a reference count from the lpfc module when the |
| 10519 | * character device is closed |
| 10520 | **/ |
| 10521 | static int |
| 10522 | lpfc_mgmt_release(struct inode *inode, struct file *filep) |
| 10523 | { |
| 10524 | module_put(THIS_MODULE); |
| 10525 | return 0; |
| 10526 | } |
| 10527 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10528 | static struct pci_device_id lpfc_id_table[] = { |
| 10529 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 10530 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 10531 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 10532 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10533 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 10534 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10535 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 10536 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10537 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 10538 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10539 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 10540 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10541 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 10542 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10543 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 10544 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10545 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 10546 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10547 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 10548 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10549 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 10550 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10551 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 10552 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10553 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 10554 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10555 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 10556 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10557 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 10558 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10559 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 10560 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10561 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 10562 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10563 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 10564 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10565 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 10566 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10567 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 10568 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10569 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 10570 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10571 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 10572 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10573 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 10574 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10575 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 10576 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10577 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 10578 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10579 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 10580 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10581 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 10582 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10583 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 10584 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 10585 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 10586 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10587 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 10588 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10589 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 10590 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10591 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 10592 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10593 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 10594 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10595 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 10596 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10597 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 10598 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10599 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 10600 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10601 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 10602 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10603 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 10604 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10605 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 10606 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10607 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10608 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 10609 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 10610 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 10611 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 10612 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10613 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 10614 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 10615 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 10616 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10617 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 10618 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 10619 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
| 10620 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10621 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, |
| 10622 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10623 | { 0 } |
| 10624 | }; |
| 10625 | |
| 10626 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 10627 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 10628 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10629 | .error_detected = lpfc_io_error_detected, |
| 10630 | .slot_reset = lpfc_io_slot_reset, |
| 10631 | .resume = lpfc_io_resume, |
| 10632 | }; |
| 10633 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10634 | static struct pci_driver lpfc_driver = { |
| 10635 | .name = LPFC_DRIVER_NAME, |
| 10636 | .id_table = lpfc_id_table, |
| 10637 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10638 | .remove = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10639 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10640 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10641 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10642 | }; |
| 10643 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10644 | static const struct file_operations lpfc_mgmt_fop = { |
| 10645 | .open = lpfc_mgmt_open, |
| 10646 | .release = lpfc_mgmt_release, |
| 10647 | }; |
| 10648 | |
| 10649 | static struct miscdevice lpfc_mgmt_dev = { |
| 10650 | .minor = MISC_DYNAMIC_MINOR, |
| 10651 | .name = "lpfcmgmt", |
| 10652 | .fops = &lpfc_mgmt_fop, |
| 10653 | }; |
| 10654 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10655 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10656 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10657 | * |
| 10658 | * This routine is to be invoked when the lpfc module is loaded into the |
| 10659 | * kernel. The special kernel macro module_init() is used to indicate the |
| 10660 | * role of this routine to the kernel as lpfc module entry point. |
| 10661 | * |
| 10662 | * Return codes |
| 10663 | * 0 - successful |
| 10664 | * -ENOMEM - FC attach transport failed |
| 10665 | * all others - failed |
| 10666 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10667 | static int __init |
| 10668 | lpfc_init(void) |
| 10669 | { |
| 10670 | int error = 0; |
| 10671 | |
| 10672 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10673 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10674 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10675 | error = misc_register(&lpfc_mgmt_dev); |
| 10676 | if (error) |
| 10677 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 10678 | "misc_register returned with status %d", error); |
| 10679 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10680 | if (lpfc_enable_npiv) { |
| 10681 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 10682 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 10683 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10684 | lpfc_transport_template = |
| 10685 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10686 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10687 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10688 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10689 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10690 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 10691 | if (lpfc_vport_transport_template == NULL) { |
| 10692 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10693 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10694 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10695 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10696 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10697 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10698 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10699 | if (lpfc_enable_npiv) |
| 10700 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10701 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10702 | |
| 10703 | return error; |
| 10704 | } |
| 10705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10707 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10708 | * |
| 10709 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 10710 | * The special kernel macro module_exit() is used to indicate the role of |
| 10711 | * this routine to the kernel as lpfc module exit point. |
| 10712 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10713 | static void __exit |
| 10714 | lpfc_exit(void) |
| 10715 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10716 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10717 | pci_unregister_driver(&lpfc_driver); |
| 10718 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10719 | if (lpfc_enable_npiv) |
| 10720 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10721 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10722 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 10723 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10724 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 10725 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 10726 | } |
| 10727 | |
| 10728 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10729 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 10730 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10731 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 10732 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 10733 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10734 | } |
| 10735 | |
| 10736 | module_init(lpfc_init); |
| 10737 | module_exit(lpfc_exit); |
| 10738 | MODULE_LICENSE("GPL"); |
| 10739 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 10740 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 10741 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |