| 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 | 792581d | 2011-03-11 16:06:44 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2011 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 *); |
| 67 | static void lpfc_free_sgl_list(struct lpfc_hba *); |
| 68 | static int lpfc_init_sgl_list(struct lpfc_hba *); |
| 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 *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 76 | |
| 77 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 78 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 79 | static DEFINE_IDR(lpfc_hba_index); |
| 80 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 81 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 82 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 83 | * @phba: pointer to lpfc hba data structure. |
| 84 | * |
| 85 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 86 | * mailbox command. It retrieves the revision information from the HBA and |
| 87 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 88 | * configuration of the HBA. |
| 89 | * |
| 90 | * Return codes: |
| 91 | * 0 - success. |
| 92 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 93 | * Any other value - indicates an error. |
| 94 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 95 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 96 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 97 | { |
| 98 | lpfc_vpd_t *vp = &phba->vpd; |
| 99 | int i = 0, rc; |
| 100 | LPFC_MBOXQ_t *pmb; |
| 101 | MAILBOX_t *mb; |
| 102 | char *lpfc_vpd_data = NULL; |
| 103 | uint16_t offset = 0; |
| 104 | static char licensed[56] = |
| 105 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 106 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | |
| 108 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 109 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 110 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | return -ENOMEM; |
| 112 | } |
| 113 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 114 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 115 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | |
| 117 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 118 | if (init_key) { |
| 119 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 121 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 122 | *ptext = cpu_to_be32(*ptext); |
| 123 | init_key = 0; |
| 124 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 125 | |
| 126 | lpfc_read_nv(phba, pmb); |
| 127 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 128 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 129 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 130 | sizeof (licensed)); |
| 131 | |
| 132 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 133 | |
| 134 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 135 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 136 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | "error, mbxCmd x%x READ_NVPARM, " |
| 138 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 139 | mb->mbxCommand, mb->mbxStatus); |
| 140 | mempool_free(pmb, phba->mbox_mem_pool); |
| 141 | return -ERESTART; |
| 142 | } |
| 143 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 144 | sizeof(phba->wwnn)); |
| 145 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 146 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | } |
| 148 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 149 | phba->sli3_options = 0x0; |
| 150 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | /* Setup and issue mailbox READ REV command */ |
| 152 | lpfc_read_rev(phba, pmb); |
| 153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 154 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 156 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | mb->mbxCommand, mb->mbxStatus); |
| 159 | mempool_free( pmb, phba->mbox_mem_pool); |
| 160 | return -ERESTART; |
| 161 | } |
| 162 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 163 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 164 | /* |
| 165 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 166 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 167 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 168 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 170 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 171 | "0440 Adapter failed to init, READ_REV has " |
| 172 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 173 | mempool_free(pmb, phba->mbox_mem_pool); |
| 174 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 175 | } |
| 176 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 177 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 178 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 179 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 180 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 183 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 184 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 185 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 186 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 187 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 188 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 190 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 191 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 192 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 193 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 194 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 195 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 196 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 197 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 198 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 199 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 200 | /* If the sli feature level is less then 9, we must |
| 201 | * tear down all RPIs and VPIs on link down if NPIV |
| 202 | * is enabled. |
| 203 | */ |
| 204 | if (vp->rev.feaLevelHigh < 9) |
| 205 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 208 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 209 | sizeof (phba->RandomData)); |
| 210 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 211 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 213 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 214 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 216 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 217 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 218 | |
| 219 | if (rc != MBX_SUCCESS) { |
| 220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 221 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 222 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 224 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 225 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 226 | /* dump mem may return a zero when finished or we got a |
| 227 | * mailbox error, either way we are done. |
| 228 | */ |
| 229 | if (mb->un.varDmp.word_cnt == 0) |
| 230 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 231 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 232 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 233 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 234 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 235 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 237 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 238 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | |
| 240 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | out_free_mbox: |
| 242 | mempool_free(pmb, phba->mbox_mem_pool); |
| 243 | return 0; |
| 244 | } |
| 245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 247 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 248 | * @phba: pointer to lpfc hba data structure. |
| 249 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 250 | * |
| 251 | * This is the completion handler for driver's configuring asynchronous event |
| 252 | * mailbox command to the device. If the mailbox command returns successfully, |
| 253 | * it will set internal async event support flag to 1; otherwise, it will |
| 254 | * set internal async event support flag to 0. |
| 255 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 256 | static void |
| 257 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 258 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 259 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 260 | phba->temp_sensor_support = 1; |
| 261 | else |
| 262 | phba->temp_sensor_support = 0; |
| 263 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 264 | return; |
| 265 | } |
| 266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 268 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 269 | * @phba: pointer to lpfc hba data structure. |
| 270 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 271 | * |
| 272 | * This is the completion handler for dump mailbox command for getting |
| 273 | * wake up parameters. When this command complete, the response contain |
| 274 | * Option rom version of the HBA. This function translate the version number |
| 275 | * into a human readable string and store it in OptionROMVersion. |
| 276 | **/ |
| 277 | static void |
| 278 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 279 | { |
| 280 | struct prog_id *prg; |
| 281 | uint32_t prog_id_word; |
| 282 | char dist = ' '; |
| 283 | /* character array used for decoding dist type. */ |
| 284 | char dist_char[] = "nabx"; |
| 285 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 286 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 287 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 288 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 289 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 290 | |
| 291 | prg = (struct prog_id *) &prog_id_word; |
| 292 | |
| 293 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 294 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 295 | |
| 296 | /* Decode the Option rom version word to a readable string */ |
| 297 | if (prg->dist < 4) |
| 298 | dist = dist_char[prg->dist]; |
| 299 | |
| 300 | if ((prg->dist == 3) && (prg->num == 0)) |
| 301 | sprintf(phba->OptionROMVersion, "%d.%d%d", |
| 302 | prg->ver, prg->rev, prg->lev); |
| 303 | else |
| 304 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", |
| 305 | prg->ver, prg->rev, prg->lev, |
| 306 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 307 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 308 | return; |
| 309 | } |
| 310 | |
| 311 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 312 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 313 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 314 | * @vport: pointer to lpfc vport data structure. |
| 315 | * |
| 316 | * |
| 317 | * Return codes |
| 318 | * None. |
| 319 | **/ |
| 320 | void |
| 321 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 322 | { |
| 323 | /* If the soft name exists then update it using the service params */ |
| 324 | if (vport->phba->cfg_soft_wwnn) |
| 325 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 326 | vport->fc_sparam.nodeName.u.wwn); |
| 327 | if (vport->phba->cfg_soft_wwpn) |
| 328 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 329 | vport->fc_sparam.portName.u.wwn); |
| 330 | |
| 331 | /* |
| 332 | * If the name is empty or there exists a soft name |
| 333 | * then copy the service params name, otherwise use the fc name |
| 334 | */ |
| 335 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 336 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 337 | sizeof(struct lpfc_name)); |
| 338 | else |
| 339 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 340 | sizeof(struct lpfc_name)); |
| 341 | |
| 342 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) |
| 343 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 344 | sizeof(struct lpfc_name)); |
| 345 | else |
| 346 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 347 | sizeof(struct lpfc_name)); |
| 348 | } |
| 349 | |
| 350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 351 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 352 | * @phba: pointer to lpfc hba data structure. |
| 353 | * |
| 354 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 355 | * command call. It performs all internal resource and state setups on the |
| 356 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 357 | * ELS ring timers, etc. |
| 358 | * |
| 359 | * Return codes |
| 360 | * 0 - success. |
| 361 | * Any other value - error. |
| 362 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 363 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 364 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 365 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 366 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 368 | LPFC_MBOXQ_t *pmb; |
| 369 | MAILBOX_t *mb; |
| 370 | struct lpfc_dmabuf *mp; |
| 371 | struct lpfc_sli *psli = &phba->sli; |
| 372 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 373 | int i, j; |
| 374 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 375 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 376 | spin_lock_irq(&phba->hbalock); |
| 377 | /* |
| 378 | * If the Config port completed correctly the HBA is not |
| 379 | * over heated any more. |
| 380 | */ |
| 381 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 382 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 383 | spin_unlock_irq(&phba->hbalock); |
| 384 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 386 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 387 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 388 | return -ENOMEM; |
| 389 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 390 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 391 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 392 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 393 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 394 | if (rc) { |
| 395 | mempool_free(pmb, phba->mbox_mem_pool); |
| 396 | return -ENOMEM; |
| 397 | } |
| 398 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 399 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 400 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 402 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 403 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 404 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 405 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 406 | mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 407 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 409 | kfree(mp); |
| 410 | return -EIO; |
| 411 | } |
| 412 | |
| 413 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 414 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 415 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 417 | kfree(mp); |
| 418 | pmb->context1 = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 419 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 420 | |
| 421 | /* Update the fc_host data structures with new wwn. */ |
| 422 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 423 | 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] | 424 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 425 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 427 | /* This should be consolidated into parse_vpd ? - mr */ |
| 428 | if (phba->SerialNumber[0] == 0) { |
| 429 | uint8_t *outptr; |
| 430 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 431 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | for (i = 0; i < 12; i++) { |
| 433 | status = *outptr++; |
| 434 | j = ((status & 0xf0) >> 4); |
| 435 | if (j <= 9) |
| 436 | phba->SerialNumber[i] = |
| 437 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 438 | else |
| 439 | phba->SerialNumber[i] = |
| 440 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 441 | i++; |
| 442 | j = (status & 0xf); |
| 443 | if (j <= 9) |
| 444 | phba->SerialNumber[i] = |
| 445 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 446 | else |
| 447 | phba->SerialNumber[i] = |
| 448 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 449 | } |
| 450 | } |
| 451 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 452 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 453 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 454 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 456 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 457 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 458 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | mempool_free( pmb, phba->mbox_mem_pool); |
| 461 | return -EIO; |
| 462 | } |
| 463 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 464 | /* Check if the port is disabled */ |
| 465 | lpfc_sli_read_link_ste(phba); |
| 466 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 468 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 469 | phba->cfg_hba_queue_depth = |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 470 | (mb->un.varRdConfig.max_xri + 1) - |
| 471 | lpfc_sli4_get_els_iocb_cnt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | |
| 473 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 474 | |
| 475 | /* Get the default values for Model Name and Description */ |
| 476 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 477 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 480 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 481 | if (psli->ring[psli->extra_ring].cmdringaddr) |
| 482 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 483 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
| 484 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 485 | if (psli->ring[psli->next_ring].cmdringaddr) |
| 486 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 487 | |
| 488 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 489 | if (phba->sli_rev != 3) |
| 490 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 492 | /* |
| 493 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 494 | */ |
| 495 | if (phba->intr_type == MSIX) { |
| 496 | rc = lpfc_config_msi(phba, pmb); |
| 497 | if (rc) { |
| 498 | mempool_free(pmb, phba->mbox_mem_pool); |
| 499 | return -EIO; |
| 500 | } |
| 501 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 502 | if (rc != MBX_SUCCESS) { |
| 503 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 504 | "0352 Config MSI mailbox command " |
| 505 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 506 | pmb->u.mb.mbxCommand, |
| 507 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 508 | mempool_free(pmb, phba->mbox_mem_pool); |
| 509 | return -EIO; |
| 510 | } |
| 511 | } |
| 512 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 513 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 514 | /* Initialize ERATT handling flag */ |
| 515 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 516 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 518 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 519 | spin_unlock_irq(&phba->hbalock); |
| 520 | return -EIO; |
| 521 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 522 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 523 | if (psli->num_rings > 0) |
| 524 | status |= HC_R0INT_ENA; |
| 525 | if (psli->num_rings > 1) |
| 526 | status |= HC_R1INT_ENA; |
| 527 | if (psli->num_rings > 2) |
| 528 | status |= HC_R2INT_ENA; |
| 529 | if (psli->num_rings > 3) |
| 530 | status |= HC_R3INT_ENA; |
| 531 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 532 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 533 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 534 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | writel(status, phba->HCregaddr); |
| 537 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 538 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 539 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 540 | /* Set up ring-0 (ELS) timer */ |
| 541 | timeout = phba->fc_ratov * 2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 542 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 543 | /* Set up heart beat (HB) timer */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 544 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 545 | phba->hb_outstanding = 0; |
| 546 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 547 | /* Set up error attention (ERATT) polling timer */ |
| 548 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 549 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 550 | if (phba->hba_flag & LINK_DISABLED) { |
| 551 | lpfc_printf_log(phba, |
| 552 | KERN_ERR, LOG_INIT, |
| 553 | "2598 Adapter Link is disabled.\n"); |
| 554 | lpfc_down_link(phba, pmb); |
| 555 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 556 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 557 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 558 | lpfc_printf_log(phba, |
| 559 | KERN_ERR, LOG_INIT, |
| 560 | "2599 Adapter failed to issue DOWN_LINK" |
| 561 | " mbox command rc 0x%x\n", rc); |
| 562 | |
| 563 | mempool_free(pmb, phba->mbox_mem_pool); |
| 564 | return -EIO; |
| 565 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 566 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 567 | mempool_free(pmb, phba->mbox_mem_pool); |
| 568 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 569 | if (rc) |
| 570 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 | } |
| 572 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 573 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 574 | if (!pmb) { |
| 575 | phba->link_state = LPFC_HBA_ERROR; |
| 576 | return -ENOMEM; |
| 577 | } |
| 578 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 579 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 580 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 581 | pmb->vport = phba->pport; |
| 582 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 584 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 585 | lpfc_printf_log(phba, |
| 586 | KERN_ERR, |
| 587 | LOG_INIT, |
| 588 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 589 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 590 | rc); |
| 591 | mempool_free(pmb, phba->mbox_mem_pool); |
| 592 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 593 | |
| 594 | /* Get Option rom version */ |
| 595 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 596 | if (!pmb) { |
| 597 | phba->link_state = LPFC_HBA_ERROR; |
| 598 | return -ENOMEM; |
| 599 | } |
| 600 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 601 | lpfc_dump_wakeup_param(phba, pmb); |
| 602 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 603 | pmb->vport = phba->pport; |
| 604 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 605 | |
| 606 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 608 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 609 | mempool_free(pmb, phba->mbox_mem_pool); |
| 610 | } |
| 611 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 612 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 613 | } |
| 614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 615 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 616 | * lpfc_hba_init_link - Initialize the FC link |
| 617 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 618 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 619 | * |
| 620 | * This routine will issue the INIT_LINK mailbox command call. |
| 621 | * It is available to other drivers through the lpfc_hba data |
| 622 | * structure for use as a delayed link up mechanism with the |
| 623 | * module parameter lpfc_suppress_link_up. |
| 624 | * |
| 625 | * Return code |
| 626 | * 0 - success |
| 627 | * Any other value - error |
| 628 | **/ |
| 629 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 630 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 631 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 632 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 637 | * @phba: pointer to lpfc hba data structure. |
| 638 | * @fc_topology: desired fc topology. |
| 639 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 640 | * |
| 641 | * This routine will issue the INIT_LINK mailbox command call. |
| 642 | * It is available to other drivers through the lpfc_hba data |
| 643 | * structure for use as a delayed link up mechanism with the |
| 644 | * module parameter lpfc_suppress_link_up. |
| 645 | * |
| 646 | * Return code |
| 647 | * 0 - success |
| 648 | * Any other value - error |
| 649 | **/ |
| 650 | int |
| 651 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 652 | uint32_t flag) |
| 653 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 654 | struct lpfc_vport *vport = phba->pport; |
| 655 | LPFC_MBOXQ_t *pmb; |
| 656 | MAILBOX_t *mb; |
| 657 | int rc; |
| 658 | |
| 659 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 660 | if (!pmb) { |
| 661 | phba->link_state = LPFC_HBA_ERROR; |
| 662 | return -ENOMEM; |
| 663 | } |
| 664 | mb = &pmb->u.mb; |
| 665 | pmb->vport = vport; |
| 666 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 667 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 668 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 669 | !(phba->lmt & LMT_1Gb)) || |
| 670 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 671 | !(phba->lmt & LMT_2Gb)) || |
| 672 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 673 | !(phba->lmt & LMT_4Gb)) || |
| 674 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 675 | !(phba->lmt & LMT_8Gb)) || |
| 676 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 677 | !(phba->lmt & LMT_10Gb)) || |
| 678 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
| 679 | !(phba->lmt & LMT_16Gb))) { |
| 680 | /* Reset link speed to auto */ |
| 681 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 682 | "1302 Invalid speed for this board:%d " |
| 683 | "Reset link speed to auto.\n", |
| 684 | phba->cfg_link_speed); |
| 685 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 686 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 687 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 688 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 689 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 690 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 691 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 692 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 693 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 694 | "0498 Adapter failed to init, mbxCmd x%x " |
| 695 | "INIT_LINK, mbxStatus x%x\n", |
| 696 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 697 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 698 | /* Clear all interrupt enable conditions */ |
| 699 | writel(0, phba->HCregaddr); |
| 700 | readl(phba->HCregaddr); /* flush */ |
| 701 | /* Clear all pending interrupts */ |
| 702 | writel(0xffffffff, phba->HAregaddr); |
| 703 | readl(phba->HAregaddr); /* flush */ |
| 704 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 705 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 706 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 707 | mempool_free(pmb, phba->mbox_mem_pool); |
| 708 | return -EIO; |
| 709 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 710 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 711 | if (flag == MBX_POLL) |
| 712 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 719 | * @phba: pointer to lpfc hba data structure. |
| 720 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 721 | * |
| 722 | * This routine will issue the DOWN_LINK mailbox command call. |
| 723 | * It is available to other drivers through the lpfc_hba data |
| 724 | * structure for use to stop the link. |
| 725 | * |
| 726 | * Return code |
| 727 | * 0 - success |
| 728 | * Any other value - error |
| 729 | **/ |
| 730 | int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 731 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 732 | { |
| 733 | LPFC_MBOXQ_t *pmb; |
| 734 | int rc; |
| 735 | |
| 736 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 737 | if (!pmb) { |
| 738 | phba->link_state = LPFC_HBA_ERROR; |
| 739 | return -ENOMEM; |
| 740 | } |
| 741 | |
| 742 | lpfc_printf_log(phba, |
| 743 | KERN_ERR, LOG_INIT, |
| 744 | "0491 Adapter Link is disabled.\n"); |
| 745 | lpfc_down_link(phba, pmb); |
| 746 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 747 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 748 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 749 | lpfc_printf_log(phba, |
| 750 | KERN_ERR, LOG_INIT, |
| 751 | "2522 Adapter failed to issue DOWN_LINK" |
| 752 | " mbox command rc 0x%x\n", rc); |
| 753 | |
| 754 | mempool_free(pmb, phba->mbox_mem_pool); |
| 755 | return -EIO; |
| 756 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 757 | if (flag == MBX_POLL) |
| 758 | mempool_free(pmb, phba->mbox_mem_pool); |
| 759 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 764 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 765 | * @phba: pointer to lpfc HBA data structure. |
| 766 | * |
| 767 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 768 | * bringing down the SLI Layer. |
| 769 | * |
| 770 | * Return codes |
| 771 | * 0 - success. |
| 772 | * Any other value - error. |
| 773 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 775 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 776 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 777 | struct lpfc_vport **vports; |
| 778 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 779 | |
| 780 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 781 | /* Disable interrupts */ |
| 782 | writel(0, phba->HCregaddr); |
| 783 | readl(phba->HCregaddr); /* flush */ |
| 784 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 786 | if (phba->pport->load_flag & FC_UNLOADING) |
| 787 | lpfc_cleanup_discovery_resources(phba->pport); |
| 788 | else { |
| 789 | vports = lpfc_create_vport_work_array(phba); |
| 790 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 791 | for (i = 0; i <= phba->max_vports && |
| 792 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 793 | lpfc_cleanup_discovery_resources(vports[i]); |
| 794 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 795 | } |
| 796 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | } |
| 798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 799 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 800 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 801 | * @phba: pointer to lpfc HBA data structure. |
| 802 | * |
| 803 | * This routine will do uninitialization after the HBA is reset when bring |
| 804 | * down the SLI Layer. |
| 805 | * |
| 806 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 807 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 808 | * Any other value - error. |
| 809 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 810 | static int |
| 811 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 812 | { |
| 813 | struct lpfc_sli *psli = &phba->sli; |
| 814 | struct lpfc_sli_ring *pring; |
| 815 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 816 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 817 | int i; |
| 818 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 819 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 820 | lpfc_sli_hbqbuf_free_all(phba); |
| 821 | else { |
| 822 | /* Cleanup preposted buffers on the ELS ring */ |
| 823 | pring = &psli->ring[LPFC_ELS_RING]; |
| 824 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 825 | list_del(&mp->list); |
| 826 | pring->postbufq_cnt--; |
| 827 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 828 | kfree(mp); |
| 829 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 830 | } |
| 831 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 832 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 833 | for (i = 0; i < psli->num_rings; i++) { |
| 834 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 835 | |
| 836 | /* At this point in time the HBA is either reset or DOA. Either |
| 837 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 838 | */ |
| 839 | list_splice_init(&pring->txcmplq, &completions); |
| 840 | pring->txcmplq_cnt = 0; |
| 841 | spin_unlock_irq(&phba->hbalock); |
| 842 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 843 | /* Cancel all the IOCBs from the completions list */ |
| 844 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 845 | IOERR_SLI_ABORTED); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 846 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 847 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 848 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 849 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 850 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 851 | |
| 852 | return 0; |
| 853 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 854 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 855 | /** |
| 856 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 857 | * @phba: pointer to lpfc HBA data structure. |
| 858 | * |
| 859 | * This routine will do uninitialization after the HBA is reset when bring |
| 860 | * down the SLI Layer. |
| 861 | * |
| 862 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 863 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 864 | * Any other value - error. |
| 865 | **/ |
| 866 | static int |
| 867 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 868 | { |
| 869 | struct lpfc_scsi_buf *psb, *psb_next; |
| 870 | LIST_HEAD(aborts); |
| 871 | int ret; |
| 872 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 873 | struct lpfc_sglq *sglq_entry = NULL; |
| 874 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 875 | ret = lpfc_hba_down_post_s3(phba); |
| 876 | if (ret) |
| 877 | return ret; |
| 878 | /* At this point in time the HBA is either reset or DOA. Either |
| 879 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
| 880 | * on the lpfc_sgl_list so that it can either be freed if the |
| 881 | * driver is unloading or reposted if the driver is restarting |
| 882 | * the port. |
| 883 | */ |
| 884 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ |
| 885 | /* scsl_buf_list */ |
| 886 | /* abts_sgl_list_lock required because worker thread uses this |
| 887 | * list. |
| 888 | */ |
| 889 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 890 | list_for_each_entry(sglq_entry, |
| 891 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 892 | sglq_entry->state = SGL_FREED; |
| 893 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 894 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
| 895 | &phba->sli4_hba.lpfc_sgl_list); |
| 896 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
| 897 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 898 | * list. |
| 899 | */ |
| 900 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 901 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 902 | &aborts); |
| 903 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 904 | spin_unlock_irq(&phba->hbalock); |
| 905 | |
| 906 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 907 | psb->pCmd = NULL; |
| 908 | psb->status = IOSTAT_SUCCESS; |
| 909 | } |
| 910 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
| 911 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); |
| 912 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | /** |
| 917 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 918 | * @phba: pointer to lpfc HBA data structure. |
| 919 | * |
| 920 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 921 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 922 | * |
| 923 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 924 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 925 | * Any other value - error. |
| 926 | **/ |
| 927 | int |
| 928 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 929 | { |
| 930 | return (*phba->lpfc_hba_down_post)(phba); |
| 931 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 934 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 935 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 936 | * |
| 937 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 938 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 939 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 940 | * event will be used by the worker thread to invoke the actual timeout |
| 941 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 942 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 943 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 944 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 945 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 946 | lpfc_hb_timeout(unsigned long ptr) |
| 947 | { |
| 948 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 949 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 950 | unsigned long iflag; |
| 951 | |
| 952 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 953 | |
| 954 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 955 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 956 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 957 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 958 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 959 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 960 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 961 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 962 | if (!tmo_posted) |
| 963 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 964 | return; |
| 965 | } |
| 966 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 967 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 968 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 969 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 970 | * |
| 971 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 972 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 973 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 974 | * event will be used by the worker thread to invoke the actual timeout |
| 975 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 976 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 977 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 978 | **/ |
| 979 | static void |
| 980 | lpfc_rrq_timeout(unsigned long ptr) |
| 981 | { |
| 982 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 983 | unsigned long iflag; |
| 984 | |
| 985 | phba = (struct lpfc_hba *)ptr; |
| 986 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 987 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 988 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 989 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 993 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 994 | * @phba: pointer to lpfc hba data structure. |
| 995 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 996 | * |
| 997 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 998 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 999 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1000 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1001 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1002 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1003 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1004 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1005 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1006 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1007 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1008 | static void |
| 1009 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1010 | { |
| 1011 | unsigned long drvr_flag; |
| 1012 | |
| 1013 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1014 | phba->hb_outstanding = 0; |
| 1015 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1016 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1017 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1018 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1019 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1020 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1021 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1022 | mod_timer(&phba->hb_tmofunc, |
| 1023 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1028 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1029 | * @phba: pointer to lpfc hba data structure. |
| 1030 | * |
| 1031 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1032 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1033 | * handler performs any periodic operations needed for the device. If such |
| 1034 | * periodic event has already been attended to either in the interrupt handler |
| 1035 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1036 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1037 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1038 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1039 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1040 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1041 | * to offline. |
| 1042 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1043 | void |
| 1044 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1045 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1046 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1047 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1048 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1049 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1050 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1051 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1052 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1053 | vports = lpfc_create_vport_work_array(phba); |
| 1054 | if (vports != NULL) |
| 1055 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 1056 | lpfc_rcv_seq_check_edtov(vports[i]); |
| 1057 | lpfc_destroy_vport_work_array(phba, vports); |
| 1058 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1059 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1060 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1061 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1062 | return; |
| 1063 | |
| 1064 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1065 | |
| 1066 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 1067 | jiffies)) { |
| 1068 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1069 | if (!phba->hb_outstanding) |
| 1070 | mod_timer(&phba->hb_tmofunc, |
| 1071 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 1072 | else |
| 1073 | mod_timer(&phba->hb_tmofunc, |
| 1074 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 1075 | return; |
| 1076 | } |
| 1077 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1078 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1079 | if (phba->elsbuf_cnt && |
| 1080 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1081 | spin_lock_irq(&phba->hbalock); |
| 1082 | list_splice_init(&phba->elsbuf, &completions); |
| 1083 | phba->elsbuf_cnt = 0; |
| 1084 | phba->elsbuf_prev_cnt = 0; |
| 1085 | spin_unlock_irq(&phba->hbalock); |
| 1086 | |
| 1087 | while (!list_empty(&completions)) { |
| 1088 | list_remove_head(&completions, buf_ptr, |
| 1089 | struct lpfc_dmabuf, list); |
| 1090 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1091 | kfree(buf_ptr); |
| 1092 | } |
| 1093 | } |
| 1094 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1095 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1096 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1097 | if (phba->cfg_enable_hba_heartbeat) { |
| 1098 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1099 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1100 | (list_empty(&psli->mboxq))) { |
| 1101 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1102 | GFP_KERNEL); |
| 1103 | if (!pmboxq) { |
| 1104 | mod_timer(&phba->hb_tmofunc, |
| 1105 | jiffies + |
| 1106 | HZ * LPFC_HB_MBOX_INTERVAL); |
| 1107 | return; |
| 1108 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1109 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1110 | lpfc_heart_beat(phba, pmboxq); |
| 1111 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1112 | pmboxq->vport = phba->pport; |
| 1113 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1114 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1115 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1116 | if (retval != MBX_BUSY && |
| 1117 | retval != MBX_SUCCESS) { |
| 1118 | mempool_free(pmboxq, |
| 1119 | phba->mbox_mem_pool); |
| 1120 | mod_timer(&phba->hb_tmofunc, |
| 1121 | jiffies + |
| 1122 | HZ * LPFC_HB_MBOX_INTERVAL); |
| 1123 | return; |
| 1124 | } |
| 1125 | phba->skipped_hb = 0; |
| 1126 | phba->hb_outstanding = 1; |
| 1127 | } else if (time_before_eq(phba->last_completion_time, |
| 1128 | phba->skipped_hb)) { |
| 1129 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1130 | "2857 Last completion time not " |
| 1131 | " updated in %d ms\n", |
| 1132 | jiffies_to_msecs(jiffies |
| 1133 | - phba->last_completion_time)); |
| 1134 | } else |
| 1135 | phba->skipped_hb = jiffies; |
| 1136 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1137 | mod_timer(&phba->hb_tmofunc, |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1138 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1139 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1140 | } else { |
| 1141 | /* |
| 1142 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1143 | * we need to give the hb mailbox cmd a chance to |
| 1144 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1145 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1146 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1147 | "0459 Adapter heartbeat still out" |
| 1148 | "standing:last compl time was %d ms.\n", |
| 1149 | jiffies_to_msecs(jiffies |
| 1150 | - phba->last_completion_time)); |
| 1151 | mod_timer(&phba->hb_tmofunc, |
| 1152 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1153 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1158 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1159 | * @phba: pointer to lpfc hba data structure. |
| 1160 | * |
| 1161 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1162 | * other than Port Error 6 has been detected. |
| 1163 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1164 | static void |
| 1165 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1166 | { |
| 1167 | struct lpfc_sli *psli = &phba->sli; |
| 1168 | |
| 1169 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1170 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1171 | spin_unlock_irq(&phba->hbalock); |
| 1172 | lpfc_offline_prep(phba); |
| 1173 | |
| 1174 | lpfc_offline(phba); |
| 1175 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1176 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1177 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1178 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1179 | lpfc_hba_down_post(phba); |
| 1180 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1181 | lpfc_unblock_mgmt_io(phba); |
| 1182 | phba->link_state = LPFC_HBA_ERROR; |
| 1183 | return; |
| 1184 | } |
| 1185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1186 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1187 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1188 | * @phba: pointer to lpfc hba data structure. |
| 1189 | * |
| 1190 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1191 | * other than Port Error 6 has been detected. |
| 1192 | **/ |
| 1193 | static void |
| 1194 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1195 | { |
| 1196 | lpfc_offline_prep(phba); |
| 1197 | lpfc_offline(phba); |
| 1198 | lpfc_sli4_brdreset(phba); |
| 1199 | lpfc_hba_down_post(phba); |
| 1200 | lpfc_sli4_post_status_check(phba); |
| 1201 | lpfc_unblock_mgmt_io(phba); |
| 1202 | phba->link_state = LPFC_HBA_ERROR; |
| 1203 | } |
| 1204 | |
| 1205 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1206 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1207 | * @phba: pointer to lpfc hba data structure. |
| 1208 | * |
| 1209 | * This routine is invoked to handle the deferred HBA hardware error |
| 1210 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1211 | * and another ER bit in the host status register. The driver will |
| 1212 | * wait until the ER1 bit clears before handling the error condition. |
| 1213 | **/ |
| 1214 | static void |
| 1215 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1216 | { |
| 1217 | uint32_t old_host_status = phba->work_hs; |
| 1218 | struct lpfc_sli_ring *pring; |
| 1219 | struct lpfc_sli *psli = &phba->sli; |
| 1220 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1221 | /* If the pci channel is offline, ignore possible errors, |
| 1222 | * since we cannot communicate with the pci card anyway. |
| 1223 | */ |
| 1224 | if (pci_channel_offline(phba->pcidev)) { |
| 1225 | spin_lock_irq(&phba->hbalock); |
| 1226 | phba->hba_flag &= ~DEFER_ERATT; |
| 1227 | spin_unlock_irq(&phba->hbalock); |
| 1228 | return; |
| 1229 | } |
| 1230 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1231 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1232 | "0479 Deferred Adapter Hardware Error " |
| 1233 | "Data: x%x x%x x%x\n", |
| 1234 | phba->work_hs, |
| 1235 | phba->work_status[0], phba->work_status[1]); |
| 1236 | |
| 1237 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1238 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1239 | spin_unlock_irq(&phba->hbalock); |
| 1240 | |
| 1241 | |
| 1242 | /* |
| 1243 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1244 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1245 | * SCSI layer retry it after re-establishing link. |
| 1246 | */ |
| 1247 | pring = &psli->ring[psli->fcp_ring]; |
| 1248 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1249 | |
| 1250 | /* |
| 1251 | * There was a firmware error. Take the hba offline and then |
| 1252 | * attempt to restart it. |
| 1253 | */ |
| 1254 | lpfc_offline_prep(phba); |
| 1255 | lpfc_offline(phba); |
| 1256 | |
| 1257 | /* Wait for the ER1 bit to clear.*/ |
| 1258 | while (phba->work_hs & HS_FFER1) { |
| 1259 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1260 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1261 | phba->work_hs = UNPLUG_ERR ; |
| 1262 | break; |
| 1263 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1264 | /* If driver is unloading let the worker thread continue */ |
| 1265 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1266 | phba->work_hs = 0; |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | /* |
| 1272 | * This is to ptrotect against a race condition in which |
| 1273 | * first write to the host attention register clear the |
| 1274 | * host status register. |
| 1275 | */ |
| 1276 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1277 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1278 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1279 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1280 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1281 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1282 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1283 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1284 | } |
| 1285 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1286 | static void |
| 1287 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1288 | { |
| 1289 | struct lpfc_board_event_header board_event; |
| 1290 | struct Scsi_Host *shost; |
| 1291 | |
| 1292 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1293 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1294 | shost = lpfc_shost_from_vport(phba->pport); |
| 1295 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1296 | sizeof(board_event), |
| 1297 | (char *) &board_event, |
| 1298 | LPFC_NL_VENDOR_ID); |
| 1299 | } |
| 1300 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1301 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1302 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1303 | * @phba: pointer to lpfc hba data structure. |
| 1304 | * |
| 1305 | * This routine is invoked to handle the following HBA hardware error |
| 1306 | * conditions: |
| 1307 | * 1 - HBA error attention interrupt |
| 1308 | * 2 - DMA ring index out of range |
| 1309 | * 3 - Mailbox command came back as unknown |
| 1310 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1311 | static void |
| 1312 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1314 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1315 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1317 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1318 | unsigned long temperature; |
| 1319 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1320 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1321 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1322 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1323 | * since we cannot communicate with the pci card anyway. |
| 1324 | */ |
| 1325 | if (pci_channel_offline(phba->pcidev)) { |
| 1326 | spin_lock_irq(&phba->hbalock); |
| 1327 | phba->hba_flag &= ~DEFER_ERATT; |
| 1328 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1329 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1330 | } |
| 1331 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1332 | /* If resets are disabled then leave the HBA alone and return */ |
| 1333 | if (!phba->cfg_enable_hba_reset) |
| 1334 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1336 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1337 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1338 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1339 | if (phba->hba_flag & DEFER_ERATT) |
| 1340 | lpfc_handle_deferred_eratt(phba); |
| 1341 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1342 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1343 | if (phba->work_hs & HS_FFER6) |
| 1344 | /* Re-establishing Link */ |
| 1345 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1346 | "1301 Re-establishing Link " |
| 1347 | "Data: x%x x%x x%x\n", |
| 1348 | phba->work_hs, phba->work_status[0], |
| 1349 | phba->work_status[1]); |
| 1350 | if (phba->work_hs & HS_FFER8) |
| 1351 | /* Device Zeroization */ |
| 1352 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1353 | "2861 Host Authentication device " |
| 1354 | "zeroization Data:x%x x%x x%x\n", |
| 1355 | phba->work_hs, phba->work_status[0], |
| 1356 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1357 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1358 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1359 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1360 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | |
| 1362 | /* |
| 1363 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1364 | * That could cause the I/Os dropped by the firmware. |
| 1365 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1366 | * retry it after re-establishing link. |
| 1367 | */ |
| 1368 | pring = &psli->ring[psli->fcp_ring]; |
| 1369 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 1370 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | /* |
| 1372 | * There was a firmware error. Take the hba offline and then |
| 1373 | * attempt to restart it. |
| 1374 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1375 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1377 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1379 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | return; |
| 1381 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1382 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1383 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1384 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1385 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1386 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1387 | temp_event_data.data = (uint32_t)temperature; |
| 1388 | |
| 1389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1390 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1391 | "(%ld), taking this port offline " |
| 1392 | "Data: x%x x%x x%x\n", |
| 1393 | temperature, phba->work_hs, |
| 1394 | phba->work_status[0], phba->work_status[1]); |
| 1395 | |
| 1396 | shost = lpfc_shost_from_vport(phba->pport); |
| 1397 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1398 | sizeof(temp_event_data), |
| 1399 | (char *) &temp_event_data, |
| 1400 | SCSI_NL_VID_TYPE_PCI |
| 1401 | | PCI_VENDOR_ID_EMULEX); |
| 1402 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1403 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1404 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1405 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1406 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | } else { |
| 1409 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1410 | * failure is a value other than FFER6. Do not call the offline |
| 1411 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | */ |
| 1413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1414 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1415 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1416 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | phba->work_status[0], phba->work_status[1]); |
| 1418 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1419 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1420 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1421 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1422 | sizeof(event_data), (char *) &event_data, |
| 1423 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1424 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1425 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1427 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | } |
| 1429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1430 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1431 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1432 | * @phba: pointer to lpfc hba data structure. |
| 1433 | * |
| 1434 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1435 | * conditions. |
| 1436 | **/ |
| 1437 | static void |
| 1438 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1439 | { |
| 1440 | struct lpfc_vport *vport = phba->pport; |
| 1441 | uint32_t event_data; |
| 1442 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1443 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1444 | struct lpfc_register portstat_reg = {0}; |
| 1445 | uint32_t reg_err1, reg_err2; |
| 1446 | uint32_t uerrlo_reg, uemasklo_reg; |
| 1447 | uint32_t pci_rd_rc1, pci_rd_rc2; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1448 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1449 | |
| 1450 | /* If the pci channel is offline, ignore possible errors, since |
| 1451 | * we cannot communicate with the pci card anyway. |
| 1452 | */ |
| 1453 | if (pci_channel_offline(phba->pcidev)) |
| 1454 | return; |
| 1455 | /* If resets are disabled then leave the HBA alone and return */ |
| 1456 | if (!phba->cfg_enable_hba_reset) |
| 1457 | return; |
| 1458 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1459 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1460 | switch (if_type) { |
| 1461 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1462 | pci_rd_rc1 = lpfc_readl( |
| 1463 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1464 | &uerrlo_reg); |
| 1465 | pci_rd_rc2 = lpfc_readl( |
| 1466 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1467 | &uemasklo_reg); |
| 1468 | /* consider PCI bus read error as pci_channel_offline */ |
| 1469 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1470 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1471 | lpfc_sli4_offline_eratt(phba); |
| 1472 | break; |
| 1473 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1474 | pci_rd_rc1 = lpfc_readl( |
| 1475 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1476 | &portstat_reg.word0); |
| 1477 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1478 | if (pci_rd_rc1 == -EIO) { |
| 1479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1480 | "3151 PCI bus read access failure: x%x\n", |
| 1481 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1482 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1483 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1484 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1485 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1486 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
| 1487 | /* TODO: Register for Overtemp async events. */ |
| 1488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1489 | "2889 Port Overtemperature event, " |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 1490 | "taking port offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1491 | spin_lock_irq(&phba->hbalock); |
| 1492 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1493 | spin_unlock_irq(&phba->hbalock); |
| 1494 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1495 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1496 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1497 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1498 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) |
| 1499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1500 | "3143 Port Down: Firmware Restarted\n"); |
| 1501 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1502 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1504 | "3144 Port Down: Debug Dump\n"); |
| 1505 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1506 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1508 | "3145 Port Down: Provisioning\n"); |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 1509 | /* |
| 1510 | * On error status condition, driver need to wait for port |
| 1511 | * ready before performing reset. |
| 1512 | */ |
| 1513 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
| 1514 | if (!rc) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 1515 | /* need reset: attempt for port recovery */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1517 | "2887 Reset Needed: Attempting Port " |
| 1518 | "Recovery...\n"); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 1519 | lpfc_offline_prep(phba); |
| 1520 | lpfc_offline(phba); |
| 1521 | lpfc_sli_brdrestart(phba); |
| 1522 | if (lpfc_online(phba) == 0) { |
| 1523 | lpfc_unblock_mgmt_io(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1524 | /* don't report event on forced debug dump */ |
| 1525 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1526 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1527 | return; |
| 1528 | else |
| 1529 | break; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 1530 | } |
| 1531 | /* fall through for not able to recover */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1532 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1534 | "3152 Unrecoverable error, bring the port " |
| 1535 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1536 | lpfc_sli4_offline_eratt(phba); |
| 1537 | break; |
| 1538 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1539 | default: |
| 1540 | break; |
| 1541 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1542 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1543 | "3123 Report dump event to upper layer\n"); |
| 1544 | /* Send an internal error event to mgmt application */ |
| 1545 | lpfc_board_errevt_to_mgmt(phba); |
| 1546 | |
| 1547 | event_data = FC_REG_DUMP_EVENT; |
| 1548 | shost = lpfc_shost_from_vport(vport); |
| 1549 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1550 | sizeof(event_data), (char *) &event_data, |
| 1551 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /** |
| 1555 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1556 | * @phba: pointer to lpfc HBA data structure. |
| 1557 | * |
| 1558 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1559 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1560 | * |
| 1561 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1562 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1563 | * Any other value - error. |
| 1564 | **/ |
| 1565 | void |
| 1566 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1567 | { |
| 1568 | (*phba->lpfc_handle_eratt)(phba); |
| 1569 | } |
| 1570 | |
| 1571 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1572 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1573 | * @phba: pointer to lpfc hba data structure. |
| 1574 | * |
| 1575 | * This routine is invoked from the worker thread to handle a HBA host |
| 1576 | * attention link event. |
| 1577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1579 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1581 | struct lpfc_vport *vport = phba->pport; |
| 1582 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | LPFC_MBOXQ_t *pmb; |
| 1584 | volatile uint32_t control; |
| 1585 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1586 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | |
| 1588 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1589 | if (!pmb) { |
| 1590 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | |
| 1594 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1595 | if (!mp) { |
| 1596 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1598 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1599 | |
| 1600 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1601 | if (!mp->virt) { |
| 1602 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1604 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1606 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1607 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1608 | |
| 1609 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 1610 | lpfc_read_topology(phba, pmb, mp); |
| 1611 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1612 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1613 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1614 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1615 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1616 | if (rc == MBX_NOT_FINISHED) { |
| 1617 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1618 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1619 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | |
| 1621 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1622 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | writel(HA_LATT, phba->HAregaddr); |
| 1624 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | |
| 1627 | return; |
| 1628 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1629 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1630 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1631 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1632 | lpfc_handle_latt_free_mp: |
| 1633 | kfree(mp); |
| 1634 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1635 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | lpfc_handle_latt_err_exit: |
| 1637 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1638 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1639 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1640 | control = readl(phba->HCregaddr); |
| 1641 | control |= HC_LAINT_ENA; |
| 1642 | writel(control, phba->HCregaddr); |
| 1643 | readl(phba->HCregaddr); /* flush */ |
| 1644 | |
| 1645 | /* Clear Link Attention in HA REG */ |
| 1646 | writel(HA_LATT, phba->HAregaddr); |
| 1647 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1652 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1653 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | |
| 1655 | return; |
| 1656 | } |
| 1657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1659 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1660 | * @phba: pointer to lpfc hba data structure. |
| 1661 | * @vpd: pointer to the vital product data. |
| 1662 | * @len: length of the vital product data in bytes. |
| 1663 | * |
| 1664 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1665 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1666 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1667 | * |
| 1668 | * Return codes |
| 1669 | * 0 - pointer to the VPD passed in is NULL |
| 1670 | * 1 - success |
| 1671 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1672 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | { |
| 1675 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1676 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1677 | int i, j; |
| 1678 | int finished = 0; |
| 1679 | int index = 0; |
| 1680 | |
| 1681 | if (!vpd) |
| 1682 | return 0; |
| 1683 | |
| 1684 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1685 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1686 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1688 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1689 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | switch (vpd[index]) { |
| 1691 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1692 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1693 | index += 1; |
| 1694 | lenlo = vpd[index]; |
| 1695 | index += 1; |
| 1696 | lenhi = vpd[index]; |
| 1697 | index += 1; |
| 1698 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1699 | index += i; |
| 1700 | break; |
| 1701 | case 0x90: |
| 1702 | index += 1; |
| 1703 | lenlo = vpd[index]; |
| 1704 | index += 1; |
| 1705 | lenhi = vpd[index]; |
| 1706 | index += 1; |
| 1707 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1708 | if (Length > len - index) |
| 1709 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | while (Length > 0) { |
| 1711 | /* Look for Serial Number */ |
| 1712 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1713 | index += 2; |
| 1714 | i = vpd[index]; |
| 1715 | index += 1; |
| 1716 | j = 0; |
| 1717 | Length -= (3+i); |
| 1718 | while(i--) { |
| 1719 | phba->SerialNumber[j++] = vpd[index++]; |
| 1720 | if (j == 31) |
| 1721 | break; |
| 1722 | } |
| 1723 | phba->SerialNumber[j] = 0; |
| 1724 | continue; |
| 1725 | } |
| 1726 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1727 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1728 | index += 2; |
| 1729 | i = vpd[index]; |
| 1730 | index += 1; |
| 1731 | j = 0; |
| 1732 | Length -= (3+i); |
| 1733 | while(i--) { |
| 1734 | phba->ModelDesc[j++] = vpd[index++]; |
| 1735 | if (j == 255) |
| 1736 | break; |
| 1737 | } |
| 1738 | phba->ModelDesc[j] = 0; |
| 1739 | continue; |
| 1740 | } |
| 1741 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1742 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1743 | index += 2; |
| 1744 | i = vpd[index]; |
| 1745 | index += 1; |
| 1746 | j = 0; |
| 1747 | Length -= (3+i); |
| 1748 | while(i--) { |
| 1749 | phba->ModelName[j++] = vpd[index++]; |
| 1750 | if (j == 79) |
| 1751 | break; |
| 1752 | } |
| 1753 | phba->ModelName[j] = 0; |
| 1754 | continue; |
| 1755 | } |
| 1756 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1757 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1758 | index += 2; |
| 1759 | i = vpd[index]; |
| 1760 | index += 1; |
| 1761 | j = 0; |
| 1762 | Length -= (3+i); |
| 1763 | while(i--) { |
| 1764 | phba->ProgramType[j++] = vpd[index++]; |
| 1765 | if (j == 255) |
| 1766 | break; |
| 1767 | } |
| 1768 | phba->ProgramType[j] = 0; |
| 1769 | continue; |
| 1770 | } |
| 1771 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1772 | phba->vpd_flag |= VPD_PORT; |
| 1773 | index += 2; |
| 1774 | i = vpd[index]; |
| 1775 | index += 1; |
| 1776 | j = 0; |
| 1777 | Length -= (3+i); |
| 1778 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1779 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 1780 | (phba->sli4_hba.pport_name_sta == |
| 1781 | LPFC_SLI4_PPNAME_GET)) { |
| 1782 | j++; |
| 1783 | index++; |
| 1784 | } else |
| 1785 | phba->Port[j++] = vpd[index++]; |
| 1786 | if (j == 19) |
| 1787 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 1789 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 1790 | (phba->sli4_hba.pport_name_sta == |
| 1791 | LPFC_SLI4_PPNAME_NON)) |
| 1792 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | continue; |
| 1794 | } |
| 1795 | else { |
| 1796 | index += 2; |
| 1797 | i = vpd[index]; |
| 1798 | index += 1; |
| 1799 | index += i; |
| 1800 | Length -= (3 + i); |
| 1801 | } |
| 1802 | } |
| 1803 | finished = 0; |
| 1804 | break; |
| 1805 | case 0x78: |
| 1806 | finished = 1; |
| 1807 | break; |
| 1808 | default: |
| 1809 | index ++; |
| 1810 | break; |
| 1811 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1812 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1813 | |
| 1814 | return(1); |
| 1815 | } |
| 1816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1818 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1819 | * @phba: pointer to lpfc hba data structure. |
| 1820 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1821 | * @descp: pointer to the data structure to hold the derived description. |
| 1822 | * |
| 1823 | * This routine retrieves HBA's description based on its registered PCI device |
| 1824 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1825 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1826 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1827 | * function returns, the @mdp will be filled with the model name. |
| 1828 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1830 | 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] | 1831 | { |
| 1832 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1833 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1834 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1835 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1836 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1837 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1838 | char *name; |
| 1839 | char *bus; |
| 1840 | char *function; |
| 1841 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1842 | |
| 1843 | if (mdp && mdp[0] != '\0' |
| 1844 | && descp && descp[0] != '\0') |
| 1845 | return; |
| 1846 | |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 1847 | if (phba->lmt & LMT_16Gb) |
| 1848 | max_speed = 16; |
| 1849 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1850 | max_speed = 10; |
| 1851 | else if (phba->lmt & LMT_8Gb) |
| 1852 | max_speed = 8; |
| 1853 | else if (phba->lmt & LMT_4Gb) |
| 1854 | max_speed = 4; |
| 1855 | else if (phba->lmt & LMT_2Gb) |
| 1856 | max_speed = 2; |
| 1857 | else |
| 1858 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1859 | |
| 1860 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1861 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1862 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1863 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1864 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1865 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | case PCI_DEVICE_ID_SUPERFLY: |
| 1867 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1868 | m = (typeof(m)){"LP7000", "PCI", |
| 1869 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1871 | m = (typeof(m)){"LP7000E", "PCI", |
| 1872 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | break; |
| 1874 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1875 | m = (typeof(m)){"LP8000", "PCI", |
| 1876 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | break; |
| 1878 | case PCI_DEVICE_ID_CENTAUR: |
| 1879 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1880 | m = (typeof(m)){"LP9002", "PCI", |
| 1881 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | else |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1883 | m = (typeof(m)){"LP9000", "PCI", |
| 1884 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | break; |
| 1886 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1887 | m = (typeof(m)){"LP952", "PCI", |
| 1888 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | break; |
| 1890 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1891 | m = (typeof(m)){"LP9802", "PCI-X", |
| 1892 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | break; |
| 1894 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1895 | m = (typeof(m)){"LP10000", "PCI-X", |
| 1896 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1897 | break; |
| 1898 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1899 | m = (typeof(m)){"LPX1000", "PCI-X", |
| 1900 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | break; |
| 1902 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1903 | m = (typeof(m)){"LP982", "PCI-X", |
| 1904 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1905 | break; |
| 1906 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1907 | m = (typeof(m)){"LP1050", "PCI-X", |
| 1908 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1909 | break; |
| 1910 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1911 | m = (typeof(m)){"LP11000", "PCI-X2", |
| 1912 | "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1913 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1914 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1915 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
| 1916 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1917 | break; |
| 1918 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1919 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
| 1920 | "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1921 | break; |
| 1922 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1923 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1924 | break; |
| 1925 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1926 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1927 | break; |
| 1928 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1929 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1930 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1931 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1932 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1933 | break; |
| 1934 | case PCI_DEVICE_ID_BSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1935 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | break; |
| 1937 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1938 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1939 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1940 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1941 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1942 | break; |
| 1943 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1944 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1945 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1946 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1947 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1948 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | break; |
| 1950 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1951 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | break; |
| 1953 | case PCI_DEVICE_ID_LP101: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1954 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | break; |
| 1956 | case PCI_DEVICE_ID_LP10000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1957 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1958 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1959 | case PCI_DEVICE_ID_LP11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1960 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1961 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1962 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1963 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1964 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1965 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1966 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1967 | break; |
| 1968 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1969 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1970 | break; |
| 1971 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1972 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1973 | break; |
| 1974 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1975 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1976 | break; |
| 1977 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1978 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1979 | break; |
| 1980 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1981 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1982 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1983 | case PCI_DEVICE_ID_HORNET: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1984 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1985 | GE = 1; |
| 1986 | break; |
| 1987 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1988 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 1989 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1990 | break; |
| 1991 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1992 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
| 1993 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1994 | break; |
| 1995 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 1996 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
| 1997 | "Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1998 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1999 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2000 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2001 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2002 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2003 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2004 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2005 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2006 | break; |
| 2007 | case PCI_DEVICE_ID_FALCON: |
| 2008 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2009 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2010 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2011 | case PCI_DEVICE_ID_BALIUS: |
| 2012 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
| 2013 | "Fibre Channel Adapter"}; |
| 2014 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2015 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2016 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2017 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2018 | break; |
| 2019 | case PCI_DEVICE_ID_LANCER_FCOE: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2020 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2021 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2022 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2023 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2024 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2025 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2026 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2028 | |
| 2029 | if (mdp && mdp[0] == '\0') |
| 2030 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2031 | /* |
| 2032 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2033 | * and we put the port number on the end |
| 2034 | */ |
| 2035 | if (descp && descp[0] == '\0') { |
| 2036 | if (oneConnect) |
| 2037 | snprintf(descp, 255, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2038 | "Emulex OneConnect %s, %s Initiator, Port %s", |
| 2039 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2040 | phba->Port); |
| 2041 | else |
| 2042 | snprintf(descp, 255, |
| 2043 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2044 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2045 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2046 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | } |
| 2048 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2049 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2050 | * 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] | 2051 | * @phba: pointer to lpfc hba data structure. |
| 2052 | * @pring: pointer to a IOCB ring. |
| 2053 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2054 | * |
| 2055 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2056 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2057 | * |
| 2058 | * Return codes |
| 2059 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2060 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2062 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2063 | { |
| 2064 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2065 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | struct lpfc_dmabuf *mp1, *mp2; |
| 2067 | |
| 2068 | cnt += pring->missbufcnt; |
| 2069 | |
| 2070 | /* While there are buffers to post */ |
| 2071 | while (cnt > 0) { |
| 2072 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2073 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | if (iocb == NULL) { |
| 2075 | pring->missbufcnt = cnt; |
| 2076 | return cnt; |
| 2077 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | icmd = &iocb->iocb; |
| 2079 | |
| 2080 | /* 2 buffers can be posted per command */ |
| 2081 | /* Allocate buffer to post */ |
| 2082 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2083 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2084 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2085 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2086 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2087 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2088 | pring->missbufcnt = cnt; |
| 2089 | return cnt; |
| 2090 | } |
| 2091 | |
| 2092 | INIT_LIST_HEAD(&mp1->list); |
| 2093 | /* Allocate buffer to post */ |
| 2094 | if (cnt > 1) { |
| 2095 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2096 | if (mp2) |
| 2097 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2098 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2099 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2100 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2102 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2103 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | pring->missbufcnt = cnt; |
| 2105 | return cnt; |
| 2106 | } |
| 2107 | |
| 2108 | INIT_LIST_HEAD(&mp2->list); |
| 2109 | } else { |
| 2110 | mp2 = NULL; |
| 2111 | } |
| 2112 | |
| 2113 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2114 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2115 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2116 | icmd->ulpBdeCount = 1; |
| 2117 | cnt--; |
| 2118 | if (mp2) { |
| 2119 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2120 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2121 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2122 | cnt--; |
| 2123 | icmd->ulpBdeCount = 2; |
| 2124 | } |
| 2125 | |
| 2126 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2127 | icmd->ulpLe = 1; |
| 2128 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2129 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2130 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2131 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2132 | kfree(mp1); |
| 2133 | cnt++; |
| 2134 | if (mp2) { |
| 2135 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2136 | kfree(mp2); |
| 2137 | cnt++; |
| 2138 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2139 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | return cnt; |
| 2142 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2143 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2144 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | } |
| 2147 | pring->missbufcnt = 0; |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2151 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2152 | * 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] | 2153 | * @phba: pointer to lpfc hba data structure. |
| 2154 | * |
| 2155 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2156 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 2157 | * set to 64 IOCBs. |
| 2158 | * |
| 2159 | * Return codes |
| 2160 | * 0 - success (currently always success) |
| 2161 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | { |
| 2165 | struct lpfc_sli *psli = &phba->sli; |
| 2166 | |
| 2167 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2168 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | /* Ring 2 - FCP no buffers needed */ |
| 2170 | |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
| 2174 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2177 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2178 | * @HashResultPointer: pointer to an array as hash table. |
| 2179 | * |
| 2180 | * This routine sets up the initial values to the array of hash table entries |
| 2181 | * for the LC HBAs. |
| 2182 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | static void |
| 2184 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2185 | { |
| 2186 | HashResultPointer[0] = 0x67452301; |
| 2187 | HashResultPointer[1] = 0xEFCDAB89; |
| 2188 | HashResultPointer[2] = 0x98BADCFE; |
| 2189 | HashResultPointer[3] = 0x10325476; |
| 2190 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2191 | } |
| 2192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2194 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2195 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2196 | * @HashWorkingPointer: pointer to an working hash table. |
| 2197 | * |
| 2198 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2199 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2200 | * The results are putting back to the initial hash table, returned through |
| 2201 | * the @HashResultPointer as the result hash table. |
| 2202 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | static void |
| 2204 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2205 | { |
| 2206 | int t; |
| 2207 | uint32_t TEMP; |
| 2208 | uint32_t A, B, C, D, E; |
| 2209 | t = 16; |
| 2210 | do { |
| 2211 | HashWorkingPointer[t] = |
| 2212 | S(1, |
| 2213 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2214 | 8] ^ |
| 2215 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2216 | } while (++t <= 79); |
| 2217 | t = 0; |
| 2218 | A = HashResultPointer[0]; |
| 2219 | B = HashResultPointer[1]; |
| 2220 | C = HashResultPointer[2]; |
| 2221 | D = HashResultPointer[3]; |
| 2222 | E = HashResultPointer[4]; |
| 2223 | |
| 2224 | do { |
| 2225 | if (t < 20) { |
| 2226 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2227 | } else if (t < 40) { |
| 2228 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2229 | } else if (t < 60) { |
| 2230 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2231 | } else { |
| 2232 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2233 | } |
| 2234 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2235 | E = D; |
| 2236 | D = C; |
| 2237 | C = S(30, B); |
| 2238 | B = A; |
| 2239 | A = TEMP; |
| 2240 | } while (++t <= 79); |
| 2241 | |
| 2242 | HashResultPointer[0] += A; |
| 2243 | HashResultPointer[1] += B; |
| 2244 | HashResultPointer[2] += C; |
| 2245 | HashResultPointer[3] += D; |
| 2246 | HashResultPointer[4] += E; |
| 2247 | |
| 2248 | } |
| 2249 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2251 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2252 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2253 | * @HashWorking: pointer to the entry of the working hash array. |
| 2254 | * |
| 2255 | * This routine calculates the working hash array referred by @HashWorking |
| 2256 | * from the challenge random numbers associated with the host, referred by |
| 2257 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2258 | * array and returned by reference through @HashWorking. |
| 2259 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | static void |
| 2261 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2262 | { |
| 2263 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2264 | } |
| 2265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2266 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2267 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2268 | * @phba: pointer to lpfc hba data structure. |
| 2269 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2270 | * |
| 2271 | * This routine performs the special handling for LC HBA initialization. |
| 2272 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | void |
| 2274 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2275 | { |
| 2276 | int t; |
| 2277 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2278 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2280 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | if (!HashWorking) |
| 2282 | return; |
| 2283 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2285 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2286 | |
| 2287 | for (t = 0; t < 7; t++) |
| 2288 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2289 | |
| 2290 | lpfc_sha_init(hbainit); |
| 2291 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2292 | kfree(HashWorking); |
| 2293 | } |
| 2294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2296 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2297 | * @vport: pointer to a virtual N_Port data structure. |
| 2298 | * |
| 2299 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2300 | * It invokes the discovery state machine to perform necessary state |
| 2301 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2302 | * the physical port is treated as @vport 0. |
| 2303 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2304 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2305 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2307 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2309 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2311 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2312 | lpfc_port_link_failure(vport); |
| 2313 | |
| 2314 | 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] | 2315 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2316 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2317 | NLP_STE_UNUSED_NODE); |
| 2318 | if (!ndlp) |
| 2319 | continue; |
| 2320 | spin_lock_irq(&phba->ndlp_lock); |
| 2321 | NLP_SET_FREE_REQ(ndlp); |
| 2322 | spin_unlock_irq(&phba->ndlp_lock); |
| 2323 | /* Trigger the release of the ndlp memory */ |
| 2324 | lpfc_nlp_put(ndlp); |
| 2325 | continue; |
| 2326 | } |
| 2327 | spin_lock_irq(&phba->ndlp_lock); |
| 2328 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2329 | /* The ndlp should not be in memory free mode already */ |
| 2330 | spin_unlock_irq(&phba->ndlp_lock); |
| 2331 | continue; |
| 2332 | } else |
| 2333 | /* Indicate request for freeing ndlp memory */ |
| 2334 | NLP_SET_FREE_REQ(ndlp); |
| 2335 | spin_unlock_irq(&phba->ndlp_lock); |
| 2336 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2337 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2338 | ndlp->nlp_DID == Fabric_DID) { |
| 2339 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2340 | lpfc_nlp_put(ndlp); |
| 2341 | continue; |
| 2342 | } |
| 2343 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2344 | /* take care of nodes in unused state before the state |
| 2345 | * machine taking action. |
| 2346 | */ |
| 2347 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2348 | lpfc_nlp_put(ndlp); |
| 2349 | continue; |
| 2350 | } |
| 2351 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2352 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2353 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2354 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2355 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2356 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2357 | NLP_EVT_DEVICE_RM); |
| 2358 | } |
| 2359 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2360 | /* At this point, ALL ndlp's should be gone |
| 2361 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2362 | * Lets wait for this to happen, if needed. |
| 2363 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2364 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2365 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2366 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2367 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2368 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2369 | &vport->fc_nodes, nlp_listp) { |
| 2370 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2371 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2372 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2373 | "usgmap:x%x refcnt:%d\n", |
| 2374 | ndlp->nlp_DID, (void *)ndlp, |
| 2375 | ndlp->nlp_usg_map, |
| 2376 | atomic_read( |
| 2377 | &ndlp->kref.refcount)); |
| 2378 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2379 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2380 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2381 | |
| 2382 | /* Wait for any activity on ndlps to settle */ |
| 2383 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2384 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2385 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | } |
| 2387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2388 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2389 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2390 | * @vport: pointer to a virtual N_Port data structure. |
| 2391 | * |
| 2392 | * This routine stops all the timers associated with a @vport. This function |
| 2393 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2394 | * port is treated as @vport 0. |
| 2395 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2396 | void |
| 2397 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2399 | del_timer_sync(&vport->els_tmofunc); |
| 2400 | del_timer_sync(&vport->fc_fdmitmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2401 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2402 | lpfc_can_disctmo(vport); |
| 2403 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | } |
| 2405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2406 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2407 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2408 | * @phba: pointer to lpfc hba data structure. |
| 2409 | * |
| 2410 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2411 | * caller of this routine should already hold the host lock. |
| 2412 | **/ |
| 2413 | void |
| 2414 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2415 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2416 | /* Clear pending FCF rediscovery wait flag */ |
| 2417 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2418 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2419 | /* Now, try to stop the timer */ |
| 2420 | del_timer(&phba->fcf.redisc_wait); |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2425 | * @phba: pointer to lpfc hba data structure. |
| 2426 | * |
| 2427 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2428 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2429 | * lock held before proceeding with disabling the timer and clearing the |
| 2430 | * wait timer pendig flag. |
| 2431 | **/ |
| 2432 | void |
| 2433 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2434 | { |
| 2435 | spin_lock_irq(&phba->hbalock); |
| 2436 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2437 | /* FCF rediscovery timer already fired or stopped */ |
| 2438 | spin_unlock_irq(&phba->hbalock); |
| 2439 | return; |
| 2440 | } |
| 2441 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2442 | /* Clear failover in progress flags */ |
| 2443 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2444 | spin_unlock_irq(&phba->hbalock); |
| 2445 | } |
| 2446 | |
| 2447 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2448 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2449 | * @phba: pointer to lpfc hba data structure. |
| 2450 | * |
| 2451 | * This routine stops all the timers associated with a HBA. This function is |
| 2452 | * invoked before either putting a HBA offline or unloading the driver. |
| 2453 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2454 | void |
| 2455 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2457 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2459 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2460 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2461 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2462 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2463 | del_timer_sync(&phba->rrq_tmr); |
| 2464 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2465 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2466 | phba->hb_outstanding = 0; |
| 2467 | |
| 2468 | switch (phba->pci_dev_grp) { |
| 2469 | case LPFC_PCI_DEV_LP: |
| 2470 | /* Stop any LightPulse device specific driver timers */ |
| 2471 | del_timer_sync(&phba->fcp_poll_timer); |
| 2472 | break; |
| 2473 | case LPFC_PCI_DEV_OC: |
| 2474 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2475 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2476 | break; |
| 2477 | default: |
| 2478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2479 | "0297 Invalid device group (x%x)\n", |
| 2480 | phba->pci_dev_grp); |
| 2481 | break; |
| 2482 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2483 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2484 | } |
| 2485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2486 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2487 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2488 | * @phba: pointer to lpfc hba data structure. |
| 2489 | * |
| 2490 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2491 | * management interface is marked as blocked, all the user space access to |
| 2492 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2493 | * all be blocked. The HBA is set to block the management interface when the |
| 2494 | * driver prepares the HBA interface for online or offline. |
| 2495 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2496 | static void |
| 2497 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| 2498 | { |
| 2499 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2500 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2501 | unsigned long timeout; |
| 2502 | |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2503 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2504 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2505 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2506 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2507 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2508 | /* Determine how long we might wait for the active mailbox |
| 2509 | * command to be gracefully completed by firmware. |
| 2510 | */ |
| 2511 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2512 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2513 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2514 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2515 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2516 | /* Wait for the outstnading mailbox command to complete */ |
| 2517 | while (phba->sli.mbox_active) { |
| 2518 | /* Check active mailbox complete status every 2ms */ |
| 2519 | msleep(2); |
| 2520 | if (time_after(jiffies, timeout)) { |
| 2521 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2522 | "2813 Mgmt IO is Blocked %x " |
| 2523 | "- mbox cmd %x still active\n", |
| 2524 | phba->sli.sli_flag, actcmd); |
| 2525 | break; |
| 2526 | } |
| 2527 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2530 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2531 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2532 | * @phba: pointer to lpfc hba data structure. |
| 2533 | * |
| 2534 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2535 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2536 | * is to fixup the temporary rpi assignments. |
| 2537 | **/ |
| 2538 | void |
| 2539 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 2540 | { |
| 2541 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 2542 | struct lpfc_vport **vports; |
| 2543 | int i; |
| 2544 | |
| 2545 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 2546 | return; |
| 2547 | |
| 2548 | vports = lpfc_create_vport_work_array(phba); |
| 2549 | if (vports != NULL) { |
| 2550 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 2551 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2552 | continue; |
| 2553 | |
| 2554 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2555 | &vports[i]->fc_nodes, |
| 2556 | nlp_listp) { |
| 2557 | if (NLP_CHK_NODE_ACT(ndlp)) |
| 2558 | ndlp->nlp_rpi = |
| 2559 | lpfc_sli4_alloc_rpi(phba); |
| 2560 | } |
| 2561 | } |
| 2562 | } |
| 2563 | lpfc_destroy_vport_work_array(phba, vports); |
| 2564 | } |
| 2565 | |
| 2566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2567 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2568 | * @phba: pointer to lpfc hba data structure. |
| 2569 | * |
| 2570 | * This routine initializes the HBA and brings a HBA online. During this |
| 2571 | * process, the management interface is blocked to prevent user space access |
| 2572 | * to the HBA interfering with the driver initialization. |
| 2573 | * |
| 2574 | * Return codes |
| 2575 | * 0 - successful |
| 2576 | * 1 - failed |
| 2577 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2579 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2580 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2581 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2582 | struct lpfc_vport **vports; |
| 2583 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2584 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2585 | if (!phba) |
| 2586 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 2587 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2588 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2589 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2590 | return 0; |
| 2591 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2592 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2593 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2594 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2595 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2597 | if (!lpfc_sli_queue_setup(phba)) { |
| 2598 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2600 | } |
| 2601 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2602 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2603 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 2604 | lpfc_unblock_mgmt_io(phba); |
| 2605 | return 1; |
| 2606 | } |
| 2607 | } else { |
| 2608 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 2609 | lpfc_unblock_mgmt_io(phba); |
| 2610 | return 1; |
| 2611 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2614 | vports = lpfc_create_vport_work_array(phba); |
| 2615 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2616 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2617 | struct Scsi_Host *shost; |
| 2618 | shost = lpfc_shost_from_vport(vports[i]); |
| 2619 | spin_lock_irq(shost->host_lock); |
| 2620 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 2621 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 2622 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2623 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2624 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2625 | spin_unlock_irq(shost->host_lock); |
| 2626 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2627 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2629 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | return 0; |
| 2631 | } |
| 2632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2634 | * 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] | 2635 | * @phba: pointer to lpfc hba data structure. |
| 2636 | * |
| 2637 | * This routine marks a HBA's management interface as not blocked. Once the |
| 2638 | * HBA's management interface is marked as not blocked, all the user space |
| 2639 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 2640 | * interface will be allowed. The HBA is set to block the management interface |
| 2641 | * when the driver prepares the HBA interface for online or offline and then |
| 2642 | * set to unblock the management interface afterwards. |
| 2643 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2644 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2645 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 2646 | { |
| 2647 | unsigned long iflag; |
| 2648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2649 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2650 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 2651 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2652 | } |
| 2653 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2654 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2655 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2656 | * @phba: pointer to lpfc hba data structure. |
| 2657 | * |
| 2658 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 2659 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 2660 | * queue to make it ready to be brought offline. |
| 2661 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2662 | void |
| 2663 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 2664 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2665 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2666 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2667 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2668 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2669 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2671 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2672 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2674 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | |
| 2676 | lpfc_linkdown(phba); |
| 2677 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2678 | /* Issue an unreg_login to all nodes on all vports */ |
| 2679 | vports = lpfc_create_vport_work_array(phba); |
| 2680 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2681 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2682 | if (vports[i]->load_flag & FC_UNLOADING) |
| 2683 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2684 | shost = lpfc_shost_from_vport(vports[i]); |
| 2685 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2686 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2687 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 2688 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 2689 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2690 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2691 | shost = lpfc_shost_from_vport(vports[i]); |
| 2692 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2693 | &vports[i]->fc_nodes, |
| 2694 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2695 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2696 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2697 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 2698 | continue; |
| 2699 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 2700 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2701 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 2702 | lpfc_disc_state_machine(vports[i], ndlp, |
| 2703 | NULL, NLP_EVT_DEVICE_RM); |
| 2704 | } |
| 2705 | spin_lock_irq(shost->host_lock); |
| 2706 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2707 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2708 | /* |
| 2709 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 2710 | * RPI. Get a new RPI when the adapter port |
| 2711 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2712 | */ |
| 2713 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2714 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2715 | lpfc_unreg_rpi(vports[i], ndlp); |
| 2716 | } |
| 2717 | } |
| 2718 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2719 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2721 | lpfc_sli_mbox_sys_shutdown(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2725 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2726 | * @phba: pointer to lpfc hba data structure. |
| 2727 | * |
| 2728 | * This routine actually brings a HBA offline. It stops all the timers |
| 2729 | * associated with the HBA, brings down the SLI layer, and eventually |
| 2730 | * marks the HBA as in offline state for the upper layer protocol. |
| 2731 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2732 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2733 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2734 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2735 | struct Scsi_Host *shost; |
| 2736 | struct lpfc_vport **vports; |
| 2737 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2738 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2739 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2740 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 2741 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2742 | /* stop port and all timers associated with this hba */ |
| 2743 | lpfc_stop_port(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2744 | vports = lpfc_create_vport_work_array(phba); |
| 2745 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2746 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2747 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2748 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2749 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2750 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 2752 | now. */ |
| 2753 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2754 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2755 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2756 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2757 | vports = lpfc_create_vport_work_array(phba); |
| 2758 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2759 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2760 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2761 | spin_lock_irq(shost->host_lock); |
| 2762 | vports[i]->work_port_events = 0; |
| 2763 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 2764 | spin_unlock_irq(shost->host_lock); |
| 2765 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2766 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2767 | } |
| 2768 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2769 | /** |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 2770 | * lpfc_scsi_buf_update - Update the scsi_buffers that are already allocated. |
| 2771 | * @phba: pointer to lpfc hba data structure. |
| 2772 | * |
| 2773 | * This routine goes through all the scsi buffers in the system and updates the |
| 2774 | * Physical XRIs assigned to the SCSI buffer because these may change after any |
| 2775 | * firmware reset |
| 2776 | * |
| 2777 | * Return codes |
| 2778 | * 0 - successful (for now, it always returns 0) |
| 2779 | **/ |
| 2780 | int |
| 2781 | lpfc_scsi_buf_update(struct lpfc_hba *phba) |
| 2782 | { |
| 2783 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2784 | |
| 2785 | spin_lock_irq(&phba->hbalock); |
| 2786 | spin_lock(&phba->scsi_buf_list_lock); |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 2787 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 2788 | sb->cur_iocbq.sli4_xritag = |
| 2789 | phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag]; |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 2790 | set_bit(sb->cur_iocbq.sli4_lxritag, phba->sli4_hba.xri_bmask); |
| 2791 | phba->sli4_hba.max_cfg_param.xri_used++; |
| 2792 | phba->sli4_hba.xri_count++; |
| 2793 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 2794 | spin_unlock(&phba->scsi_buf_list_lock); |
| 2795 | spin_unlock_irq(&phba->hbalock); |
| 2796 | return 0; |
| 2797 | } |
| 2798 | |
| 2799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2800 | * 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] | 2801 | * @phba: pointer to lpfc hba data structure. |
| 2802 | * |
| 2803 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 2804 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 2805 | * the internal resources before the device is removed from the system. |
| 2806 | * |
| 2807 | * Return codes |
| 2808 | * 0 - successful (for now, it always returns 0) |
| 2809 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2810 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2811 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2812 | { |
| 2813 | struct lpfc_scsi_buf *sb, *sb_next; |
| 2814 | struct lpfc_iocbq *io, *io_next; |
| 2815 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2816 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2818 | spin_lock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2819 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 2820 | list_del(&sb->list); |
| 2821 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2822 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | kfree(sb); |
| 2824 | phba->total_scsi_bufs--; |
| 2825 | } |
James Smart | 1c6f4ef5 | 2009-11-18 15:40:49 -0500 | [diff] [blame] | 2826 | spin_unlock(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | |
| 2828 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 2829 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 2830 | list_del(&io->list); |
| 2831 | kfree(io); |
| 2832 | phba->total_iocbq_bufs--; |
| 2833 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2836 | return 0; |
| 2837 | } |
| 2838 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2840 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2841 | * @phba: pointer to lpfc hba data structure. |
| 2842 | * @instance: a unique integer ID to this FC port. |
| 2843 | * @dev: pointer to the device data structure. |
| 2844 | * |
| 2845 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 2846 | * can be created on top of either a physical port or a virtual port provided |
| 2847 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 2848 | * and associates the FC port created before adding the shost into the SCSI |
| 2849 | * layer. |
| 2850 | * |
| 2851 | * Return codes |
| 2852 | * @vport - pointer to the virtual N_Port data structure. |
| 2853 | * NULL - port create failed. |
| 2854 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2855 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2856 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2857 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2858 | struct lpfc_vport *vport; |
| 2859 | struct Scsi_Host *shost; |
| 2860 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2861 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2862 | if (dev != &phba->pcidev->dev) |
| 2863 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 2864 | sizeof(struct lpfc_vport)); |
| 2865 | else |
| 2866 | shost = scsi_host_alloc(&lpfc_template, |
| 2867 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2868 | if (!shost) |
| 2869 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2870 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2871 | vport = (struct lpfc_vport *) shost->hostdata; |
| 2872 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2873 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2874 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2875 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2876 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2877 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2878 | shost->unique_id = instance; |
| 2879 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2880 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2881 | shost->this_id = -1; |
| 2882 | shost->max_cmd_len = 16; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2883 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2884 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 2885 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2886 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 2887 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 2888 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2889 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | * Set initial can_queue value since 0 is no longer supported and |
| 2891 | * scsi_add_host will fail. This will be adjusted later based on the |
| 2892 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2893 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2894 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2895 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2896 | shost->transportt = lpfc_vport_transport_template; |
| 2897 | vport->port_type = LPFC_NPIV_PORT; |
| 2898 | } else { |
| 2899 | shost->transportt = lpfc_transport_template; |
| 2900 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 2901 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2902 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2903 | /* Initialize all internally managed lists. */ |
| 2904 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2905 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2906 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2907 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2908 | init_timer(&vport->fc_disctmo); |
| 2909 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2910 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2911 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2912 | init_timer(&vport->fc_fdmitmo); |
| 2913 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2914 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2915 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2916 | init_timer(&vport->els_tmofunc); |
| 2917 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2918 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2919 | |
| 2920 | init_timer(&vport->delayed_disc_tmo); |
| 2921 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; |
| 2922 | vport->delayed_disc_tmo.data = (unsigned long)vport; |
| 2923 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 2924 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2925 | if (error) |
| 2926 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2927 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2928 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2929 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2930 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2931 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2932 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2933 | out_put_shost: |
| 2934 | scsi_host_put(shost); |
| 2935 | out: |
| 2936 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2937 | } |
| 2938 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2939 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2940 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2941 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 2942 | * |
| 2943 | * This routine destroys a FC port from the upper layer protocol. All the |
| 2944 | * resources associated with the port are released. |
| 2945 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2946 | void |
| 2947 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2948 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2949 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2950 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2951 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2952 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2953 | fc_remove_host(shost); |
| 2954 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2955 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2956 | spin_lock_irq(&phba->hbalock); |
| 2957 | list_del_init(&vport->listentry); |
| 2958 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2959 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2960 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2961 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2962 | } |
| 2963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2964 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2965 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2966 | * |
| 2967 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 2968 | * uses the kernel idr facility to perform the task. |
| 2969 | * |
| 2970 | * Return codes: |
| 2971 | * instance - a unique integer ID allocated as the new instance. |
| 2972 | * -1 - lpfc get instance failed. |
| 2973 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2974 | int |
| 2975 | lpfc_get_instance(void) |
| 2976 | { |
| 2977 | int instance = 0; |
| 2978 | |
| 2979 | /* Assign an unused number */ |
| 2980 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 2981 | return -1; |
| 2982 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 2983 | return -1; |
| 2984 | return instance; |
| 2985 | } |
| 2986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2987 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2988 | * 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] | 2989 | * @shost: pointer to SCSI host data structure. |
| 2990 | * @time: elapsed time of the scan in jiffies. |
| 2991 | * |
| 2992 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 2993 | * whether the scan host is finished. |
| 2994 | * |
| 2995 | * Note: there is no scan_start function as adapter initialization will have |
| 2996 | * asynchronously kicked off the link initialization. |
| 2997 | * |
| 2998 | * Return codes |
| 2999 | * 0 - SCSI host scan is not over yet. |
| 3000 | * 1 - SCSI host scan is over. |
| 3001 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3002 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 3003 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3004 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3005 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3006 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3007 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3008 | spin_lock_irq(shost->host_lock); |
| 3009 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3010 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3011 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3012 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3013 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3014 | if (time >= 30 * HZ) { |
| 3015 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3016 | "0461 Scanning longer than 30 " |
| 3017 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3018 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3019 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3020 | } |
| 3021 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 3022 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3023 | "0465 Link down longer than 15 " |
| 3024 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3025 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3026 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3027 | } |
| 3028 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3029 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3030 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3031 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3032 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3033 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3034 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3036 | goto finished; |
| 3037 | |
| 3038 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3039 | |
| 3040 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3041 | spin_unlock_irq(shost->host_lock); |
| 3042 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3043 | } |
| 3044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3046 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3047 | * @shost: pointer to SCSI host data structure. |
| 3048 | * |
| 3049 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 3050 | * SCSI host can be either on top of a physical port or a virtual port. |
| 3051 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3052 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 3053 | { |
| 3054 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 3055 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3056 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3057 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3058 | */ |
| 3059 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3060 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 3061 | 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] | 3062 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 3063 | |
| 3064 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3065 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3066 | fc_host_supported_fc4s(shost)[2] = 1; |
| 3067 | fc_host_supported_fc4s(shost)[7] = 1; |
| 3068 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3069 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 3070 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3071 | |
| 3072 | fc_host_supported_speeds(shost) = 0; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3073 | if (phba->lmt & LMT_16Gb) |
| 3074 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3075 | if (phba->lmt & LMT_10Gb) |
| 3076 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3077 | if (phba->lmt & LMT_8Gb) |
| 3078 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3079 | if (phba->lmt & LMT_4Gb) |
| 3080 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 3081 | if (phba->lmt & LMT_2Gb) |
| 3082 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 3083 | if (phba->lmt & LMT_1Gb) |
| 3084 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 3085 | |
| 3086 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3087 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 3088 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3089 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 3090 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 3091 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3092 | /* This value is also unchanging */ |
| 3093 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3094 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3095 | fc_host_active_fc4s(shost)[2] = 1; |
| 3096 | fc_host_active_fc4s(shost)[7] = 1; |
| 3097 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3098 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3099 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3100 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3101 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3102 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3104 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3105 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3106 | * @phba: pointer to lpfc hba data structure. |
| 3107 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3108 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 3109 | * from generating interrupts and stops the device driver's timers for the |
| 3110 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3111 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3112 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3113 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3114 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3115 | /* Clear all interrupt enable conditions */ |
| 3116 | writel(0, phba->HCregaddr); |
| 3117 | readl(phba->HCregaddr); /* flush */ |
| 3118 | /* Clear all pending interrupts */ |
| 3119 | writel(0xffffffff, phba->HAregaddr); |
| 3120 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3121 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3122 | /* Reset some HBA SLI setup states */ |
| 3123 | lpfc_stop_hba_timers(phba); |
| 3124 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 3125 | } |
| 3126 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3127 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3128 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3129 | * @phba: pointer to lpfc hba data structure. |
| 3130 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3131 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 3132 | * from generating interrupts and stops the device driver's timers for the |
| 3133 | * device. |
| 3134 | **/ |
| 3135 | static void |
| 3136 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 3137 | { |
| 3138 | /* Reset some HBA SLI4 setup states */ |
| 3139 | lpfc_stop_hba_timers(phba); |
| 3140 | phba->pport->work_port_events = 0; |
| 3141 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 3146 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3147 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3148 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 3149 | * the API jump table function pointer from the lpfc_hba struct. |
| 3150 | **/ |
| 3151 | void |
| 3152 | lpfc_stop_port(struct lpfc_hba *phba) |
| 3153 | { |
| 3154 | phba->lpfc_stop_port(phba); |
| 3155 | } |
| 3156 | |
| 3157 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3158 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 3159 | * @phba: Pointer to hba for which this call is being executed. |
| 3160 | * |
| 3161 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 3162 | **/ |
| 3163 | void |
| 3164 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 3165 | { |
| 3166 | unsigned long fcf_redisc_wait_tmo = |
| 3167 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 3168 | /* Start fcf rediscovery wait period timer */ |
| 3169 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 3170 | spin_lock_irq(&phba->hbalock); |
| 3171 | /* Allow action to new fcf asynchronous event */ |
| 3172 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 3173 | /* Mark the FCF rediscovery pending state */ |
| 3174 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 3175 | spin_unlock_irq(&phba->hbalock); |
| 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 3180 | * @ptr: Map to lpfc_hba data structure pointer. |
| 3181 | * |
| 3182 | * This routine is invoked when waiting for FCF table rediscover has been |
| 3183 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 3184 | * wait period, a new FCF event shall be added to the FCOE async event |
| 3185 | * list, and then worker thread shall be waked up for processing from the |
| 3186 | * worker thread context. |
| 3187 | **/ |
| 3188 | void |
| 3189 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
| 3190 | { |
| 3191 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; |
| 3192 | |
| 3193 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 3194 | spin_lock_irq(&phba->hbalock); |
| 3195 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3196 | spin_unlock_irq(&phba->hbalock); |
| 3197 | return; |
| 3198 | } |
| 3199 | /* Clear FCF rediscovery timer pending flag */ |
| 3200 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 3201 | /* FCF rediscovery event to worker thread */ |
| 3202 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 3203 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3204 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3205 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3206 | /* wake up worker thread */ |
| 3207 | lpfc_worker_wake_up(phba); |
| 3208 | } |
| 3209 | |
| 3210 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3211 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 3212 | * @phba: pointer to lpfc hba data structure. |
| 3213 | * @acqe_link: pointer to the async link completion queue entry. |
| 3214 | * |
| 3215 | * This routine is to parse the SLI4 link-attention link fault code and |
| 3216 | * translate it into the base driver's read link attention mailbox command |
| 3217 | * status. |
| 3218 | * |
| 3219 | * Return: Link-attention status in terms of base driver's coding. |
| 3220 | **/ |
| 3221 | static uint16_t |
| 3222 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 3223 | struct lpfc_acqe_link *acqe_link) |
| 3224 | { |
| 3225 | uint16_t latt_fault; |
| 3226 | |
| 3227 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 3228 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 3229 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 3230 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 3231 | latt_fault = 0; |
| 3232 | break; |
| 3233 | default: |
| 3234 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3235 | "0398 Invalid link fault code: x%x\n", |
| 3236 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 3237 | latt_fault = MBXERR_ERROR; |
| 3238 | break; |
| 3239 | } |
| 3240 | return latt_fault; |
| 3241 | } |
| 3242 | |
| 3243 | /** |
| 3244 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 3245 | * @phba: pointer to lpfc hba data structure. |
| 3246 | * @acqe_link: pointer to the async link completion queue entry. |
| 3247 | * |
| 3248 | * This routine is to parse the SLI4 link attention type and translate it |
| 3249 | * into the base driver's link attention type coding. |
| 3250 | * |
| 3251 | * Return: Link attention type in terms of base driver's coding. |
| 3252 | **/ |
| 3253 | static uint8_t |
| 3254 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 3255 | struct lpfc_acqe_link *acqe_link) |
| 3256 | { |
| 3257 | uint8_t att_type; |
| 3258 | |
| 3259 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 3260 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 3261 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3262 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3263 | break; |
| 3264 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 3265 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3266 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3267 | break; |
| 3268 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3269 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3270 | break; |
| 3271 | default: |
| 3272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3273 | "0399 Invalid link attention type: x%x\n", |
| 3274 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3275 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3276 | break; |
| 3277 | } |
| 3278 | return att_type; |
| 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
| 3283 | * @phba: pointer to lpfc hba data structure. |
| 3284 | * @acqe_link: pointer to the async link completion queue entry. |
| 3285 | * |
| 3286 | * This routine is to parse the SLI4 link-attention link speed and translate |
| 3287 | * it into the base driver's link-attention link speed coding. |
| 3288 | * |
| 3289 | * Return: Link-attention link speed in terms of base driver's coding. |
| 3290 | **/ |
| 3291 | static uint8_t |
| 3292 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, |
| 3293 | struct lpfc_acqe_link *acqe_link) |
| 3294 | { |
| 3295 | uint8_t link_speed; |
| 3296 | |
| 3297 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { |
| 3298 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3299 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3300 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3301 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3302 | break; |
| 3303 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3304 | link_speed = LPFC_LINK_SPEED_1GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3305 | break; |
| 3306 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3307 | link_speed = LPFC_LINK_SPEED_10GHZ; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3308 | break; |
| 3309 | default: |
| 3310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3311 | "0483 Invalid link-attention link speed: x%x\n", |
| 3312 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3313 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3314 | break; |
| 3315 | } |
| 3316 | return link_speed; |
| 3317 | } |
| 3318 | |
| 3319 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3320 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3321 | * @phba: pointer to lpfc hba data structure. |
| 3322 | * @acqe_link: pointer to the async link completion queue entry. |
| 3323 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3324 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3325 | **/ |
| 3326 | static void |
| 3327 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 3328 | struct lpfc_acqe_link *acqe_link) |
| 3329 | { |
| 3330 | struct lpfc_dmabuf *mp; |
| 3331 | LPFC_MBOXQ_t *pmb; |
| 3332 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3333 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3334 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3335 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3336 | |
| 3337 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3338 | 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] | 3339 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 3340 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3341 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3342 | if (!pmb) { |
| 3343 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3344 | "0395 The mboxq allocation failed\n"); |
| 3345 | return; |
| 3346 | } |
| 3347 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3348 | if (!mp) { |
| 3349 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3350 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 3351 | goto out_free_pmb; |
| 3352 | } |
| 3353 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3354 | if (!mp->virt) { |
| 3355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3356 | "0397 The mbuf allocation failed\n"); |
| 3357 | goto out_free_dmabuf; |
| 3358 | } |
| 3359 | |
| 3360 | /* Cleanup any outstanding ELS commands */ |
| 3361 | lpfc_els_flush_all_cmd(phba); |
| 3362 | |
| 3363 | /* Block ELS IOCBs until we have done process link event */ |
| 3364 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3365 | |
| 3366 | /* Update link event statistics */ |
| 3367 | phba->sli.slistat.link_event++; |
| 3368 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3369 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3370 | lpfc_read_topology(phba, pmb, mp); |
| 3371 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3372 | pmb->vport = phba->pport; |
| 3373 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3374 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3375 | phba->sli4_hba.link_state.speed = |
| 3376 | bf_get(lpfc_acqe_link_speed, acqe_link); |
| 3377 | phba->sli4_hba.link_state.duplex = |
| 3378 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 3379 | phba->sli4_hba.link_state.status = |
| 3380 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3381 | phba->sli4_hba.link_state.type = |
| 3382 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 3383 | phba->sli4_hba.link_state.number = |
| 3384 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3385 | phba->sli4_hba.link_state.fault = |
| 3386 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 3387 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3388 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
| 3389 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 3390 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 3391 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 3392 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3393 | phba->sli4_hba.link_state.speed, |
| 3394 | phba->sli4_hba.link_state.topology, |
| 3395 | phba->sli4_hba.link_state.status, |
| 3396 | phba->sli4_hba.link_state.type, |
| 3397 | phba->sli4_hba.link_state.number, |
| 3398 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3399 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3400 | /* |
| 3401 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 3402 | * topology info. Note: Optional for non FC-AL ports. |
| 3403 | */ |
| 3404 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 3405 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3406 | if (rc == MBX_NOT_FINISHED) |
| 3407 | goto out_free_dmabuf; |
| 3408 | return; |
| 3409 | } |
| 3410 | /* |
| 3411 | * For FCoE Mode: fill in all the topology information we need and call |
| 3412 | * the READ_TOPOLOGY completion routine to continue without actually |
| 3413 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 3414 | */ |
| 3415 | /* Parse and translate status field */ |
| 3416 | mb = &pmb->u.mb; |
| 3417 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 3418 | |
| 3419 | /* Parse and translate link attention fields */ |
| 3420 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 3421 | la->eventTag = acqe_link->event_tag; |
| 3422 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 3423 | bf_set(lpfc_mbx_read_top_link_spd, la, |
| 3424 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); |
| 3425 | |
| 3426 | /* Fake the the following irrelvant fields */ |
| 3427 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 3428 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 3429 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 3430 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 3431 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 3432 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3433 | |
| 3434 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3435 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3436 | |
| 3437 | return; |
| 3438 | |
| 3439 | out_free_dmabuf: |
| 3440 | kfree(mp); |
| 3441 | out_free_pmb: |
| 3442 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3443 | } |
| 3444 | |
| 3445 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3446 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 3447 | * @phba: pointer to lpfc hba data structure. |
| 3448 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 3449 | * |
| 3450 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 3451 | * that the event was received and then issue a read_topology mailbox command so |
| 3452 | * that the rest of the driver will treat it the same as SLI3. |
| 3453 | **/ |
| 3454 | static void |
| 3455 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 3456 | { |
| 3457 | struct lpfc_dmabuf *mp; |
| 3458 | LPFC_MBOXQ_t *pmb; |
| 3459 | int rc; |
| 3460 | |
| 3461 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 3462 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 3463 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3464 | "2895 Non FC link Event detected.(%d)\n", |
| 3465 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 3466 | return; |
| 3467 | } |
| 3468 | /* Keep the link status for extra SLI4 state machine reference */ |
| 3469 | phba->sli4_hba.link_state.speed = |
| 3470 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); |
| 3471 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 3472 | phba->sli4_hba.link_state.topology = |
| 3473 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 3474 | phba->sli4_hba.link_state.status = |
| 3475 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 3476 | phba->sli4_hba.link_state.type = |
| 3477 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 3478 | phba->sli4_hba.link_state.number = |
| 3479 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 3480 | phba->sli4_hba.link_state.fault = |
| 3481 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 3482 | phba->sli4_hba.link_state.logical_speed = |
| 3483 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); |
| 3484 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3485 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 3486 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 3487 | "%dMbps Fault:%d\n", |
| 3488 | phba->sli4_hba.link_state.speed, |
| 3489 | phba->sli4_hba.link_state.topology, |
| 3490 | phba->sli4_hba.link_state.status, |
| 3491 | phba->sli4_hba.link_state.type, |
| 3492 | phba->sli4_hba.link_state.number, |
| 3493 | phba->sli4_hba.link_state.logical_speed * 10, |
| 3494 | phba->sli4_hba.link_state.fault); |
| 3495 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3496 | if (!pmb) { |
| 3497 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3498 | "2897 The mboxq allocation failed\n"); |
| 3499 | return; |
| 3500 | } |
| 3501 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3502 | if (!mp) { |
| 3503 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3504 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 3505 | goto out_free_pmb; |
| 3506 | } |
| 3507 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 3508 | if (!mp->virt) { |
| 3509 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3510 | "2899 The mbuf allocation failed\n"); |
| 3511 | goto out_free_dmabuf; |
| 3512 | } |
| 3513 | |
| 3514 | /* Cleanup any outstanding ELS commands */ |
| 3515 | lpfc_els_flush_all_cmd(phba); |
| 3516 | |
| 3517 | /* Block ELS IOCBs until we have done process link event */ |
| 3518 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 3519 | |
| 3520 | /* Update link event statistics */ |
| 3521 | phba->sli.slistat.link_event++; |
| 3522 | |
| 3523 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 3524 | lpfc_read_topology(phba, pmb, mp); |
| 3525 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 3526 | pmb->vport = phba->pport; |
| 3527 | |
| 3528 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 3529 | if (rc == MBX_NOT_FINISHED) |
| 3530 | goto out_free_dmabuf; |
| 3531 | return; |
| 3532 | |
| 3533 | out_free_dmabuf: |
| 3534 | kfree(mp); |
| 3535 | out_free_pmb: |
| 3536 | mempool_free(pmb, phba->mbox_mem_pool); |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 3541 | * @phba: pointer to lpfc hba data structure. |
| 3542 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 3543 | * |
| 3544 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 3545 | **/ |
| 3546 | static void |
| 3547 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 3548 | { |
| 3549 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3550 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 3551 | "x%08x SLI Event Type:%d", |
| 3552 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 3553 | bf_get(lpfc_trailer_type, acqe_sli)); |
| 3554 | return; |
| 3555 | } |
| 3556 | |
| 3557 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3558 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 3559 | * @vport: pointer to vport data structure. |
| 3560 | * |
| 3561 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 3562 | * response to a CVL event. |
| 3563 | * |
| 3564 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 3565 | * return NULL. |
| 3566 | **/ |
| 3567 | static struct lpfc_nodelist * |
| 3568 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 3569 | { |
| 3570 | struct lpfc_nodelist *ndlp; |
| 3571 | struct Scsi_Host *shost; |
| 3572 | struct lpfc_hba *phba; |
| 3573 | |
| 3574 | if (!vport) |
| 3575 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3576 | phba = vport->phba; |
| 3577 | if (!phba) |
| 3578 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 3579 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 3580 | if (!ndlp) { |
| 3581 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 3582 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3583 | if (!ndlp) |
| 3584 | return 0; |
| 3585 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
| 3586 | /* Set the node type */ |
| 3587 | ndlp->nlp_type |= NLP_FABRIC; |
| 3588 | /* Put ndlp onto node list */ |
| 3589 | lpfc_enqueue_node(vport, ndlp); |
| 3590 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 3591 | /* re-setup ndlp without removing from node list */ |
| 3592 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 3593 | if (!ndlp) |
| 3594 | return 0; |
| 3595 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3596 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 3597 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3598 | return NULL; |
| 3599 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3600 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 3601 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3602 | return NULL; |
| 3603 | shost = lpfc_shost_from_vport(vport); |
| 3604 | if (!shost) |
| 3605 | return NULL; |
| 3606 | lpfc_linkdown_port(vport); |
| 3607 | lpfc_cleanup_pending_mbox(vport); |
| 3608 | spin_lock_irq(shost->host_lock); |
| 3609 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 3610 | spin_unlock_irq(shost->host_lock); |
| 3611 | |
| 3612 | return ndlp; |
| 3613 | } |
| 3614 | |
| 3615 | /** |
| 3616 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 3617 | * @vport: pointer to lpfc hba data structure. |
| 3618 | * |
| 3619 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 3620 | * response to a FCF dead event. |
| 3621 | **/ |
| 3622 | static void |
| 3623 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 3624 | { |
| 3625 | struct lpfc_vport **vports; |
| 3626 | int i; |
| 3627 | |
| 3628 | vports = lpfc_create_vport_work_array(phba); |
| 3629 | if (vports) |
| 3630 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 3631 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 3632 | lpfc_destroy_vport_work_array(phba, vports); |
| 3633 | } |
| 3634 | |
| 3635 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3636 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3637 | * @phba: pointer to lpfc hba data structure. |
| 3638 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 3639 | * |
| 3640 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 3641 | **/ |
| 3642 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3643 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3644 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3645 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3646 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3647 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3648 | struct lpfc_vport *vport; |
| 3649 | struct lpfc_nodelist *ndlp; |
| 3650 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3651 | int active_vlink_present; |
| 3652 | struct lpfc_vport **vports; |
| 3653 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3654 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3655 | phba->fc_eventTag = acqe_fip->event_tag; |
| 3656 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3657 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3658 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 3659 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 3660 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3661 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 3662 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3663 | "2546 New FCF event, evt_tag:x%x, " |
| 3664 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3665 | acqe_fip->event_tag, |
| 3666 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 3667 | else |
| 3668 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 3669 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3670 | "2788 FCF param modified event, " |
| 3671 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3672 | acqe_fip->event_tag, |
| 3673 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3674 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3675 | /* |
| 3676 | * During period of FCF discovery, read the FCF |
| 3677 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3678 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3679 | */ |
| 3680 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 3681 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3682 | "2779 Read FCF (x%x) for updating " |
| 3683 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3684 | acqe_fip->index); |
| 3685 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3686 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3687 | |
| 3688 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3689 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3690 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3691 | spin_unlock_irq(&phba->hbalock); |
| 3692 | break; |
| 3693 | } |
| 3694 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 3695 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 3696 | spin_unlock_irq(&phba->hbalock); |
| 3697 | break; |
| 3698 | } |
| 3699 | |
| 3700 | /* If the FCF has been in discovered state, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 3701 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
| 3702 | spin_unlock_irq(&phba->hbalock); |
| 3703 | break; |
| 3704 | } |
| 3705 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3706 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3707 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 3708 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3709 | "2770 Start FCF table scan per async FCF " |
| 3710 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3711 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3712 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 3713 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3714 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3715 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 3716 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3717 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3718 | break; |
| 3719 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3720 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3721 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 3722 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3723 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 3724 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3725 | break; |
| 3726 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3727 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 3728 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3729 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3730 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3731 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3732 | /* |
| 3733 | * If we are in the middle of FCF failover process, clear |
| 3734 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3735 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3736 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3737 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3738 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3739 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3740 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3741 | break; |
| 3742 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3743 | spin_unlock_irq(&phba->hbalock); |
| 3744 | |
| 3745 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3746 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3747 | break; |
| 3748 | |
| 3749 | /* |
| 3750 | * Otherwise, request the port to rediscover the entire FCF |
| 3751 | * table for a fast recovery from case that the current FCF |
| 3752 | * is no longer valid as we are not in the middle of FCF |
| 3753 | * failover process already. |
| 3754 | */ |
| 3755 | spin_lock_irq(&phba->hbalock); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3756 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3757 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3758 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3759 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3760 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 3761 | "2771 Start FCF fast failover process due to " |
| 3762 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3763 | "\n", acqe_fip->event_tag, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3764 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 3765 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3766 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 3767 | LOG_DISCOVERY, |
| 3768 | "2772 Issue FCF rediscover mabilbox " |
| 3769 | "command failed, fail through to FCF " |
| 3770 | "dead event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3771 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3772 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3773 | spin_unlock_irq(&phba->hbalock); |
| 3774 | /* |
| 3775 | * Last resort will fail over by treating this |
| 3776 | * as a link down to FCF registration. |
| 3777 | */ |
| 3778 | lpfc_sli4_fcf_dead_failthrough(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3779 | } else { |
| 3780 | /* Reset FCF roundrobin bmask for new discovery */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3781 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3782 | /* |
| 3783 | * Handling fast FCF failover to a DEAD FCF event is |
| 3784 | * considered equalivant to receiving CVL to all vports. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3785 | */ |
| 3786 | lpfc_sli4_perform_all_vport_cvl(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3787 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3788 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3789 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 3790 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3791 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3792 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3793 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 3794 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3795 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 3796 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3797 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3798 | if (!ndlp) |
| 3799 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3800 | active_vlink_present = 0; |
| 3801 | |
| 3802 | vports = lpfc_create_vport_work_array(phba); |
| 3803 | if (vports) { |
| 3804 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 3805 | i++) { |
| 3806 | if ((!(vports[i]->fc_flag & |
| 3807 | FC_VPORT_CVL_RCVD)) && |
| 3808 | (vports[i]->port_state > LPFC_FDISC)) { |
| 3809 | active_vlink_present = 1; |
| 3810 | break; |
| 3811 | } |
| 3812 | } |
| 3813 | lpfc_destroy_vport_work_array(phba, vports); |
| 3814 | } |
| 3815 | |
| 3816 | if (active_vlink_present) { |
| 3817 | /* |
| 3818 | * If there are other active VLinks present, |
| 3819 | * re-instantiate the Vlink using FDISC. |
| 3820 | */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3821 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3822 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3823 | spin_lock_irq(shost->host_lock); |
| 3824 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 3825 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3826 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 3827 | vport->port_state = LPFC_FDISC; |
| 3828 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3829 | /* |
| 3830 | * Otherwise, we request port to rediscover |
| 3831 | * the entire FCF table for a fast recovery |
| 3832 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3833 | * is no longer valid if we are not already |
| 3834 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3835 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3836 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3837 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3838 | spin_unlock_irq(&phba->hbalock); |
| 3839 | break; |
| 3840 | } |
| 3841 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3842 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3843 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3844 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 3845 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 3846 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3847 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3848 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3849 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3850 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 3851 | LOG_DISCOVERY, |
| 3852 | "2774 Issue FCF rediscover " |
| 3853 | "mabilbox command failed, " |
| 3854 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3855 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 3856 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 3857 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3858 | /* |
| 3859 | * Last resort will be re-try on the |
| 3860 | * the current registered FCF entry. |
| 3861 | */ |
| 3862 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 3863 | } else |
| 3864 | /* |
| 3865 | * Reset FCF roundrobin bmask for new |
| 3866 | * discovery. |
| 3867 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 3868 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 3869 | } |
| 3870 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3871 | default: |
| 3872 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3873 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3874 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3875 | break; |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | /** |
| 3880 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 3881 | * @phba: pointer to lpfc hba data structure. |
| 3882 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 3883 | * |
| 3884 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 3885 | **/ |
| 3886 | static void |
| 3887 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 3888 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 3889 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3890 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3891 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3892 | "0290 The SLI4 DCBX asynchronous event is not " |
| 3893 | "handled yet\n"); |
| 3894 | } |
| 3895 | |
| 3896 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 3897 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 3898 | * @phba: pointer to lpfc hba data structure. |
| 3899 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 3900 | * |
| 3901 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 3902 | * is an asynchronous notified of a logical link speed change. The Port |
| 3903 | * reports the logical link speed in units of 10Mbps. |
| 3904 | **/ |
| 3905 | static void |
| 3906 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 3907 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 3908 | { |
| 3909 | uint16_t prev_ll_spd; |
| 3910 | |
| 3911 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 3912 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 3913 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 3914 | phba->sli4_hba.link_state.logical_speed = |
| 3915 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); |
| 3916 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3917 | "2789 GRP5 Async Event: Updating logical link speed " |
| 3918 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), |
| 3919 | (phba->sli4_hba.link_state.logical_speed*10)); |
| 3920 | } |
| 3921 | |
| 3922 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3923 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 3924 | * @phba: pointer to lpfc hba data structure. |
| 3925 | * |
| 3926 | * This routine is invoked by the worker thread to process all the pending |
| 3927 | * SLI4 asynchronous events. |
| 3928 | **/ |
| 3929 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 3930 | { |
| 3931 | struct lpfc_cq_event *cq_event; |
| 3932 | |
| 3933 | /* First, declare the async event has been handled */ |
| 3934 | spin_lock_irq(&phba->hbalock); |
| 3935 | phba->hba_flag &= ~ASYNC_EVENT; |
| 3936 | spin_unlock_irq(&phba->hbalock); |
| 3937 | /* Now, handle all the async events */ |
| 3938 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 3939 | /* Get the first event from the head of the event queue */ |
| 3940 | spin_lock_irq(&phba->hbalock); |
| 3941 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 3942 | cq_event, struct lpfc_cq_event, list); |
| 3943 | spin_unlock_irq(&phba->hbalock); |
| 3944 | /* Process the asynchronous event */ |
| 3945 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 3946 | case LPFC_TRAILER_CODE_LINK: |
| 3947 | lpfc_sli4_async_link_evt(phba, |
| 3948 | &cq_event->cqe.acqe_link); |
| 3949 | break; |
| 3950 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3951 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3952 | break; |
| 3953 | case LPFC_TRAILER_CODE_DCBX: |
| 3954 | lpfc_sli4_async_dcbx_evt(phba, |
| 3955 | &cq_event->cqe.acqe_dcbx); |
| 3956 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 3957 | case LPFC_TRAILER_CODE_GRP5: |
| 3958 | lpfc_sli4_async_grp5_evt(phba, |
| 3959 | &cq_event->cqe.acqe_grp5); |
| 3960 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 3961 | case LPFC_TRAILER_CODE_FC: |
| 3962 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 3963 | break; |
| 3964 | case LPFC_TRAILER_CODE_SLI: |
| 3965 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 3966 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3967 | default: |
| 3968 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3969 | "1804 Invalid asynchrous event code: " |
| 3970 | "x%x\n", bf_get(lpfc_trailer_code, |
| 3971 | &cq_event->cqe.mcqe_cmpl)); |
| 3972 | break; |
| 3973 | } |
| 3974 | /* Free the completion event processed to the free pool */ |
| 3975 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3980 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 3981 | * @phba: pointer to lpfc hba data structure. |
| 3982 | * |
| 3983 | * This routine is invoked by the worker thread to process FCF table |
| 3984 | * rediscovery pending completion event. |
| 3985 | **/ |
| 3986 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 3987 | { |
| 3988 | int rc; |
| 3989 | |
| 3990 | spin_lock_irq(&phba->hbalock); |
| 3991 | /* Clear FCF rediscovery timeout event */ |
| 3992 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 3993 | /* Clear driver fast failover FCF record flag */ |
| 3994 | phba->fcf.failover_rec.flag = 0; |
| 3995 | /* Set state for FCF fast failover */ |
| 3996 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 3997 | spin_unlock_irq(&phba->hbalock); |
| 3998 | |
| 3999 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4000 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4001 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4002 | 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] | 4003 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4004 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 4005 | "2747 Issue FCF scan read FCF mailbox " |
| 4006 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4010 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 4011 | * @phba: pointer to lpfc hba data structure. |
| 4012 | * @dev_grp: The HBA PCI-Device group number. |
| 4013 | * |
| 4014 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 4015 | * API jump table entries. |
| 4016 | * |
| 4017 | * Return: 0 if success, otherwise -ENODEV |
| 4018 | **/ |
| 4019 | int |
| 4020 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4021 | { |
| 4022 | int rc; |
| 4023 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4024 | /* Set up lpfc PCI-device group */ |
| 4025 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4026 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4027 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 4028 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 4029 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4030 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4031 | /* Set up device INIT API function jump table */ |
| 4032 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 4033 | if (rc) |
| 4034 | return -ENODEV; |
| 4035 | /* Set up SCSI API function jump table */ |
| 4036 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 4037 | if (rc) |
| 4038 | return -ENODEV; |
| 4039 | /* Set up SLI API function jump table */ |
| 4040 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 4041 | if (rc) |
| 4042 | return -ENODEV; |
| 4043 | /* Set up MBOX API function jump table */ |
| 4044 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 4045 | if (rc) |
| 4046 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4047 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4048 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4052 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4053 | * @phba: pointer to lpfc hba data structure. |
| 4054 | * @intr_mode: active interrupt mode adopted. |
| 4055 | * |
| 4056 | * This routine it invoked to log the currently used active interrupt mode |
| 4057 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4058 | **/ |
| 4059 | 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] | 4060 | { |
| 4061 | switch (intr_mode) { |
| 4062 | case 0: |
| 4063 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4064 | "0470 Enable INTx interrupt mode.\n"); |
| 4065 | break; |
| 4066 | case 1: |
| 4067 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4068 | "0481 Enabled MSI interrupt mode.\n"); |
| 4069 | break; |
| 4070 | case 2: |
| 4071 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4072 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 4073 | break; |
| 4074 | default: |
| 4075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4076 | "0482 Illegal interrupt mode.\n"); |
| 4077 | break; |
| 4078 | } |
| 4079 | return; |
| 4080 | } |
| 4081 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4082 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4083 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4084 | * @phba: pointer to lpfc hba data structure. |
| 4085 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4086 | * This routine is invoked to enable the PCI device that is common to all |
| 4087 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4088 | * |
| 4089 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4090 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4091 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4092 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4093 | static int |
| 4094 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4095 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4096 | struct pci_dev *pdev; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4097 | int bars = 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4098 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4099 | /* Obtain PCI device reference */ |
| 4100 | if (!phba->pcidev) |
| 4101 | goto out_error; |
| 4102 | else |
| 4103 | pdev = phba->pcidev; |
| 4104 | /* Select PCI BARs */ |
| 4105 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4106 | /* Enable PCI device */ |
| 4107 | if (pci_enable_device_mem(pdev)) |
| 4108 | goto out_error; |
| 4109 | /* Request PCI resource for the device */ |
| 4110 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| 4111 | goto out_disable_device; |
| 4112 | /* Set up device as PCI master and save state for EEH */ |
| 4113 | pci_set_master(pdev); |
| 4114 | pci_try_set_mwi(pdev); |
| 4115 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4116 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4117 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
| 4118 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) |
| 4119 | pdev->needs_freset = 1; |
| 4120 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4121 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4122 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4123 | out_disable_device: |
| 4124 | pci_disable_device(pdev); |
| 4125 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 4126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4127 | "1401 Failed to enable pci device, bars:x%x\n", bars); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4128 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4132 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4133 | * @phba: pointer to lpfc hba data structure. |
| 4134 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4135 | * This routine is invoked to disable the PCI device that is common to all |
| 4136 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4137 | **/ |
| 4138 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4139 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4140 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4141 | struct pci_dev *pdev; |
| 4142 | int bars; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4143 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4144 | /* Obtain PCI device reference */ |
| 4145 | if (!phba->pcidev) |
| 4146 | return; |
| 4147 | else |
| 4148 | pdev = phba->pcidev; |
| 4149 | /* Select PCI BARs */ |
| 4150 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 4151 | /* Release PCI resource and disable PCI device */ |
| 4152 | pci_release_selected_regions(pdev, bars); |
| 4153 | pci_disable_device(pdev); |
| 4154 | /* Null out PCI private reference to driver */ |
| 4155 | pci_set_drvdata(pdev, NULL); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4156 | |
| 4157 | return; |
| 4158 | } |
| 4159 | |
| 4160 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4161 | * lpfc_reset_hba - Reset a hba |
| 4162 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4163 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4164 | * This routine is invoked to reset a hba device. It brings the HBA |
| 4165 | * offline, performs a board restart, and then brings the board back |
| 4166 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 4167 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4168 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4169 | void |
| 4170 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4171 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4172 | /* If resets are disabled then set error state and return. */ |
| 4173 | if (!phba->cfg_enable_hba_reset) { |
| 4174 | phba->link_state = LPFC_HBA_ERROR; |
| 4175 | return; |
| 4176 | } |
| 4177 | lpfc_offline_prep(phba); |
| 4178 | lpfc_offline(phba); |
| 4179 | lpfc_sli_brdrestart(phba); |
| 4180 | lpfc_online(phba); |
| 4181 | lpfc_unblock_mgmt_io(phba); |
| 4182 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4184 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4185 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 4186 | * @phba: pointer to lpfc hba data structure. |
| 4187 | * |
| 4188 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4189 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4190 | * enable the number of virtual functions to the physical function. As |
| 4191 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4192 | * API call does not considered as an error condition for most of the device. |
| 4193 | **/ |
| 4194 | uint16_t |
| 4195 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 4196 | { |
| 4197 | struct pci_dev *pdev = phba->pcidev; |
| 4198 | uint16_t nr_virtfn; |
| 4199 | int pos; |
| 4200 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4201 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 4202 | if (pos == 0) |
| 4203 | return 0; |
| 4204 | |
| 4205 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 4206 | return nr_virtfn; |
| 4207 | } |
| 4208 | |
| 4209 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4210 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 4211 | * @phba: pointer to lpfc hba data structure. |
| 4212 | * @nr_vfn: number of virtual functions to be enabled. |
| 4213 | * |
| 4214 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 4215 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 4216 | * enable the number of virtual functions to the physical function. As |
| 4217 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 4218 | * API call does not considered as an error condition for most of the device. |
| 4219 | **/ |
| 4220 | int |
| 4221 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 4222 | { |
| 4223 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4224 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4225 | int rc; |
| 4226 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 4227 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 4228 | if (nr_vfn > max_nr_vfn) { |
| 4229 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4230 | "3057 Requested vfs (%d) greater than " |
| 4231 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 4232 | return -EINVAL; |
| 4233 | } |
| 4234 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4235 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 4236 | if (rc) { |
| 4237 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4238 | "2806 Failed to enable sriov on this device " |
| 4239 | "with vfn number nr_vf:%d, rc:%d\n", |
| 4240 | nr_vfn, rc); |
| 4241 | } else |
| 4242 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4243 | "2807 Successful enable sriov on this device " |
| 4244 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 4245 | return rc; |
| 4246 | } |
| 4247 | |
| 4248 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4249 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. |
| 4250 | * @phba: pointer to lpfc hba data structure. |
| 4251 | * |
| 4252 | * This routine is invoked to set up the driver internal resources specific to |
| 4253 | * support the SLI-3 HBA device it attached to. |
| 4254 | * |
| 4255 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4256 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4257 | * other values - error |
| 4258 | **/ |
| 4259 | static int |
| 4260 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 4261 | { |
| 4262 | struct lpfc_sli *psli; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4263 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4265 | /* |
| 4266 | * Initialize timers used by driver |
| 4267 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4268 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4269 | /* Heartbeat timer */ |
| 4270 | init_timer(&phba->hb_tmofunc); |
| 4271 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4272 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 4273 | |
| 4274 | psli = &phba->sli; |
| 4275 | /* MBOX heartbeat timer */ |
| 4276 | init_timer(&psli->mbox_tmo); |
| 4277 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4278 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4279 | /* FCP polling mode timer */ |
| 4280 | init_timer(&phba->fcp_poll_timer); |
| 4281 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
| 4282 | phba->fcp_poll_timer.data = (unsigned long) phba; |
| 4283 | /* Fabric block timer */ |
| 4284 | init_timer(&phba->fabric_block_timer); |
| 4285 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4286 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4287 | /* EA polling mode timer */ |
| 4288 | init_timer(&phba->eratt_poll); |
| 4289 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4290 | phba->eratt_poll.data = (unsigned long) phba; |
| 4291 | |
| 4292 | /* Host attention work mask setup */ |
| 4293 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 4294 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 4295 | |
| 4296 | /* Get all the module params for configuring this host */ |
| 4297 | lpfc_get_cfgparam(phba); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 4298 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 4299 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 4300 | /* check for menlo minimum sg count */ |
| 4301 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 4302 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 4303 | } |
| 4304 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4305 | /* |
| 4306 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4307 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4308 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4309 | */ |
| 4310 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 4311 | sizeof(struct fcp_rsp) + |
| 4312 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 4313 | |
| 4314 | if (phba->cfg_enable_bg) { |
| 4315 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 4316 | phba->cfg_sg_dma_buf_size += |
| 4317 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); |
| 4318 | } |
| 4319 | |
| 4320 | /* Also reinitialize the host templates with new values. */ |
| 4321 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4322 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4323 | |
| 4324 | phba->max_vpi = LPFC_MAX_VPI; |
| 4325 | /* This will be set to correct value after config_port mbox */ |
| 4326 | phba->max_vports = 0; |
| 4327 | |
| 4328 | /* |
| 4329 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 4330 | */ |
| 4331 | lpfc_sli_setup(phba); |
| 4332 | lpfc_sli_queue_setup(phba); |
| 4333 | |
| 4334 | /* Allocate device driver memory */ |
| 4335 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 4336 | return -ENOMEM; |
| 4337 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4338 | /* |
| 4339 | * Enable sr-iov virtual functions if supported and configured |
| 4340 | * through the module parameter. |
| 4341 | */ |
| 4342 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4343 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4344 | phba->cfg_sriov_nr_virtfn); |
| 4345 | if (rc) { |
| 4346 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4347 | "2808 Requested number of SR-IOV " |
| 4348 | "virtual functions (%d) is not " |
| 4349 | "supported\n", |
| 4350 | phba->cfg_sriov_nr_virtfn); |
| 4351 | phba->cfg_sriov_nr_virtfn = 0; |
| 4352 | } |
| 4353 | } |
| 4354 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4355 | return 0; |
| 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 4360 | * @phba: pointer to lpfc hba data structure. |
| 4361 | * |
| 4362 | * This routine is invoked to unset the driver internal resources set up |
| 4363 | * specific for supporting the SLI-3 HBA device it attached to. |
| 4364 | **/ |
| 4365 | static void |
| 4366 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 4367 | { |
| 4368 | /* Free device driver memory allocated */ |
| 4369 | lpfc_mem_free_all(phba); |
| 4370 | |
| 4371 | return; |
| 4372 | } |
| 4373 | |
| 4374 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4375 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 4376 | * @phba: pointer to lpfc hba data structure. |
| 4377 | * |
| 4378 | * This routine is invoked to set up the driver internal resources specific to |
| 4379 | * support the SLI-4 HBA device it attached to. |
| 4380 | * |
| 4381 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4382 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4383 | * other values - error |
| 4384 | **/ |
| 4385 | static int |
| 4386 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 4387 | { |
| 4388 | struct lpfc_sli *psli; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4389 | LPFC_MBOXQ_t *mboxq; |
| 4390 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; |
| 4391 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 4392 | struct lpfc_mqe *mqe; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4393 | int longs, sli_family; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4394 | int sges_per_segment; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4395 | |
| 4396 | /* Before proceed, wait for POST done and device ready */ |
| 4397 | rc = lpfc_sli4_post_status_check(phba); |
| 4398 | if (rc) |
| 4399 | return -ENODEV; |
| 4400 | |
| 4401 | /* |
| 4402 | * Initialize timers used by driver |
| 4403 | */ |
| 4404 | |
| 4405 | /* Heartbeat timer */ |
| 4406 | init_timer(&phba->hb_tmofunc); |
| 4407 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 4408 | phba->hb_tmofunc.data = (unsigned long)phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 4409 | init_timer(&phba->rrq_tmr); |
| 4410 | phba->rrq_tmr.function = lpfc_rrq_timeout; |
| 4411 | phba->rrq_tmr.data = (unsigned long)phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4412 | |
| 4413 | psli = &phba->sli; |
| 4414 | /* MBOX heartbeat timer */ |
| 4415 | init_timer(&psli->mbox_tmo); |
| 4416 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
| 4417 | psli->mbox_tmo.data = (unsigned long) phba; |
| 4418 | /* Fabric block timer */ |
| 4419 | init_timer(&phba->fabric_block_timer); |
| 4420 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 4421 | phba->fabric_block_timer.data = (unsigned long) phba; |
| 4422 | /* EA polling mode timer */ |
| 4423 | init_timer(&phba->eratt_poll); |
| 4424 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 4425 | phba->eratt_poll.data = (unsigned long) phba; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4426 | /* FCF rediscover timer */ |
| 4427 | init_timer(&phba->fcf.redisc_wait); |
| 4428 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; |
| 4429 | phba->fcf.redisc_wait.data = (unsigned long)phba; |
| 4430 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4431 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4432 | * Control structure for handling external multi-buffer mailbox |
| 4433 | * command pass-through. |
| 4434 | */ |
| 4435 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 4436 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 4437 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4438 | |
| 4439 | /* |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4440 | * We need to do a READ_CONFIG mailbox command here before |
| 4441 | * calling lpfc_get_cfgparam. For VFs this will report the |
| 4442 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. |
| 4443 | * All of the resources allocated |
| 4444 | * for this Port are tied to these values. |
| 4445 | */ |
| 4446 | /* Get all the module params for configuring this host */ |
| 4447 | lpfc_get_cfgparam(phba); |
| 4448 | phba->max_vpi = LPFC_MAX_VPI; |
| 4449 | /* This will be set to correct value after the read_config mbox */ |
| 4450 | phba->max_vports = 0; |
| 4451 | |
| 4452 | /* Program the default value of vlan_id and fc_map */ |
| 4453 | phba->valid_vlan = 0; |
| 4454 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4455 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4456 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4457 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4458 | /* With BlockGuard we can have multiple SGEs per Data Segemnt */ |
| 4459 | sges_per_segment = 1; |
| 4460 | if (phba->cfg_enable_bg) |
| 4461 | sges_per_segment = 2; |
| 4462 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4463 | /* |
| 4464 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 4465 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
| 4466 | * 2 segments are added since the IOCB needs a command and response bde. |
| 4467 | * To insure that the scsi sgl does not cross a 4k page boundary only |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4468 | * sgl sizes of must be a power of 2. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4469 | */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4470 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4471 | (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) * |
| 4472 | sizeof(struct sli4_sge))); |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 4473 | |
| 4474 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); |
| 4475 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; |
| 4476 | switch (sli_family) { |
| 4477 | case LPFC_SLI_INTF_FAMILY_BE2: |
| 4478 | case LPFC_SLI_INTF_FAMILY_BE3: |
| 4479 | /* There is a single hint for BE - 2 pages per BPL. */ |
| 4480 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == |
| 4481 | LPFC_SLI_INTF_SLI_HINT1_1) |
| 4482 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; |
| 4483 | break; |
| 4484 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: |
| 4485 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: |
| 4486 | default: |
| 4487 | break; |
| 4488 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4489 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4490 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
| 4491 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; |
| 4492 | dma_buf_size = dma_buf_size << 1) |
| 4493 | ; |
| 4494 | if (dma_buf_size == max_buf_size) |
| 4495 | phba->cfg_sg_seg_cnt = (dma_buf_size - |
| 4496 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - |
| 4497 | (2 * sizeof(struct sli4_sge))) / |
| 4498 | sizeof(struct sli4_sge); |
| 4499 | phba->cfg_sg_dma_buf_size = dma_buf_size; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4500 | |
| 4501 | /* Initialize buffer queue management fields */ |
| 4502 | hbq_count = lpfc_sli_hbq_count(); |
| 4503 | for (i = 0; i < hbq_count; ++i) |
| 4504 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 4505 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 4506 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 4507 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 4508 | |
| 4509 | /* |
| 4510 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 4511 | */ |
| 4512 | /* Initialize the Abort scsi buffer list used by driver */ |
| 4513 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 4514 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 4515 | /* This abort list used by worker thread */ |
| 4516 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); |
| 4517 | |
| 4518 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4519 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4520 | */ |
| 4521 | |
| 4522 | /* Driver internel slow-path CQ Event pool */ |
| 4523 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 4524 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 4525 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4526 | /* Asynchronous event CQ Event work queue list */ |
| 4527 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 4528 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 4529 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 4530 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 4531 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 4532 | /* Receive queue CQ Event work queue list */ |
| 4533 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 4534 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4535 | /* Initialize extent block lists. */ |
| 4536 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 4537 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 4538 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 4539 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 4540 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4541 | /* Initialize the driver internal SLI layer lists. */ |
| 4542 | lpfc_sli_setup(phba); |
| 4543 | lpfc_sli_queue_setup(phba); |
| 4544 | |
| 4545 | /* Allocate device driver memory */ |
| 4546 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 4547 | if (rc) |
| 4548 | return -ENOMEM; |
| 4549 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4550 | /* IF Type 2 ports get initialized now. */ |
| 4551 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4552 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 4553 | rc = lpfc_pci_function_reset(phba); |
| 4554 | if (unlikely(rc)) |
| 4555 | return -ENODEV; |
| 4556 | } |
| 4557 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4558 | /* Create the bootstrap mailbox command */ |
| 4559 | rc = lpfc_create_bootstrap_mbox(phba); |
| 4560 | if (unlikely(rc)) |
| 4561 | goto out_free_mem; |
| 4562 | |
| 4563 | /* Set up the host's endian order with the device. */ |
| 4564 | rc = lpfc_setup_endian_order(phba); |
| 4565 | if (unlikely(rc)) |
| 4566 | goto out_free_bsmbx; |
| 4567 | |
| 4568 | /* Set up the hba's configuration parameters. */ |
| 4569 | rc = lpfc_sli4_read_config(phba); |
| 4570 | if (unlikely(rc)) |
| 4571 | goto out_free_bsmbx; |
| 4572 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 4573 | /* IF Type 0 ports get initialized now. */ |
| 4574 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 4575 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 4576 | rc = lpfc_pci_function_reset(phba); |
| 4577 | if (unlikely(rc)) |
| 4578 | goto out_free_bsmbx; |
| 4579 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4580 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4581 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4582 | GFP_KERNEL); |
| 4583 | if (!mboxq) { |
| 4584 | rc = -ENOMEM; |
| 4585 | goto out_free_bsmbx; |
| 4586 | } |
| 4587 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4588 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4589 | lpfc_supported_pages(mboxq); |
| 4590 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4591 | if (!rc) { |
| 4592 | mqe = &mboxq->u.mqe; |
| 4593 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 4594 | LPFC_MAX_SUPPORTED_PAGES); |
| 4595 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 4596 | switch (pn_page[i]) { |
| 4597 | case LPFC_SLI4_PARAMETERS: |
| 4598 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 4599 | break; |
| 4600 | default: |
| 4601 | break; |
| 4602 | } |
| 4603 | } |
| 4604 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 4605 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 4606 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 4607 | if (rc) { |
| 4608 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4609 | rc = -EIO; |
| 4610 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4611 | } |
| 4612 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4613 | /* |
| 4614 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4615 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 4616 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 4617 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4618 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 4619 | if (rc) { |
| 4620 | if (phba->sli4_hba.extents_in_use && |
| 4621 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 4622 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4623 | "2999 Unsupported SLI4 Parameters " |
| 4624 | "Extents and RPI headers enabled.\n"); |
| 4625 | goto out_free_bsmbx; |
| 4626 | } |
| 4627 | } |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4628 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4629 | /* Verify all the SLI4 queues */ |
| 4630 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4631 | if (rc) |
| 4632 | goto out_free_bsmbx; |
| 4633 | |
| 4634 | /* Create driver internal CQE event pool */ |
| 4635 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 4636 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4637 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4638 | |
| 4639 | /* Initialize and populate the iocb list per host */ |
| 4640 | rc = lpfc_init_sgl_list(phba); |
| 4641 | if (rc) { |
| 4642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4643 | "1400 Failed to initialize sgl list.\n"); |
| 4644 | goto out_destroy_cq_event_pool; |
| 4645 | } |
| 4646 | rc = lpfc_init_active_sgl_array(phba); |
| 4647 | if (rc) { |
| 4648 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4649 | "1430 Failed to initialize sgl list.\n"); |
| 4650 | goto out_free_sgl_list; |
| 4651 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4652 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 4653 | if (rc) { |
| 4654 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4655 | "1432 Failed to initialize rpi headers.\n"); |
| 4656 | goto out_free_active_sgl; |
| 4657 | } |
| 4658 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4659 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4660 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 4661 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4662 | GFP_KERNEL); |
| 4663 | if (!phba->fcf.fcf_rr_bmask) { |
| 4664 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4665 | "2759 Failed allocate memory for FCF round " |
| 4666 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4667 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4668 | goto out_remove_rpi_hdrs; |
| 4669 | } |
| 4670 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4671 | /* |
| 4672 | * The cfg_fcp_eq_count can be zero whenever there is exactly one |
| 4673 | * interrupt vector. This is not an error |
| 4674 | */ |
| 4675 | if (phba->cfg_fcp_eq_count) { |
| 4676 | phba->sli4_hba.fcp_eq_hdl = |
| 4677 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4678 | phba->cfg_fcp_eq_count), GFP_KERNEL); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 4679 | if (!phba->sli4_hba.fcp_eq_hdl) { |
| 4680 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4681 | "2572 Failed allocate memory for " |
| 4682 | "fast-path per-EQ handle array\n"); |
| 4683 | rc = -ENOMEM; |
| 4684 | goto out_free_fcf_rr_bmask; |
| 4685 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * |
| 4689 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); |
| 4690 | if (!phba->sli4_hba.msix_entries) { |
| 4691 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4692 | "2573 Failed allocate memory for msi-x " |
| 4693 | "interrupt vector entries\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 4694 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4695 | goto out_free_fcp_eq_hdl; |
| 4696 | } |
| 4697 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 4698 | /* |
| 4699 | * Enable sr-iov virtual functions if supported and configured |
| 4700 | * through the module parameter. |
| 4701 | */ |
| 4702 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 4703 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 4704 | phba->cfg_sriov_nr_virtfn); |
| 4705 | if (rc) { |
| 4706 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4707 | "3020 Requested number of SR-IOV " |
| 4708 | "virtual functions (%d) is not " |
| 4709 | "supported\n", |
| 4710 | phba->cfg_sriov_nr_virtfn); |
| 4711 | phba->cfg_sriov_nr_virtfn = 0; |
| 4712 | } |
| 4713 | } |
| 4714 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 4715 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4716 | |
| 4717 | out_free_fcp_eq_hdl: |
| 4718 | kfree(phba->sli4_hba.fcp_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4719 | out_free_fcf_rr_bmask: |
| 4720 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4721 | out_remove_rpi_hdrs: |
| 4722 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 4723 | out_free_active_sgl: |
| 4724 | lpfc_free_active_sgl(phba); |
| 4725 | out_free_sgl_list: |
| 4726 | lpfc_free_sgl_list(phba); |
| 4727 | out_destroy_cq_event_pool: |
| 4728 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4729 | out_free_bsmbx: |
| 4730 | lpfc_destroy_bootstrap_mbox(phba); |
| 4731 | out_free_mem: |
| 4732 | lpfc_mem_free(phba); |
| 4733 | return rc; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 4738 | * @phba: pointer to lpfc hba data structure. |
| 4739 | * |
| 4740 | * This routine is invoked to unset the driver internal resources set up |
| 4741 | * specific for supporting the SLI-4 HBA device it attached to. |
| 4742 | **/ |
| 4743 | static void |
| 4744 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 4745 | { |
| 4746 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 4747 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4748 | /* Free memory allocated for msi-x interrupt vector entries */ |
| 4749 | kfree(phba->sli4_hba.msix_entries); |
| 4750 | |
| 4751 | /* Free memory allocated for fast-path work queue handles */ |
| 4752 | kfree(phba->sli4_hba.fcp_eq_hdl); |
| 4753 | |
| 4754 | /* Free the allocated rpi headers. */ |
| 4755 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 4756 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4757 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4758 | /* Free eligible FCF index bmask */ |
| 4759 | kfree(phba->fcf.fcf_rr_bmask); |
| 4760 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4761 | /* Free the ELS sgl list */ |
| 4762 | lpfc_free_active_sgl(phba); |
| 4763 | lpfc_free_sgl_list(phba); |
| 4764 | |
| 4765 | /* Free the SCSI sgl management array */ |
| 4766 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); |
| 4767 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4768 | /* Free the completion queue EQ event pool */ |
| 4769 | lpfc_sli4_cq_event_release_all(phba); |
| 4770 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 4771 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4772 | /* Release resource identifiers. */ |
| 4773 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 4774 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4775 | /* Free the bsmbx region. */ |
| 4776 | lpfc_destroy_bootstrap_mbox(phba); |
| 4777 | |
| 4778 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 4779 | lpfc_mem_free_all(phba); |
| 4780 | |
| 4781 | /* Free the current connect table */ |
| 4782 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4783 | &phba->fcf_conn_rec_list, list) { |
| 4784 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4785 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4786 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4787 | |
| 4788 | return; |
| 4789 | } |
| 4790 | |
| 4791 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4792 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4793 | * @phba: The hba struct for which this call is being executed. |
| 4794 | * @dev_grp: The HBA PCI-Device group number. |
| 4795 | * |
| 4796 | * This routine sets up the device INIT interface API function jump table |
| 4797 | * in @phba struct. |
| 4798 | * |
| 4799 | * Returns: 0 - success, -ENODEV - failure. |
| 4800 | **/ |
| 4801 | int |
| 4802 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 4803 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 4804 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 4805 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 4806 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4807 | switch (dev_grp) { |
| 4808 | case LPFC_PCI_DEV_LP: |
| 4809 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 4810 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 4811 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 4812 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4813 | case LPFC_PCI_DEV_OC: |
| 4814 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 4815 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 4816 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 4817 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4818 | default: |
| 4819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4820 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 4821 | dev_grp); |
| 4822 | return -ENODEV; |
| 4823 | break; |
| 4824 | } |
| 4825 | return 0; |
| 4826 | } |
| 4827 | |
| 4828 | /** |
| 4829 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
| 4830 | * @phba: pointer to lpfc hba data structure. |
| 4831 | * |
| 4832 | * This routine is invoked to set up the driver internal resources before the |
| 4833 | * device specific resource setup to support the HBA device it attached to. |
| 4834 | * |
| 4835 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4836 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4837 | * other values - error |
| 4838 | **/ |
| 4839 | static int |
| 4840 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
| 4841 | { |
| 4842 | /* |
| 4843 | * Driver resources common to all SLI revisions |
| 4844 | */ |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 4845 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4846 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4847 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4848 | /* Initialize ndlp management spinlock */ |
| 4849 | spin_lock_init(&phba->ndlp_lock); |
| 4850 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4851 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4852 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 4853 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4855 | /* Initialize the wait queue head for the kernel thread */ |
| 4856 | init_waitqueue_head(&phba->work_waitq); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4857 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4858 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
| 4859 | spin_lock_init(&phba->scsi_buf_list_lock); |
| 4860 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4861 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4862 | /* Initialize the fabric iocb list */ |
| 4863 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4864 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4865 | /* Initialize list to save ELS buffers */ |
| 4866 | INIT_LIST_HEAD(&phba->elsbuf); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4867 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4868 | /* Initialize FCF connection rec list */ |
| 4869 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4870 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4871 | return 0; |
| 4872 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4873 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4874 | /** |
| 4875 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 4876 | * @phba: pointer to lpfc hba data structure. |
| 4877 | * |
| 4878 | * This routine is invoked to set up the driver internal resources after the |
| 4879 | * device specific resource setup to support the HBA device it attached to. |
| 4880 | * |
| 4881 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4882 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4883 | * other values - error |
| 4884 | **/ |
| 4885 | static int |
| 4886 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 4887 | { |
| 4888 | int error; |
| 4889 | |
| 4890 | /* Startup the kernel thread for this host adapter. */ |
| 4891 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 4892 | "lpfc_worker_%d", phba->brd_no); |
| 4893 | if (IS_ERR(phba->worker_thread)) { |
| 4894 | error = PTR_ERR(phba->worker_thread); |
| 4895 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 4896 | } |
| 4897 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4898 | return 0; |
| 4899 | } |
| 4900 | |
| 4901 | /** |
| 4902 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 4903 | * @phba: pointer to lpfc hba data structure. |
| 4904 | * |
| 4905 | * This routine is invoked to unset the driver internal resources set up after |
| 4906 | * the device specific resource setup for supporting the HBA device it |
| 4907 | * attached to. |
| 4908 | **/ |
| 4909 | static void |
| 4910 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 4911 | { |
| 4912 | /* Stop kernel worker thread */ |
| 4913 | kthread_stop(phba->worker_thread); |
| 4914 | } |
| 4915 | |
| 4916 | /** |
| 4917 | * lpfc_free_iocb_list - Free iocb list. |
| 4918 | * @phba: pointer to lpfc hba data structure. |
| 4919 | * |
| 4920 | * This routine is invoked to free the driver's IOCB list and memory. |
| 4921 | **/ |
| 4922 | static void |
| 4923 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 4924 | { |
| 4925 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 4926 | |
| 4927 | spin_lock_irq(&phba->hbalock); |
| 4928 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 4929 | &phba->lpfc_iocb_list, list) { |
| 4930 | list_del(&iocbq_entry->list); |
| 4931 | kfree(iocbq_entry); |
| 4932 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 4933 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4934 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4935 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4936 | return; |
| 4937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4939 | /** |
| 4940 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 4941 | * @phba: pointer to lpfc hba data structure. |
| 4942 | * |
| 4943 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 4944 | * list and set up the IOCB tag array accordingly. |
| 4945 | * |
| 4946 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4947 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4948 | * other values - error |
| 4949 | **/ |
| 4950 | static int |
| 4951 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 4952 | { |
| 4953 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 4954 | uint16_t iotag; |
| 4955 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | |
| 4957 | /* Initialize and populate the iocb list per host. */ |
| 4958 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4959 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4960 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4961 | if (iocbq_entry == NULL) { |
| 4962 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 4963 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 4964 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | goto out_free_iocbq; |
| 4966 | } |
| 4967 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4968 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 4969 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4970 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4971 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4972 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 4973 | goto out_free_iocbq; |
| 4974 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4975 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4976 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4977 | |
| 4978 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 4980 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4981 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | } |
| 4983 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4984 | return 0; |
| 4985 | |
| 4986 | out_free_iocbq: |
| 4987 | lpfc_free_iocb_list(phba); |
| 4988 | |
| 4989 | return -ENOMEM; |
| 4990 | } |
| 4991 | |
| 4992 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4993 | * lpfc_free_sgl_list - Free sgl list. |
| 4994 | * @phba: pointer to lpfc hba data structure. |
| 4995 | * |
| 4996 | * This routine is invoked to free the driver's sgl list and memory. |
| 4997 | **/ |
| 4998 | static void |
| 4999 | lpfc_free_sgl_list(struct lpfc_hba *phba) |
| 5000 | { |
| 5001 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 5002 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5003 | |
| 5004 | spin_lock_irq(&phba->hbalock); |
| 5005 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); |
| 5006 | spin_unlock_irq(&phba->hbalock); |
| 5007 | |
| 5008 | list_for_each_entry_safe(sglq_entry, sglq_next, |
| 5009 | &sglq_list, list) { |
| 5010 | list_del(&sglq_entry->list); |
| 5011 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 5012 | kfree(sglq_entry); |
| 5013 | phba->sli4_hba.total_sglq_bufs--; |
| 5014 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5015 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
| 5016 | } |
| 5017 | |
| 5018 | /** |
| 5019 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 5020 | * @phba: pointer to lpfc hba data structure. |
| 5021 | * |
| 5022 | * This routine is invoked to allocate the driver's active sgl memory. |
| 5023 | * This array will hold the sglq_entry's for active IOs. |
| 5024 | **/ |
| 5025 | static int |
| 5026 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 5027 | { |
| 5028 | int size; |
| 5029 | size = sizeof(struct lpfc_sglq *); |
| 5030 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 5031 | |
| 5032 | phba->sli4_hba.lpfc_sglq_active_list = |
| 5033 | kzalloc(size, GFP_KERNEL); |
| 5034 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 5035 | return -ENOMEM; |
| 5036 | return 0; |
| 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 5041 | * @phba: pointer to lpfc hba data structure. |
| 5042 | * |
| 5043 | * This routine is invoked to walk through the array of active sglq entries |
| 5044 | * and free all of the resources. |
| 5045 | * This is just a place holder for now. |
| 5046 | **/ |
| 5047 | static void |
| 5048 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 5049 | { |
| 5050 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 5051 | } |
| 5052 | |
| 5053 | /** |
| 5054 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 5055 | * @phba: pointer to lpfc hba data structure. |
| 5056 | * |
| 5057 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 5058 | * list and set up the sgl xritag tag array accordingly. |
| 5059 | * |
| 5060 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5061 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5062 | * other values - error |
| 5063 | **/ |
| 5064 | static int |
| 5065 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 5066 | { |
| 5067 | struct lpfc_sglq *sglq_entry = NULL; |
| 5068 | int i; |
| 5069 | int els_xri_cnt; |
| 5070 | |
| 5071 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 5072 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5073 | "2400 ELS XRI count %d.\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5074 | els_xri_cnt); |
| 5075 | /* Initialize and populate the sglq list per host/VF. */ |
| 5076 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); |
| 5077 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 5078 | |
| 5079 | /* Sanity check on XRI management */ |
| 5080 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { |
| 5081 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5082 | "2562 No room left for SCSI XRI allocation: " |
| 5083 | "max_xri=%d, els_xri=%d\n", |
| 5084 | phba->sli4_hba.max_cfg_param.max_xri, |
| 5085 | els_xri_cnt); |
| 5086 | return -ENOMEM; |
| 5087 | } |
| 5088 | |
| 5089 | /* Allocate memory for the ELS XRI management array */ |
| 5090 | phba->sli4_hba.lpfc_els_sgl_array = |
| 5091 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), |
| 5092 | GFP_KERNEL); |
| 5093 | |
| 5094 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
| 5095 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5096 | "2401 Failed to allocate memory for ELS " |
| 5097 | "XRI management array of size %d.\n", |
| 5098 | els_xri_cnt); |
| 5099 | return -ENOMEM; |
| 5100 | } |
| 5101 | |
| 5102 | /* Keep the SCSI XRI into the XRI management array */ |
| 5103 | phba->sli4_hba.scsi_xri_max = |
| 5104 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 5105 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5106 | phba->sli4_hba.lpfc_scsi_psb_array = |
| 5107 | kzalloc((sizeof(struct lpfc_scsi_buf *) * |
| 5108 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); |
| 5109 | |
| 5110 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { |
| 5111 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5112 | "2563 Failed to allocate memory for SCSI " |
| 5113 | "XRI management array of size %d.\n", |
| 5114 | phba->sli4_hba.scsi_xri_max); |
| 5115 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
| 5116 | return -ENOMEM; |
| 5117 | } |
| 5118 | |
| 5119 | for (i = 0; i < els_xri_cnt; i++) { |
| 5120 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); |
| 5121 | if (sglq_entry == NULL) { |
| 5122 | printk(KERN_ERR "%s: only allocated %d sgls of " |
| 5123 | "expected %d count. Unloading driver.\n", |
| 5124 | __func__, i, els_xri_cnt); |
| 5125 | goto out_free_mem; |
| 5126 | } |
| 5127 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5128 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 5129 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); |
| 5130 | if (sglq_entry->virt == NULL) { |
| 5131 | kfree(sglq_entry); |
| 5132 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" |
| 5133 | "Unloading driver.\n", __func__); |
| 5134 | goto out_free_mem; |
| 5135 | } |
| 5136 | sglq_entry->sgl = sglq_entry->virt; |
| 5137 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 5138 | |
| 5139 | /* The list order is used by later block SGL registraton */ |
| 5140 | spin_lock_irq(&phba->hbalock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 5141 | sglq_entry->state = SGL_FREED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5142 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
| 5143 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; |
| 5144 | phba->sli4_hba.total_sglq_bufs++; |
| 5145 | spin_unlock_irq(&phba->hbalock); |
| 5146 | } |
| 5147 | return 0; |
| 5148 | |
| 5149 | out_free_mem: |
| 5150 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); |
| 5151 | lpfc_free_sgl_list(phba); |
| 5152 | return -ENOMEM; |
| 5153 | } |
| 5154 | |
| 5155 | /** |
| 5156 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 5157 | * @phba: pointer to lpfc hba data structure. |
| 5158 | * |
| 5159 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5160 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5161 | * 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] | 5162 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 5163 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5164 | * |
| 5165 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5166 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5167 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5168 | **/ |
| 5169 | int |
| 5170 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 5171 | { |
| 5172 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5173 | struct lpfc_rpi_hdr *rpi_hdr; |
| 5174 | |
| 5175 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5176 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5177 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5178 | if (phba->sli4_hba.extents_in_use) |
| 5179 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5180 | |
| 5181 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 5182 | if (!rpi_hdr) { |
| 5183 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 5184 | "0391 Error during rpi post operation\n"); |
| 5185 | lpfc_sli4_remove_rpis(phba); |
| 5186 | rc = -ENODEV; |
| 5187 | } |
| 5188 | |
| 5189 | return rc; |
| 5190 | } |
| 5191 | |
| 5192 | /** |
| 5193 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 5194 | * @phba: pointer to lpfc hba data structure. |
| 5195 | * |
| 5196 | * This routine is invoked to allocate a single 4KB memory region to |
| 5197 | * support rpis and stores them in the phba. This single region |
| 5198 | * provides support for up to 64 rpis. The region is used globally |
| 5199 | * by the device. |
| 5200 | * |
| 5201 | * Returns: |
| 5202 | * A valid rpi hdr on success. |
| 5203 | * A NULL pointer on any failure. |
| 5204 | **/ |
| 5205 | struct lpfc_rpi_hdr * |
| 5206 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 5207 | { |
| 5208 | uint16_t rpi_limit, curr_rpi_range; |
| 5209 | struct lpfc_dmabuf *dmabuf; |
| 5210 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5211 | uint32_t rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5212 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5213 | /* |
| 5214 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 5215 | * required. Set the expected maximum count and let the actual value |
| 5216 | * get set when extents are fully allocated. |
| 5217 | */ |
| 5218 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5219 | return NULL; |
| 5220 | if (phba->sli4_hba.extents_in_use) |
| 5221 | return NULL; |
| 5222 | |
| 5223 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5224 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5225 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5226 | |
| 5227 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5228 | /* |
| 5229 | * Establish the starting RPI in this header block. The starting |
| 5230 | * rpi is normalized to a zero base because the physical rpi is |
| 5231 | * port based. |
| 5232 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 5233 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5234 | spin_unlock_irq(&phba->hbalock); |
| 5235 | |
| 5236 | /* |
| 5237 | * The port has a limited number of rpis. The increment here |
| 5238 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value |
| 5239 | * and to allow the full max_rpi range per port. |
| 5240 | */ |
| 5241 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5242 | rpi_count = rpi_limit - curr_rpi_range; |
| 5243 | else |
| 5244 | rpi_count = LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5245 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5246 | if (!rpi_count) |
| 5247 | return NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5248 | /* |
| 5249 | * First allocate the protocol header region for the port. The |
| 5250 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 5251 | */ |
| 5252 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5253 | if (!dmabuf) |
| 5254 | return NULL; |
| 5255 | |
| 5256 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5257 | LPFC_HDR_TEMPLATE_SIZE, |
| 5258 | &dmabuf->phys, |
| 5259 | GFP_KERNEL); |
| 5260 | if (!dmabuf->virt) { |
| 5261 | rpi_hdr = NULL; |
| 5262 | goto err_free_dmabuf; |
| 5263 | } |
| 5264 | |
| 5265 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); |
| 5266 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 5267 | rpi_hdr = NULL; |
| 5268 | goto err_free_coherent; |
| 5269 | } |
| 5270 | |
| 5271 | /* Save the rpi header data for cleanup later. */ |
| 5272 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 5273 | if (!rpi_hdr) |
| 5274 | goto err_free_coherent; |
| 5275 | |
| 5276 | rpi_hdr->dmabuf = dmabuf; |
| 5277 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 5278 | rpi_hdr->page_count = 1; |
| 5279 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5280 | |
| 5281 | /* The rpi_hdr stores the logical index only. */ |
| 5282 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5283 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 5284 | |
| 5285 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5286 | * The next_rpi stores the next logical module-64 rpi value used |
| 5287 | * to post physical rpis in subsequent rpi postings. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5288 | */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 5289 | phba->sli4_hba.next_rpi += rpi_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5290 | spin_unlock_irq(&phba->hbalock); |
| 5291 | return rpi_hdr; |
| 5292 | |
| 5293 | err_free_coherent: |
| 5294 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 5295 | dmabuf->virt, dmabuf->phys); |
| 5296 | err_free_dmabuf: |
| 5297 | kfree(dmabuf); |
| 5298 | return NULL; |
| 5299 | } |
| 5300 | |
| 5301 | /** |
| 5302 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 5303 | * @phba: pointer to lpfc hba data structure. |
| 5304 | * |
| 5305 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5306 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 5307 | * presumes the caller has released all rpis consumed by fabric or port |
| 5308 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5309 | **/ |
| 5310 | void |
| 5311 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 5312 | { |
| 5313 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 5314 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5315 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5316 | goto exit; |
| 5317 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5318 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 5319 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 5320 | list_del(&rpi_hdr->list); |
| 5321 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 5322 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 5323 | kfree(rpi_hdr->dmabuf); |
| 5324 | kfree(rpi_hdr); |
| 5325 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5326 | exit: |
| 5327 | /* There are no rpis available to the port now. */ |
| 5328 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5332 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 5333 | * @pdev: pointer to pci device data structure. |
| 5334 | * |
| 5335 | * This routine is invoked to allocate the driver hba data structure for an |
| 5336 | * HBA device. If the allocation is successful, the phba reference to the |
| 5337 | * PCI device data structure is set. |
| 5338 | * |
| 5339 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5340 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5341 | * NULL - error |
| 5342 | **/ |
| 5343 | static struct lpfc_hba * |
| 5344 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 5345 | { |
| 5346 | struct lpfc_hba *phba; |
| 5347 | |
| 5348 | /* Allocate memory for HBA structure */ |
| 5349 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 5350 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 5351 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5352 | return NULL; |
| 5353 | } |
| 5354 | |
| 5355 | /* Set reference to PCI device in HBA structure */ |
| 5356 | phba->pcidev = pdev; |
| 5357 | |
| 5358 | /* Assign an unused board number */ |
| 5359 | phba->brd_no = lpfc_get_instance(); |
| 5360 | if (phba->brd_no < 0) { |
| 5361 | kfree(phba); |
| 5362 | return NULL; |
| 5363 | } |
| 5364 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 5365 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5366 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 5367 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5368 | return phba; |
| 5369 | } |
| 5370 | |
| 5371 | /** |
| 5372 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 5373 | * @phba: pointer to lpfc hba data structure. |
| 5374 | * |
| 5375 | * This routine is invoked to free the driver hba data structure with an |
| 5376 | * HBA device. |
| 5377 | **/ |
| 5378 | static void |
| 5379 | lpfc_hba_free(struct lpfc_hba *phba) |
| 5380 | { |
| 5381 | /* Release the driver assigned board number */ |
| 5382 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 5383 | |
| 5384 | kfree(phba); |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | /** |
| 5389 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 5390 | * @phba: pointer to lpfc hba data structure. |
| 5391 | * |
| 5392 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 5393 | * host with it. |
| 5394 | * |
| 5395 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5396 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5397 | * other values - error |
| 5398 | **/ |
| 5399 | static int |
| 5400 | lpfc_create_shost(struct lpfc_hba *phba) |
| 5401 | { |
| 5402 | struct lpfc_vport *vport; |
| 5403 | struct Scsi_Host *shost; |
| 5404 | |
| 5405 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5406 | phba->fc_edtov = FF_DEF_EDTOV; |
| 5407 | phba->fc_ratov = FF_DEF_RATOV; |
| 5408 | phba->fc_altov = FF_DEF_ALTOV; |
| 5409 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 5410 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5411 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 5412 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5413 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5414 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5415 | |
| 5416 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5417 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5418 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5419 | /* Put reference to SCSI host to driver's device private data */ |
| 5420 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5421 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5422 | return 0; |
| 5423 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5424 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5425 | /** |
| 5426 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 5427 | * @phba: pointer to lpfc hba data structure. |
| 5428 | * |
| 5429 | * This routine is invoked to destroy HBA physical port and the associated |
| 5430 | * SCSI host. |
| 5431 | **/ |
| 5432 | static void |
| 5433 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 5434 | { |
| 5435 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5436 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5437 | /* Destroy physical port that associated with the SCSI host */ |
| 5438 | destroy_port(vport); |
| 5439 | |
| 5440 | return; |
| 5441 | } |
| 5442 | |
| 5443 | /** |
| 5444 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 5445 | * @phba: pointer to lpfc hba data structure. |
| 5446 | * @shost: the shost to be used to detect Block guard settings. |
| 5447 | * |
| 5448 | * This routine sets up the local Block guard protocol settings for @shost. |
| 5449 | * This routine also allocates memory for debugging bg buffers. |
| 5450 | **/ |
| 5451 | static void |
| 5452 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 5453 | { |
| 5454 | int pagecnt = 10; |
| 5455 | if (lpfc_prot_mask && lpfc_prot_guard) { |
| 5456 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5457 | "1478 Registering BlockGuard with the " |
| 5458 | "SCSI layer\n"); |
| 5459 | scsi_host_set_prot(shost, lpfc_prot_mask); |
| 5460 | scsi_host_set_guard(shost, lpfc_prot_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 5461 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5462 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5463 | while (pagecnt) { |
| 5464 | spin_lock_init(&_dump_buf_lock); |
| 5465 | _dump_buf_data = |
| 5466 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5467 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5468 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5469 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5470 | "_dump_buf_data at 0x%p\n", |
| 5471 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5472 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5473 | memset(_dump_buf_data, 0, |
| 5474 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5475 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5476 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5477 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5478 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5479 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5480 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5481 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5482 | "memory for hexdump\n"); |
| 5483 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5484 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5485 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5486 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5487 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5488 | while (pagecnt) { |
| 5489 | _dump_buf_dif = |
| 5490 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 5491 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5492 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5493 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5494 | "_dump_buf_dif at 0x%p\n", |
| 5495 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5496 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5497 | memset(_dump_buf_dif, 0, |
| 5498 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5499 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5500 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5501 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5502 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 5503 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5504 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5505 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5506 | "memory for hexdump\n"); |
| 5507 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 5508 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 5509 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5510 | _dump_buf_dif); |
| 5511 | } |
| 5512 | |
| 5513 | /** |
| 5514 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 5515 | * @phba: pointer to lpfc hba data structure. |
| 5516 | * |
| 5517 | * This routine is invoked to perform all the necessary post initialization |
| 5518 | * setup for the device. |
| 5519 | **/ |
| 5520 | static void |
| 5521 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 5522 | { |
| 5523 | struct Scsi_Host *shost; |
| 5524 | struct lpfc_adapter_event_header adapter_event; |
| 5525 | |
| 5526 | /* Get the default values for Model Name and Description */ |
| 5527 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 5528 | |
| 5529 | /* |
| 5530 | * hba setup may have changed the hba_queue_depth so we need to |
| 5531 | * adjust the value of can_queue. |
| 5532 | */ |
| 5533 | shost = pci_get_drvdata(phba->pcidev); |
| 5534 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 5535 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 5536 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5537 | |
| 5538 | lpfc_host_attrib_init(shost); |
| 5539 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5540 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 5541 | spin_lock_irq(shost->host_lock); |
| 5542 | lpfc_poll_start_timer(phba); |
| 5543 | spin_unlock_irq(shost->host_lock); |
| 5544 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 5545 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5546 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5547 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5548 | /* Send board arrival event to upper layer */ |
| 5549 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 5550 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 5551 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5552 | sizeof(adapter_event), |
| 5553 | (char *) &adapter_event, |
| 5554 | LPFC_NL_VENDOR_ID); |
| 5555 | return; |
| 5556 | } |
| 5557 | |
| 5558 | /** |
| 5559 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 5560 | * @phba: pointer to lpfc hba data structure. |
| 5561 | * |
| 5562 | * This routine is invoked to set up the PCI device memory space for device |
| 5563 | * with SLI-3 interface spec. |
| 5564 | * |
| 5565 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5566 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5567 | * other values - error |
| 5568 | **/ |
| 5569 | static int |
| 5570 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 5571 | { |
| 5572 | struct pci_dev *pdev; |
| 5573 | unsigned long bar0map_len, bar2map_len; |
| 5574 | int i, hbq_count; |
| 5575 | void *ptr; |
| 5576 | int error = -ENODEV; |
| 5577 | |
| 5578 | /* Obtain PCI device reference */ |
| 5579 | if (!phba->pcidev) |
| 5580 | return error; |
| 5581 | else |
| 5582 | pdev = phba->pcidev; |
| 5583 | |
| 5584 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5585 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 5586 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 5587 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 5588 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5589 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 5590 | } |
| 5591 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5592 | |
| 5593 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 5594 | * required by each mapping. |
| 5595 | */ |
| 5596 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 5597 | bar0map_len = pci_resource_len(pdev, 0); |
| 5598 | |
| 5599 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 5600 | bar2map_len = pci_resource_len(pdev, 2); |
| 5601 | |
| 5602 | /* Map HBA SLIM to a kernel virtual address. */ |
| 5603 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 5604 | if (!phba->slim_memmap_p) { |
| 5605 | dev_printk(KERN_ERR, &pdev->dev, |
| 5606 | "ioremap failed for SLIM memory.\n"); |
| 5607 | goto out; |
| 5608 | } |
| 5609 | |
| 5610 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 5611 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 5612 | if (!phba->ctrl_regs_memmap_p) { |
| 5613 | dev_printk(KERN_ERR, &pdev->dev, |
| 5614 | "ioremap failed for HBA control registers.\n"); |
| 5615 | goto out_iounmap_slim; |
| 5616 | } |
| 5617 | |
| 5618 | /* Allocate memory for SLI-2 structures */ |
| 5619 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
| 5620 | SLI2_SLIM_SIZE, |
| 5621 | &phba->slim2p.phys, |
| 5622 | GFP_KERNEL); |
| 5623 | if (!phba->slim2p.virt) |
| 5624 | goto out_iounmap; |
| 5625 | |
| 5626 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
| 5627 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 5628 | phba->mbox_ext = (phba->slim2p.virt + |
| 5629 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5630 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 5631 | phba->IOCBs = (phba->slim2p.virt + |
| 5632 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 5633 | |
| 5634 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 5635 | lpfc_sli_hbq_size(), |
| 5636 | &phba->hbqslimp.phys, |
| 5637 | GFP_KERNEL); |
| 5638 | if (!phba->hbqslimp.virt) |
| 5639 | goto out_free_slim; |
| 5640 | |
| 5641 | hbq_count = lpfc_sli_hbq_count(); |
| 5642 | ptr = phba->hbqslimp.virt; |
| 5643 | for (i = 0; i < hbq_count; ++i) { |
| 5644 | phba->hbqs[i].hbq_virt = ptr; |
| 5645 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 5646 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 5647 | sizeof(struct lpfc_hbq_entry)); |
| 5648 | } |
| 5649 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 5650 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 5651 | |
| 5652 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 5653 | |
| 5654 | INIT_LIST_HEAD(&phba->rb_pend_list); |
| 5655 | |
| 5656 | phba->MBslimaddr = phba->slim_memmap_p; |
| 5657 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 5658 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 5659 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 5660 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 5661 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5662 | return 0; |
| 5663 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5664 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5665 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5666 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5667 | out_iounmap: |
| 5668 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 5669 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5670 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5671 | out: |
| 5672 | return error; |
| 5673 | } |
| 5674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5675 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5676 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 5677 | * @phba: pointer to lpfc hba data structure. |
| 5678 | * |
| 5679 | * This routine is invoked to unset the PCI device memory space for device |
| 5680 | * with SLI-3 interface spec. |
| 5681 | **/ |
| 5682 | static void |
| 5683 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 5684 | { |
| 5685 | struct pci_dev *pdev; |
| 5686 | |
| 5687 | /* Obtain PCI device reference */ |
| 5688 | if (!phba->pcidev) |
| 5689 | return; |
| 5690 | else |
| 5691 | pdev = phba->pcidev; |
| 5692 | |
| 5693 | /* Free coherent DMA memory allocated */ |
| 5694 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 5695 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 5696 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 5697 | phba->slim2p.virt, phba->slim2p.phys); |
| 5698 | |
| 5699 | /* I/O memory unmap */ |
| 5700 | iounmap(phba->ctrl_regs_memmap_p); |
| 5701 | iounmap(phba->slim_memmap_p); |
| 5702 | |
| 5703 | return; |
| 5704 | } |
| 5705 | |
| 5706 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5707 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 5708 | * @phba: pointer to lpfc hba data structure. |
| 5709 | * |
| 5710 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 5711 | * done and check status. |
| 5712 | * |
| 5713 | * Return 0 if successful, otherwise -ENODEV. |
| 5714 | **/ |
| 5715 | int |
| 5716 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 5717 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5718 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 5719 | struct lpfc_register reg_data; |
| 5720 | int i, port_error = 0; |
| 5721 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5722 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5723 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 5724 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5725 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5726 | return -ENODEV; |
| 5727 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5728 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 5729 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5730 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 5731 | &portsmphr_reg.word0) || |
| 5732 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5733 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5734 | port_error = -ENODEV; |
| 5735 | break; |
| 5736 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5737 | if (LPFC_POST_STAGE_PORT_READY == |
| 5738 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5739 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5740 | msleep(10); |
| 5741 | } |
| 5742 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5743 | /* |
| 5744 | * If there was a port error during POST, then don't proceed with |
| 5745 | * other register reads as the data may not be valid. Just exit. |
| 5746 | */ |
| 5747 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5749 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 5750 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 5751 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 5752 | portsmphr_reg.word0, |
| 5753 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 5754 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 5755 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 5756 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 5757 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 5758 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 5759 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 5760 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 5761 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5762 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5763 | "2534 Device Info: SLIFamily=0x%x, " |
| 5764 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 5765 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5766 | bf_get(lpfc_sli_intf_sli_family, |
| 5767 | &phba->sli4_hba.sli_intf), |
| 5768 | bf_get(lpfc_sli_intf_slirev, |
| 5769 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5770 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5771 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5772 | bf_get(lpfc_sli_intf_sli_hint1, |
| 5773 | &phba->sli4_hba.sli_intf), |
| 5774 | bf_get(lpfc_sli_intf_sli_hint2, |
| 5775 | &phba->sli4_hba.sli_intf), |
| 5776 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5777 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5778 | /* |
| 5779 | * Check for other Port errors during the initialization |
| 5780 | * process. Fail the load if the port did not come up |
| 5781 | * correctly. |
| 5782 | */ |
| 5783 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 5784 | &phba->sli4_hba.sli_intf); |
| 5785 | switch (if_type) { |
| 5786 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 5787 | phba->sli4_hba.ue_mask_lo = |
| 5788 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 5789 | phba->sli4_hba.ue_mask_hi = |
| 5790 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 5791 | uerrlo_reg.word0 = |
| 5792 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 5793 | uerrhi_reg.word0 = |
| 5794 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 5795 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 5796 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 5797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5798 | "1422 Unrecoverable Error " |
| 5799 | "Detected during POST " |
| 5800 | "uerr_lo_reg=0x%x, " |
| 5801 | "uerr_hi_reg=0x%x, " |
| 5802 | "ue_mask_lo_reg=0x%x, " |
| 5803 | "ue_mask_hi_reg=0x%x\n", |
| 5804 | uerrlo_reg.word0, |
| 5805 | uerrhi_reg.word0, |
| 5806 | phba->sli4_hba.ue_mask_lo, |
| 5807 | phba->sli4_hba.ue_mask_hi); |
| 5808 | port_error = -ENODEV; |
| 5809 | } |
| 5810 | break; |
| 5811 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 5812 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 5813 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 5814 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5815 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 5816 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5817 | phba->work_status[0] = |
| 5818 | readl(phba->sli4_hba.u.if_type2. |
| 5819 | ERR1regaddr); |
| 5820 | phba->work_status[1] = |
| 5821 | readl(phba->sli4_hba.u.if_type2. |
| 5822 | ERR2regaddr); |
| 5823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame^] | 5824 | "2888 Unrecoverable port error " |
| 5825 | "following POST: port status reg " |
| 5826 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5827 | "error 1=0x%x, error 2=0x%x\n", |
| 5828 | reg_data.word0, |
| 5829 | portsmphr_reg.word0, |
| 5830 | phba->work_status[0], |
| 5831 | phba->work_status[1]); |
| 5832 | port_error = -ENODEV; |
| 5833 | } |
| 5834 | break; |
| 5835 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 5836 | default: |
| 5837 | break; |
| 5838 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5839 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5840 | return port_error; |
| 5841 | } |
| 5842 | |
| 5843 | /** |
| 5844 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 5845 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5846 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5847 | * |
| 5848 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 5849 | * memory map. |
| 5850 | **/ |
| 5851 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5852 | 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] | 5853 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5854 | switch (if_type) { |
| 5855 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 5856 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 5857 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 5858 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 5859 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 5860 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 5861 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 5862 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 5863 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 5864 | phba->sli4_hba.SLIINTFregaddr = |
| 5865 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 5866 | break; |
| 5867 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 5868 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5869 | phba->sli4_hba.conf_regs_memmap_p + |
| 5870 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5871 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5872 | phba->sli4_hba.conf_regs_memmap_p + |
| 5873 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5874 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5875 | phba->sli4_hba.conf_regs_memmap_p + |
| 5876 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5877 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5878 | phba->sli4_hba.conf_regs_memmap_p + |
| 5879 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5880 | phba->sli4_hba.SLIINTFregaddr = |
| 5881 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 5882 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 5883 | phba->sli4_hba.conf_regs_memmap_p + |
| 5884 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5885 | phba->sli4_hba.RQDBregaddr = |
| 5886 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; |
| 5887 | phba->sli4_hba.WQDBregaddr = |
| 5888 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; |
| 5889 | phba->sli4_hba.EQCQDBregaddr = |
| 5890 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 5891 | phba->sli4_hba.MQDBregaddr = |
| 5892 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 5893 | phba->sli4_hba.BMBXregaddr = |
| 5894 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 5895 | break; |
| 5896 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 5897 | default: |
| 5898 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 5899 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 5900 | if_type); |
| 5901 | break; |
| 5902 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /** |
| 5906 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 5907 | * @phba: pointer to lpfc hba data structure. |
| 5908 | * |
| 5909 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 5910 | * memory map. |
| 5911 | **/ |
| 5912 | static void |
| 5913 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 5914 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5915 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 5916 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5917 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5918 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5919 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5920 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5921 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 5922 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | /** |
| 5926 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 5927 | * @phba: pointer to lpfc hba data structure. |
| 5928 | * @vf: virtual function number |
| 5929 | * |
| 5930 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 5931 | * based on the given viftual function number, @vf. |
| 5932 | * |
| 5933 | * Return 0 if successful, otherwise -ENODEV. |
| 5934 | **/ |
| 5935 | static int |
| 5936 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 5937 | { |
| 5938 | if (vf > LPFC_VIR_FUNC_MAX) |
| 5939 | return -ENODEV; |
| 5940 | |
| 5941 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 5942 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); |
| 5943 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 5944 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); |
| 5945 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 5946 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 5947 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 5948 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 5949 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 5950 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 5951 | return 0; |
| 5952 | } |
| 5953 | |
| 5954 | /** |
| 5955 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 5956 | * @phba: pointer to lpfc hba data structure. |
| 5957 | * |
| 5958 | * This routine is invoked to create the bootstrap mailbox |
| 5959 | * region consistent with the SLI-4 interface spec. This |
| 5960 | * routine allocates all memory necessary to communicate |
| 5961 | * mailbox commands to the port and sets up all alignment |
| 5962 | * needs. No locks are expected to be held when calling |
| 5963 | * this routine. |
| 5964 | * |
| 5965 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5966 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5967 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5968 | **/ |
| 5969 | static int |
| 5970 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 5971 | { |
| 5972 | uint32_t bmbx_size; |
| 5973 | struct lpfc_dmabuf *dmabuf; |
| 5974 | struct dma_address *dma_address; |
| 5975 | uint32_t pa_addr; |
| 5976 | uint64_t phys_addr; |
| 5977 | |
| 5978 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5979 | if (!dmabuf) |
| 5980 | return -ENOMEM; |
| 5981 | |
| 5982 | /* |
| 5983 | * The bootstrap mailbox region is comprised of 2 parts |
| 5984 | * plus an alignment restriction of 16 bytes. |
| 5985 | */ |
| 5986 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
| 5987 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 5988 | bmbx_size, |
| 5989 | &dmabuf->phys, |
| 5990 | GFP_KERNEL); |
| 5991 | if (!dmabuf->virt) { |
| 5992 | kfree(dmabuf); |
| 5993 | return -ENOMEM; |
| 5994 | } |
| 5995 | memset(dmabuf->virt, 0, bmbx_size); |
| 5996 | |
| 5997 | /* |
| 5998 | * Initialize the bootstrap mailbox pointers now so that the register |
| 5999 | * operations are simple later. The mailbox dma address is required |
| 6000 | * to be 16-byte aligned. Also align the virtual memory as each |
| 6001 | * maibox is copied into the bmbx mailbox region before issuing the |
| 6002 | * command to the port. |
| 6003 | */ |
| 6004 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 6005 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 6006 | |
| 6007 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 6008 | LPFC_ALIGN_16_BYTE); |
| 6009 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 6010 | LPFC_ALIGN_16_BYTE); |
| 6011 | |
| 6012 | /* |
| 6013 | * Set the high and low physical addresses now. The SLI4 alignment |
| 6014 | * requirement is 16 bytes and the mailbox is posted to the port |
| 6015 | * as two 30-bit addresses. The other data is a bit marking whether |
| 6016 | * the 30-bit address is the high or low address. |
| 6017 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 6018 | * clean on 32 bit machines. |
| 6019 | */ |
| 6020 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 6021 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 6022 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 6023 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 6024 | LPFC_BMBX_BIT1_ADDR_HI); |
| 6025 | |
| 6026 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 6027 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 6028 | LPFC_BMBX_BIT1_ADDR_LO); |
| 6029 | return 0; |
| 6030 | } |
| 6031 | |
| 6032 | /** |
| 6033 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 6034 | * @phba: pointer to lpfc hba data structure. |
| 6035 | * |
| 6036 | * This routine is invoked to teardown the bootstrap mailbox |
| 6037 | * region and release all host resources. This routine requires |
| 6038 | * the caller to ensure all mailbox commands recovered, no |
| 6039 | * additional mailbox comands are sent, and interrupts are disabled |
| 6040 | * before calling this routine. |
| 6041 | * |
| 6042 | **/ |
| 6043 | static void |
| 6044 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 6045 | { |
| 6046 | dma_free_coherent(&phba->pcidev->dev, |
| 6047 | phba->sli4_hba.bmbx.bmbx_size, |
| 6048 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 6049 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 6050 | |
| 6051 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 6052 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 6053 | } |
| 6054 | |
| 6055 | /** |
| 6056 | * lpfc_sli4_read_config - Get the config parameters. |
| 6057 | * @phba: pointer to lpfc hba data structure. |
| 6058 | * |
| 6059 | * This routine is invoked to read the configuration parameters from the HBA. |
| 6060 | * The configuration parameters are used to set the base and maximum values |
| 6061 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 6062 | * allocation for the port. |
| 6063 | * |
| 6064 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6065 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6066 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6067 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6068 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6069 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6070 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 6071 | { |
| 6072 | LPFC_MBOXQ_t *pmb; |
| 6073 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6074 | union lpfc_sli4_cfg_shdr *shdr; |
| 6075 | uint32_t shdr_status, shdr_add_status; |
| 6076 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 6077 | struct lpfc_rsrc_desc_fcfcoe *desc; |
| 6078 | uint32_t desc_count; |
| 6079 | int length, i, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6080 | |
| 6081 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6082 | if (!pmb) { |
| 6083 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6084 | "2011 Unable to allocate memory for issuing " |
| 6085 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 6086 | return -ENOMEM; |
| 6087 | } |
| 6088 | |
| 6089 | lpfc_read_config(phba, pmb); |
| 6090 | |
| 6091 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6092 | if (rc != MBX_SUCCESS) { |
| 6093 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6094 | "2012 Mailbox failed , mbxCmd x%x " |
| 6095 | "READ_CONFIG, mbxStatus x%x\n", |
| 6096 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6097 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6098 | rc = -EIO; |
| 6099 | } else { |
| 6100 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6101 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 6102 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 6103 | phba->sli4_hba.lnk_info.lnk_tp = |
| 6104 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 6105 | phba->sli4_hba.lnk_info.lnk_no = |
| 6106 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 6107 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6108 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 6109 | phba->sli4_hba.lnk_info.lnk_tp, |
| 6110 | phba->sli4_hba.lnk_info.lnk_no); |
| 6111 | } else |
| 6112 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6113 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 6114 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6115 | phba->sli4_hba.extents_in_use = |
| 6116 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6117 | phba->sli4_hba.max_cfg_param.max_xri = |
| 6118 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 6119 | phba->sli4_hba.max_cfg_param.xri_base = |
| 6120 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 6121 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 6122 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 6123 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 6124 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 6125 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 6126 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 6127 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 6128 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 6129 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 6130 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 6131 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 6132 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 6133 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 6134 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6135 | phba->sli4_hba.max_cfg_param.max_eq = |
| 6136 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 6137 | phba->sli4_hba.max_cfg_param.max_rq = |
| 6138 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 6139 | phba->sli4_hba.max_cfg_param.max_wq = |
| 6140 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 6141 | phba->sli4_hba.max_cfg_param.max_cq = |
| 6142 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 6143 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 6144 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 6145 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6146 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 6147 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 6148 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6149 | phba->max_vports = phba->max_vpi; |
| 6150 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6151 | "2003 cfg params Extents? %d " |
| 6152 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6153 | "VPI(B:%d M:%d) " |
| 6154 | "VFI(B:%d M:%d) " |
| 6155 | "RPI(B:%d M:%d) " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6156 | "FCFI(Count:%d)\n", |
| 6157 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6158 | phba->sli4_hba.max_cfg_param.xri_base, |
| 6159 | phba->sli4_hba.max_cfg_param.max_xri, |
| 6160 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 6161 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 6162 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 6163 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 6164 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 6165 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6166 | phba->sli4_hba.max_cfg_param.max_fcfi); |
| 6167 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6168 | |
| 6169 | if (rc) |
| 6170 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6171 | |
| 6172 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6173 | if (phba->cfg_hba_queue_depth > |
| 6174 | (phba->sli4_hba.max_cfg_param.max_xri - |
| 6175 | lpfc_sli4_get_els_iocb_cnt(phba))) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6176 | phba->cfg_hba_queue_depth = |
James Smart | b92938b | 2010-06-07 15:24:12 -0400 | [diff] [blame] | 6177 | phba->sli4_hba.max_cfg_param.max_xri - |
| 6178 | lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6179 | |
| 6180 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 6181 | LPFC_SLI_INTF_IF_TYPE_2) |
| 6182 | goto read_cfg_out; |
| 6183 | |
| 6184 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 6185 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 6186 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6187 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6188 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 6189 | length, LPFC_SLI4_MBX_EMBED); |
| 6190 | |
| 6191 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 6192 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6193 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 6194 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6195 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6196 | if (rc || shdr_status || shdr_add_status) { |
| 6197 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6198 | "3026 Mailbox failed , mbxCmd x%x " |
| 6199 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 6200 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 6201 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 6202 | rc = -EIO; |
| 6203 | goto read_cfg_out; |
| 6204 | } |
| 6205 | |
| 6206 | /* search for fc_fcoe resrouce descriptor */ |
| 6207 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
| 6208 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; |
| 6209 | |
| 6210 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
| 6211 | desc = (struct lpfc_rsrc_desc_fcfcoe *) |
| 6212 | &get_func_cfg->func_cfg.desc[i]; |
| 6213 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
| 6214 | bf_get(lpfc_rsrc_desc_pcie_type, desc)) { |
| 6215 | phba->sli4_hba.iov.pf_number = |
| 6216 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 6217 | phba->sli4_hba.iov.vf_number = |
| 6218 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 6219 | break; |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 6224 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6225 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 6226 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 6227 | phba->sli4_hba.iov.vf_number); |
| 6228 | else { |
| 6229 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6230 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 6231 | "Resrouce Descriptor:x%x\n", |
| 6232 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
| 6233 | rc = -EIO; |
| 6234 | } |
| 6235 | |
| 6236 | read_cfg_out: |
| 6237 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6238 | return rc; |
| 6239 | } |
| 6240 | |
| 6241 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6242 | * 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] | 6243 | * @phba: pointer to lpfc hba data structure. |
| 6244 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6245 | * This routine is invoked to setup the port-side endian order when |
| 6246 | * the port if_type is 0. This routine has no function for other |
| 6247 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6248 | * |
| 6249 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6250 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6251 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6252 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6253 | **/ |
| 6254 | static int |
| 6255 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 6256 | { |
| 6257 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6258 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6259 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 6260 | HOST_ENDIAN_HIGH_WORD1}; |
| 6261 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6262 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 6263 | switch (if_type) { |
| 6264 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 6265 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6266 | GFP_KERNEL); |
| 6267 | if (!mboxq) { |
| 6268 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6269 | "0492 Unable to allocate memory for " |
| 6270 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 6271 | "command\n"); |
| 6272 | return -ENOMEM; |
| 6273 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6274 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6275 | /* |
| 6276 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 6277 | * two words to contain special data values and no other data. |
| 6278 | */ |
| 6279 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 6280 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 6281 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6282 | if (rc != MBX_SUCCESS) { |
| 6283 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6284 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 6285 | "failed with status x%x\n", |
| 6286 | rc); |
| 6287 | rc = -EIO; |
| 6288 | } |
| 6289 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6290 | break; |
| 6291 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 6292 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 6293 | default: |
| 6294 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6295 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6296 | return rc; |
| 6297 | } |
| 6298 | |
| 6299 | /** |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6300 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6301 | * @phba: pointer to lpfc hba data structure. |
| 6302 | * |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6303 | * This routine is invoked to check the user settable queue counts for EQs and |
| 6304 | * CQs. after this routine is called the counts will be set to valid values that |
| 6305 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 6306 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6307 | * |
| 6308 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6309 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6310 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6311 | **/ |
| 6312 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6313 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6314 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6315 | int cfg_fcp_wq_count; |
| 6316 | int cfg_fcp_eq_count; |
| 6317 | |
| 6318 | /* |
| 6319 | * Sanity check for confiugred queue parameters against the run-time |
| 6320 | * device parameters |
| 6321 | */ |
| 6322 | |
| 6323 | /* Sanity check on FCP fast-path WQ parameters */ |
| 6324 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; |
| 6325 | if (cfg_fcp_wq_count > |
| 6326 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { |
| 6327 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - |
| 6328 | LPFC_SP_WQN_DEF; |
| 6329 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { |
| 6330 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6331 | "2581 Not enough WQs (%d) from " |
| 6332 | "the pci function for supporting " |
| 6333 | "FCP WQs (%d)\n", |
| 6334 | phba->sli4_hba.max_cfg_param.max_wq, |
| 6335 | phba->cfg_fcp_wq_count); |
| 6336 | goto out_error; |
| 6337 | } |
| 6338 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6339 | "2582 Not enough WQs (%d) from the pci " |
| 6340 | "function for supporting the requested " |
| 6341 | "FCP WQs (%d), the actual FCP WQs can " |
| 6342 | "be supported: %d\n", |
| 6343 | phba->sli4_hba.max_cfg_param.max_wq, |
| 6344 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); |
| 6345 | } |
| 6346 | /* The actual number of FCP work queues adopted */ |
| 6347 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; |
| 6348 | |
| 6349 | /* Sanity check on FCP fast-path EQ parameters */ |
| 6350 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; |
| 6351 | if (cfg_fcp_eq_count > |
| 6352 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { |
| 6353 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - |
| 6354 | LPFC_SP_EQN_DEF; |
| 6355 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { |
| 6356 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6357 | "2574 Not enough EQs (%d) from the " |
| 6358 | "pci function for supporting FCP " |
| 6359 | "EQs (%d)\n", |
| 6360 | phba->sli4_hba.max_cfg_param.max_eq, |
| 6361 | phba->cfg_fcp_eq_count); |
| 6362 | goto out_error; |
| 6363 | } |
| 6364 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6365 | "2575 Not enough EQs (%d) from the pci " |
| 6366 | "function for supporting the requested " |
| 6367 | "FCP EQs (%d), the actual FCP EQs can " |
| 6368 | "be supported: %d\n", |
| 6369 | phba->sli4_hba.max_cfg_param.max_eq, |
| 6370 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); |
| 6371 | } |
| 6372 | /* It does not make sense to have more EQs than WQs */ |
| 6373 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { |
| 6374 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 6375 | "2593 The FCP EQ count(%d) cannot be greater " |
| 6376 | "than the FCP WQ count(%d), limiting the " |
| 6377 | "FCP EQ count to %d\n", cfg_fcp_eq_count, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6378 | phba->cfg_fcp_wq_count, |
| 6379 | phba->cfg_fcp_wq_count); |
| 6380 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; |
| 6381 | } |
| 6382 | /* The actual number of FCP event queues adopted */ |
| 6383 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; |
| 6384 | /* The overall number of event queues used */ |
| 6385 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; |
| 6386 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6387 | /* Get EQ depth from module parameter, fake the default for now */ |
| 6388 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 6389 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 6390 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6391 | /* Get CQ depth from module parameter, fake the default for now */ |
| 6392 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 6393 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
| 6394 | |
| 6395 | return 0; |
| 6396 | out_error: |
| 6397 | return -ENOMEM; |
| 6398 | } |
| 6399 | |
| 6400 | /** |
| 6401 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 6402 | * @phba: pointer to lpfc hba data structure. |
| 6403 | * |
| 6404 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 6405 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 6406 | * count (queue depth) shall be taken from the module parameter. For now, |
| 6407 | * we just use some constant number as place holder. |
| 6408 | * |
| 6409 | * Return codes |
| 6410 | * 0 - sucessful |
| 6411 | * -ENOMEM - No availble memory |
| 6412 | * -EIO - The mailbox failed to complete successfully. |
| 6413 | **/ |
| 6414 | int |
| 6415 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 6416 | { |
| 6417 | struct lpfc_queue *qdesc; |
| 6418 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 6419 | |
| 6420 | /* |
| 6421 | * Create Event Queues (EQs) |
| 6422 | */ |
| 6423 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6424 | /* Create slow path event queue */ |
| 6425 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6426 | phba->sli4_hba.eq_ecount); |
| 6427 | if (!qdesc) { |
| 6428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6429 | "0496 Failed allocate slow-path EQ\n"); |
| 6430 | goto out_error; |
| 6431 | } |
| 6432 | phba->sli4_hba.sp_eq = qdesc; |
| 6433 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6434 | /* |
| 6435 | * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be |
| 6436 | * zero whenever there is exactly one interrupt vector. This is not |
| 6437 | * an error. |
| 6438 | */ |
| 6439 | if (phba->cfg_fcp_eq_count) { |
| 6440 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6441 | phba->cfg_fcp_eq_count), GFP_KERNEL); |
| 6442 | if (!phba->sli4_hba.fp_eq) { |
| 6443 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6444 | "2576 Failed allocate memory for " |
| 6445 | "fast-path EQ record array\n"); |
| 6446 | goto out_free_sp_eq; |
| 6447 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6448 | } |
| 6449 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 6450 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
| 6451 | phba->sli4_hba.eq_ecount); |
| 6452 | if (!qdesc) { |
| 6453 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6454 | "0497 Failed allocate fast-path EQ\n"); |
| 6455 | goto out_free_fp_eq; |
| 6456 | } |
| 6457 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; |
| 6458 | } |
| 6459 | |
| 6460 | /* |
| 6461 | * Create Complete Queues (CQs) |
| 6462 | */ |
| 6463 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6464 | /* Create slow-path Mailbox Command Complete Queue */ |
| 6465 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6466 | phba->sli4_hba.cq_ecount); |
| 6467 | if (!qdesc) { |
| 6468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6469 | "0500 Failed allocate slow-path mailbox CQ\n"); |
| 6470 | goto out_free_fp_eq; |
| 6471 | } |
| 6472 | phba->sli4_hba.mbx_cq = qdesc; |
| 6473 | |
| 6474 | /* Create slow-path ELS Complete Queue */ |
| 6475 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6476 | phba->sli4_hba.cq_ecount); |
| 6477 | if (!qdesc) { |
| 6478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6479 | "0501 Failed allocate slow-path ELS CQ\n"); |
| 6480 | goto out_free_mbx_cq; |
| 6481 | } |
| 6482 | phba->sli4_hba.els_cq = qdesc; |
| 6483 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6484 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6485 | /* |
| 6486 | * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs. |
| 6487 | * If there are no FCP EQs then create exactly one FCP CQ. |
| 6488 | */ |
| 6489 | if (phba->cfg_fcp_eq_count) |
| 6490 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6491 | phba->cfg_fcp_eq_count), |
| 6492 | GFP_KERNEL); |
| 6493 | else |
| 6494 | phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *), |
| 6495 | GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6496 | if (!phba->sli4_hba.fcp_cq) { |
| 6497 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6498 | "2577 Failed allocate memory for fast-path " |
| 6499 | "CQ record array\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6500 | goto out_free_els_cq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6501 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6502 | fcp_cqidx = 0; |
| 6503 | do { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6504 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
| 6505 | phba->sli4_hba.cq_ecount); |
| 6506 | if (!qdesc) { |
| 6507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6508 | "0499 Failed allocate fast-path FCP " |
| 6509 | "CQ (%d)\n", fcp_cqidx); |
| 6510 | goto out_free_fcp_cq; |
| 6511 | } |
| 6512 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6513 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6514 | |
| 6515 | /* Create Mailbox Command Queue */ |
| 6516 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 6517 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 6518 | |
| 6519 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, |
| 6520 | phba->sli4_hba.mq_ecount); |
| 6521 | if (!qdesc) { |
| 6522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6523 | "0505 Failed allocate slow-path MQ\n"); |
| 6524 | goto out_free_fcp_cq; |
| 6525 | } |
| 6526 | phba->sli4_hba.mbx_wq = qdesc; |
| 6527 | |
| 6528 | /* |
| 6529 | * Create all the Work Queues (WQs) |
| 6530 | */ |
| 6531 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 6532 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 6533 | |
| 6534 | /* Create slow-path ELS Work Queue */ |
| 6535 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6536 | phba->sli4_hba.wq_ecount); |
| 6537 | if (!qdesc) { |
| 6538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6539 | "0504 Failed allocate slow-path ELS WQ\n"); |
| 6540 | goto out_free_mbx_wq; |
| 6541 | } |
| 6542 | phba->sli4_hba.els_wq = qdesc; |
| 6543 | |
| 6544 | /* Create fast-path FCP Work Queue(s) */ |
| 6545 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * |
| 6546 | phba->cfg_fcp_wq_count), GFP_KERNEL); |
| 6547 | if (!phba->sli4_hba.fcp_wq) { |
| 6548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6549 | "2578 Failed allocate memory for fast-path " |
| 6550 | "WQ record array\n"); |
| 6551 | goto out_free_els_wq; |
| 6552 | } |
| 6553 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { |
| 6554 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, |
| 6555 | phba->sli4_hba.wq_ecount); |
| 6556 | if (!qdesc) { |
| 6557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6558 | "0503 Failed allocate fast-path FCP " |
| 6559 | "WQ (%d)\n", fcp_wqidx); |
| 6560 | goto out_free_fcp_wq; |
| 6561 | } |
| 6562 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; |
| 6563 | } |
| 6564 | |
| 6565 | /* |
| 6566 | * Create Receive Queue (RQ) |
| 6567 | */ |
| 6568 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 6569 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
| 6570 | |
| 6571 | /* Create Receive Queue for header */ |
| 6572 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6573 | phba->sli4_hba.rq_ecount); |
| 6574 | if (!qdesc) { |
| 6575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6576 | "0506 Failed allocate receive HRQ\n"); |
| 6577 | goto out_free_fcp_wq; |
| 6578 | } |
| 6579 | phba->sli4_hba.hdr_rq = qdesc; |
| 6580 | |
| 6581 | /* Create Receive Queue for data */ |
| 6582 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, |
| 6583 | phba->sli4_hba.rq_ecount); |
| 6584 | if (!qdesc) { |
| 6585 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6586 | "0507 Failed allocate receive DRQ\n"); |
| 6587 | goto out_free_hdr_rq; |
| 6588 | } |
| 6589 | phba->sli4_hba.dat_rq = qdesc; |
| 6590 | |
| 6591 | return 0; |
| 6592 | |
| 6593 | out_free_hdr_rq: |
| 6594 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 6595 | phba->sli4_hba.hdr_rq = NULL; |
| 6596 | out_free_fcp_wq: |
| 6597 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { |
| 6598 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); |
| 6599 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; |
| 6600 | } |
| 6601 | kfree(phba->sli4_hba.fcp_wq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6602 | phba->sli4_hba.fcp_wq = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6603 | out_free_els_wq: |
| 6604 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 6605 | phba->sli4_hba.els_wq = NULL; |
| 6606 | out_free_mbx_wq: |
| 6607 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 6608 | phba->sli4_hba.mbx_wq = NULL; |
| 6609 | out_free_fcp_cq: |
| 6610 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { |
| 6611 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); |
| 6612 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; |
| 6613 | } |
| 6614 | kfree(phba->sli4_hba.fcp_cq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6615 | phba->sli4_hba.fcp_cq = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6616 | out_free_els_cq: |
| 6617 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 6618 | phba->sli4_hba.els_cq = NULL; |
| 6619 | out_free_mbx_cq: |
| 6620 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 6621 | phba->sli4_hba.mbx_cq = NULL; |
| 6622 | out_free_fp_eq: |
| 6623 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { |
| 6624 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); |
| 6625 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; |
| 6626 | } |
| 6627 | kfree(phba->sli4_hba.fp_eq); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6628 | phba->sli4_hba.fp_eq = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6629 | out_free_sp_eq: |
| 6630 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); |
| 6631 | phba->sli4_hba.sp_eq = NULL; |
| 6632 | out_error: |
| 6633 | return -ENOMEM; |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 6638 | * @phba: pointer to lpfc hba data structure. |
| 6639 | * |
| 6640 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 6641 | * operation. |
| 6642 | * |
| 6643 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6644 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6645 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6646 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6647 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6648 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6649 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 6650 | { |
| 6651 | int fcp_qidx; |
| 6652 | |
| 6653 | /* Release mailbox command work queue */ |
| 6654 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); |
| 6655 | phba->sli4_hba.mbx_wq = NULL; |
| 6656 | |
| 6657 | /* Release ELS work queue */ |
| 6658 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); |
| 6659 | phba->sli4_hba.els_wq = NULL; |
| 6660 | |
| 6661 | /* Release FCP work queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6662 | if (phba->sli4_hba.fcp_wq != NULL) |
| 6663 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; |
| 6664 | fcp_qidx++) |
| 6665 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6666 | kfree(phba->sli4_hba.fcp_wq); |
| 6667 | phba->sli4_hba.fcp_wq = NULL; |
| 6668 | |
| 6669 | /* Release unsolicited receive queue */ |
| 6670 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); |
| 6671 | phba->sli4_hba.hdr_rq = NULL; |
| 6672 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); |
| 6673 | phba->sli4_hba.dat_rq = NULL; |
| 6674 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6675 | /* Release ELS complete queue */ |
| 6676 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); |
| 6677 | phba->sli4_hba.els_cq = NULL; |
| 6678 | |
| 6679 | /* Release mailbox command complete queue */ |
| 6680 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); |
| 6681 | phba->sli4_hba.mbx_cq = NULL; |
| 6682 | |
| 6683 | /* Release FCP response complete queue */ |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6684 | fcp_qidx = 0; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6685 | if (phba->sli4_hba.fcp_cq != NULL) |
| 6686 | do |
| 6687 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); |
| 6688 | while (++fcp_qidx < phba->cfg_fcp_eq_count); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6689 | kfree(phba->sli4_hba.fcp_cq); |
| 6690 | phba->sli4_hba.fcp_cq = NULL; |
| 6691 | |
| 6692 | /* Release fast-path event queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6693 | if (phba->sli4_hba.fp_eq != NULL) |
| 6694 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; |
| 6695 | fcp_qidx++) |
| 6696 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6697 | kfree(phba->sli4_hba.fp_eq); |
| 6698 | phba->sli4_hba.fp_eq = NULL; |
| 6699 | |
| 6700 | /* Release slow-path event queue */ |
| 6701 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); |
| 6702 | phba->sli4_hba.sp_eq = NULL; |
| 6703 | |
| 6704 | return; |
| 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 6709 | * @phba: pointer to lpfc hba data structure. |
| 6710 | * |
| 6711 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 6712 | * operation. |
| 6713 | * |
| 6714 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6715 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6716 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 6717 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6718 | **/ |
| 6719 | int |
| 6720 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 6721 | { |
| 6722 | int rc = -ENOMEM; |
| 6723 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; |
| 6724 | int fcp_cq_index = 0; |
| 6725 | |
| 6726 | /* |
| 6727 | * Set up Event Queues (EQs) |
| 6728 | */ |
| 6729 | |
| 6730 | /* Set up slow-path event queue */ |
| 6731 | if (!phba->sli4_hba.sp_eq) { |
| 6732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6733 | "0520 Slow-path EQ not allocated\n"); |
| 6734 | goto out_error; |
| 6735 | } |
| 6736 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, |
| 6737 | LPFC_SP_DEF_IMAX); |
| 6738 | if (rc) { |
| 6739 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6740 | "0521 Failed setup of slow-path EQ: " |
| 6741 | "rc = 0x%x\n", rc); |
| 6742 | goto out_error; |
| 6743 | } |
| 6744 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6745 | "2583 Slow-path EQ setup: queue-id=%d\n", |
| 6746 | phba->sli4_hba.sp_eq->queue_id); |
| 6747 | |
| 6748 | /* Set up fast-path event queue */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6749 | if (phba->cfg_fcp_eq_count && !phba->sli4_hba.fp_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6751 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6752 | rc = -ENOMEM; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6753 | goto out_destroy_sp_eq; |
| 6754 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6755 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
| 6756 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { |
| 6757 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6758 | "0522 Fast-path EQ (%d) not " |
| 6759 | "allocated\n", fcp_eqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6760 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6761 | goto out_destroy_fp_eq; |
| 6762 | } |
| 6763 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], |
| 6764 | phba->cfg_fcp_imax); |
| 6765 | if (rc) { |
| 6766 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6767 | "0523 Failed setup of fast-path EQ " |
| 6768 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); |
| 6769 | goto out_destroy_fp_eq; |
| 6770 | } |
| 6771 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6772 | "2584 Fast-path EQ setup: " |
| 6773 | "queue[%d]-id=%d\n", fcp_eqidx, |
| 6774 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); |
| 6775 | } |
| 6776 | |
| 6777 | /* |
| 6778 | * Set up Complete Queues (CQs) |
| 6779 | */ |
| 6780 | |
| 6781 | /* Set up slow-path MBOX Complete Queue as the first CQ */ |
| 6782 | if (!phba->sli4_hba.mbx_cq) { |
| 6783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6784 | "0528 Mailbox CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6785 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6786 | goto out_destroy_fp_eq; |
| 6787 | } |
| 6788 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, |
| 6789 | LPFC_MCQ, LPFC_MBOX); |
| 6790 | if (rc) { |
| 6791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6792 | "0529 Failed setup of slow-path mailbox CQ: " |
| 6793 | "rc = 0x%x\n", rc); |
| 6794 | goto out_destroy_fp_eq; |
| 6795 | } |
| 6796 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6797 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 6798 | phba->sli4_hba.mbx_cq->queue_id, |
| 6799 | phba->sli4_hba.sp_eq->queue_id); |
| 6800 | |
| 6801 | /* Set up slow-path ELS Complete Queue */ |
| 6802 | if (!phba->sli4_hba.els_cq) { |
| 6803 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6804 | "0530 ELS CQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6805 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6806 | goto out_destroy_mbx_cq; |
| 6807 | } |
| 6808 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, |
| 6809 | LPFC_WCQ, LPFC_ELS); |
| 6810 | if (rc) { |
| 6811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6812 | "0531 Failed setup of slow-path ELS CQ: " |
| 6813 | "rc = 0x%x\n", rc); |
| 6814 | goto out_destroy_mbx_cq; |
| 6815 | } |
| 6816 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6817 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", |
| 6818 | phba->sli4_hba.els_cq->queue_id, |
| 6819 | phba->sli4_hba.sp_eq->queue_id); |
| 6820 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6821 | /* Set up fast-path FCP Response Complete Queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6822 | if (!phba->sli4_hba.fcp_cq) { |
| 6823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6824 | "3148 Fast-path FCP CQ array not " |
| 6825 | "allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6826 | rc = -ENOMEM; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6827 | goto out_destroy_els_cq; |
| 6828 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6829 | fcp_cqidx = 0; |
| 6830 | do { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6831 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
| 6832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6833 | "0526 Fast-path FCP CQ (%d) not " |
| 6834 | "allocated\n", fcp_cqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6835 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6836 | goto out_destroy_fcp_cq; |
| 6837 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6838 | if (phba->cfg_fcp_eq_count) |
| 6839 | rc = lpfc_cq_create(phba, |
| 6840 | phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 6841 | phba->sli4_hba.fp_eq[fcp_cqidx], |
| 6842 | LPFC_WCQ, LPFC_FCP); |
| 6843 | else |
| 6844 | rc = lpfc_cq_create(phba, |
| 6845 | phba->sli4_hba.fcp_cq[fcp_cqidx], |
| 6846 | phba->sli4_hba.sp_eq, |
| 6847 | LPFC_WCQ, LPFC_FCP); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6848 | if (rc) { |
| 6849 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6850 | "0527 Failed setup of fast-path FCP " |
| 6851 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); |
| 6852 | goto out_destroy_fcp_cq; |
| 6853 | } |
| 6854 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6855 | "2588 FCP CQ setup: cq[%d]-id=%d, " |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6856 | "parent %seq[%d]-id=%d\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6857 | fcp_cqidx, |
| 6858 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6859 | (phba->cfg_fcp_eq_count) ? "" : "sp_", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6860 | fcp_cqidx, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6861 | (phba->cfg_fcp_eq_count) ? |
| 6862 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id : |
| 6863 | phba->sli4_hba.sp_eq->queue_id); |
| 6864 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6865 | |
| 6866 | /* |
| 6867 | * Set up all the Work Queues (WQs) |
| 6868 | */ |
| 6869 | |
| 6870 | /* Set up Mailbox Command Queue */ |
| 6871 | if (!phba->sli4_hba.mbx_wq) { |
| 6872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6873 | "0538 Slow-path MQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6874 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6875 | goto out_destroy_fcp_cq; |
| 6876 | } |
| 6877 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, |
| 6878 | phba->sli4_hba.mbx_cq, LPFC_MBOX); |
| 6879 | if (rc) { |
| 6880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6881 | "0539 Failed setup of slow-path MQ: " |
| 6882 | "rc = 0x%x\n", rc); |
| 6883 | goto out_destroy_fcp_cq; |
| 6884 | } |
| 6885 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6886 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 6887 | phba->sli4_hba.mbx_wq->queue_id, |
| 6888 | phba->sli4_hba.mbx_cq->queue_id); |
| 6889 | |
| 6890 | /* Set up slow-path ELS Work Queue */ |
| 6891 | if (!phba->sli4_hba.els_wq) { |
| 6892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6893 | "0536 Slow-path ELS WQ not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6894 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6895 | goto out_destroy_mbx_wq; |
| 6896 | } |
| 6897 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, |
| 6898 | phba->sli4_hba.els_cq, LPFC_ELS); |
| 6899 | if (rc) { |
| 6900 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6901 | "0537 Failed setup of slow-path ELS WQ: " |
| 6902 | "rc = 0x%x\n", rc); |
| 6903 | goto out_destroy_mbx_wq; |
| 6904 | } |
| 6905 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6906 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 6907 | phba->sli4_hba.els_wq->queue_id, |
| 6908 | phba->sli4_hba.els_cq->queue_id); |
| 6909 | |
| 6910 | /* Set up fast-path FCP Work Queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6911 | if (!phba->sli4_hba.fcp_wq) { |
| 6912 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6913 | "3149 Fast-path FCP WQ array not " |
| 6914 | "allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6915 | rc = -ENOMEM; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6916 | goto out_destroy_els_wq; |
| 6917 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6918 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { |
| 6919 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { |
| 6920 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6921 | "0534 Fast-path FCP WQ (%d) not " |
| 6922 | "allocated\n", fcp_wqidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6923 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6924 | goto out_destroy_fcp_wq; |
| 6925 | } |
| 6926 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], |
| 6927 | phba->sli4_hba.fcp_cq[fcp_cq_index], |
| 6928 | LPFC_FCP); |
| 6929 | if (rc) { |
| 6930 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6931 | "0535 Failed setup of fast-path FCP " |
| 6932 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); |
| 6933 | goto out_destroy_fcp_wq; |
| 6934 | } |
| 6935 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6936 | "2591 FCP WQ setup: wq[%d]-id=%d, " |
| 6937 | "parent cq[%d]-id=%d\n", |
| 6938 | fcp_wqidx, |
| 6939 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, |
| 6940 | fcp_cq_index, |
| 6941 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); |
| 6942 | /* Round robin FCP Work Queue's Completion Queue assignment */ |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6943 | if (phba->cfg_fcp_eq_count) |
| 6944 | fcp_cq_index = ((fcp_cq_index + 1) % |
| 6945 | phba->cfg_fcp_eq_count); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | /* |
| 6949 | * Create Receive Queue (RQ) |
| 6950 | */ |
| 6951 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 6952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6953 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 6954 | rc = -ENOMEM; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6955 | goto out_destroy_fcp_wq; |
| 6956 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 6957 | |
| 6958 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); |
| 6959 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); |
| 6960 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6961 | 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] | 6962 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6963 | if (rc) { |
| 6964 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6965 | "0541 Failed setup of Receive Queue: " |
| 6966 | "rc = 0x%x\n", rc); |
| 6967 | goto out_destroy_fcp_wq; |
| 6968 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 6969 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6970 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6971 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 6972 | "parent cq-id=%d\n", |
| 6973 | phba->sli4_hba.hdr_rq->queue_id, |
| 6974 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6975 | phba->sli4_hba.els_cq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6976 | return 0; |
| 6977 | |
| 6978 | out_destroy_fcp_wq: |
| 6979 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) |
| 6980 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6981 | out_destroy_els_wq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6982 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 6983 | out_destroy_mbx_wq: |
| 6984 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 6985 | out_destroy_fcp_cq: |
| 6986 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) |
| 6987 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6988 | out_destroy_els_cq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6989 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 6990 | out_destroy_mbx_cq: |
| 6991 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 6992 | out_destroy_fp_eq: |
| 6993 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
| 6994 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6995 | out_destroy_sp_eq: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6996 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); |
| 6997 | out_error: |
| 6998 | return rc; |
| 6999 | } |
| 7000 | |
| 7001 | /** |
| 7002 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 7003 | * @phba: pointer to lpfc hba data structure. |
| 7004 | * |
| 7005 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 7006 | * operation. |
| 7007 | * |
| 7008 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7009 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7010 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7011 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7012 | **/ |
| 7013 | void |
| 7014 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 7015 | { |
| 7016 | int fcp_qidx; |
| 7017 | |
| 7018 | /* Unset mailbox command work queue */ |
| 7019 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 7020 | /* Unset ELS work queue */ |
| 7021 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 7022 | /* Unset unsolicited receive queue */ |
| 7023 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); |
| 7024 | /* Unset FCP work queue */ |
| 7025 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) |
| 7026 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); |
| 7027 | /* Unset mailbox command complete queue */ |
| 7028 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 7029 | /* Unset ELS complete queue */ |
| 7030 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7031 | /* Unset FCP response complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7032 | if (phba->sli4_hba.fcp_cq) { |
| 7033 | fcp_qidx = 0; |
| 7034 | do { |
| 7035 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
| 7036 | } while (++fcp_qidx < phba->cfg_fcp_eq_count); |
| 7037 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7038 | /* Unset fast-path event queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7039 | if (phba->sli4_hba.fp_eq) { |
| 7040 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; |
| 7041 | fcp_qidx++) |
| 7042 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); |
| 7043 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7044 | /* Unset slow-path event queue */ |
| 7045 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); |
| 7046 | } |
| 7047 | |
| 7048 | /** |
| 7049 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 7050 | * @phba: pointer to lpfc hba data structure. |
| 7051 | * |
| 7052 | * This routine is invoked to allocate and set up a pool of completion queue |
| 7053 | * events. The body of the completion queue event is a completion queue entry |
| 7054 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 7055 | * the following HBA completion queue events for the worker thread to process: |
| 7056 | * - Mailbox asynchronous events |
| 7057 | * - Receive queue completion unsolicited events |
| 7058 | * Later, this can be used for all the slow-path events. |
| 7059 | * |
| 7060 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7061 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7062 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | **/ |
| 7064 | static int |
| 7065 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 7066 | { |
| 7067 | struct lpfc_cq_event *cq_event; |
| 7068 | int i; |
| 7069 | |
| 7070 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 7071 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 7072 | if (!cq_event) |
| 7073 | goto out_pool_create_fail; |
| 7074 | list_add_tail(&cq_event->list, |
| 7075 | &phba->sli4_hba.sp_cqe_event_pool); |
| 7076 | } |
| 7077 | return 0; |
| 7078 | |
| 7079 | out_pool_create_fail: |
| 7080 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7081 | return -ENOMEM; |
| 7082 | } |
| 7083 | |
| 7084 | /** |
| 7085 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 7086 | * @phba: pointer to lpfc hba data structure. |
| 7087 | * |
| 7088 | * This routine is invoked to free the pool of completion queue events at |
| 7089 | * driver unload time. Note that, it is the responsibility of the driver |
| 7090 | * cleanup routine to free all the outstanding completion-queue events |
| 7091 | * allocated from this pool back into the pool before invoking this routine |
| 7092 | * to destroy the pool. |
| 7093 | **/ |
| 7094 | static void |
| 7095 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 7096 | { |
| 7097 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 7098 | |
| 7099 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 7100 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 7101 | list_del(&cq_event->list); |
| 7102 | kfree(cq_event); |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | /** |
| 7107 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7108 | * @phba: pointer to lpfc hba data structure. |
| 7109 | * |
| 7110 | * This routine is the lock free version of the API invoked to allocate a |
| 7111 | * completion-queue event from the free pool. |
| 7112 | * |
| 7113 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7114 | * NULL otherwise. |
| 7115 | **/ |
| 7116 | struct lpfc_cq_event * |
| 7117 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7118 | { |
| 7119 | struct lpfc_cq_event *cq_event = NULL; |
| 7120 | |
| 7121 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 7122 | struct lpfc_cq_event, list); |
| 7123 | return cq_event; |
| 7124 | } |
| 7125 | |
| 7126 | /** |
| 7127 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 7128 | * @phba: pointer to lpfc hba data structure. |
| 7129 | * |
| 7130 | * This routine is the lock version of the API invoked to allocate a |
| 7131 | * completion-queue event from the free pool. |
| 7132 | * |
| 7133 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 7134 | * NULL otherwise. |
| 7135 | **/ |
| 7136 | struct lpfc_cq_event * |
| 7137 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 7138 | { |
| 7139 | struct lpfc_cq_event *cq_event; |
| 7140 | unsigned long iflags; |
| 7141 | |
| 7142 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7143 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 7144 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7145 | return cq_event; |
| 7146 | } |
| 7147 | |
| 7148 | /** |
| 7149 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7150 | * @phba: pointer to lpfc hba data structure. |
| 7151 | * @cq_event: pointer to the completion queue event to be freed. |
| 7152 | * |
| 7153 | * This routine is the lock free version of the API invoked to release a |
| 7154 | * completion-queue event back into the free pool. |
| 7155 | **/ |
| 7156 | void |
| 7157 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7158 | struct lpfc_cq_event *cq_event) |
| 7159 | { |
| 7160 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 7161 | } |
| 7162 | |
| 7163 | /** |
| 7164 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 7165 | * @phba: pointer to lpfc hba data structure. |
| 7166 | * @cq_event: pointer to the completion queue event to be freed. |
| 7167 | * |
| 7168 | * This routine is the lock version of the API invoked to release a |
| 7169 | * completion-queue event back into the free pool. |
| 7170 | **/ |
| 7171 | void |
| 7172 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 7173 | struct lpfc_cq_event *cq_event) |
| 7174 | { |
| 7175 | unsigned long iflags; |
| 7176 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7177 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 7178 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7179 | } |
| 7180 | |
| 7181 | /** |
| 7182 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 7183 | * @phba: pointer to lpfc hba data structure. |
| 7184 | * |
| 7185 | * This routine is to free all the pending completion-queue events to the |
| 7186 | * back into the free pool for device reset. |
| 7187 | **/ |
| 7188 | static void |
| 7189 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 7190 | { |
| 7191 | LIST_HEAD(cqelist); |
| 7192 | struct lpfc_cq_event *cqe; |
| 7193 | unsigned long iflags; |
| 7194 | |
| 7195 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 7196 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 7197 | /* Pending FCP XRI abort events */ |
| 7198 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 7199 | &cqelist); |
| 7200 | /* Pending ELS XRI abort events */ |
| 7201 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 7202 | &cqelist); |
| 7203 | /* Pending asynnc events */ |
| 7204 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 7205 | &cqelist); |
| 7206 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7207 | |
| 7208 | while (!list_empty(&cqelist)) { |
| 7209 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 7210 | lpfc_sli4_cq_event_release(phba, cqe); |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | /** |
| 7215 | * lpfc_pci_function_reset - Reset pci function. |
| 7216 | * @phba: pointer to lpfc hba data structure. |
| 7217 | * |
| 7218 | * This routine is invoked to request a PCI function reset. It will destroys |
| 7219 | * all resources assigned to the PCI function which originates this request. |
| 7220 | * |
| 7221 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7222 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7223 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7224 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7225 | **/ |
| 7226 | int |
| 7227 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 7228 | { |
| 7229 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7230 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7231 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7232 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7233 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7234 | struct lpfc_register reg_data; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7235 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7236 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7237 | switch (if_type) { |
| 7238 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7239 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7240 | GFP_KERNEL); |
| 7241 | if (!mboxq) { |
| 7242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7243 | "0494 Unable to allocate memory for " |
| 7244 | "issuing SLI_FUNCTION_RESET mailbox " |
| 7245 | "command\n"); |
| 7246 | return -ENOMEM; |
| 7247 | } |
| 7248 | |
| 7249 | /* Setup PCI function reset mailbox-ioctl command */ |
| 7250 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7251 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 7252 | LPFC_SLI4_MBX_EMBED); |
| 7253 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7254 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7255 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7256 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7257 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7258 | &shdr->response); |
| 7259 | if (rc != MBX_TIMEOUT) |
| 7260 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7261 | if (shdr_status || shdr_add_status || rc) { |
| 7262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7263 | "0495 SLI_FUNCTION_RESET mailbox " |
| 7264 | "failed with status x%x add_status x%x," |
| 7265 | " mbx status x%x\n", |
| 7266 | shdr_status, shdr_add_status, rc); |
| 7267 | rc = -ENXIO; |
| 7268 | } |
| 7269 | break; |
| 7270 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7271 | for (num_resets = 0; |
| 7272 | num_resets < MAX_IF_TYPE_2_RESETS; |
| 7273 | num_resets++) { |
| 7274 | reg_data.word0 = 0; |
| 7275 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 7276 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 7277 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 7278 | LPFC_SLIPORT_INIT_PORT); |
| 7279 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 7280 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame^] | 7281 | /* flush */ |
| 7282 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7283 | /* |
| 7284 | * Poll the Port Status Register and wait for RDY for |
| 7285 | * up to 10 seconds. If the port doesn't respond, treat |
| 7286 | * it as an error. If the port responds with RN, start |
| 7287 | * the loop again. |
| 7288 | */ |
| 7289 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7290 | msleep(10); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7291 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 7292 | STATUSregaddr, ®_data.word0)) { |
| 7293 | rc = -ENODEV; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7294 | goto out; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7295 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7296 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
| 7297 | reset_again++; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7298 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 7299 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7300 | } |
| 7301 | |
| 7302 | /* |
| 7303 | * If the port responds to the init request with |
| 7304 | * reset needed, delay for a bit and restart the loop. |
| 7305 | */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 7306 | if (reset_again && (rdy_chk < 1000)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7307 | msleep(10); |
| 7308 | reset_again = 0; |
| 7309 | continue; |
| 7310 | } |
| 7311 | |
| 7312 | /* Detect any port errors. */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7313 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
| 7314 | (rdy_chk >= 1000)) { |
| 7315 | phba->work_status[0] = readl( |
| 7316 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 7317 | phba->work_status[1] = readl( |
| 7318 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 7319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame^] | 7320 | "2890 Port error detected during port " |
| 7321 | "reset(%d): port status reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7322 | "error 1=0x%x, error 2=0x%x\n", |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame^] | 7323 | num_resets, reg_data.word0, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7324 | phba->work_status[0], |
| 7325 | phba->work_status[1]); |
| 7326 | rc = -ENODEV; |
| 7327 | } |
| 7328 | |
| 7329 | /* |
| 7330 | * Terminate the outer loop provided the Port indicated |
| 7331 | * ready within 10 seconds. |
| 7332 | */ |
| 7333 | if (rdy_chk < 1000) |
| 7334 | break; |
| 7335 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7336 | /* delay driver action following IF_TYPE_2 function reset */ |
| 7337 | msleep(100); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7338 | break; |
| 7339 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7340 | default: |
| 7341 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7342 | } |
| 7343 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 7344 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7345 | /* Catch the not-ready port failure after a port reset. */ |
| 7346 | if (num_resets >= MAX_IF_TYPE_2_RESETS) |
| 7347 | rc = -ENODEV; |
| 7348 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7349 | return rc; |
| 7350 | } |
| 7351 | |
| 7352 | /** |
| 7353 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands |
| 7354 | * @phba: pointer to lpfc hba data structure. |
| 7355 | * @cnt: number of nop mailbox commands to send. |
| 7356 | * |
| 7357 | * This routine is invoked to send a number @cnt of NOP mailbox command and |
| 7358 | * wait for each command to complete. |
| 7359 | * |
| 7360 | * Return: the number of NOP mailbox command completed. |
| 7361 | **/ |
| 7362 | static int |
| 7363 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) |
| 7364 | { |
| 7365 | LPFC_MBOXQ_t *mboxq; |
| 7366 | int length, cmdsent; |
| 7367 | uint32_t mbox_tmo; |
| 7368 | uint32_t rc = 0; |
| 7369 | uint32_t shdr_status, shdr_add_status; |
| 7370 | union lpfc_sli4_cfg_shdr *shdr; |
| 7371 | |
| 7372 | if (cnt == 0) { |
| 7373 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7374 | "2518 Requested to send 0 NOP mailbox cmd\n"); |
| 7375 | return cnt; |
| 7376 | } |
| 7377 | |
| 7378 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7379 | if (!mboxq) { |
| 7380 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7381 | "2519 Unable to allocate memory for issuing " |
| 7382 | "NOP mailbox command\n"); |
| 7383 | return 0; |
| 7384 | } |
| 7385 | |
| 7386 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ |
| 7387 | length = (sizeof(struct lpfc_mbx_nop) - |
| 7388 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7389 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7390 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); |
| 7391 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7392 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
| 7393 | if (!phba->sli4_hba.intr_enable) |
| 7394 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7395 | else { |
| 7396 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7397 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7398 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7399 | if (rc == MBX_TIMEOUT) |
| 7400 | break; |
| 7401 | /* Check return status */ |
| 7402 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7403 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7404 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7405 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 7406 | &shdr->response); |
| 7407 | if (shdr_status || shdr_add_status || rc) { |
| 7408 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7409 | "2520 NOP mailbox command failed " |
| 7410 | "status x%x add_status x%x mbx " |
| 7411 | "status x%x\n", shdr_status, |
| 7412 | shdr_add_status, rc); |
| 7413 | break; |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | if (rc != MBX_TIMEOUT) |
| 7418 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7419 | |
| 7420 | return cmdsent; |
| 7421 | } |
| 7422 | |
| 7423 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7424 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 7425 | * @phba: pointer to lpfc hba data structure. |
| 7426 | * |
| 7427 | * This routine is invoked to set up the PCI device memory space for device |
| 7428 | * with SLI-4 interface spec. |
| 7429 | * |
| 7430 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7431 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7432 | * other values - error |
| 7433 | **/ |
| 7434 | static int |
| 7435 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 7436 | { |
| 7437 | struct pci_dev *pdev; |
| 7438 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 7439 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7440 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7441 | |
| 7442 | /* Obtain PCI device reference */ |
| 7443 | if (!phba->pcidev) |
| 7444 | return error; |
| 7445 | else |
| 7446 | pdev = phba->pcidev; |
| 7447 | |
| 7448 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7449 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7450 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7451 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7452 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7453 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7454 | } |
| 7455 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7456 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7457 | /* |
| 7458 | * The BARs and register set definitions and offset locations are |
| 7459 | * dependent on the if_type. |
| 7460 | */ |
| 7461 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 7462 | &phba->sli4_hba.sli_intf.word0)) { |
| 7463 | return error; |
| 7464 | } |
| 7465 | |
| 7466 | /* There is no SLI3 failback for SLI4 devices. */ |
| 7467 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 7468 | LPFC_SLI_INTF_VALID) { |
| 7469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7470 | "2894 SLI_INTF reg contents invalid " |
| 7471 | "sli_intf reg 0x%x\n", |
| 7472 | phba->sli4_hba.sli_intf.word0); |
| 7473 | return error; |
| 7474 | } |
| 7475 | |
| 7476 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7477 | /* |
| 7478 | * Get the bus address of SLI4 device Bar regions and the |
| 7479 | * number of bytes required by each mapping. The mapping of the |
| 7480 | * particular PCI BARs regions is dependent on the type of |
| 7481 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7482 | */ |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7483 | if (pci_resource_start(pdev, 0)) { |
| 7484 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7485 | bar0map_len = pci_resource_len(pdev, 0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7486 | |
| 7487 | /* |
| 7488 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 7489 | * addr |
| 7490 | */ |
| 7491 | phba->sli4_hba.conf_regs_memmap_p = |
| 7492 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 7493 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7494 | dev_printk(KERN_ERR, &pdev->dev, |
| 7495 | "ioremap failed for SLI4 PCI config " |
| 7496 | "registers.\n"); |
| 7497 | goto out; |
| 7498 | } |
| 7499 | /* Set up BAR0 PCI config space register memory map */ |
| 7500 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 7501 | } else { |
| 7502 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 7503 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7504 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7505 | dev_printk(KERN_ERR, &pdev->dev, |
| 7506 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 7507 | goto out; |
| 7508 | } |
| 7509 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7510 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7511 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 7512 | dev_printk(KERN_ERR, &pdev->dev, |
| 7513 | "ioremap failed for SLI4 PCI config " |
| 7514 | "registers.\n"); |
| 7515 | goto out; |
| 7516 | } |
| 7517 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7518 | } |
| 7519 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7520 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7521 | (pci_resource_start(pdev, 2))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7522 | /* |
| 7523 | * Map SLI4 if type 0 HBA Control Register base to a kernel |
| 7524 | * virtual address and setup the registers. |
| 7525 | */ |
| 7526 | phba->pci_bar1_map = pci_resource_start(pdev, 2); |
| 7527 | bar1map_len = pci_resource_len(pdev, 2); |
| 7528 | phba->sli4_hba.ctrl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7529 | ioremap(phba->pci_bar1_map, bar1map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7530 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 7531 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7532 | "ioremap failed for SLI4 HBA control registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7533 | goto out_iounmap_conf; |
| 7534 | } |
| 7535 | lpfc_sli4_bar1_register_memmap(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7536 | } |
| 7537 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7538 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
| 7539 | (pci_resource_start(pdev, 4))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7540 | /* |
| 7541 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel |
| 7542 | * virtual address and setup the registers. |
| 7543 | */ |
| 7544 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
| 7545 | bar2map_len = pci_resource_len(pdev, 4); |
| 7546 | phba->sli4_hba.drbl_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7547 | ioremap(phba->pci_bar2_map, bar2map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7548 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 7549 | dev_printk(KERN_ERR, &pdev->dev, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7550 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7551 | goto out_iounmap_ctrl; |
| 7552 | } |
| 7553 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 7554 | if (error) |
| 7555 | goto out_iounmap_all; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7556 | } |
| 7557 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7558 | return 0; |
| 7559 | |
| 7560 | out_iounmap_all: |
| 7561 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7562 | out_iounmap_ctrl: |
| 7563 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7564 | out_iounmap_conf: |
| 7565 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7566 | out: |
| 7567 | return error; |
| 7568 | } |
| 7569 | |
| 7570 | /** |
| 7571 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 7572 | * @phba: pointer to lpfc hba data structure. |
| 7573 | * |
| 7574 | * This routine is invoked to unset the PCI device memory space for device |
| 7575 | * with SLI-4 interface spec. |
| 7576 | **/ |
| 7577 | static void |
| 7578 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 7579 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7580 | uint32_t if_type; |
| 7581 | 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] | 7582 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 7583 | switch (if_type) { |
| 7584 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7585 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 7586 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 7587 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7588 | break; |
| 7589 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7590 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 7591 | break; |
| 7592 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7593 | default: |
| 7594 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 7595 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7596 | if_type); |
| 7597 | break; |
| 7598 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7602 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 7603 | * @phba: pointer to lpfc hba data structure. |
| 7604 | * |
| 7605 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 7606 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is |
| 7607 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once |
| 7608 | * invoked, enables either all or nothing, depending on the current |
| 7609 | * availability of PCI vector resources. The device driver is responsible |
| 7610 | * for calling the individual request_irq() to register each MSI-X vector |
| 7611 | * with a interrupt handler, which is done in this function. Note that |
| 7612 | * later when device is unloading, the driver should always call free_irq() |
| 7613 | * on all MSI-X vectors it has done request_irq() on before calling |
| 7614 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 7615 | * will be left with MSI-X enabled and leaks its vectors. |
| 7616 | * |
| 7617 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7618 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7619 | * other values - error |
| 7620 | **/ |
| 7621 | static int |
| 7622 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 7623 | { |
| 7624 | int rc, i; |
| 7625 | LPFC_MBOXQ_t *pmb; |
| 7626 | |
| 7627 | /* Set up MSI-X multi-message vectors */ |
| 7628 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7629 | phba->msix_entries[i].entry = i; |
| 7630 | |
| 7631 | /* Configure MSI-X capability structure */ |
| 7632 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
| 7633 | ARRAY_SIZE(phba->msix_entries)); |
| 7634 | if (rc) { |
| 7635 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7636 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
| 7637 | goto msi_fail_out; |
| 7638 | } |
| 7639 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7640 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7641 | "0477 MSI-X entry[%d]: vector=x%x " |
| 7642 | "message=%d\n", i, |
| 7643 | phba->msix_entries[i].vector, |
| 7644 | phba->msix_entries[i].entry); |
| 7645 | /* |
| 7646 | * Assign MSI-X vectors to interrupt handlers |
| 7647 | */ |
| 7648 | |
| 7649 | /* vector-0 is associated to slow-path handler */ |
| 7650 | rc = request_irq(phba->msix_entries[0].vector, |
| 7651 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
| 7652 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 7653 | if (rc) { |
| 7654 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7655 | "0421 MSI-X slow-path request_irq failed " |
| 7656 | "(%d)\n", rc); |
| 7657 | goto msi_fail_out; |
| 7658 | } |
| 7659 | |
| 7660 | /* vector-1 is associated to fast-path handler */ |
| 7661 | rc = request_irq(phba->msix_entries[1].vector, |
| 7662 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
| 7663 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 7664 | |
| 7665 | if (rc) { |
| 7666 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7667 | "0429 MSI-X fast-path request_irq failed " |
| 7668 | "(%d)\n", rc); |
| 7669 | goto irq_fail_out; |
| 7670 | } |
| 7671 | |
| 7672 | /* |
| 7673 | * Configure HBA MSI-X attention conditions to messages |
| 7674 | */ |
| 7675 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7676 | |
| 7677 | if (!pmb) { |
| 7678 | rc = -ENOMEM; |
| 7679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7680 | "0474 Unable to allocate memory for issuing " |
| 7681 | "MBOX_CONFIG_MSI command\n"); |
| 7682 | goto mem_fail_out; |
| 7683 | } |
| 7684 | rc = lpfc_config_msi(phba, pmb); |
| 7685 | if (rc) |
| 7686 | goto mbx_fail_out; |
| 7687 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 7688 | if (rc != MBX_SUCCESS) { |
| 7689 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 7690 | "0351 Config MSI mailbox command failed, " |
| 7691 | "mbxCmd x%x, mbxStatus x%x\n", |
| 7692 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 7693 | goto mbx_fail_out; |
| 7694 | } |
| 7695 | |
| 7696 | /* Free memory allocated for mailbox command */ |
| 7697 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7698 | return rc; |
| 7699 | |
| 7700 | mbx_fail_out: |
| 7701 | /* Free memory allocated for mailbox command */ |
| 7702 | mempool_free(pmb, phba->mbox_mem_pool); |
| 7703 | |
| 7704 | mem_fail_out: |
| 7705 | /* free the irq already requested */ |
| 7706 | free_irq(phba->msix_entries[1].vector, phba); |
| 7707 | |
| 7708 | irq_fail_out: |
| 7709 | /* free the irq already requested */ |
| 7710 | free_irq(phba->msix_entries[0].vector, phba); |
| 7711 | |
| 7712 | msi_fail_out: |
| 7713 | /* Unconfigure MSI-X capability structure */ |
| 7714 | pci_disable_msix(phba->pcidev); |
| 7715 | return rc; |
| 7716 | } |
| 7717 | |
| 7718 | /** |
| 7719 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
| 7720 | * @phba: pointer to lpfc hba data structure. |
| 7721 | * |
| 7722 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 7723 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
| 7724 | **/ |
| 7725 | static void |
| 7726 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
| 7727 | { |
| 7728 | int i; |
| 7729 | |
| 7730 | /* Free up MSI-X multi-message vectors */ |
| 7731 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 7732 | free_irq(phba->msix_entries[i].vector, phba); |
| 7733 | /* Disable MSI-X */ |
| 7734 | pci_disable_msix(phba->pcidev); |
| 7735 | |
| 7736 | return; |
| 7737 | } |
| 7738 | |
| 7739 | /** |
| 7740 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 7741 | * @phba: pointer to lpfc hba data structure. |
| 7742 | * |
| 7743 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 7744 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 7745 | * enable the MSI vector. The device driver is responsible for calling the |
| 7746 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 7747 | * is done in this function. |
| 7748 | * |
| 7749 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7750 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7751 | * other values - error |
| 7752 | */ |
| 7753 | static int |
| 7754 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 7755 | { |
| 7756 | int rc; |
| 7757 | |
| 7758 | rc = pci_enable_msi(phba->pcidev); |
| 7759 | if (!rc) |
| 7760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7761 | "0462 PCI enable MSI mode success.\n"); |
| 7762 | else { |
| 7763 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7764 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 7765 | return rc; |
| 7766 | } |
| 7767 | |
| 7768 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 7769 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 7770 | if (rc) { |
| 7771 | pci_disable_msi(phba->pcidev); |
| 7772 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7773 | "0478 MSI request_irq failed (%d)\n", rc); |
| 7774 | } |
| 7775 | return rc; |
| 7776 | } |
| 7777 | |
| 7778 | /** |
| 7779 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
| 7780 | * @phba: pointer to lpfc hba data structure. |
| 7781 | * |
| 7782 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 7783 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
| 7784 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 7785 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 7786 | * its vector. |
| 7787 | */ |
| 7788 | static void |
| 7789 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
| 7790 | { |
| 7791 | free_irq(phba->pcidev->irq, phba); |
| 7792 | pci_disable_msi(phba->pcidev); |
| 7793 | return; |
| 7794 | } |
| 7795 | |
| 7796 | /** |
| 7797 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 7798 | * @phba: pointer to lpfc hba data structure. |
| 7799 | * |
| 7800 | * This routine is invoked to enable device interrupt and associate driver's |
| 7801 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 7802 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 7803 | * will try to fallback from the configured interrupt mode to an interrupt |
| 7804 | * mode which is supported by the platform, kernel, and device in the order |
| 7805 | * of: |
| 7806 | * MSI-X -> MSI -> IRQ. |
| 7807 | * |
| 7808 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7809 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7810 | * other values - error |
| 7811 | **/ |
| 7812 | static uint32_t |
| 7813 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 7814 | { |
| 7815 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 7816 | int retval; |
| 7817 | |
| 7818 | if (cfg_mode == 2) { |
| 7819 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 7820 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 7821 | if (!retval) { |
| 7822 | /* Now, try to enable MSI-X interrupt mode */ |
| 7823 | retval = lpfc_sli_enable_msix(phba); |
| 7824 | if (!retval) { |
| 7825 | /* Indicate initialization to MSI-X mode */ |
| 7826 | phba->intr_type = MSIX; |
| 7827 | intr_mode = 2; |
| 7828 | } |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | /* Fallback to MSI if MSI-X initialization failed */ |
| 7833 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 7834 | retval = lpfc_sli_enable_msi(phba); |
| 7835 | if (!retval) { |
| 7836 | /* Indicate initialization to MSI mode */ |
| 7837 | phba->intr_type = MSI; |
| 7838 | intr_mode = 1; |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 7843 | if (phba->intr_type == NONE) { |
| 7844 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 7845 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 7846 | if (!retval) { |
| 7847 | /* Indicate initialization to INTx mode */ |
| 7848 | phba->intr_type = INTx; |
| 7849 | intr_mode = 0; |
| 7850 | } |
| 7851 | } |
| 7852 | return intr_mode; |
| 7853 | } |
| 7854 | |
| 7855 | /** |
| 7856 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 7857 | * @phba: pointer to lpfc hba data structure. |
| 7858 | * |
| 7859 | * This routine is invoked to disable device interrupt and disassociate the |
| 7860 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 7861 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 7862 | * release the interrupt vector(s) for the message signaled interrupt. |
| 7863 | **/ |
| 7864 | static void |
| 7865 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 7866 | { |
| 7867 | /* Disable the currently initialized interrupt mode */ |
| 7868 | if (phba->intr_type == MSIX) |
| 7869 | lpfc_sli_disable_msix(phba); |
| 7870 | else if (phba->intr_type == MSI) |
| 7871 | lpfc_sli_disable_msi(phba); |
| 7872 | else if (phba->intr_type == INTx) |
| 7873 | free_irq(phba->pcidev->irq, phba); |
| 7874 | |
| 7875 | /* Reset interrupt management states */ |
| 7876 | phba->intr_type = NONE; |
| 7877 | phba->sli.slistat.sli_intr = 0; |
| 7878 | |
| 7879 | return; |
| 7880 | } |
| 7881 | |
| 7882 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7883 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 7884 | * @phba: pointer to lpfc hba data structure. |
| 7885 | * |
| 7886 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
| 7887 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called |
| 7888 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, |
| 7889 | * enables either all or nothing, depending on the current availability of |
| 7890 | * PCI vector resources. The device driver is responsible for calling the |
| 7891 | * individual request_irq() to register each MSI-X vector with a interrupt |
| 7892 | * handler, which is done in this function. Note that later when device is |
| 7893 | * unloading, the driver should always call free_irq() on all MSI-X vectors |
| 7894 | * it has done request_irq() on before calling pci_disable_msix(). Failure |
| 7895 | * to do so results in a BUG_ON() and a device will be left with MSI-X |
| 7896 | * enabled and leaks its vectors. |
| 7897 | * |
| 7898 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7899 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7900 | * other values - error |
| 7901 | **/ |
| 7902 | static int |
| 7903 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 7904 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7905 | int vectors, rc, index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7906 | |
| 7907 | /* Set up MSI-X multi-message vectors */ |
| 7908 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) |
| 7909 | phba->sli4_hba.msix_entries[index].entry = index; |
| 7910 | |
| 7911 | /* Configure MSI-X capability structure */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7912 | vectors = phba->sli4_hba.cfg_eqn; |
| 7913 | enable_msix_vectors: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7914 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7915 | vectors); |
| 7916 | if (rc > 1) { |
| 7917 | vectors = rc; |
| 7918 | goto enable_msix_vectors; |
| 7919 | } else if (rc) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7920 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7921 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
| 7922 | goto msi_fail_out; |
| 7923 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7924 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7925 | /* Log MSI-X vector assignment */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7926 | for (index = 0; index < vectors; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7927 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7928 | "0489 MSI-X entry[%d]: vector=x%x " |
| 7929 | "message=%d\n", index, |
| 7930 | phba->sli4_hba.msix_entries[index].vector, |
| 7931 | phba->sli4_hba.msix_entries[index].entry); |
| 7932 | /* |
| 7933 | * Assign MSI-X vectors to interrupt handlers |
| 7934 | */ |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7935 | if (vectors > 1) |
| 7936 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, |
| 7937 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, |
| 7938 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 7939 | else |
| 7940 | /* All Interrupts need to be handled by one EQ */ |
| 7941 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, |
| 7942 | &lpfc_sli4_intr_handler, IRQF_SHARED, |
| 7943 | LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7944 | if (rc) { |
| 7945 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7946 | "0485 MSI-X slow-path request_irq failed " |
| 7947 | "(%d)\n", rc); |
| 7948 | goto msi_fail_out; |
| 7949 | } |
| 7950 | |
| 7951 | /* The rest of the vector(s) are associated to fast-path handler(s) */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7952 | for (index = 1; index < vectors; index++) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7953 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
| 7954 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; |
| 7955 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, |
| 7956 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, |
| 7957 | LPFC_FP_DRIVER_HANDLER_NAME, |
| 7958 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); |
| 7959 | if (rc) { |
| 7960 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7961 | "0486 MSI-X fast-path (%d) " |
| 7962 | "request_irq failed (%d)\n", index, rc); |
| 7963 | goto cfg_fail_out; |
| 7964 | } |
| 7965 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7966 | phba->sli4_hba.msix_vec_nr = vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7967 | |
| 7968 | return rc; |
| 7969 | |
| 7970 | cfg_fail_out: |
| 7971 | /* free the irq already requested */ |
| 7972 | for (--index; index >= 1; index--) |
| 7973 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, |
| 7974 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); |
| 7975 | |
| 7976 | /* free the irq already requested */ |
| 7977 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); |
| 7978 | |
| 7979 | msi_fail_out: |
| 7980 | /* Unconfigure MSI-X capability structure */ |
| 7981 | pci_disable_msix(phba->pcidev); |
| 7982 | return rc; |
| 7983 | } |
| 7984 | |
| 7985 | /** |
| 7986 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device |
| 7987 | * @phba: pointer to lpfc hba data structure. |
| 7988 | * |
| 7989 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 7990 | * MSI-X interrupt mode to device with SLI-4 interface spec. |
| 7991 | **/ |
| 7992 | static void |
| 7993 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
| 7994 | { |
| 7995 | int index; |
| 7996 | |
| 7997 | /* Free up MSI-X multi-message vectors */ |
| 7998 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); |
| 7999 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8000 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8001 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
| 8002 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8003 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8004 | /* Disable MSI-X */ |
| 8005 | pci_disable_msix(phba->pcidev); |
| 8006 | |
| 8007 | return; |
| 8008 | } |
| 8009 | |
| 8010 | /** |
| 8011 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 8012 | * @phba: pointer to lpfc hba data structure. |
| 8013 | * |
| 8014 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 8015 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 8016 | * to enable the MSI vector. The device driver is responsible for calling |
| 8017 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 8018 | * which is done in this function. |
| 8019 | * |
| 8020 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8021 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8022 | * other values - error |
| 8023 | **/ |
| 8024 | static int |
| 8025 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 8026 | { |
| 8027 | int rc, index; |
| 8028 | |
| 8029 | rc = pci_enable_msi(phba->pcidev); |
| 8030 | if (!rc) |
| 8031 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8032 | "0487 PCI enable MSI mode success.\n"); |
| 8033 | else { |
| 8034 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8035 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 8036 | return rc; |
| 8037 | } |
| 8038 | |
| 8039 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8040 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8041 | if (rc) { |
| 8042 | pci_disable_msi(phba->pcidev); |
| 8043 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8044 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8045 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8046 | } |
| 8047 | |
| 8048 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { |
| 8049 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8050 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8051 | } |
| 8052 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8053 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8054 | } |
| 8055 | |
| 8056 | /** |
| 8057 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device |
| 8058 | * @phba: pointer to lpfc hba data structure. |
| 8059 | * |
| 8060 | * This routine is invoked to disable the MSI interrupt mode to device with |
| 8061 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has |
| 8062 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
| 8063 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
| 8064 | * its vector. |
| 8065 | **/ |
| 8066 | static void |
| 8067 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) |
| 8068 | { |
| 8069 | free_irq(phba->pcidev->irq, phba); |
| 8070 | pci_disable_msi(phba->pcidev); |
| 8071 | return; |
| 8072 | } |
| 8073 | |
| 8074 | /** |
| 8075 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 8076 | * @phba: pointer to lpfc hba data structure. |
| 8077 | * |
| 8078 | * This routine is invoked to enable device interrupt and associate driver's |
| 8079 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 8080 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 8081 | * the driver will try to fallback from the configured interrupt mode to an |
| 8082 | * interrupt mode which is supported by the platform, kernel, and device in |
| 8083 | * the order of: |
| 8084 | * MSI-X -> MSI -> IRQ. |
| 8085 | * |
| 8086 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8087 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8088 | * other values - error |
| 8089 | **/ |
| 8090 | static uint32_t |
| 8091 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 8092 | { |
| 8093 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 8094 | int retval, index; |
| 8095 | |
| 8096 | if (cfg_mode == 2) { |
| 8097 | /* Preparation before conf_msi mbox cmd */ |
| 8098 | retval = 0; |
| 8099 | if (!retval) { |
| 8100 | /* Now, try to enable MSI-X interrupt mode */ |
| 8101 | retval = lpfc_sli4_enable_msix(phba); |
| 8102 | if (!retval) { |
| 8103 | /* Indicate initialization to MSI-X mode */ |
| 8104 | phba->intr_type = MSIX; |
| 8105 | intr_mode = 2; |
| 8106 | } |
| 8107 | } |
| 8108 | } |
| 8109 | |
| 8110 | /* Fallback to MSI if MSI-X initialization failed */ |
| 8111 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 8112 | retval = lpfc_sli4_enable_msi(phba); |
| 8113 | if (!retval) { |
| 8114 | /* Indicate initialization to MSI mode */ |
| 8115 | phba->intr_type = MSI; |
| 8116 | intr_mode = 1; |
| 8117 | } |
| 8118 | } |
| 8119 | |
| 8120 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 8121 | if (phba->intr_type == NONE) { |
| 8122 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 8123 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 8124 | if (!retval) { |
| 8125 | /* Indicate initialization to INTx mode */ |
| 8126 | phba->intr_type = INTx; |
| 8127 | intr_mode = 0; |
| 8128 | for (index = 0; index < phba->cfg_fcp_eq_count; |
| 8129 | index++) { |
| 8130 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
| 8131 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; |
| 8132 | } |
| 8133 | } |
| 8134 | } |
| 8135 | return intr_mode; |
| 8136 | } |
| 8137 | |
| 8138 | /** |
| 8139 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 8140 | * @phba: pointer to lpfc hba data structure. |
| 8141 | * |
| 8142 | * This routine is invoked to disable device interrupt and disassociate |
| 8143 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 8144 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 8145 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 8146 | **/ |
| 8147 | static void |
| 8148 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 8149 | { |
| 8150 | /* Disable the currently initialized interrupt mode */ |
| 8151 | if (phba->intr_type == MSIX) |
| 8152 | lpfc_sli4_disable_msix(phba); |
| 8153 | else if (phba->intr_type == MSI) |
| 8154 | lpfc_sli4_disable_msi(phba); |
| 8155 | else if (phba->intr_type == INTx) |
| 8156 | free_irq(phba->pcidev->irq, phba); |
| 8157 | |
| 8158 | /* Reset interrupt management states */ |
| 8159 | phba->intr_type = NONE; |
| 8160 | phba->sli.slistat.sli_intr = 0; |
| 8161 | |
| 8162 | return; |
| 8163 | } |
| 8164 | |
| 8165 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8166 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 8167 | * @phba: pointer to lpfc hba data structure. |
| 8168 | * |
| 8169 | * This routine is invoked to unset the HBA device initialization steps to |
| 8170 | * a device with SLI-3 interface spec. |
| 8171 | **/ |
| 8172 | static void |
| 8173 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 8174 | { |
| 8175 | struct lpfc_vport *vport = phba->pport; |
| 8176 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8177 | |
| 8178 | spin_lock_irq(shost->host_lock); |
| 8179 | vport->load_flag |= FC_UNLOADING; |
| 8180 | spin_unlock_irq(shost->host_lock); |
| 8181 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8182 | kfree(phba->vpi_bmask); |
| 8183 | kfree(phba->vpi_ids); |
| 8184 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8185 | lpfc_stop_hba_timers(phba); |
| 8186 | |
| 8187 | phba->pport->work_port_events = 0; |
| 8188 | |
| 8189 | lpfc_sli_hba_down(phba); |
| 8190 | |
| 8191 | lpfc_sli_brdrestart(phba); |
| 8192 | |
| 8193 | lpfc_sli_disable_intr(phba); |
| 8194 | |
| 8195 | return; |
| 8196 | } |
| 8197 | |
| 8198 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8199 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. |
| 8200 | * @phba: pointer to lpfc hba data structure. |
| 8201 | * |
| 8202 | * This routine is invoked to unset the HBA device initialization steps to |
| 8203 | * a device with SLI-4 interface spec. |
| 8204 | **/ |
| 8205 | static void |
| 8206 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) |
| 8207 | { |
| 8208 | struct lpfc_vport *vport = phba->pport; |
| 8209 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 8210 | |
| 8211 | spin_lock_irq(shost->host_lock); |
| 8212 | vport->load_flag |= FC_UNLOADING; |
| 8213 | spin_unlock_irq(shost->host_lock); |
| 8214 | |
| 8215 | phba->pport->work_port_events = 0; |
| 8216 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8217 | /* Stop the SLI4 device port */ |
| 8218 | lpfc_stop_port(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8219 | |
| 8220 | lpfc_sli4_disable_intr(phba); |
| 8221 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8222 | /* Reset SLI4 HBA FCoE function */ |
| 8223 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8224 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8225 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8226 | return; |
| 8227 | } |
| 8228 | |
| 8229 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8230 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 8231 | * @phba: Pointer to HBA context object. |
| 8232 | * |
| 8233 | * This function is called in the SLI4 code path to wait for completion |
| 8234 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 8235 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 8236 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 8237 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 8238 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 8239 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 8240 | * the rest of the driver unload resource release. |
| 8241 | **/ |
| 8242 | static void |
| 8243 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 8244 | { |
| 8245 | int wait_time = 0; |
| 8246 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8247 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8248 | |
| 8249 | while (!fcp_xri_cmpl || !els_xri_cmpl) { |
| 8250 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
| 8251 | if (!fcp_xri_cmpl) |
| 8252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8253 | "2877 FCP XRI exchange busy " |
| 8254 | "wait time: %d seconds.\n", |
| 8255 | wait_time/1000); |
| 8256 | if (!els_xri_cmpl) |
| 8257 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8258 | "2878 ELS XRI exchange busy " |
| 8259 | "wait time: %d seconds.\n", |
| 8260 | wait_time/1000); |
| 8261 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 8262 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 8263 | } else { |
| 8264 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 8265 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 8266 | } |
| 8267 | fcp_xri_cmpl = |
| 8268 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 8269 | els_xri_cmpl = |
| 8270 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 8271 | } |
| 8272 | } |
| 8273 | |
| 8274 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8275 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 8276 | * @phba: Pointer to HBA context object. |
| 8277 | * |
| 8278 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 8279 | * function. The caller is not required to hold any lock. This routine |
| 8280 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 8281 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 8282 | * free any pending commands. |
| 8283 | **/ |
| 8284 | static void |
| 8285 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 8286 | { |
| 8287 | int wait_cnt = 0; |
| 8288 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8289 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8290 | |
| 8291 | lpfc_stop_hba_timers(phba); |
| 8292 | phba->sli4_hba.intr_enable = 0; |
| 8293 | |
| 8294 | /* |
| 8295 | * Gracefully wait out the potential current outstanding asynchronous |
| 8296 | * mailbox command. |
| 8297 | */ |
| 8298 | |
| 8299 | /* First, block any pending async mailbox command from posted */ |
| 8300 | spin_lock_irq(&phba->hbalock); |
| 8301 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 8302 | spin_unlock_irq(&phba->hbalock); |
| 8303 | /* Now, trying to wait it out if we can */ |
| 8304 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8305 | msleep(10); |
| 8306 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 8307 | break; |
| 8308 | } |
| 8309 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 8310 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8311 | spin_lock_irq(&phba->hbalock); |
| 8312 | mboxq = phba->sli.mbox_active; |
| 8313 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8314 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8315 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8316 | phba->sli.mbox_active = NULL; |
| 8317 | spin_unlock_irq(&phba->hbalock); |
| 8318 | } |
| 8319 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 8320 | /* Abort all iocbs associated with the hba */ |
| 8321 | lpfc_sli_hba_iocb_abort(phba); |
| 8322 | |
| 8323 | /* Wait for completion of device XRI exchange busy */ |
| 8324 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 8325 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8326 | /* Disable PCI subsystem interrupt */ |
| 8327 | lpfc_sli4_disable_intr(phba); |
| 8328 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8329 | /* Disable SR-IOV if enabled */ |
| 8330 | if (phba->cfg_sriov_nr_virtfn) |
| 8331 | pci_disable_sriov(pdev); |
| 8332 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8333 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8334 | kthread_stop(phba->worker_thread); |
| 8335 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8336 | /* Reset SLI4 HBA FCoE function */ |
| 8337 | lpfc_pci_function_reset(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8338 | lpfc_sli4_queue_destroy(phba); |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 8339 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8340 | /* Stop the SLI4 device port */ |
| 8341 | phba->pport->work_port_events = 0; |
| 8342 | } |
| 8343 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8344 | /** |
| 8345 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 8346 | * @phba: Pointer to HBA context object. |
| 8347 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8348 | * |
| 8349 | * This function is called in the SLI4 code path to read the port's |
| 8350 | * sli4 capabilities. |
| 8351 | * |
| 8352 | * This function may be be called from any context that can block-wait |
| 8353 | * for the completion. The expectation is that this routine is called |
| 8354 | * typically from probe_one or from the online routine. |
| 8355 | **/ |
| 8356 | int |
| 8357 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8358 | { |
| 8359 | int rc; |
| 8360 | struct lpfc_mqe *mqe; |
| 8361 | struct lpfc_pc_sli4_params *sli4_params; |
| 8362 | uint32_t mbox_tmo; |
| 8363 | |
| 8364 | rc = 0; |
| 8365 | mqe = &mboxq->u.mqe; |
| 8366 | |
| 8367 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8368 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8369 | if (!phba->sli4_hba.intr_enable) |
| 8370 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8371 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8372 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8373 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8374 | } |
| 8375 | |
| 8376 | if (unlikely(rc)) |
| 8377 | return 1; |
| 8378 | |
| 8379 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8380 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 8381 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 8382 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 8383 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 8384 | &mqe->un.sli4_params); |
| 8385 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 8386 | &mqe->un.sli4_params); |
| 8387 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 8388 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 8389 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 8390 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 8391 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 8392 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 8393 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 8394 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 8395 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 8396 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 8397 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 8398 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 8399 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 8400 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 8401 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 8402 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 8403 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 8404 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 8405 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 8406 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 8407 | 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] | 8408 | |
| 8409 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8410 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8411 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8412 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8413 | return rc; |
| 8414 | } |
| 8415 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8416 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8417 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 8418 | * @phba: Pointer to HBA context object. |
| 8419 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 8420 | * |
| 8421 | * This function is called in the SLI4 code path to read the port's |
| 8422 | * sli4 capabilities. |
| 8423 | * |
| 8424 | * This function may be be called from any context that can block-wait |
| 8425 | * for the completion. The expectation is that this routine is called |
| 8426 | * typically from probe_one or from the online routine. |
| 8427 | **/ |
| 8428 | int |
| 8429 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8430 | { |
| 8431 | int rc; |
| 8432 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 8433 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8434 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8435 | int length; |
| 8436 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 8437 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8438 | /* |
| 8439 | * By default, the driver assumes the SLI4 port requires RPI |
| 8440 | * header postings. The SLI4_PARAM response will correct this |
| 8441 | * assumption. |
| 8442 | */ |
| 8443 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 8444 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8445 | /* Read the port's SLI4 Config Parameters */ |
| 8446 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 8447 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8448 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8449 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 8450 | length, LPFC_SLI4_MBX_EMBED); |
| 8451 | if (!phba->sli4_hba.intr_enable) |
| 8452 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8453 | else { |
| 8454 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 8455 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 8456 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8457 | if (unlikely(rc)) |
| 8458 | return rc; |
| 8459 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 8460 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 8461 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 8462 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 8463 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 8464 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 8465 | mbx_sli4_parameters); |
| 8466 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 8467 | mbx_sli4_parameters); |
| 8468 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 8469 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 8470 | else |
| 8471 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 8472 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 8473 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
| 8474 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 8475 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 8476 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 8477 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
| 8478 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 8479 | mbx_sli4_parameters); |
| 8480 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 8481 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8482 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 8483 | 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] | 8484 | |
| 8485 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 8486 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 8487 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 8488 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8489 | return 0; |
| 8490 | } |
| 8491 | |
| 8492 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8493 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 8494 | * @pdev: pointer to PCI device |
| 8495 | * @pid: pointer to PCI device identifier |
| 8496 | * |
| 8497 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 8498 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8499 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 8500 | * information of the device and driver to see if the driver state that it can |
| 8501 | * support this kind of device. If the match is successful, the driver core |
| 8502 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 8503 | * does all the initialization that it needs to do to handle the HBA properly. |
| 8504 | * |
| 8505 | * Return code |
| 8506 | * 0 - driver can claim the device |
| 8507 | * negative value - driver can not claim the device |
| 8508 | **/ |
| 8509 | static int __devinit |
| 8510 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 8511 | { |
| 8512 | struct lpfc_hba *phba; |
| 8513 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8514 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8515 | int error; |
| 8516 | uint32_t cfg_mode, intr_mode; |
| 8517 | |
| 8518 | /* Allocate memory for HBA structure */ |
| 8519 | phba = lpfc_hba_alloc(pdev); |
| 8520 | if (!phba) |
| 8521 | return -ENOMEM; |
| 8522 | |
| 8523 | /* Perform generic PCI device enabling operation */ |
| 8524 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8525 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8526 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8527 | |
| 8528 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 8529 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 8530 | if (error) |
| 8531 | goto out_disable_pci_dev; |
| 8532 | |
| 8533 | /* Set up SLI-3 specific device PCI memory space */ |
| 8534 | error = lpfc_sli_pci_mem_setup(phba); |
| 8535 | if (error) { |
| 8536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8537 | "1402 Failed to set up pci memory space.\n"); |
| 8538 | goto out_disable_pci_dev; |
| 8539 | } |
| 8540 | |
| 8541 | /* Set up phase-1 common device driver resources */ |
| 8542 | error = lpfc_setup_driver_resource_phase1(phba); |
| 8543 | if (error) { |
| 8544 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8545 | "1403 Failed to set up driver resource.\n"); |
| 8546 | goto out_unset_pci_mem_s3; |
| 8547 | } |
| 8548 | |
| 8549 | /* Set up SLI-3 specific device driver resources */ |
| 8550 | error = lpfc_sli_driver_resource_setup(phba); |
| 8551 | if (error) { |
| 8552 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8553 | "1404 Failed to set up driver resource.\n"); |
| 8554 | goto out_unset_pci_mem_s3; |
| 8555 | } |
| 8556 | |
| 8557 | /* Initialize and populate the iocb list per host */ |
| 8558 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 8559 | if (error) { |
| 8560 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8561 | "1405 Failed to initialize iocb list.\n"); |
| 8562 | goto out_unset_driver_resource_s3; |
| 8563 | } |
| 8564 | |
| 8565 | /* Set up common device driver resources */ |
| 8566 | error = lpfc_setup_driver_resource_phase2(phba); |
| 8567 | if (error) { |
| 8568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8569 | "1406 Failed to set up driver resource.\n"); |
| 8570 | goto out_free_iocb_list; |
| 8571 | } |
| 8572 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 8573 | /* Get the default values for Model Name and Description */ |
| 8574 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 8575 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8576 | /* Create SCSI host to the physical port */ |
| 8577 | error = lpfc_create_shost(phba); |
| 8578 | if (error) { |
| 8579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8580 | "1407 Failed to create scsi host.\n"); |
| 8581 | goto out_unset_driver_resource; |
| 8582 | } |
| 8583 | |
| 8584 | /* Configure sysfs attributes */ |
| 8585 | vport = phba->pport; |
| 8586 | error = lpfc_alloc_sysfs_attr(vport); |
| 8587 | if (error) { |
| 8588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8589 | "1476 Failed to allocate sysfs attr\n"); |
| 8590 | goto out_destroy_shost; |
| 8591 | } |
| 8592 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8593 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8594 | /* Now, trying to enable interrupt and bring up the device */ |
| 8595 | cfg_mode = phba->cfg_use_msi; |
| 8596 | while (true) { |
| 8597 | /* Put device to a known state before enabling interrupt */ |
| 8598 | lpfc_stop_port(phba); |
| 8599 | /* Configure and enable interrupt */ |
| 8600 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 8601 | if (intr_mode == LPFC_INTR_ERROR) { |
| 8602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8603 | "0431 Failed to enable interrupt.\n"); |
| 8604 | error = -ENODEV; |
| 8605 | goto out_free_sysfs_attr; |
| 8606 | } |
| 8607 | /* SLI-3 HBA setup */ |
| 8608 | if (lpfc_sli_hba_setup(phba)) { |
| 8609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8610 | "1477 Failed to set up hba\n"); |
| 8611 | error = -ENODEV; |
| 8612 | goto out_remove_device; |
| 8613 | } |
| 8614 | |
| 8615 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 8616 | msleep(50); |
| 8617 | /* Check active interrupts on message signaled interrupts */ |
| 8618 | if (intr_mode == 0 || |
| 8619 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 8620 | /* Log the current active interrupt mode */ |
| 8621 | phba->intr_mode = intr_mode; |
| 8622 | lpfc_log_intr_mode(phba, intr_mode); |
| 8623 | break; |
| 8624 | } else { |
| 8625 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8626 | "0447 Configure interrupt mode (%d) " |
| 8627 | "failed active interrupt test.\n", |
| 8628 | intr_mode); |
| 8629 | /* Disable the current interrupt mode */ |
| 8630 | lpfc_sli_disable_intr(phba); |
| 8631 | /* Try next level of interrupt mode */ |
| 8632 | cfg_mode = --intr_mode; |
| 8633 | } |
| 8634 | } |
| 8635 | |
| 8636 | /* Perform post initialization setup */ |
| 8637 | lpfc_post_init_setup(phba); |
| 8638 | |
| 8639 | /* Check if there are static vports to be created. */ |
| 8640 | lpfc_create_static_vport(phba); |
| 8641 | |
| 8642 | return 0; |
| 8643 | |
| 8644 | out_remove_device: |
| 8645 | lpfc_unset_hba(phba); |
| 8646 | out_free_sysfs_attr: |
| 8647 | lpfc_free_sysfs_attr(vport); |
| 8648 | out_destroy_shost: |
| 8649 | lpfc_destroy_shost(phba); |
| 8650 | out_unset_driver_resource: |
| 8651 | lpfc_unset_driver_resource_phase2(phba); |
| 8652 | out_free_iocb_list: |
| 8653 | lpfc_free_iocb_list(phba); |
| 8654 | out_unset_driver_resource_s3: |
| 8655 | lpfc_sli_driver_resource_unset(phba); |
| 8656 | out_unset_pci_mem_s3: |
| 8657 | lpfc_sli_pci_mem_unset(phba); |
| 8658 | out_disable_pci_dev: |
| 8659 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 8660 | if (shost) |
| 8661 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8662 | out_free_phba: |
| 8663 | lpfc_hba_free(phba); |
| 8664 | return error; |
| 8665 | } |
| 8666 | |
| 8667 | /** |
| 8668 | * 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] | 8669 | * @pdev: pointer to PCI device |
| 8670 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8671 | * This routine is to be called to disattach a device with SLI-3 interface |
| 8672 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 8673 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 8674 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8675 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8676 | static void __devexit |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8677 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8678 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8679 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8680 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8681 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8682 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8683 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8684 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 8685 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8686 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8687 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 8688 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8689 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8690 | lpfc_free_sysfs_attr(vport); |
| 8691 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8692 | /* Release all the vports against this physical port */ |
| 8693 | vports = lpfc_create_vport_work_array(phba); |
| 8694 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8695 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 8696 | fc_vport_terminate(vports[i]->fc_vport); |
| 8697 | lpfc_destroy_vport_work_array(phba, vports); |
| 8698 | |
| 8699 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8700 | fc_remove_host(shost); |
| 8701 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 8702 | lpfc_cleanup(vport); |
| 8703 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8704 | /* |
| 8705 | * Bring down the SLI Layer. This step disable all interrupts, |
| 8706 | * clears the rings, discards all mailbox commands, and resets |
| 8707 | * the HBA. |
| 8708 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8709 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 8710 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8711 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8712 | /* Stop kthread signal shall trigger work_done one more time */ |
| 8713 | kthread_stop(phba->worker_thread); |
| 8714 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8715 | lpfc_sli_brdrestart(phba); |
| 8716 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 8717 | kfree(phba->vpi_bmask); |
| 8718 | kfree(phba->vpi_ids); |
| 8719 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8720 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8721 | spin_lock_irq(&phba->hbalock); |
| 8722 | list_del_init(&vport->listentry); |
| 8723 | spin_unlock_irq(&phba->hbalock); |
| 8724 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8725 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8726 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8727 | /* Disable SR-IOV if enabled */ |
| 8728 | if (phba->cfg_sriov_nr_virtfn) |
| 8729 | pci_disable_sriov(pdev); |
| 8730 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8731 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8732 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8733 | |
| 8734 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8735 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8736 | |
| 8737 | /* |
| 8738 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 8739 | * corresponding pools here. |
| 8740 | */ |
| 8741 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8742 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8743 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8744 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 8745 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8746 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8747 | /* Free resources associated with SLI2 interface */ |
| 8748 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8749 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8750 | |
| 8751 | /* unmap adapter SLIM and Control Registers */ |
| 8752 | iounmap(phba->ctrl_regs_memmap_p); |
| 8753 | iounmap(phba->slim_memmap_p); |
| 8754 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8755 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8756 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 8757 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8758 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8759 | } |
| 8760 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8761 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8762 | * 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] | 8763 | * @pdev: pointer to PCI device |
| 8764 | * @msg: power management message |
| 8765 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8766 | * This routine is to be called from the kernel's PCI subsystem to support |
| 8767 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 8768 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 8769 | * worker thread for the device, turning off device's interrupt and DMA, |
| 8770 | * and bring the device offline. Note that as the driver implements the |
| 8771 | * minimum PM requirements to a power-aware driver's PM support for the |
| 8772 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 8773 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 8774 | * fully reinitialize its device during resume() method call, the driver will |
| 8775 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 8776 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8777 | * |
| 8778 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8779 | * 0 - driver suspended the device |
| 8780 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8781 | **/ |
| 8782 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8783 | 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] | 8784 | { |
| 8785 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8786 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 8787 | |
| 8788 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8789 | "0473 PCI device Power Management suspend.\n"); |
| 8790 | |
| 8791 | /* Bring down the device */ |
| 8792 | lpfc_offline_prep(phba); |
| 8793 | lpfc_offline(phba); |
| 8794 | kthread_stop(phba->worker_thread); |
| 8795 | |
| 8796 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8797 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8798 | |
| 8799 | /* Save device state to PCI config space */ |
| 8800 | pci_save_state(pdev); |
| 8801 | pci_set_power_state(pdev, PCI_D3hot); |
| 8802 | |
| 8803 | return 0; |
| 8804 | } |
| 8805 | |
| 8806 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8807 | * 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] | 8808 | * @pdev: pointer to PCI device |
| 8809 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8810 | * This routine is to be called from the kernel's PCI subsystem to support |
| 8811 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 8812 | * invokes this method, it restores the device's PCI config space state and |
| 8813 | * fully reinitializes the device and brings it online. Note that as the |
| 8814 | * driver implements the minimum PM requirements to a power-aware driver's |
| 8815 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 8816 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 8817 | * driver will fully reinitialize its device during resume() method call, |
| 8818 | * the device will be set to PCI_D0 directly in PCI config space before |
| 8819 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8820 | * |
| 8821 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8822 | * 0 - driver suspended the device |
| 8823 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8824 | **/ |
| 8825 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8826 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8827 | { |
| 8828 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8829 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8830 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8831 | int error; |
| 8832 | |
| 8833 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8834 | "0452 PCI device Power Management resume.\n"); |
| 8835 | |
| 8836 | /* Restore device state from PCI config space */ |
| 8837 | pci_set_power_state(pdev, PCI_D0); |
| 8838 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8839 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 8840 | /* |
| 8841 | * As the new kernel behavior of pci_restore_state() API call clears |
| 8842 | * device saved_state flag, need to save the restored state again. |
| 8843 | */ |
| 8844 | pci_save_state(pdev); |
| 8845 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8846 | if (pdev->is_busmaster) |
| 8847 | pci_set_master(pdev); |
| 8848 | |
| 8849 | /* Startup the kernel thread for this host adapter. */ |
| 8850 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 8851 | "lpfc_worker_%d", phba->brd_no); |
| 8852 | if (IS_ERR(phba->worker_thread)) { |
| 8853 | error = PTR_ERR(phba->worker_thread); |
| 8854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8855 | "0434 PM resume failed to start worker " |
| 8856 | "thread: error=x%x.\n", error); |
| 8857 | return error; |
| 8858 | } |
| 8859 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8860 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8861 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8862 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8863 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8864 | "0430 PM resume Failed to enable interrupt\n"); |
| 8865 | return -EIO; |
| 8866 | } else |
| 8867 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8868 | |
| 8869 | /* Restart HBA and bring it online */ |
| 8870 | lpfc_sli_brdrestart(phba); |
| 8871 | lpfc_online(phba); |
| 8872 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 8873 | /* Log the current active interrupt mode */ |
| 8874 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 8875 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 8876 | return 0; |
| 8877 | } |
| 8878 | |
| 8879 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8880 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 8881 | * @phba: pointer to lpfc hba data structure. |
| 8882 | * |
| 8883 | * 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] | 8884 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8885 | **/ |
| 8886 | static void |
| 8887 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 8888 | { |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8889 | struct lpfc_sli *psli = &phba->sli; |
| 8890 | struct lpfc_sli_ring *pring; |
| 8891 | |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8893 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8894 | |
| 8895 | /* |
| 8896 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 8897 | * and let the SCSI mid-layer to retry them to recover. |
| 8898 | */ |
| 8899 | pring = &psli->ring[psli->fcp_ring]; |
| 8900 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8901 | } |
| 8902 | |
| 8903 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8904 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 8905 | * @phba: pointer to lpfc hba data structure. |
| 8906 | * |
| 8907 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 8908 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 8909 | * pending I/Os. |
| 8910 | **/ |
| 8911 | static void |
| 8912 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 8913 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8915 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8916 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8917 | /* Block any management I/Os to the device */ |
| 8918 | lpfc_block_mgmt_io(phba); |
| 8919 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8920 | /* Block all SCSI devices' I/Os on the host */ |
| 8921 | lpfc_scsi_dev_block(phba); |
| 8922 | |
| 8923 | /* stop all timers */ |
| 8924 | lpfc_stop_hba_timers(phba); |
| 8925 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8926 | /* Disable interrupt and pci device */ |
| 8927 | lpfc_sli_disable_intr(phba); |
| 8928 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8929 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8930 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 8931 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | /** |
| 8935 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 8936 | * @phba: pointer to lpfc hba data structure. |
| 8937 | * |
| 8938 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 8939 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 8940 | * pending I/Os. |
| 8941 | **/ |
| 8942 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8943 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8944 | { |
| 8945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8946 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 8947 | /* Block all SCSI devices' I/Os on the host */ |
| 8948 | lpfc_scsi_dev_block(phba); |
| 8949 | |
| 8950 | /* stop all timers */ |
| 8951 | lpfc_stop_hba_timers(phba); |
| 8952 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8953 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 8954 | lpfc_sli_flush_fcp_rings(phba); |
| 8955 | } |
| 8956 | |
| 8957 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8958 | * 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] | 8959 | * @pdev: pointer to PCI device. |
| 8960 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8961 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8962 | * This routine is called from the PCI subsystem for I/O error handling to |
| 8963 | * device with SLI-3 interface spec. This function is called by the PCI |
| 8964 | * subsystem after a PCI bus error affecting this device has been detected. |
| 8965 | * When this function is invoked, it will need to stop all the I/Os and |
| 8966 | * interrupt(s) to the device. Once that is done, it will return |
| 8967 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 8968 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8969 | * |
| 8970 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8971 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8972 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 8973 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8974 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8975 | static pci_ers_result_t |
| 8976 | 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] | 8977 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 8978 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8979 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8980 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8981 | switch (state) { |
| 8982 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 8983 | /* Non-fatal error, prepare for recovery */ |
| 8984 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8985 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8986 | case pci_channel_io_frozen: |
| 8987 | /* Fatal error, prepare for slot reset */ |
| 8988 | lpfc_sli_prep_dev_for_reset(phba); |
| 8989 | return PCI_ERS_RESULT_NEED_RESET; |
| 8990 | case pci_channel_io_perm_failure: |
| 8991 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 8992 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8993 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 8994 | default: |
| 8995 | /* Unknown state, prepare and request slot reset */ |
| 8996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8997 | "0472 Unknown PCI error state: x%x\n", state); |
| 8998 | lpfc_sli_prep_dev_for_reset(phba); |
| 8999 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 9000 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9001 | } |
| 9002 | |
| 9003 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9004 | * 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] | 9005 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9006 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9007 | * This routine is called from the PCI subsystem for error handling to |
| 9008 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 9009 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 9010 | * During the PCI subsystem error recovery, after driver returns |
| 9011 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9012 | * recovery and then call this routine before calling the .resume method |
| 9013 | * to recover the device. This function will initialize the HBA device, |
| 9014 | * enable the interrupt, but it will just put the HBA to offline state |
| 9015 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9016 | * |
| 9017 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9018 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9019 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9020 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9021 | static pci_ers_result_t |
| 9022 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9023 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9024 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9025 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9026 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9027 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9028 | |
| 9029 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 9030 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9031 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9032 | "PCI device after reset.\n"); |
| 9033 | return PCI_ERS_RESULT_DISCONNECT; |
| 9034 | } |
| 9035 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9036 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9037 | |
| 9038 | /* |
| 9039 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9040 | * device saved_state flag, need to save the restored state again. |
| 9041 | */ |
| 9042 | pci_save_state(pdev); |
| 9043 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 9044 | if (pdev->is_busmaster) |
| 9045 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9046 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9047 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9048 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9049 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9050 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9051 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9052 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9053 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9055 | "0427 Cannot re-enable interrupt after " |
| 9056 | "slot reset.\n"); |
| 9057 | return PCI_ERS_RESULT_DISCONNECT; |
| 9058 | } else |
| 9059 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9060 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9061 | /* Take device offline, it will perform cleanup */ |
| 9062 | lpfc_offline_prep(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9063 | lpfc_offline(phba); |
| 9064 | lpfc_sli_brdrestart(phba); |
| 9065 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 9066 | /* Log the current active interrupt mode */ |
| 9067 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9068 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9069 | return PCI_ERS_RESULT_RECOVERED; |
| 9070 | } |
| 9071 | |
| 9072 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9073 | * 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] | 9074 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9075 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9076 | * This routine is called from the PCI subsystem for error handling to device |
| 9077 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 9078 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9079 | * error recovery. After this call, traffic can start to flow from this device |
| 9080 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9081 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9082 | static void |
| 9083 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9084 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 9085 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9086 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9087 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 9088 | /* 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] | 9089 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 9090 | |
| 9091 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9092 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9093 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9094 | } |
| 9095 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9096 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9097 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 9098 | * @phba: pointer to lpfc hba data structure. |
| 9099 | * |
| 9100 | * returns the number of ELS/CT IOCBs to reserve |
| 9101 | **/ |
| 9102 | int |
| 9103 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 9104 | { |
| 9105 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 9106 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9107 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 9108 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9109 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9110 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9111 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9112 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9113 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9114 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9115 | return 100; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9116 | else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9117 | return 150; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9118 | } else |
| 9119 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9120 | } |
| 9121 | |
| 9122 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9123 | * lpfc_write_firmware - attempt to write a firmware image to the port |
| 9124 | * @phba: pointer to lpfc hba data structure. |
| 9125 | * @fw: pointer to firmware image returned from request_firmware. |
| 9126 | * |
| 9127 | * returns the number of bytes written if write is successful. |
| 9128 | * returns a negative error value if there were errors. |
| 9129 | * returns 0 if firmware matches currently active firmware on port. |
| 9130 | **/ |
| 9131 | int |
| 9132 | lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw) |
| 9133 | { |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9134 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9135 | struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data; |
| 9136 | struct list_head dma_buffer_list; |
| 9137 | int i, rc = 0; |
| 9138 | struct lpfc_dmabuf *dmabuf, *next; |
| 9139 | uint32_t offset = 0, temp_offset = 0; |
| 9140 | |
| 9141 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9142 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
| 9143 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != |
| 9144 | LPFC_FILE_TYPE_GROUP) || |
| 9145 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || |
| 9146 | (be32_to_cpu(image->size) != fw->size)) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9147 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9148 | "3022 Invalid FW image found. " |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9149 | "Magic:%x Type:%x ID:%x\n", |
| 9150 | be32_to_cpu(image->magic_number), |
| 9151 | bf_get_be32(lpfc_grp_hdr_file_type, image), |
| 9152 | bf_get_be32(lpfc_grp_hdr_id, image)); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9153 | return -EINVAL; |
| 9154 | } |
| 9155 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9156 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9158 | "3023 Updating Firmware. Current Version:%s " |
| 9159 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9160 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9161 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 9162 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 9163 | GFP_KERNEL); |
| 9164 | if (!dmabuf) { |
| 9165 | rc = -ENOMEM; |
| 9166 | goto out; |
| 9167 | } |
| 9168 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 9169 | SLI4_PAGE_SIZE, |
| 9170 | &dmabuf->phys, |
| 9171 | GFP_KERNEL); |
| 9172 | if (!dmabuf->virt) { |
| 9173 | kfree(dmabuf); |
| 9174 | rc = -ENOMEM; |
| 9175 | goto out; |
| 9176 | } |
| 9177 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 9178 | } |
| 9179 | while (offset < fw->size) { |
| 9180 | temp_offset = offset; |
| 9181 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9182 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9183 | memcpy(dmabuf->virt, |
| 9184 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9185 | fw->size - temp_offset); |
| 9186 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9187 | break; |
| 9188 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9189 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 9190 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9191 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9192 | } |
| 9193 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 9194 | (fw->size - offset), &offset); |
| 9195 | if (rc) { |
| 9196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9197 | "3024 Firmware update failed. " |
| 9198 | "%d\n", rc); |
| 9199 | goto out; |
| 9200 | } |
| 9201 | } |
| 9202 | rc = offset; |
| 9203 | } |
| 9204 | out: |
| 9205 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 9206 | list_del(&dmabuf->list); |
| 9207 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 9208 | dmabuf->virt, dmabuf->phys); |
| 9209 | kfree(dmabuf); |
| 9210 | } |
| 9211 | return rc; |
| 9212 | } |
| 9213 | |
| 9214 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9215 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 9216 | * @pdev: pointer to PCI device |
| 9217 | * @pid: pointer to PCI device identifier |
| 9218 | * |
| 9219 | * This routine is called from the kernel's PCI subsystem to device with |
| 9220 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9221 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 9222 | * information of the device and driver to see if the driver state that it |
| 9223 | * can support this kind of device. If the match is successful, the driver |
| 9224 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 9225 | * it does all the initialization that it needs to do to handle the HBA |
| 9226 | * properly. |
| 9227 | * |
| 9228 | * Return code |
| 9229 | * 0 - driver can claim the device |
| 9230 | * negative value - driver can not claim the device |
| 9231 | **/ |
| 9232 | static int __devinit |
| 9233 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9234 | { |
| 9235 | struct lpfc_hba *phba; |
| 9236 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9237 | struct Scsi_Host *shost = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9238 | int error; |
| 9239 | uint32_t cfg_mode, intr_mode; |
| 9240 | int mcnt; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9241 | int adjusted_fcp_eq_count; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9242 | const struct firmware *fw; |
| 9243 | uint8_t file_name[16]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9244 | |
| 9245 | /* Allocate memory for HBA structure */ |
| 9246 | phba = lpfc_hba_alloc(pdev); |
| 9247 | if (!phba) |
| 9248 | return -ENOMEM; |
| 9249 | |
| 9250 | /* Perform generic PCI device enabling operation */ |
| 9251 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9252 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9253 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9254 | |
| 9255 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 9256 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 9257 | if (error) |
| 9258 | goto out_disable_pci_dev; |
| 9259 | |
| 9260 | /* Set up SLI-4 specific device PCI memory space */ |
| 9261 | error = lpfc_sli4_pci_mem_setup(phba); |
| 9262 | if (error) { |
| 9263 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9264 | "1410 Failed to set up pci memory space.\n"); |
| 9265 | goto out_disable_pci_dev; |
| 9266 | } |
| 9267 | |
| 9268 | /* Set up phase-1 common device driver resources */ |
| 9269 | error = lpfc_setup_driver_resource_phase1(phba); |
| 9270 | if (error) { |
| 9271 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9272 | "1411 Failed to set up driver resource.\n"); |
| 9273 | goto out_unset_pci_mem_s4; |
| 9274 | } |
| 9275 | |
| 9276 | /* Set up SLI-4 Specific device driver resources */ |
| 9277 | error = lpfc_sli4_driver_resource_setup(phba); |
| 9278 | if (error) { |
| 9279 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9280 | "1412 Failed to set up driver resource.\n"); |
| 9281 | goto out_unset_pci_mem_s4; |
| 9282 | } |
| 9283 | |
| 9284 | /* Initialize and populate the iocb list per host */ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9285 | |
| 9286 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9287 | "2821 initialize iocb list %d.\n", |
| 9288 | phba->cfg_iocb_cnt*1024); |
| 9289 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); |
| 9290 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9291 | if (error) { |
| 9292 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9293 | "1413 Failed to initialize iocb list.\n"); |
| 9294 | goto out_unset_driver_resource_s4; |
| 9295 | } |
| 9296 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9297 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 9298 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 9299 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9300 | /* Set up common device driver resources */ |
| 9301 | error = lpfc_setup_driver_resource_phase2(phba); |
| 9302 | if (error) { |
| 9303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9304 | "1414 Failed to set up driver resource.\n"); |
| 9305 | goto out_free_iocb_list; |
| 9306 | } |
| 9307 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 9308 | /* Get the default values for Model Name and Description */ |
| 9309 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9310 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9311 | /* Create SCSI host to the physical port */ |
| 9312 | error = lpfc_create_shost(phba); |
| 9313 | if (error) { |
| 9314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9315 | "1415 Failed to create scsi host.\n"); |
| 9316 | goto out_unset_driver_resource; |
| 9317 | } |
| 9318 | |
| 9319 | /* Configure sysfs attributes */ |
| 9320 | vport = phba->pport; |
| 9321 | error = lpfc_alloc_sysfs_attr(vport); |
| 9322 | if (error) { |
| 9323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9324 | "1416 Failed to allocate sysfs attr\n"); |
| 9325 | goto out_destroy_shost; |
| 9326 | } |
| 9327 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9328 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9329 | /* Now, trying to enable interrupt and bring up the device */ |
| 9330 | cfg_mode = phba->cfg_use_msi; |
| 9331 | while (true) { |
| 9332 | /* Put device to a known state before enabling interrupt */ |
| 9333 | lpfc_stop_port(phba); |
| 9334 | /* Configure and enable interrupt */ |
| 9335 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 9336 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9337 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9338 | "0426 Failed to enable interrupt.\n"); |
| 9339 | error = -ENODEV; |
| 9340 | goto out_free_sysfs_attr; |
| 9341 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9342 | /* Default to single EQ for non-MSI-X */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 9343 | if (phba->intr_type != MSIX) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9344 | adjusted_fcp_eq_count = 0; |
| 9345 | else if (phba->sli4_hba.msix_vec_nr < |
| 9346 | phba->cfg_fcp_eq_count + 1) |
| 9347 | adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; |
| 9348 | else |
| 9349 | adjusted_fcp_eq_count = phba->cfg_fcp_eq_count; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9350 | phba->cfg_fcp_eq_count = adjusted_fcp_eq_count; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9351 | /* Set up SLI-4 HBA */ |
| 9352 | if (lpfc_sli4_hba_setup(phba)) { |
| 9353 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9354 | "1421 Failed to set up hba\n"); |
| 9355 | error = -ENODEV; |
| 9356 | goto out_disable_intr; |
| 9357 | } |
| 9358 | |
| 9359 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
| 9360 | if (intr_mode != 0) |
| 9361 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, |
| 9362 | LPFC_ACT_INTR_CNT); |
| 9363 | |
| 9364 | /* Check active interrupts received only for MSI/MSI-X */ |
| 9365 | if (intr_mode == 0 || |
| 9366 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
| 9367 | /* Log the current active interrupt mode */ |
| 9368 | phba->intr_mode = intr_mode; |
| 9369 | lpfc_log_intr_mode(phba, intr_mode); |
| 9370 | break; |
| 9371 | } |
| 9372 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9373 | "0451 Configure interrupt mode (%d) " |
| 9374 | "failed active interrupt test.\n", |
| 9375 | intr_mode); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9376 | /* Unset the previous SLI-4 HBA setup. */ |
| 9377 | /* |
| 9378 | * TODO: Is this operation compatible with IF TYPE 2 |
| 9379 | * devices? All port state is deleted and cleared. |
| 9380 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9381 | lpfc_sli4_unset_hba(phba); |
| 9382 | /* Try next level of interrupt mode */ |
| 9383 | cfg_mode = --intr_mode; |
| 9384 | } |
| 9385 | |
| 9386 | /* Perform post initialization setup */ |
| 9387 | lpfc_post_init_setup(phba); |
| 9388 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 9389 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
| 9390 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 9391 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 9392 | snprintf(file_name, 16, "%s.grp", phba->ModelName); |
| 9393 | error = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 9394 | if (!error) { |
| 9395 | lpfc_write_firmware(phba, fw); |
| 9396 | release_firmware(fw); |
| 9397 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 9398 | } |
| 9399 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 9400 | /* Check if there are static vports to be created. */ |
| 9401 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9402 | return 0; |
| 9403 | |
| 9404 | out_disable_intr: |
| 9405 | lpfc_sli4_disable_intr(phba); |
| 9406 | out_free_sysfs_attr: |
| 9407 | lpfc_free_sysfs_attr(vport); |
| 9408 | out_destroy_shost: |
| 9409 | lpfc_destroy_shost(phba); |
| 9410 | out_unset_driver_resource: |
| 9411 | lpfc_unset_driver_resource_phase2(phba); |
| 9412 | out_free_iocb_list: |
| 9413 | lpfc_free_iocb_list(phba); |
| 9414 | out_unset_driver_resource_s4: |
| 9415 | lpfc_sli4_driver_resource_unset(phba); |
| 9416 | out_unset_pci_mem_s4: |
| 9417 | lpfc_sli4_pci_mem_unset(phba); |
| 9418 | out_disable_pci_dev: |
| 9419 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9420 | if (shost) |
| 9421 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9422 | out_free_phba: |
| 9423 | lpfc_hba_free(phba); |
| 9424 | return error; |
| 9425 | } |
| 9426 | |
| 9427 | /** |
| 9428 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 9429 | * @pdev: pointer to PCI device |
| 9430 | * |
| 9431 | * This routine is called from the kernel's PCI subsystem to device with |
| 9432 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 9433 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 9434 | * device to be removed from the PCI subsystem properly. |
| 9435 | **/ |
| 9436 | static void __devexit |
| 9437 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 9438 | { |
| 9439 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9440 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 9441 | struct lpfc_vport **vports; |
| 9442 | struct lpfc_hba *phba = vport->phba; |
| 9443 | int i; |
| 9444 | |
| 9445 | /* Mark the device unloading flag */ |
| 9446 | spin_lock_irq(&phba->hbalock); |
| 9447 | vport->load_flag |= FC_UNLOADING; |
| 9448 | spin_unlock_irq(&phba->hbalock); |
| 9449 | |
| 9450 | /* Free the HBA sysfs attributes */ |
| 9451 | lpfc_free_sysfs_attr(vport); |
| 9452 | |
| 9453 | /* Release all the vports against this physical port */ |
| 9454 | vports = lpfc_create_vport_work_array(phba); |
| 9455 | if (vports != NULL) |
| 9456 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
| 9457 | fc_vport_terminate(vports[i]->fc_vport); |
| 9458 | lpfc_destroy_vport_work_array(phba, vports); |
| 9459 | |
| 9460 | /* Remove FC host and then SCSI host with the physical port */ |
| 9461 | fc_remove_host(shost); |
| 9462 | scsi_remove_host(shost); |
| 9463 | |
| 9464 | /* Perform cleanup on the physical port */ |
| 9465 | lpfc_cleanup(vport); |
| 9466 | |
| 9467 | /* |
| 9468 | * Bring down the SLI Layer. This step disables all interrupts, |
| 9469 | * clears the rings, discards all mailbox commands, and resets |
| 9470 | * the HBA FCoE function. |
| 9471 | */ |
| 9472 | lpfc_debugfs_terminate(vport); |
| 9473 | lpfc_sli4_hba_unset(phba); |
| 9474 | |
| 9475 | spin_lock_irq(&phba->hbalock); |
| 9476 | list_del_init(&vport->listentry); |
| 9477 | spin_unlock_irq(&phba->hbalock); |
| 9478 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 9479 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9480 | * buffers are released to their corresponding pools here. |
| 9481 | */ |
| 9482 | lpfc_scsi_free(phba); |
| 9483 | lpfc_sli4_driver_resource_unset(phba); |
| 9484 | |
| 9485 | /* Unmap adapter Control and Doorbell registers */ |
| 9486 | lpfc_sli4_pci_mem_unset(phba); |
| 9487 | |
| 9488 | /* Release PCI resources and disable device's PCI function */ |
| 9489 | scsi_host_put(shost); |
| 9490 | lpfc_disable_pci_dev(phba); |
| 9491 | |
| 9492 | /* Finally, free the driver's device data structure */ |
| 9493 | lpfc_hba_free(phba); |
| 9494 | |
| 9495 | return; |
| 9496 | } |
| 9497 | |
| 9498 | /** |
| 9499 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 9500 | * @pdev: pointer to PCI device |
| 9501 | * @msg: power management message |
| 9502 | * |
| 9503 | * This routine is called from the kernel's PCI subsystem to support system |
| 9504 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 9505 | * this method, it quiesces the device by stopping the driver's worker |
| 9506 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 9507 | * the device offline. Note that as the driver implements the minimum PM |
| 9508 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 9509 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 9510 | * method call will be treated as SUSPEND and the driver will fully |
| 9511 | * reinitialize its device during resume() method call, the driver will set |
| 9512 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 9513 | * according to the @msg provided by the PM. |
| 9514 | * |
| 9515 | * Return code |
| 9516 | * 0 - driver suspended the device |
| 9517 | * Error otherwise |
| 9518 | **/ |
| 9519 | static int |
| 9520 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 9521 | { |
| 9522 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9523 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9524 | |
| 9525 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9526 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9527 | |
| 9528 | /* Bring down the device */ |
| 9529 | lpfc_offline_prep(phba); |
| 9530 | lpfc_offline(phba); |
| 9531 | kthread_stop(phba->worker_thread); |
| 9532 | |
| 9533 | /* Disable interrupt from device */ |
| 9534 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9535 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9536 | |
| 9537 | /* Save device state to PCI config space */ |
| 9538 | pci_save_state(pdev); |
| 9539 | pci_set_power_state(pdev, PCI_D3hot); |
| 9540 | |
| 9541 | return 0; |
| 9542 | } |
| 9543 | |
| 9544 | /** |
| 9545 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 9546 | * @pdev: pointer to PCI device |
| 9547 | * |
| 9548 | * This routine is called from the kernel's PCI subsystem to support system |
| 9549 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 9550 | * this method, it restores the device's PCI config space state and fully |
| 9551 | * reinitializes the device and brings it online. Note that as the driver |
| 9552 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 9553 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 9554 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 9555 | * will fully reinitialize its device during resume() method call, the device |
| 9556 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 9557 | * state. |
| 9558 | * |
| 9559 | * Return code |
| 9560 | * 0 - driver suspended the device |
| 9561 | * Error otherwise |
| 9562 | **/ |
| 9563 | static int |
| 9564 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 9565 | { |
| 9566 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9567 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9568 | uint32_t intr_mode; |
| 9569 | int error; |
| 9570 | |
| 9571 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9572 | "0292 PCI device Power Management resume.\n"); |
| 9573 | |
| 9574 | /* Restore device state from PCI config space */ |
| 9575 | pci_set_power_state(pdev, PCI_D0); |
| 9576 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9577 | |
| 9578 | /* |
| 9579 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9580 | * device saved_state flag, need to save the restored state again. |
| 9581 | */ |
| 9582 | pci_save_state(pdev); |
| 9583 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9584 | if (pdev->is_busmaster) |
| 9585 | pci_set_master(pdev); |
| 9586 | |
| 9587 | /* Startup the kernel thread for this host adapter. */ |
| 9588 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 9589 | "lpfc_worker_%d", phba->brd_no); |
| 9590 | if (IS_ERR(phba->worker_thread)) { |
| 9591 | error = PTR_ERR(phba->worker_thread); |
| 9592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9593 | "0293 PM resume failed to start worker " |
| 9594 | "thread: error=x%x.\n", error); |
| 9595 | return error; |
| 9596 | } |
| 9597 | |
| 9598 | /* Configure and enable interrupt */ |
| 9599 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9600 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9602 | "0294 PM resume Failed to enable interrupt\n"); |
| 9603 | return -EIO; |
| 9604 | } else |
| 9605 | phba->intr_mode = intr_mode; |
| 9606 | |
| 9607 | /* Restart HBA and bring it online */ |
| 9608 | lpfc_sli_brdrestart(phba); |
| 9609 | lpfc_online(phba); |
| 9610 | |
| 9611 | /* Log the current active interrupt mode */ |
| 9612 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9613 | |
| 9614 | return 0; |
| 9615 | } |
| 9616 | |
| 9617 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9618 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 9619 | * @phba: pointer to lpfc hba data structure. |
| 9620 | * |
| 9621 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 9622 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 9623 | **/ |
| 9624 | static void |
| 9625 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 9626 | { |
| 9627 | struct lpfc_sli *psli = &phba->sli; |
| 9628 | struct lpfc_sli_ring *pring; |
| 9629 | |
| 9630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9631 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 9632 | /* |
| 9633 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 9634 | * and let the SCSI mid-layer to retry them to recover. |
| 9635 | */ |
| 9636 | pring = &psli->ring[psli->fcp_ring]; |
| 9637 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 9638 | } |
| 9639 | |
| 9640 | /** |
| 9641 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 9642 | * @phba: pointer to lpfc hba data structure. |
| 9643 | * |
| 9644 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 9645 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 9646 | * pending I/Os. |
| 9647 | **/ |
| 9648 | static void |
| 9649 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 9650 | { |
| 9651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9652 | "2826 PCI channel disable preparing for reset\n"); |
| 9653 | |
| 9654 | /* Block any management I/Os to the device */ |
| 9655 | lpfc_block_mgmt_io(phba); |
| 9656 | |
| 9657 | /* Block all SCSI devices' I/Os on the host */ |
| 9658 | lpfc_scsi_dev_block(phba); |
| 9659 | |
| 9660 | /* stop all timers */ |
| 9661 | lpfc_stop_hba_timers(phba); |
| 9662 | |
| 9663 | /* Disable interrupt and pci device */ |
| 9664 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9665 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9666 | pci_disable_device(phba->pcidev); |
| 9667 | |
| 9668 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 9669 | lpfc_sli_flush_fcp_rings(phba); |
| 9670 | } |
| 9671 | |
| 9672 | /** |
| 9673 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 9674 | * @phba: pointer to lpfc hba data structure. |
| 9675 | * |
| 9676 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 9677 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 9678 | * pending I/Os. |
| 9679 | **/ |
| 9680 | static void |
| 9681 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 9682 | { |
| 9683 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9684 | "2827 PCI channel permanent disable for failure\n"); |
| 9685 | |
| 9686 | /* Block all SCSI devices' I/Os on the host */ |
| 9687 | lpfc_scsi_dev_block(phba); |
| 9688 | |
| 9689 | /* stop all timers */ |
| 9690 | lpfc_stop_hba_timers(phba); |
| 9691 | |
| 9692 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 9693 | lpfc_sli_flush_fcp_rings(phba); |
| 9694 | } |
| 9695 | |
| 9696 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9697 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 9698 | * @pdev: pointer to PCI device. |
| 9699 | * @state: the current PCI connection state. |
| 9700 | * |
| 9701 | * This routine is called from the PCI subsystem for error handling to device |
| 9702 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 9703 | * after a PCI bus error affecting this device has been detected. When this |
| 9704 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 9705 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 9706 | * for the PCI subsystem to perform proper recovery as desired. |
| 9707 | * |
| 9708 | * Return codes |
| 9709 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9710 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9711 | **/ |
| 9712 | static pci_ers_result_t |
| 9713 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 9714 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9715 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9716 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9717 | |
| 9718 | switch (state) { |
| 9719 | case pci_channel_io_normal: |
| 9720 | /* Non-fatal error, prepare for recovery */ |
| 9721 | lpfc_sli4_prep_dev_for_recover(phba); |
| 9722 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9723 | case pci_channel_io_frozen: |
| 9724 | /* Fatal error, prepare for slot reset */ |
| 9725 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9726 | return PCI_ERS_RESULT_NEED_RESET; |
| 9727 | case pci_channel_io_perm_failure: |
| 9728 | /* Permanent failure, prepare for device down */ |
| 9729 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 9730 | return PCI_ERS_RESULT_DISCONNECT; |
| 9731 | default: |
| 9732 | /* Unknown state, prepare and request slot reset */ |
| 9733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9734 | "2825 Unknown PCI error state: x%x\n", state); |
| 9735 | lpfc_sli4_prep_dev_for_reset(phba); |
| 9736 | return PCI_ERS_RESULT_NEED_RESET; |
| 9737 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9738 | } |
| 9739 | |
| 9740 | /** |
| 9741 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 9742 | * @pdev: pointer to PCI device. |
| 9743 | * |
| 9744 | * This routine is called from the PCI subsystem for error handling to device |
| 9745 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 9746 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 9747 | * PCI subsystem error recovery, after the driver returns |
| 9748 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 9749 | * recovery and then call this routine before calling the .resume method to |
| 9750 | * recover the device. This function will initialize the HBA device, enable |
| 9751 | * the interrupt, but it will just put the HBA to offline state without |
| 9752 | * passing any I/O traffic. |
| 9753 | * |
| 9754 | * Return codes |
| 9755 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 9756 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9757 | */ |
| 9758 | static pci_ers_result_t |
| 9759 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 9760 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9761 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9762 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9763 | struct lpfc_sli *psli = &phba->sli; |
| 9764 | uint32_t intr_mode; |
| 9765 | |
| 9766 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 9767 | if (pci_enable_device_mem(pdev)) { |
| 9768 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 9769 | "PCI device after reset.\n"); |
| 9770 | return PCI_ERS_RESULT_DISCONNECT; |
| 9771 | } |
| 9772 | |
| 9773 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 9774 | |
| 9775 | /* |
| 9776 | * As the new kernel behavior of pci_restore_state() API call clears |
| 9777 | * device saved_state flag, need to save the restored state again. |
| 9778 | */ |
| 9779 | pci_save_state(pdev); |
| 9780 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9781 | if (pdev->is_busmaster) |
| 9782 | pci_set_master(pdev); |
| 9783 | |
| 9784 | spin_lock_irq(&phba->hbalock); |
| 9785 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 9786 | spin_unlock_irq(&phba->hbalock); |
| 9787 | |
| 9788 | /* Configure and enable interrupt */ |
| 9789 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 9790 | if (intr_mode == LPFC_INTR_ERROR) { |
| 9791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9792 | "2824 Cannot re-enable interrupt after " |
| 9793 | "slot reset.\n"); |
| 9794 | return PCI_ERS_RESULT_DISCONNECT; |
| 9795 | } else |
| 9796 | phba->intr_mode = intr_mode; |
| 9797 | |
| 9798 | /* Log the current active interrupt mode */ |
| 9799 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 9800 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9801 | return PCI_ERS_RESULT_RECOVERED; |
| 9802 | } |
| 9803 | |
| 9804 | /** |
| 9805 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 9806 | * @pdev: pointer to PCI device |
| 9807 | * |
| 9808 | * This routine is called from the PCI subsystem for error handling to device |
| 9809 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 9810 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 9811 | * error recovery. After this call, traffic can start to flow from this device |
| 9812 | * again. |
| 9813 | **/ |
| 9814 | static void |
| 9815 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 9816 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9817 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9818 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9819 | |
| 9820 | /* |
| 9821 | * In case of slot reset, as function reset is performed through |
| 9822 | * mailbox command which needs DMA to be enabled, this operation |
| 9823 | * has to be moved to the io resume phase. Taking device offline |
| 9824 | * will perform the necessary cleanup. |
| 9825 | */ |
| 9826 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 9827 | /* Perform device reset */ |
| 9828 | lpfc_offline_prep(phba); |
| 9829 | lpfc_offline(phba); |
| 9830 | lpfc_sli_brdrestart(phba); |
| 9831 | /* Bring the device back online */ |
| 9832 | lpfc_online(phba); |
| 9833 | } |
| 9834 | |
| 9835 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 9836 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 9837 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9838 | } |
| 9839 | |
| 9840 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9841 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 9842 | * @pdev: pointer to PCI device |
| 9843 | * @pid: pointer to PCI device identifier |
| 9844 | * |
| 9845 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 9846 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 9847 | * at PCI device-specific information of the device and driver to see if the |
| 9848 | * driver state that it can support this kind of device. If the match is |
| 9849 | * successful, the driver core invokes this routine. This routine dispatches |
| 9850 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 9851 | * do all the initialization that it needs to do to handle the HBA device |
| 9852 | * properly. |
| 9853 | * |
| 9854 | * Return code |
| 9855 | * 0 - driver can claim the device |
| 9856 | * negative value - driver can not claim the device |
| 9857 | **/ |
| 9858 | static int __devinit |
| 9859 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 9860 | { |
| 9861 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9862 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9863 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9864 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9865 | return -ENODEV; |
| 9866 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9867 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9868 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9869 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9870 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9871 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 9872 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9873 | return rc; |
| 9874 | } |
| 9875 | |
| 9876 | /** |
| 9877 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 9878 | * @pdev: pointer to PCI device |
| 9879 | * |
| 9880 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 9881 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 9882 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 9883 | * remove routine, which will perform all the necessary cleanup for the |
| 9884 | * device to be removed from the PCI subsystem properly. |
| 9885 | **/ |
| 9886 | static void __devexit |
| 9887 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 9888 | { |
| 9889 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9890 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9891 | |
| 9892 | switch (phba->pci_dev_grp) { |
| 9893 | case LPFC_PCI_DEV_LP: |
| 9894 | lpfc_pci_remove_one_s3(pdev); |
| 9895 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9896 | case LPFC_PCI_DEV_OC: |
| 9897 | lpfc_pci_remove_one_s4(pdev); |
| 9898 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9899 | default: |
| 9900 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9901 | "1424 Invalid PCI device group: 0x%x\n", |
| 9902 | phba->pci_dev_grp); |
| 9903 | break; |
| 9904 | } |
| 9905 | return; |
| 9906 | } |
| 9907 | |
| 9908 | /** |
| 9909 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 9910 | * @pdev: pointer to PCI device |
| 9911 | * @msg: power management message |
| 9912 | * |
| 9913 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 9914 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 9915 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 9916 | * suspend the device. |
| 9917 | * |
| 9918 | * Return code |
| 9919 | * 0 - driver suspended the device |
| 9920 | * Error otherwise |
| 9921 | **/ |
| 9922 | static int |
| 9923 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 9924 | { |
| 9925 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9926 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9927 | int rc = -ENODEV; |
| 9928 | |
| 9929 | switch (phba->pci_dev_grp) { |
| 9930 | case LPFC_PCI_DEV_LP: |
| 9931 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 9932 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9933 | case LPFC_PCI_DEV_OC: |
| 9934 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 9935 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9936 | default: |
| 9937 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9938 | "1425 Invalid PCI device group: 0x%x\n", |
| 9939 | phba->pci_dev_grp); |
| 9940 | break; |
| 9941 | } |
| 9942 | return rc; |
| 9943 | } |
| 9944 | |
| 9945 | /** |
| 9946 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 9947 | * @pdev: pointer to PCI device |
| 9948 | * |
| 9949 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 9950 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 9951 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 9952 | * resume the device. |
| 9953 | * |
| 9954 | * Return code |
| 9955 | * 0 - driver suspended the device |
| 9956 | * Error otherwise |
| 9957 | **/ |
| 9958 | static int |
| 9959 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 9960 | { |
| 9961 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 9962 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 9963 | int rc = -ENODEV; |
| 9964 | |
| 9965 | switch (phba->pci_dev_grp) { |
| 9966 | case LPFC_PCI_DEV_LP: |
| 9967 | rc = lpfc_pci_resume_one_s3(pdev); |
| 9968 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9969 | case LPFC_PCI_DEV_OC: |
| 9970 | rc = lpfc_pci_resume_one_s4(pdev); |
| 9971 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9972 | default: |
| 9973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9974 | "1426 Invalid PCI device group: 0x%x\n", |
| 9975 | phba->pci_dev_grp); |
| 9976 | break; |
| 9977 | } |
| 9978 | return rc; |
| 9979 | } |
| 9980 | |
| 9981 | /** |
| 9982 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 9983 | * @pdev: pointer to PCI device. |
| 9984 | * @state: the current PCI connection state. |
| 9985 | * |
| 9986 | * This routine is registered to the PCI subsystem for error handling. This |
| 9987 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 9988 | * this device has been detected. When this routine is invoked, it dispatches |
| 9989 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 9990 | * routine, which will perform the proper error detected operation. |
| 9991 | * |
| 9992 | * Return codes |
| 9993 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 9994 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 9995 | **/ |
| 9996 | static pci_ers_result_t |
| 9997 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 9998 | { |
| 9999 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10000 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10001 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10002 | |
| 10003 | switch (phba->pci_dev_grp) { |
| 10004 | case LPFC_PCI_DEV_LP: |
| 10005 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 10006 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10007 | case LPFC_PCI_DEV_OC: |
| 10008 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 10009 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10010 | default: |
| 10011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10012 | "1427 Invalid PCI device group: 0x%x\n", |
| 10013 | phba->pci_dev_grp); |
| 10014 | break; |
| 10015 | } |
| 10016 | return rc; |
| 10017 | } |
| 10018 | |
| 10019 | /** |
| 10020 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 10021 | * @pdev: pointer to PCI device. |
| 10022 | * |
| 10023 | * This routine is registered to the PCI subsystem for error handling. This |
| 10024 | * function is called after PCI bus has been reset to restart the PCI card |
| 10025 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 10026 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 10027 | * routine, which will perform the proper device reset. |
| 10028 | * |
| 10029 | * Return codes |
| 10030 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 10031 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 10032 | **/ |
| 10033 | static pci_ers_result_t |
| 10034 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 10035 | { |
| 10036 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10037 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10038 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 10039 | |
| 10040 | switch (phba->pci_dev_grp) { |
| 10041 | case LPFC_PCI_DEV_LP: |
| 10042 | rc = lpfc_io_slot_reset_s3(pdev); |
| 10043 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10044 | case LPFC_PCI_DEV_OC: |
| 10045 | rc = lpfc_io_slot_reset_s4(pdev); |
| 10046 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10047 | default: |
| 10048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10049 | "1428 Invalid PCI device group: 0x%x\n", |
| 10050 | phba->pci_dev_grp); |
| 10051 | break; |
| 10052 | } |
| 10053 | return rc; |
| 10054 | } |
| 10055 | |
| 10056 | /** |
| 10057 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 10058 | * @pdev: pointer to PCI device |
| 10059 | * |
| 10060 | * This routine is registered to the PCI subsystem for error handling. It |
| 10061 | * is called when kernel error recovery tells the lpfc driver that it is |
| 10062 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 10063 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 10064 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 10065 | **/ |
| 10066 | static void |
| 10067 | lpfc_io_resume(struct pci_dev *pdev) |
| 10068 | { |
| 10069 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10070 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10071 | |
| 10072 | switch (phba->pci_dev_grp) { |
| 10073 | case LPFC_PCI_DEV_LP: |
| 10074 | lpfc_io_resume_s3(pdev); |
| 10075 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10076 | case LPFC_PCI_DEV_OC: |
| 10077 | lpfc_io_resume_s4(pdev); |
| 10078 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10079 | default: |
| 10080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10081 | "1429 Invalid PCI device group: 0x%x\n", |
| 10082 | phba->pci_dev_grp); |
| 10083 | break; |
| 10084 | } |
| 10085 | return; |
| 10086 | } |
| 10087 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10088 | /** |
| 10089 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace |
| 10090 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10091 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10092 | * |
| 10093 | * This routine puts a reference count on the lpfc module whenever the |
| 10094 | * character device is opened |
| 10095 | **/ |
| 10096 | static int |
| 10097 | lpfc_mgmt_open(struct inode *inode, struct file *filep) |
| 10098 | { |
| 10099 | try_module_get(THIS_MODULE); |
| 10100 | return 0; |
| 10101 | } |
| 10102 | |
| 10103 | /** |
| 10104 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace |
| 10105 | * @inode: pointer to the inode representing the lpfcmgmt device |
| 10106 | * @filep: pointer to the file representing the open lpfcmgmt device |
| 10107 | * |
| 10108 | * This routine removes a reference count from the lpfc module when the |
| 10109 | * character device is closed |
| 10110 | **/ |
| 10111 | static int |
| 10112 | lpfc_mgmt_release(struct inode *inode, struct file *filep) |
| 10113 | { |
| 10114 | module_put(THIS_MODULE); |
| 10115 | return 0; |
| 10116 | } |
| 10117 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10118 | static struct pci_device_id lpfc_id_table[] = { |
| 10119 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 10120 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 10121 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 10122 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10123 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 10124 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10125 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 10126 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10127 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 10128 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10129 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 10130 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10131 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 10132 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10133 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 10134 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10135 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 10136 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10137 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 10138 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10139 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 10140 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10141 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 10142 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10143 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 10144 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10145 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 10146 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10147 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 10148 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10149 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 10150 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10151 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 10152 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10153 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 10154 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10155 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 10156 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10157 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 10158 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10159 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 10160 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10161 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 10162 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10163 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 10164 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10165 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 10166 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10167 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 10168 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10169 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 10170 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 10171 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 10172 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10173 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 10174 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 10175 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 10176 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10177 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 10178 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10179 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 10180 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10181 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 10182 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10183 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 10184 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10185 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 10186 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 10187 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 10188 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10189 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 10190 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10191 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 10192 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10193 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
| 10194 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 10195 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
| 10196 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10197 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10198 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 10199 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
| 10200 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 10201 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
| 10202 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10203 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, |
| 10204 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 10205 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
| 10206 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 10207 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, |
| 10208 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10209 | { 0 } |
| 10210 | }; |
| 10211 | |
| 10212 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 10213 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10214 | static struct pci_error_handlers lpfc_err_handler = { |
| 10215 | .error_detected = lpfc_io_error_detected, |
| 10216 | .slot_reset = lpfc_io_slot_reset, |
| 10217 | .resume = lpfc_io_resume, |
| 10218 | }; |
| 10219 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10220 | static struct pci_driver lpfc_driver = { |
| 10221 | .name = LPFC_DRIVER_NAME, |
| 10222 | .id_table = lpfc_id_table, |
| 10223 | .probe = lpfc_pci_probe_one, |
| 10224 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10225 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10226 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10227 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10228 | }; |
| 10229 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10230 | static const struct file_operations lpfc_mgmt_fop = { |
| 10231 | .open = lpfc_mgmt_open, |
| 10232 | .release = lpfc_mgmt_release, |
| 10233 | }; |
| 10234 | |
| 10235 | static struct miscdevice lpfc_mgmt_dev = { |
| 10236 | .minor = MISC_DYNAMIC_MINOR, |
| 10237 | .name = "lpfcmgmt", |
| 10238 | .fops = &lpfc_mgmt_fop, |
| 10239 | }; |
| 10240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10242 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10243 | * |
| 10244 | * This routine is to be invoked when the lpfc module is loaded into the |
| 10245 | * kernel. The special kernel macro module_init() is used to indicate the |
| 10246 | * role of this routine to the kernel as lpfc module entry point. |
| 10247 | * |
| 10248 | * Return codes |
| 10249 | * 0 - successful |
| 10250 | * -ENOMEM - FC attach transport failed |
| 10251 | * all others - failed |
| 10252 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10253 | static int __init |
| 10254 | lpfc_init(void) |
| 10255 | { |
| 10256 | int error = 0; |
| 10257 | |
| 10258 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10259 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10260 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10261 | error = misc_register(&lpfc_mgmt_dev); |
| 10262 | if (error) |
| 10263 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 10264 | "misc_register returned with status %d", error); |
| 10265 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10266 | if (lpfc_enable_npiv) { |
| 10267 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 10268 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 10269 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10270 | lpfc_transport_template = |
| 10271 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10272 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10273 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10274 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10275 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10276 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 10277 | if (lpfc_vport_transport_template == NULL) { |
| 10278 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10279 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10280 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10281 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10282 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10283 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10284 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10285 | if (lpfc_enable_npiv) |
| 10286 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10287 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10288 | |
| 10289 | return error; |
| 10290 | } |
| 10291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10293 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10294 | * |
| 10295 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 10296 | * The special kernel macro module_exit() is used to indicate the role of |
| 10297 | * this routine to the kernel as lpfc module exit point. |
| 10298 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10299 | static void __exit |
| 10300 | lpfc_exit(void) |
| 10301 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 10302 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10303 | pci_unregister_driver(&lpfc_driver); |
| 10304 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 10305 | if (lpfc_enable_npiv) |
| 10306 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10307 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10308 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 10309 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10310 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 10311 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 10312 | } |
| 10313 | |
| 10314 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10315 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 10316 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 10317 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 10318 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 10319 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10320 | } |
| 10321 | |
| 10322 | module_init(lpfc_init); |
| 10323 | module_exit(lpfc_exit); |
| 10324 | MODULE_LICENSE("GPL"); |
| 10325 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 10326 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 10327 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |